From 47a743f292843794d035dcd9848d39b441125150 Mon Sep 17 00:00:00 2001 From: Mingwei Tian Date: Thu, 24 Oct 2024 20:14:51 -0700 Subject: [PATCH] Protocol config for voting round --- consensus/core/src/dag_state.rs | 7 +++++-- consensus/core/src/linearizer.rs | 4 +++- crates/sui-protocol-config/src/lib.rs | 11 +++++++---- ...sui_protocol_config__test__Mainnet_version_66.snap | 1 - ...sui_protocol_config__test__Mainnet_version_68.snap | 2 +- ...sui_protocol_config__test__Testnet_version_66.snap | 1 - ...sui_protocol_config__test__Testnet_version_68.snap | 2 +- .../sui_protocol_config__test__version_66.snap | 1 - .../sui_protocol_config__test__version_68.snap | 2 +- 9 files changed, 18 insertions(+), 13 deletions(-) diff --git a/consensus/core/src/dag_state.rs b/consensus/core/src/dag_state.rs index 9a3ee7cb9ef341..323d33f6f3fe81 100644 --- a/consensus/core/src/dag_state.rs +++ b/consensus/core/src/dag_state.rs @@ -373,9 +373,12 @@ impl DagState { voter_block: &VerifiedBlock, mut target: BlockRef, ) -> Vec { - const VOTING_ROUNDS: u32 = 5; let mut certified_blocks = vec![]; - while target.round >= voter_block.round().saturating_sub(VOTING_ROUNDS) { + while target.round + >= voter_block + .round() + .saturating_sub(self.context.protocol_config.consensus_voting_rounds()) + { let Some(target_block_info) = self.recent_blocks.get_mut(&target) else { // The target block has been GC'ed. break; diff --git a/consensus/core/src/linearizer.rs b/consensus/core/src/linearizer.rs index dba030d05271ed..ec87c2b41f453a 100644 --- a/consensus/core/src/linearizer.rs +++ b/consensus/core/src/linearizer.rs @@ -540,7 +540,9 @@ mod tests { let num_authorities = 4; let (mut context, _keys) = Context::new_for_test(num_authorities); - context.protocol_config.set_gc_depth_for_testing(gc_depth); + context + .protocol_config + .set_consensus_gc_depth_for_testing(gc_depth); let context = Arc::new(context); let dag_state = Arc::new(RwLock::new(DagState::new( context.clone(), diff --git a/crates/sui-protocol-config/src/lib.rs b/crates/sui-protocol-config/src/lib.rs index 5eb452094693a5..e0a6decda60039 100644 --- a/crates/sui-protocol-config/src/lib.rs +++ b/crates/sui-protocol-config/src/lib.rs @@ -1249,6 +1249,9 @@ pub struct ProtocolConfig { /// The maximum number of transactions included in a consensus block. consensus_max_num_transactions_in_block: Option, + /// The maximum number of rounds where transaction voting is allowed. + consensus_voting_rounds: Option, + /// The max accumulated txn execution cost per object in a Narwhal commit. Transactions /// in a checkpoint will be deferred once their touch shared objects hit this limit. /// This config is meant to be used when consensus protocol is Narwhal, where each @@ -2160,6 +2163,8 @@ impl ProtocolConfig { consensus_max_num_transactions_in_block: None, + consensus_voting_rounds: None, + max_accumulated_txn_cost_per_object_in_narwhal_commit: None, max_deferral_rounds_for_congestion_control: None, @@ -2902,6 +2907,8 @@ impl ProtocolConfig { if chain != Chain::Mainnet && chain != Chain::Testnet { cfg.feature_flags.uncompressed_g1_group_elements = true; } + + cfg.consensus_voting_rounds = Some(40); } // Use this template when making changes: // @@ -3064,10 +3071,6 @@ impl ProtocolConfig { pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) { self.feature_flags.consensus_round_prober = val; } - - pub fn set_gc_depth_for_testing(&mut self, val: u32) { - self.consensus_gc_depth = Some(val); - } } type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send; diff --git a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_66.snap b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_66.snap index 07a447b25d844a..d17db3bf8c45d7 100644 --- a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_66.snap +++ b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_66.snap @@ -326,4 +326,3 @@ max_soft_bundle_size: 5 bridge_should_try_to_finalize_committee: true max_accumulated_txn_cost_per_object_in_mysticeti_commit: 3 gas_budget_based_txn_cost_cap_factor: 400000 - diff --git a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_68.snap b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_68.snap index 7da67bf5679804..62f60d084505cf 100644 --- a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_68.snap +++ b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_68.snap @@ -324,6 +324,7 @@ random_beacon_dkg_version: 1 consensus_max_transaction_size_bytes: 262144 consensus_max_transactions_in_block_bytes: 524288 consensus_max_num_transactions_in_block: 512 +consensus_voting_rounds: 40 max_accumulated_txn_cost_per_object_in_narwhal_commit: 40 max_deferral_rounds_for_congestion_control: 10 min_checkpoint_interval_ms: 200 @@ -332,4 +333,3 @@ max_soft_bundle_size: 5 bridge_should_try_to_finalize_committee: true max_accumulated_txn_cost_per_object_in_mysticeti_commit: 3 gas_budget_based_txn_cost_cap_factor: 400000 - diff --git a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_66.snap b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_66.snap index 4d141e8b8de237..3f8d2032b0dcd7 100644 --- a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_66.snap +++ b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_66.snap @@ -327,4 +327,3 @@ max_soft_bundle_size: 5 bridge_should_try_to_finalize_committee: true max_accumulated_txn_cost_per_object_in_mysticeti_commit: 3 gas_budget_based_txn_cost_cap_factor: 400000 - diff --git a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_68.snap b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_68.snap index 7da67bf5679804..62f60d084505cf 100644 --- a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_68.snap +++ b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_68.snap @@ -324,6 +324,7 @@ random_beacon_dkg_version: 1 consensus_max_transaction_size_bytes: 262144 consensus_max_transactions_in_block_bytes: 524288 consensus_max_num_transactions_in_block: 512 +consensus_voting_rounds: 40 max_accumulated_txn_cost_per_object_in_narwhal_commit: 40 max_deferral_rounds_for_congestion_control: 10 min_checkpoint_interval_ms: 200 @@ -332,4 +333,3 @@ max_soft_bundle_size: 5 bridge_should_try_to_finalize_committee: true max_accumulated_txn_cost_per_object_in_mysticeti_commit: 3 gas_budget_based_txn_cost_cap_factor: 400000 - diff --git a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_66.snap b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_66.snap index 747c437d6bbee3..f805136ebebee4 100644 --- a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_66.snap +++ b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_66.snap @@ -337,4 +337,3 @@ max_soft_bundle_size: 5 bridge_should_try_to_finalize_committee: true max_accumulated_txn_cost_per_object_in_mysticeti_commit: 3 gas_budget_based_txn_cost_cap_factor: 400000 - diff --git a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_68.snap b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_68.snap index 957275ab7a23c4..e999cef1b43626 100644 --- a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_68.snap +++ b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_68.snap @@ -335,6 +335,7 @@ random_beacon_dkg_version: 1 consensus_max_transaction_size_bytes: 262144 consensus_max_transactions_in_block_bytes: 524288 consensus_max_num_transactions_in_block: 512 +consensus_voting_rounds: 40 max_accumulated_txn_cost_per_object_in_narwhal_commit: 40 max_deferral_rounds_for_congestion_control: 10 min_checkpoint_interval_ms: 200 @@ -343,4 +344,3 @@ max_soft_bundle_size: 5 bridge_should_try_to_finalize_committee: true max_accumulated_txn_cost_per_object_in_mysticeti_commit: 3 gas_budget_based_txn_cost_cap_factor: 400000 -