Просмотр исходного кода

src/validator/verify_txs(): verifying slot added

aggstam 3 лет назад
Родитель
Сommit
5677bb5966
1 измененных файлов с 31 добавлено и 3 удалено
  1. 31 3
      src/validator/validator.rs

+ 31 - 3
src/validator/validator.rs

@@ -157,6 +157,18 @@ impl Validator {
         Ok(state)
         Ok(state)
     }
     }
 
 
+    // ==========================
+    // State transition functions
+    // ==========================
+    // TODO TESTNET: Write down all cases below
+    // State transition checks should be happening in the following cases for a sync node:
+    // 1) When a finalized block is received
+    // 2) When a transaction is being broadcasted to us
+    // State transition checks should be happening in the following cases for a consensus participating node:
+    // 1) When a finalized block is received
+    // 2) When a transaction is being broadcasted to us
+    // ==========================
+
     /// Append to canonical state received finalized slot checkpoints from block sync task.
     /// Append to canonical state received finalized slot checkpoints from block sync task.
     // TODO: integrate this to receive_blocks, as slot checkpoints will be part of received block.
     // TODO: integrate this to receive_blocks, as slot checkpoints will be part of received block.
     pub async fn receive_slot_checkpoints(
     pub async fn receive_slot_checkpoints(
@@ -183,6 +195,7 @@ impl Validator {
         &self,
         &self,
         blockchain_overlay: BlockchainOverlayPtr,
         blockchain_overlay: BlockchainOverlayPtr,
         tx: &Transaction,
         tx: &Transaction,
+        time_keeper: &TimeKeeper,
         verifying_keys: &mut HashMap<[u8; 32], HashMap<String, VerifyingKey>>,
         verifying_keys: &mut HashMap<[u8; 32], HashMap<String, VerifyingKey>>,
     ) -> Result<()> {
     ) -> Result<()> {
         let tx_hash = tx.hash();
         let tx_hash = tx.hash();
@@ -209,7 +222,7 @@ impl Validator {
                 &wasm,
                 &wasm,
                 blockchain_overlay.clone(),
                 blockchain_overlay.clone(),
                 call.contract_id,
                 call.contract_id,
-                self.consensus.time_keeper.clone(),
+                time_keeper.clone(),
             )?;
             )?;
 
 
             debug!(target: "validator", "Executing \"metadata\" call");
             debug!(target: "validator", "Executing \"metadata\" call");
@@ -296,7 +309,12 @@ impl Validator {
     /// In case any of the transactions fail, they will be returned to the caller.
     /// In case any of the transactions fail, they will be returned to the caller.
     /// The function takes a boolean called `write` which tells it to actually write
     /// The function takes a boolean called `write` which tells it to actually write
     /// the state transitions to the database.
     /// the state transitions to the database.
-    pub async fn verify_transactions(&self, txs: &[Transaction], write: bool) -> Result<()> {
+    pub async fn verify_transactions(
+        &self,
+        txs: &[Transaction],
+        verifying_slot: u64,
+        write: bool,
+    ) -> Result<()> {
         debug!(target: "validator", "Verifying {} transactions", txs.len());
         debug!(target: "validator", "Verifying {} transactions", txs.len());
 
 
         debug!(target: "validator", "Instantiating BlockchainOverlay");
         debug!(target: "validator", "Instantiating BlockchainOverlay");
@@ -315,10 +333,20 @@ impl Validator {
             }
             }
         }
         }
 
 
+        // Generate a time keeper using transaction verifying slot
+        let time_keeper = TimeKeeper::new(
+            self.consensus.time_keeper.genesis_ts,
+            self.consensus.time_keeper.epoch_length,
+            self.consensus.time_keeper.slot_time,
+            verifying_slot,
+        );
+
         // Iterate over transactions and attempt to verify them
         // Iterate over transactions and attempt to verify them
         for tx in txs {
         for tx in txs {
             blockchain_overlay.lock().unwrap().checkpoint();
             blockchain_overlay.lock().unwrap().checkpoint();
-            if let Err(e) = self.verify_transaction(blockchain_overlay.clone(), tx, &mut vks).await
+            if let Err(e) = self
+                .verify_transaction(blockchain_overlay.clone(), tx, &time_keeper, &mut vks)
+                .await
             {
             {
                 warn!(target: "validator", "Transaction verification failed: {}", e);
                 warn!(target: "validator", "Transaction verification failed: {}", e);
                 erroneous_txs.push(tx.clone());
                 erroneous_txs.push(tx.clone());