diff --git a/crates/iota-core/src/authority.rs b/crates/iota-core/src/authority.rs index 6a7d4c317c0..a0bf8f330f0 100644 --- a/crates/iota-core/src/authority.rs +++ b/crates/iota-core/src/authority.rs @@ -4356,19 +4356,11 @@ impl AuthorityState { /// has voted to upgrade to. If the proposed protocol version is not /// supported, None is returned. fn is_protocol_version_supported_v1( - current_protocol_version: ProtocolVersion, proposed_protocol_version: ProtocolVersion, - protocol_config: &ProtocolConfig, committee: &Committee, capabilities: Vec, mut buffer_stake_bps: u64, ) -> Option<(ProtocolVersion, Vec)> { - if proposed_protocol_version > current_protocol_version + 1 - && !protocol_config.advance_to_highest_supported_protocol_version() - { - return None; - } - if buffer_stake_bps > 10000 { warn!("clamping buffer_stake_bps to 10000"); buffer_stake_bps = 10000; @@ -4444,19 +4436,11 @@ impl AuthorityState { } fn is_protocol_version_supported_v2( - current_protocol_version: ProtocolVersion, proposed_protocol_version: ProtocolVersion, - protocol_config: &ProtocolConfig, committee: &Committee, capabilities: Vec, mut buffer_stake_bps: u64, ) -> Option<(ProtocolVersion, Vec)> { - if proposed_protocol_version > current_protocol_version + 1 - && !protocol_config.advance_to_highest_supported_protocol_version() - { - return None; - } - if buffer_stake_bps > 10000 { warn!("clamping buffer_stake_bps to 10000"); buffer_stake_bps = 10000; @@ -4538,7 +4522,6 @@ impl AuthorityState { /// returns the current protocol version and system packages. fn choose_protocol_version_and_system_packages_v1( current_protocol_version: ProtocolVersion, - protocol_config: &ProtocolConfig, committee: &Committee, capabilities: Vec, buffer_stake_bps: u64, @@ -4547,9 +4530,7 @@ impl AuthorityState { let mut system_packages = vec![]; while let Some((version, packages)) = Self::is_protocol_version_supported_v1( - current_protocol_version, next_protocol_version + 1, - protocol_config, committee, capabilities.clone(), buffer_stake_bps, @@ -4563,7 +4544,6 @@ impl AuthorityState { fn choose_protocol_version_and_system_packages_v2( current_protocol_version: ProtocolVersion, - protocol_config: &ProtocolConfig, committee: &Committee, capabilities: Vec, buffer_stake_bps: u64, @@ -4575,9 +4555,7 @@ impl AuthorityState { // incrementing the proposed protocol version by one until no further // upgrades are supported. while let Some((version, packages)) = Self::is_protocol_version_supported_v2( - current_protocol_version, next_protocol_version + 1, - protocol_config, committee, capabilities.clone(), buffer_stake_bps, @@ -4716,7 +4694,6 @@ impl AuthorityState { if epoch_store.protocol_config().authority_capabilities_v2() { Self::choose_protocol_version_and_system_packages_v2( epoch_store.protocol_version(), - epoch_store.protocol_config(), epoch_store.committee(), epoch_store .get_capabilities_v2() @@ -4726,7 +4703,6 @@ impl AuthorityState { } else { Self::choose_protocol_version_and_system_packages_v1( epoch_store.protocol_version(), - epoch_store.protocol_config(), epoch_store.committee(), epoch_store .get_capabilities_v1() diff --git a/crates/iota-core/src/unit_tests/authority_tests.rs b/crates/iota-core/src/unit_tests/authority_tests.rs index 6755e7ef763..a0ba25284db 100644 --- a/crates/iota-core/src/unit_tests/authority_tests.rs +++ b/crates/iota-core/src/unit_tests/authority_tests.rs @@ -4975,9 +4975,8 @@ async fn test_consensus_message_processed() { ); } -#[ignore = "https://github.com/iotaledger/iota/issues/2793"] -#[test] -fn test_choose_next_system_packages() { +#[sim_test] +async fn test_choose_next_system_packages() { telemetry_subscribers::init_for_testing(); let o1 = random_object_ref(); let o2 = random_object_ref(); @@ -5023,7 +5022,6 @@ fn test_choose_next_system_packages() { let committee = Committee::new_simple_test_committee().0; let v = &committee.voting_rights; let mut protocol_config = ProtocolConfig::get_for_max_version_UNSAFE(); - protocol_config.set_advance_to_highest_supported_protocol_version_for_testing(false); protocol_config.set_buffer_stake_for_protocol_upgrade_bps_for_testing(7500); // all validators agree on new system packages, but without a new protocol @@ -5039,7 +5037,6 @@ fn test_choose_next_system_packages() { (ver(1), vec![]), AuthorityState::choose_protocol_version_and_system_packages_v2( ProtocolVersion::MIN, - &protocol_config, &committee, capabilities, protocol_config.buffer_stake_for_protocol_upgrade_bps(), @@ -5058,7 +5055,6 @@ fn test_choose_next_system_packages() { (ver(1), vec![]), AuthorityState::choose_protocol_version_and_system_packages_v2( ProtocolVersion::MIN, - &protocol_config, &committee, capabilities.clone(), protocol_config.buffer_stake_for_protocol_upgrade_bps(), @@ -5072,7 +5068,6 @@ fn test_choose_next_system_packages() { (ver(2), sort(vec![o1, o2])), AuthorityState::choose_protocol_version_and_system_packages_v2( ProtocolVersion::MIN, - &protocol_config, &committee, capabilities, protocol_config.buffer_stake_for_protocol_upgrade_bps(), @@ -5091,7 +5086,6 @@ fn test_choose_next_system_packages() { (ver(1), vec![]), AuthorityState::choose_protocol_version_and_system_packages_v2( ProtocolVersion::MIN, - &protocol_config, &committee, capabilities, protocol_config.buffer_stake_for_protocol_upgrade_bps(), @@ -5110,7 +5104,6 @@ fn test_choose_next_system_packages() { (ver(2), sort(vec![o1, o2])), AuthorityState::choose_protocol_version_and_system_packages_v2( ProtocolVersion::MIN, - &protocol_config, &committee, capabilities, protocol_config.buffer_stake_for_protocol_upgrade_bps(), @@ -5129,27 +5122,24 @@ fn test_choose_next_system_packages() { (ver(1), vec![]), AuthorityState::choose_protocol_version_and_system_packages_v2( ProtocolVersion::MIN, - &protocol_config, &committee, capabilities, protocol_config.buffer_stake_for_protocol_upgrade_bps(), ) ); - // all validators support 3, but with this protocol config we cannot advance - // multiple versions at once. + // all validators support 3, so we advance by multiple versions at once. let capabilities = vec![ make_capabilities!(3, v[0].0, vec![o1, o2]), make_capabilities!(3, v[1].0, vec![o1, o2]), make_capabilities!(3, v[2].0, vec![o1, o2]), - make_capabilities!(3, v[3].0, vec![o1, o2]), + make_capabilities!(3, v[3].0, vec![o1, o3]), ]; assert_eq!( - (ver(2), sort(vec![o1, o2])), + (ver(3), sort(vec![o1, o2])), AuthorityState::choose_protocol_version_and_system_packages_v2( ProtocolVersion::MIN, - &protocol_config, &committee, capabilities, protocol_config.buffer_stake_for_protocol_upgrade_bps(), @@ -5168,28 +5158,6 @@ fn test_choose_next_system_packages() { (ver(1), vec![]), AuthorityState::choose_protocol_version_and_system_packages_v2( ProtocolVersion::MIN, - &protocol_config, - &committee, - capabilities, - protocol_config.buffer_stake_for_protocol_upgrade_bps(), - ) - ); - - protocol_config.set_advance_to_highest_supported_protocol_version_for_testing(true); - - // skip straight to version 3 - let capabilities = vec![ - make_capabilities!(3, v[0].0, vec![o1, o2]), - make_capabilities!(3, v[1].0, vec![o1, o2]), - make_capabilities!(3, v[2].0, vec![o1, o2]), - make_capabilities!(3, v[3].0, vec![o1, o3]), - ]; - - assert_eq!( - (ver(3), sort(vec![o1, o2])), - AuthorityState::choose_protocol_version_and_system_packages_v2( - ProtocolVersion::MIN, - &protocol_config, &committee, capabilities, protocol_config.buffer_stake_for_protocol_upgrade_bps(), @@ -5209,7 +5177,6 @@ fn test_choose_next_system_packages() { (ver(3), sort(vec![o1, o2])), AuthorityState::choose_protocol_version_and_system_packages_v2( ProtocolVersion::MIN, - &protocol_config, &committee, capabilities, protocol_config.buffer_stake_for_protocol_upgrade_bps(), @@ -5231,7 +5198,6 @@ fn test_choose_next_system_packages() { (ver(1), sort(vec![])), AuthorityState::choose_protocol_version_and_system_packages_v2( ProtocolVersion::MIN, - &protocol_config, &committee, capabilities, protocol_config.buffer_stake_for_protocol_upgrade_bps(), @@ -5253,7 +5219,6 @@ fn test_choose_next_system_packages() { (ver(1), sort(vec![])), AuthorityState::choose_protocol_version_and_system_packages_v2( ProtocolVersion::MIN, - &protocol_config, &committee, capabilities, protocol_config.buffer_stake_for_protocol_upgrade_bps(), diff --git a/crates/iota-protocol-config/src/lib.rs b/crates/iota-protocol-config/src/lib.rs index a74640446ff..00e2813baa2 100644 --- a/crates/iota-protocol-config/src/lib.rs +++ b/crates/iota-protocol-config/src/lib.rs @@ -37,10 +37,10 @@ impl ProtocolVersion { #[cfg(not(msim))] const MAX_ALLOWED: Self = Self::MAX; - // We create one additional "fake" version in simulator builds so that we can + // We create 4 additional "fake" versions in simulator builds so that we can // test upgrades. #[cfg(msim)] - pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1); + pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 4); pub fn new(v: u64) -> Self { Self(v) @@ -112,10 +112,6 @@ struct FeatureFlags { // Disables unnecessary invariant check in the Move VM when swapping the value out of a local #[serde(skip_serializing_if = "is_false")] disable_invariant_violation_check_in_swap_loc: bool, - // advance to highest supported protocol version at epoch change, instead of the next - // consecutive protocol version. - #[serde(skip_serializing_if = "is_false")] - advance_to_highest_supported_protocol_version: bool, // If true, checks no extra bytes in a compiled module #[serde(skip_serializing_if = "is_false")] no_extraneous_module_bytes: bool, @@ -970,11 +966,6 @@ impl ProtocolConfig { .disable_invariant_violation_check_in_swap_loc } - pub fn advance_to_highest_supported_protocol_version(&self) -> bool { - self.feature_flags - .advance_to_highest_supported_protocol_version - } - pub fn no_extraneous_module_bytes(&self) -> bool { self.feature_flags.no_extraneous_module_bytes } @@ -1624,8 +1615,6 @@ impl ProtocolConfig { cfg.feature_flags .disable_invariant_violation_check_in_swap_loc = true; cfg.feature_flags.no_extraneous_module_bytes = true; - cfg.feature_flags - .advance_to_highest_supported_protocol_version = true; cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice; cfg.feature_flags.hardened_otw_check = true; @@ -1679,8 +1668,11 @@ impl ProtocolConfig { cfg.feature_flags.authority_capabilities_v2 = true; } - // TODO: remove the never_loop attribute when the version 2 is added. + // Ignore this check for the fake versions for + // `test_choose_next_system_packages`. TODO: remove the never_loop + // attribute when the version 2 is added. #[allow(clippy::never_loop)] + #[cfg(not(msim))] for cur in 2..=version.0 { match cur { 1 => unreachable!(), @@ -1767,10 +1759,6 @@ impl ProtocolConfig { // `_for_testing`. Non-feature_flags should already have test setters defined // through macros. impl ProtocolConfig { - pub fn set_advance_to_highest_supported_protocol_version_for_testing(&mut self, val: bool) { - self.feature_flags - .advance_to_highest_supported_protocol_version = val - } pub fn set_zklogin_auth_for_testing(&mut self, val: bool) { self.feature_flags.zklogin_auth = val }