diff --git a/bin/darkfid2/darkfid_config.toml b/bin/darkfid2/darkfid_config.toml index 0b50f86bfef3..a8d387dd73fd 100644 --- a/bin/darkfid2/darkfid_config.toml +++ b/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] diff --git a/bin/darkfid2/src/main.rs b/bin/darkfid2/src/main.rs index 0dc6361b71d0..74801da75e2b 100644 --- a/bin/darkfid2/src/main.rs +++ b/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>) -> 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>) -> Result<()> { genesis_block, genesis_txs_total, vec![], - blockchain_config.testing_mode, + blockchain_config.pos_testing_mode, ); // Initialize validator diff --git a/bin/darkfid2/src/tests/harness.rs b/bin/darkfid2/src/tests/harness.rs index 290eec5e8fa5..3e7899f11261 100644 --- a/bin/darkfid2/src/tests/harness.rs +++ b/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, - 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 diff --git a/bin/darkfid2/src/tests/mod.rs b/bin/darkfid2/src/tests/mod.rs index e950af29da58..8f094755f764 100644 --- a/bin/darkfid2/src/tests/mod.rs +++ b/bin/darkfid2/src/tests/mod.rs @@ -39,7 +39,7 @@ async fn sync_pos_blocks_real(ex: Arc>) -> 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, }; diff --git a/src/validator/consensus.rs b/src/validator/consensus.rs index ed2d0880af6a..0f7a4172f592 100644 --- a/src/validator/consensus.rs +++ b/src/validator/consensus.rs @@ -56,8 +56,8 @@ pub struct Consensus { pub forks: Vec, /// 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, - testing_mode: bool, + pos_testing_mode: bool, ) -> Result { 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 { + pub fn rank(&self, pos_testing_mode: bool) -> Result { // 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 diff --git a/src/validator/mod.rs b/src/validator/mod.rs index afa49898b318..24bf50eed1a4 100644 --- a/src/validator/mod.rs +++ b/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, - /// 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, - 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 { 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() diff --git a/src/validator/utils.rs b/src/validator/utils.rs index 8e0e79011185..4a3fd41f49d1 100644 --- a/src/validator/utils.rs +++ b/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 { // 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) } diff --git a/src/validator/verification.rs b/src/validator/verification.rs index ef9d5af5a519..399c2f20e290 100644 --- a/src/validator/verification.rs +++ b/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()