From a155d2977732f7af9faf6a51e64cffe9d27b507a Mon Sep 17 00:00:00 2001 From: Mingwei Tian Date: Thu, 31 Oct 2024 17:14:48 -0700 Subject: [PATCH] [fastpath] add voting rounds and support env var override --- consensus/core/src/linearizer.rs | 4 ++- crates/sui-open-rpc/spec/openrpc.json | 1 + crates/sui-protocol-config/src/lib.rs | 26 ++++++++++++++++--- ...ocol_config__test__Mainnet_version_68.snap | 2 +- ...ocol_config__test__Testnet_version_68.snap | 2 +- ...sui_protocol_config__test__version_68.snap | 2 +- sdk/graphql-transport/src/methods.ts | 1 + .../test/compatability.test.ts | 3 +++ 8 files changed, 33 insertions(+), 8 deletions(-) diff --git a/consensus/core/src/linearizer.rs b/consensus/core/src/linearizer.rs index dba030d05271e..ec87c2b41f453 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-open-rpc/spec/openrpc.json b/crates/sui-open-rpc/spec/openrpc.json index 26f66bbd1f1a9..6e66a3af40d05 100644 --- a/crates/sui-open-rpc/spec/openrpc.json +++ b/crates/sui-open-rpc/spec/openrpc.json @@ -1429,6 +1429,7 @@ "consensus_max_num_transactions_in_block": null, "consensus_max_transaction_size_bytes": null, "consensus_max_transactions_in_block_bytes": null, + "consensus_voting_rounds": null, "crypto_invalid_arguments_cost": { "u64": "100" }, diff --git a/crates/sui-protocol-config/src/lib.rs b/crates/sui-protocol-config/src/lib.rs index caccb8d70d662..0a37adc961e5d 100644 --- a/crates/sui-protocol-config/src/lib.rs +++ b/crates/sui-protocol-config/src/lib.rs @@ -1256,6 +1256,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, + /// DEPRECATED. Do not use. max_accumulated_txn_cost_per_object_in_narwhal_commit: Option, @@ -1653,6 +1656,9 @@ impl ProtocolConfig { } pub fn mysticeti_fastpath(&self) -> bool { + if let Some(enabled) = is_mysticeti_fpc_enabled_in_env() { + return enabled; + } self.feature_flags.mysticeti_fastpath } @@ -2173,6 +2179,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, @@ -2931,6 +2939,9 @@ impl ProtocolConfig { cfg.random_beacon_reduction_lower_bound = Some(500); cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true; + + // Sets number of rounds allowed for fastpath voting in consensus. + cfg.consensus_voting_rounds = Some(40); } // Use this template when making changes: // @@ -3094,10 +3105,6 @@ impl ProtocolConfig { self.feature_flags.consensus_round_prober = val; } - pub fn set_gc_depth_for_testing(&mut self, val: u32) { - self.consensus_gc_depth = Some(val); - } - pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) { self.feature_flags .disallow_new_modules_in_deps_only_packages = val; @@ -3192,6 +3199,17 @@ macro_rules! check_limit_by_meter { }}; } +pub fn is_mysticeti_fpc_enabled_in_env() -> Option { + if let Ok(v) = std::env::var("CONSENSUS") { + if v == "mysticeti_fpc" { + return Some(true); + } else if v == "mysticeti" { + return Some(false); + } + } + None +} + #[cfg(all(test, not(msim)))] mod test { use insta::assert_yaml_snapshot; 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 492aebef1a352..a3268d2b30bb1 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 @@ -325,6 +325,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 max_txn_cost_overage_per_object_in_commit: 18446744073709551615 @@ -336,4 +337,3 @@ max_accumulated_txn_cost_per_object_in_mysticeti_commit: 18500000 max_accumulated_randomness_txn_cost_per_object_in_mysticeti_commit: 3700000 gas_budget_based_txn_cost_cap_factor: 400000 gas_budget_based_txn_cost_absolute_cap_commit_count: 50 - 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 492aebef1a352..a3268d2b30bb1 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 @@ -325,6 +325,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 max_txn_cost_overage_per_object_in_commit: 18446744073709551615 @@ -336,4 +337,3 @@ max_accumulated_txn_cost_per_object_in_mysticeti_commit: 18500000 max_accumulated_randomness_txn_cost_per_object_in_mysticeti_commit: 3700000 gas_budget_based_txn_cost_cap_factor: 400000 gas_budget_based_txn_cost_absolute_cap_commit_count: 50 - 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 68e55955524b4..3c483c53acb10 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 @@ -336,6 +336,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 max_txn_cost_overage_per_object_in_commit: 18446744073709551615 @@ -347,4 +348,3 @@ max_accumulated_txn_cost_per_object_in_mysticeti_commit: 18500000 max_accumulated_randomness_txn_cost_per_object_in_mysticeti_commit: 3700000 gas_budget_based_txn_cost_cap_factor: 400000 gas_budget_based_txn_cost_absolute_cap_commit_count: 50 - diff --git a/sdk/graphql-transport/src/methods.ts b/sdk/graphql-transport/src/methods.ts index 982940aeaefe5..3f5c2404015ba 100644 --- a/sdk/graphql-transport/src/methods.ts +++ b/sdk/graphql-transport/src/methods.ts @@ -1363,6 +1363,7 @@ export const RPC_METHODS: { binary_friend_decls: 'u16', max_package_dependencies: 'u32', bridge_should_try_to_finalize_committee: 'bool', + consensus_voting_rounds: 'u32', }; for (const { key, value } of protocolConfig.configs) { diff --git a/sdk/graphql-transport/test/compatability.test.ts b/sdk/graphql-transport/test/compatability.test.ts index d8a0fbee58d81..e91456e11365e 100644 --- a/sdk/graphql-transport/test/compatability.test.ts +++ b/sdk/graphql-transport/test/compatability.test.ts @@ -729,6 +729,9 @@ describe('GraphQL SuiClient compatibility', () => { const rpc = await toolbox.client.getProtocolConfig(); const graphql = await graphQLClient!.getProtocolConfig(); + // If this check fails and the difference is due to types, + // the config field type may need to overridden if it is not u64, + // in sdk/graphql-transport/src/methods.ts getProtocolConfig(). expect(graphql).toEqual(rpc); });