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

validator: renamed testing_mode to pos_testing_mode

aggstam 2 лет назад
Родитель
Сommit
4d3984a611

+ 6 - 6
bin/darkfid2/darkfid_config.toml

@@ -49,8 +49,8 @@ recipient = "5ZHfYpt4mpJcwBNxfEyxLzeFJUEeoePs5NQ5jVEgHrMf"
 # Skip syncing process and start node right away
 skip_sync = true
 
-# Enable testing mode for local testing
-testing_mode = true
+# Enable PoS testing mode for local testing
+pos_testing_mode = true
 
 ## Localnet sync P2P network settings
 [localnet.sync_net]
@@ -188,8 +188,8 @@ consensus = false
 # Skip syncing process and start node right away
 skip_sync = false
 
-# Enable testing mode for local testing
-testing_mode = false
+# Enable PoS testing mode for local testing
+pos_testing_mode = false
 
 ## Testnet sync P2P network settings
 [testnet.sync_net]
@@ -347,8 +347,8 @@ consensus = false
 # Skip syncing process and start node right away
 skip_sync = false
 
-# Enable testing mode for local testing
-testing_mode = false
+# Enable PoS testing mode for local testing
+pos_testing_mode = false
 
 ## Mainnet sync P2P network settings
 [mainnet.sync_net]

+ 5 - 5
bin/darkfid2/src/main.rs

@@ -162,8 +162,8 @@ pub struct BlockchainNetwork {
     pub skip_sync: bool,
 
     #[structopt(long)]
-    /// Enable testing mode for local testing
-    pub testing_mode: bool,
+    /// Enable PoS testing mode for local testing
+    pub pos_testing_mode: bool,
 
     /// Syncing network settings
     #[structopt(flatten)]
@@ -220,8 +220,8 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
         }
     };
 
-    if blockchain_config.testing_mode {
-        info!(target: "darkfid", "Node is configured to run in testing mode!");
+    if blockchain_config.pos_testing_mode {
+        info!(target: "darkfid", "Node is configured to run in PoS testing mode!");
     }
 
     // Parse the genesis block
@@ -255,7 +255,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
         genesis_block,
         genesis_txs_total,
         vec![],
-        blockchain_config.testing_mode,
+        blockchain_config.pos_testing_mode,
     );
 
     // Initialize validator

+ 2 - 2
bin/darkfid2/src/tests/harness.rs

@@ -46,7 +46,7 @@ pub struct HarnessConfig {
     pub pow_threads: usize,
     pub pow_target: usize,
     pub pow_fixed_difficulty: Option<BigUint>,
-    pub testing_node: bool,
+    pub pos_testing_mode: bool,
     pub alice_initial: u64,
     pub bob_initial: u64,
 }
@@ -92,7 +92,7 @@ impl Harness {
             genesis_block,
             genesis_txs_total,
             vec![],
-            config.testing_node,
+            config.pos_testing_mode,
         );
 
         // Generate validators using pregenerated vks

+ 1 - 1
bin/darkfid2/src/tests/mod.rs

@@ -39,7 +39,7 @@ async fn sync_pos_blocks_real(ex: Arc<Executor<'static>>) -> Result<()> {
         pow_threads,
         pow_target,
         pow_fixed_difficulty: pow_fixed_difficulty.clone(),
-        testing_node: true,
+        pos_testing_mode: true,
         alice_initial: 1000,
         bob_initial: 500,
     };

+ 14 - 10
src/validator/consensus.rs

@@ -56,8 +56,8 @@ pub struct Consensus {
     pub forks: Vec<Fork>,
     /// Canonical blockchain PoW module state
     pub module: PoWModule,
-    /// Flag to enable testing mode
-    pub testing_mode: bool,
+    /// Flag to enable PoS testing mode
+    pub pos_testing_mode: bool,
 }
 
 impl Consensus {
@@ -69,7 +69,7 @@ impl Consensus {
         pow_threads: usize,
         pow_target: usize,
         pow_fixed_difficulty: Option<BigUint>,
-        testing_mode: bool,
+        pos_testing_mode: bool,
     ) -> Result<Self> {
         let module =
             PoWModule::new(blockchain.clone(), pow_threads, pow_target, pow_fixed_difficulty)?;
@@ -81,7 +81,7 @@ impl Consensus {
             checked_finalization: 0,
             forks: vec![],
             module,
-            testing_mode,
+            pos_testing_mode,
         })
     }
 
@@ -214,7 +214,7 @@ impl Consensus {
         let (mut fork, index) = verify_proposal(self, proposal).await?;
 
         // Append proposal to the fork
-        fork.append_proposal(proposal.hash, self.testing_mode)?;
+        fork.append_proposal(proposal.hash, self.pos_testing_mode)?;
 
         // Update fork slots based on proposal version
         match proposal.block.header.version {
@@ -366,7 +366,7 @@ impl Consensus {
                 block,
                 previous,
                 expected_reward,
-                self.testing_mode,
+                self.pos_testing_mode,
             )
             .await
             .is_err()
@@ -486,9 +486,13 @@ impl Fork {
     }
 
     /// Auxiliary function to append a proposal and recalculate current fork rank
-    pub fn append_proposal(&mut self, proposal: blake3::Hash, testing_mode: bool) -> Result<()> {
+    pub fn append_proposal(
+        &mut self,
+        proposal: blake3::Hash,
+        pos_testing_mode: bool,
+    ) -> Result<()> {
         self.proposals.push(proposal);
-        self.rank = self.rank(testing_mode)?;
+        self.rank = self.rank(pos_testing_mode)?;
 
         Ok(())
     }
@@ -637,7 +641,7 @@ impl Fork {
     }
 
     /// Auxiliarry function to compute fork's rank, assuming all proposals are valid.
-    pub fn rank(&self, testing_mode: bool) -> Result<u64> {
+    pub fn rank(&self, pos_testing_mode: bool) -> Result<u64> {
         // If the fork is empty its rank is 0
         if self.proposals.is_empty() {
             return Ok(0)
@@ -659,7 +663,7 @@ impl Fork {
             } else {
                 proposal.clone()
             };
-            sum += block_rank(proposal, &previous_previous, testing_mode)?;
+            sum += block_rank(proposal, &previous_previous, pos_testing_mode)?;
         }
 
         // Use fork(proposals) length as a multiplier to compute the actual fork rank

+ 11 - 11
src/validator/mod.rs

@@ -85,8 +85,8 @@ pub struct ValidatorConfig {
     pub genesis_txs_total: u64,
     /// Whitelisted faucet pubkeys (testnet stuff)
     pub faucet_pubkeys: Vec<PublicKey>,
-    /// Flag to enable testing mode
-    pub testing_mode: bool,
+    /// Flag to enable PoS testing mode
+    pub pos_testing_mode: bool,
 }
 
 impl ValidatorConfig {
@@ -100,7 +100,7 @@ impl ValidatorConfig {
         genesis_block: BlockInfo,
         genesis_txs_total: u64,
         faucet_pubkeys: Vec<PublicKey>,
-        testing_mode: bool,
+        pos_testing_mode: bool,
     ) -> Self {
         Self {
             time_keeper,
@@ -111,7 +111,7 @@ impl ValidatorConfig {
             genesis_block,
             genesis_txs_total,
             faucet_pubkeys,
-            testing_mode,
+            pos_testing_mode,
         }
     }
 }
@@ -127,14 +127,14 @@ pub struct Validator {
     pub consensus: Consensus,
     /// Flag signalling node has finished initial sync
     pub synced: bool,
-    /// Flag to enable testing mode
-    pub testing_mode: bool,
+    /// Flag to enable PoS testing mode
+    pub pos_testing_mode: bool,
 }
 
 impl Validator {
     pub async fn new(db: &sled::Db, config: ValidatorConfig) -> Result<ValidatorPtr> {
         info!(target: "validator::new", "Initializing Validator");
-        let testing_mode = config.testing_mode;
+        let pos_testing_mode = config.pos_testing_mode;
 
         info!(target: "validator::new", "Initializing Blockchain");
         let blockchain = Blockchain::new(db)?;
@@ -168,12 +168,12 @@ impl Validator {
             config.pow_threads,
             config.pow_target,
             config.pow_fixed_difficulty,
-            testing_mode,
+            pos_testing_mode,
         )?;
 
         // Create the actual state
         let state =
-            Arc::new(RwLock::new(Self { blockchain, consensus, synced: false, testing_mode }));
+            Arc::new(RwLock::new(Self { blockchain, consensus, synced: false, pos_testing_mode }));
         info!(target: "validator::new", "Finished initializing validator");
 
         Ok(state)
@@ -388,7 +388,7 @@ impl Validator {
                 block,
                 previous,
                 expected_reward,
-                self.testing_mode,
+                self.pos_testing_mode,
             )
             .await
             .is_err()
@@ -590,7 +590,7 @@ impl Validator {
                 block,
                 previous,
                 expected_reward,
-                self.testing_mode,
+                self.pos_testing_mode,
             )
             .await
             .is_err()

+ 2 - 2
src/validator/utils.rs

@@ -107,7 +107,7 @@ pub fn deploy_native_contracts(
 pub fn block_rank(
     block: &BlockInfo,
     previous_previous: &BlockInfo,
-    testing_mode: bool,
+    pos_testing_mode: bool,
 ) -> Result<u64> {
     // Genesis block has rank 0
     if block.header.height == 0 {
@@ -120,7 +120,7 @@ pub fn block_rank(
     let nonce = u64::from_be_bytes(nonce);
 
     // First 2 blocks or testing ones have rank equal to their nonce
-    if block.header.height < 3 || testing_mode {
+    if block.header.height < 3 || pos_testing_mode {
         return Ok(nonce)
     }
 

+ 6 - 5
src/validator/verification.rs

@@ -125,7 +125,7 @@ pub async fn verify_block(
     block: &BlockInfo,
     previous: &BlockInfo,
     expected_reward: u64,
-    testing_mode: bool,
+    pos_testing_mode: bool,
 ) -> Result<()> {
     let block_hash = block.hash()?.to_string();
     debug!(target: "validator::verification::verify_block", "Validating block {}", block_hash);
@@ -158,8 +158,9 @@ pub async fn verify_block(
     // Since an overlay is used, original database is not affected.
     overlay.lock().unwrap().slots.insert(&[block.slots.last().unwrap().clone()])?;
 
-    // Verify proposal transaction if not in testing mode
-    if !testing_mode {
+    // Verify proposal transaction.
+    // For PoS blocks(version 2) verify if not in PoS testing mode.
+    if block.header.version != 2 || !pos_testing_mode {
         let tx = block.txs.last().unwrap();
         let public_key =
             verify_producer_transaction(overlay, time_keeper, tx, block.header.version).await?;
@@ -553,7 +554,7 @@ pub async fn verify_pow_proposal(
         &proposal.block,
         &previous,
         expected_reward,
-        consensus.testing_mode,
+        consensus.pos_testing_mode,
     )
     .await
     .is_err()
@@ -644,7 +645,7 @@ pub async fn verify_pos_proposal(
         &proposal.block,
         &previous,
         expected_reward,
-        consensus.testing_mode,
+        consensus.pos_testing_mode,
     )
     .await
     .is_err()