diff --git a/crates/iota-benchmark/tests/simtest.rs b/crates/iota-benchmark/tests/simtest.rs index 3785ce9f592..653432dfe11 100644 --- a/crates/iota-benchmark/tests/simtest.rs +++ b/crates/iota-benchmark/tests/simtest.rs @@ -111,7 +111,7 @@ mod test { ..Default::default() }) .with_submit_delay_step_override_millis(3000) - .with_state_accumulator_v2_enabled_callback(Arc::new(|idx| idx % 2 == 0)) + .with_state_accumulator_callback(Arc::new(|idx| idx % 2 == 0)) .build() .await .into(); diff --git a/crates/iota-config/src/node.rs b/crates/iota-config/src/node.rs index 0d652818528..9c14740f18f 100644 --- a/crates/iota-config/src/node.rs +++ b/crates/iota-config/src/node.rs @@ -236,11 +236,6 @@ pub struct NodeConfig { #[serde(default)] pub execution_cache: ExecutionCacheConfig, - // step 1 in removing the old state accumulator - #[serde(skip)] - #[serde(default = "bool_true")] - pub state_accumulator_v2: bool, - #[serde(default = "bool_true")] pub enable_validator_tx_finalizer: bool, } diff --git a/crates/iota-core/src/authority/authority_per_epoch_store.rs b/crates/iota-core/src/authority/authority_per_epoch_store.rs index 235d0c4b0f4..5f1ad2d68db 100644 --- a/crates/iota-core/src/authority/authority_per_epoch_store.rs +++ b/crates/iota-core/src/authority/authority_per_epoch_store.rs @@ -90,7 +90,7 @@ use super::{ use crate::{ authority::{ AuthorityMetrics, ResolverWrapper, - epoch_start_configuration::{EpochFlag, EpochStartConfiguration}, + epoch_start_configuration::EpochStartConfiguration, shared_object_version_manager::{ AssignedTxAndVersions, ConsensusSharedObjVerAssignment, SharedObjVerManager, }, @@ -976,15 +976,6 @@ impl AuthorityPerEpochStore { self.parent_path.clone() } - pub fn state_accumulator_v2_enabled(&self) -> bool { - let flag = match self.get_chain_identifier().chain() { - Chain::Unknown | Chain::Testnet => EpochFlag::StateAccumulatorV2EnabledTestnet, - Chain::Mainnet => EpochFlag::StateAccumulatorV2EnabledMainnet, - }; - - self.epoch_start_configuration.flags().contains(&flag) - } - /// Returns `&Arc` /// User can treat this `Arc` as `&EpochStartConfiguration`, or clone the /// Arc to pass as owned object @@ -1364,23 +1355,6 @@ impl AuthorityPerEpochStore { .map_err(Into::into) } - /// Returns future containing the state digest for the given epoch - /// once available. - /// TODO: remove once StateAccumulatorV1 is removed - pub async fn notify_read_checkpoint_state_digests( - &self, - checkpoints: Vec, - ) -> IotaResult> { - self.checkpoint_state_notify_read - .read(&checkpoints, |checkpoints| -> IotaResult<_> { - Ok(self - .tables()? - .state_hash_by_checkpoint - .multi_get(checkpoints)?) - }) - .await - } - pub async fn notify_read_running_root( &self, checkpoint: CheckpointSequenceNumber, diff --git a/crates/iota-core/src/authority/epoch_start_configuration.rs b/crates/iota-core/src/authority/epoch_start_configuration.rs index 251c6af9934..94771c361df 100644 --- a/crates/iota-core/src/authority/epoch_start_configuration.rs +++ b/crates/iota-core/src/authority/epoch_start_configuration.rs @@ -55,26 +55,20 @@ pub trait EpochStartConfigTrait { #[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] pub enum EpochFlag { WritebackCacheEnabled = 0, - - StateAccumulatorV2EnabledTestnet = 1, - StateAccumulatorV2EnabledMainnet = 2, } impl EpochFlag { pub fn default_flags_for_new_epoch(config: &NodeConfig) -> Vec { - Self::default_flags_impl(&config.execution_cache, config.state_accumulator_v2) + Self::default_flags_impl(&config.execution_cache) } /// For situations in which there is no config available (e.g. setting up a /// downloaded snapshot). pub fn default_for_no_config() -> Vec { - Self::default_flags_impl(&Default::default(), true) + Self::default_flags_impl(&Default::default()) } - fn default_flags_impl( - cache_config: &ExecutionCacheConfig, - enable_state_accumulator_v2: bool, - ) -> Vec { + fn default_flags_impl(cache_config: &ExecutionCacheConfig) -> Vec { let mut new_flags = vec![]; if matches!( @@ -84,11 +78,6 @@ impl EpochFlag { new_flags.push(EpochFlag::WritebackCacheEnabled); } - if enable_state_accumulator_v2 { - new_flags.push(EpochFlag::StateAccumulatorV2EnabledTestnet); - new_flags.push(EpochFlag::StateAccumulatorV2EnabledMainnet); - } - new_flags } } @@ -99,12 +88,6 @@ impl fmt::Display for EpochFlag { // is used as metric key match self { EpochFlag::WritebackCacheEnabled => write!(f, "WritebackCacheEnabled"), - EpochFlag::StateAccumulatorV2EnabledTestnet => { - write!(f, "StateAccumulatorV2EnabledTestnet") - } - EpochFlag::StateAccumulatorV2EnabledMainnet => { - write!(f, "StateAccumulatorV2EnabledMainnet") - } } } } diff --git a/crates/iota-core/src/state_accumulator.rs b/crates/iota-core/src/state_accumulator.rs index 3f862291682..3fa9aaad7c9 100644 --- a/crates/iota-core/src/state_accumulator.rs +++ b/crates/iota-core/src/state_accumulator.rs @@ -45,7 +45,6 @@ impl StateAccumulatorMetrics { pub enum StateAccumulator { V1(StateAccumulatorV1), - V2(StateAccumulatorV2), } pub struct StateAccumulatorV1 { @@ -53,11 +52,6 @@ pub struct StateAccumulatorV1 { metrics: Arc, } -pub struct StateAccumulatorV2 { - store: Arc, - metrics: Arc, -} - pub trait AccumulatorStore: ObjectStore + Send + Sync { fn get_root_state_accumulator_for_epoch( &self, @@ -166,11 +160,7 @@ impl StateAccumulator { epoch_store: &Arc, metrics: Arc, ) -> Self { - if epoch_store.state_accumulator_v2_enabled() { - StateAccumulator::V2(StateAccumulatorV2::new(store, metrics)) - } else { - StateAccumulator::V1(StateAccumulatorV1::new(store, metrics)) - } + StateAccumulator::V1(StateAccumulatorV1::new(store, metrics)) } pub fn new_for_tests( @@ -187,14 +177,12 @@ impl StateAccumulator { pub fn metrics(&self) -> Arc { match self { StateAccumulator::V1(impl_v1) => impl_v1.metrics.clone(), - StateAccumulator::V2(impl_v2) => impl_v2.metrics.clone(), } } pub fn set_inconsistent_state(&self, is_inconsistent_state: bool) { match self { StateAccumulator::V1(impl_v1) => &impl_v1.metrics, - StateAccumulator::V2(impl_v2) => &impl_v2.metrics, } .inconsistent_state .set(is_inconsistent_state as i64); @@ -232,12 +220,8 @@ impl StateAccumulator { checkpoint_acc: Option, ) -> IotaResult { match self { - StateAccumulator::V1(_) => { - // V1 does not have a running root accumulator - Ok(()) - } - StateAccumulator::V2(impl_v2) => { - impl_v2 + StateAccumulator::V1(impl_v1) => { + impl_v1 .accumulate_running_root(epoch_store, checkpoint_seq_num, checkpoint_acc) .await } @@ -251,12 +235,7 @@ impl StateAccumulator { ) -> IotaResult { match self { StateAccumulator::V1(impl_v1) => { - impl_v1 - .accumulate_epoch(epoch_store, last_checkpoint_of_epoch) - .await - } - StateAccumulator::V2(impl_v2) => { - impl_v2.accumulate_epoch(epoch_store, last_checkpoint_of_epoch) + impl_v1.accumulate_epoch(epoch_store, last_checkpoint_of_epoch) } } } @@ -266,9 +245,6 @@ impl StateAccumulator { StateAccumulator::V1(impl_v1) => Self::accumulate_live_object_set_impl( impl_v1.store.iter_cached_live_object_set_for_testing(), ), - StateAccumulator::V2(impl_v2) => Self::accumulate_live_object_set_impl( - impl_v2.store.iter_cached_live_object_set_for_testing(), - ), } } @@ -279,9 +255,6 @@ impl StateAccumulator { StateAccumulator::V1(impl_v1) => { Self::accumulate_live_object_set_impl(impl_v1.store.iter_live_object_set()) } - StateAccumulator::V2(impl_v2) => { - Self::accumulate_live_object_set_impl(impl_v2.store.iter_live_object_set()) - } } } @@ -290,7 +263,6 @@ impl StateAccumulator { pub fn accumulate_effects(&self, effects: Vec) -> Accumulator { match self { StateAccumulator::V1(impl_v1) => impl_v1.accumulate_effects(effects), - StateAccumulator::V2(impl_v2) => impl_v2.accumulate_effects(effects), } } @@ -339,92 +311,6 @@ impl StateAccumulatorV1 { Self { store, metrics } } - /// Unions all checkpoint accumulators at the end of the epoch to generate - /// the root state hash and persists it to db. This function is - /// idempotent. Can be called on non-consecutive epochs, e.g. to - /// accumulate epoch 3 after having last accumulated epoch 1. - pub async fn accumulate_epoch( - &self, - epoch_store: Arc, - last_checkpoint_of_epoch: CheckpointSequenceNumber, - ) -> IotaResult { - let _scope = monitored_scope("AccumulateEpochV1"); - let epoch = epoch_store.epoch(); - if let Some((_checkpoint, acc)) = self.store.get_root_state_accumulator_for_epoch(epoch)? { - return Ok(acc); - } - - // Get the next checkpoint to accumulate (first checkpoint of the epoch) - // by adding 1 to the highest checkpoint of the previous epoch - let (_highest_epoch, (next_to_accumulate, mut root_state_accumulator)) = self - .store - .get_root_state_accumulator_for_highest_epoch()? - .map(|(epoch, (checkpoint, acc))| { - ( - epoch, - ( - checkpoint - .checked_add(1) - .expect("Overflowed u64 for epoch ID"), - acc, - ), - ) - }) - .unwrap_or((0, (0, Accumulator::default()))); - - debug!( - "Accumulating epoch {} from checkpoint {} to checkpoint {} (inclusive)", - epoch, next_to_accumulate, last_checkpoint_of_epoch - ); - - let (checkpoints, mut accumulators) = epoch_store - .get_accumulators_in_checkpoint_range(next_to_accumulate, last_checkpoint_of_epoch)? - .into_iter() - .unzip::<_, _, Vec<_>, Vec<_>>(); - - let remaining_checkpoints: Vec<_> = (next_to_accumulate..=last_checkpoint_of_epoch) - .filter(|seq_num| !checkpoints.contains(seq_num)) - .collect(); - - if !remaining_checkpoints.is_empty() { - debug!( - "Awaiting accumulation of checkpoints {:?} for epoch {} accumulation", - remaining_checkpoints, epoch - ); - } - - let mut remaining_accumulators = epoch_store - .notify_read_checkpoint_state_digests(remaining_checkpoints) - .await - .expect("Failed to notify read checkpoint state digests"); - - accumulators.append(&mut remaining_accumulators); - - assert!(accumulators.len() == (last_checkpoint_of_epoch - next_to_accumulate + 1) as usize); - - for acc in accumulators { - root_state_accumulator.union(&acc); - } - - self.store.insert_state_accumulator_for_epoch( - epoch, - &last_checkpoint_of_epoch, - &root_state_accumulator, - )?; - - Ok(root_state_accumulator) - } - - pub fn accumulate_effects(&self, effects: Vec) -> Accumulator { - accumulate_effects(effects) - } -} - -impl StateAccumulatorV2 { - pub fn new(store: Arc, metrics: Arc) -> Self { - Self { store, metrics } - } - pub async fn accumulate_running_root( &self, epoch_store: &AuthorityPerEpochStore, diff --git a/crates/iota-swarm-config/src/network_config_builder.rs b/crates/iota-swarm-config/src/network_config_builder.rs index 001ce83e81a..aa51ebdfb50 100644 --- a/crates/iota-swarm-config/src/network_config_builder.rs +++ b/crates/iota-swarm-config/src/network_config_builder.rs @@ -68,12 +68,12 @@ pub enum ProtocolVersionsConfig { PerValidator(SupportedProtocolVersionsCallback), } -pub type StateAccumulatorV2EnabledCallback = Arc bool + Send + Sync + 'static>; +pub type StateAccumulatorV1EnabledCallback = Arc bool + Send + Sync + 'static>; #[derive(Clone)] -pub enum StateAccumulatorV2EnabledConfig { +pub enum StateAccumulatorV1EnabledConfig { Global(bool), - PerValidator(StateAccumulatorV2EnabledCallback), + PerValidator(StateAccumulatorV1EnabledCallback), } pub struct ConfigBuilder { @@ -92,7 +92,7 @@ pub struct ConfigBuilder { firewall_config: Option, max_submit_position: Option, submit_delay_step_override_millis: Option, - state_accumulator_v2_enabled_config: Option, + state_accumulator_config: Option, empty_validator_genesis: bool, } @@ -114,7 +114,7 @@ impl ConfigBuilder { firewall_config: None, max_submit_position: None, submit_delay_step_override_millis: None, - state_accumulator_v2_enabled_config: None, + state_accumulator_config: Some(StateAccumulatorV1EnabledConfig::Global(true)), empty_validator_genesis: false, } } @@ -236,26 +236,16 @@ impl ConfigBuilder { self } - pub fn with_state_accumulator_v2_enabled(mut self, enabled: bool) -> Self { - self.state_accumulator_v2_enabled_config = - Some(StateAccumulatorV2EnabledConfig::Global(enabled)); - self - } - - pub fn with_state_accumulator_v2_enabled_callback( + pub fn with_state_accumulator_callback( mut self, - func: StateAccumulatorV2EnabledCallback, + func: StateAccumulatorV1EnabledCallback, ) -> Self { - self.state_accumulator_v2_enabled_config = - Some(StateAccumulatorV2EnabledConfig::PerValidator(func)); + self.state_accumulator_config = Some(StateAccumulatorV1EnabledConfig::PerValidator(func)); self } - pub fn with_state_accumulator_v2_enabled_config( - mut self, - c: StateAccumulatorV2EnabledConfig, - ) -> Self { - self.state_accumulator_v2_enabled_config = Some(c); + pub fn with_state_accumulator_config(mut self, c: StateAccumulatorV1EnabledConfig) -> Self { + self.state_accumulator_config = Some(c); self } @@ -304,7 +294,7 @@ impl ConfigBuilder { firewall_config: self.firewall_config, max_submit_position: self.max_submit_position, submit_delay_step_override_millis: self.submit_delay_step_override_millis, - state_accumulator_v2_enabled_config: self.state_accumulator_v2_enabled_config, + state_accumulator_config: self.state_accumulator_config, empty_validator_genesis: self.empty_validator_genesis, } } @@ -525,14 +515,6 @@ impl ConfigBuilder { }; builder = builder.with_supported_protocol_versions(supported_versions); } - if let Some(acc_v2_config) = &self.state_accumulator_v2_enabled_config { - let state_accumulator_v2_enabled: bool = match acc_v2_config { - StateAccumulatorV2EnabledConfig::Global(enabled) => *enabled, - StateAccumulatorV2EnabledConfig::PerValidator(func) => func(idx), - }; - builder = - builder.with_state_accumulator_v2_enabled(state_accumulator_v2_enabled); - } if let Some(num_unpruned_validators) = self.num_unpruned_validators { if idx < num_unpruned_validators { builder = builder.with_unpruned_checkpoints(); diff --git a/crates/iota-swarm-config/src/node_config_builder.rs b/crates/iota-swarm-config/src/node_config_builder.rs index e3109db002d..ae2a7d488f1 100644 --- a/crates/iota-swarm-config/src/node_config_builder.rs +++ b/crates/iota-swarm-config/src/node_config_builder.rs @@ -47,13 +47,11 @@ pub struct ValidatorConfigBuilder { firewall_config: Option, max_submit_position: Option, submit_delay_step_override_millis: Option, - state_accumulator_v2: bool, } impl ValidatorConfigBuilder { pub fn new() -> Self { Self { - state_accumulator_v2: true, ..Default::default() } } @@ -116,11 +114,6 @@ impl ValidatorConfigBuilder { self } - pub fn with_state_accumulator_v2_enabled(mut self, enabled: bool) -> Self { - self.state_accumulator_v2 = enabled; - self - } - pub fn build_without_genesis(self, validator: ValidatorGenesisConfig) -> NodeConfig { let key_path = get_key_path(&validator.key_pair); let config_directory = self @@ -226,7 +219,6 @@ impl ValidatorConfigBuilder { policy_config: self.policy_config, firewall_config: self.firewall_config, execution_cache: ExecutionCacheConfig::default(), - state_accumulator_v2: self.state_accumulator_v2, enable_validator_tx_finalizer: true, } } @@ -515,7 +507,6 @@ impl FullnodeConfigBuilder { policy_config: self.policy_config, firewall_config: self.fw_config, execution_cache: ExecutionCacheConfig::default(), - state_accumulator_v2: true, // This is a validator specific feature. enable_validator_tx_finalizer: false, } diff --git a/crates/iota-swarm/src/memory/swarm.rs b/crates/iota-swarm/src/memory/swarm.rs index 858d92e7e83..adf08d93581 100644 --- a/crates/iota-swarm/src/memory/swarm.rs +++ b/crates/iota-swarm/src/memory/swarm.rs @@ -24,7 +24,7 @@ use iota_swarm_config::{ genesis_config::{AccountConfig, GenesisConfig, ValidatorGenesisConfig}, network_config::NetworkConfig, network_config_builder::{ - CommitteeConfig, ConfigBuilder, ProtocolVersionsConfig, StateAccumulatorV2EnabledConfig, + CommitteeConfig, ConfigBuilder, ProtocolVersionsConfig, StateAccumulatorV1EnabledConfig, SupportedProtocolVersionsCallback, }, node_config_builder::FullnodeConfigBuilder, @@ -65,7 +65,7 @@ pub struct SwarmBuilder { fullnode_fw_config: Option, max_submit_position: Option, submit_delay_step_override_millis: Option, - state_accumulator_v2_enabled_config: StateAccumulatorV2EnabledConfig, + state_accumulator_config: StateAccumulatorV1EnabledConfig, } impl SwarmBuilder { @@ -93,7 +93,7 @@ impl SwarmBuilder { fullnode_fw_config: None, max_submit_position: None, submit_delay_step_override_millis: None, - state_accumulator_v2_enabled_config: StateAccumulatorV2EnabledConfig::Global(true), + state_accumulator_config: StateAccumulatorV1EnabledConfig::Global(true), } } } @@ -123,7 +123,7 @@ impl SwarmBuilder { fullnode_fw_config: self.fullnode_fw_config, max_submit_position: self.max_submit_position, submit_delay_step_override_millis: self.submit_delay_step_override_millis, - state_accumulator_v2_enabled_config: self.state_accumulator_v2_enabled_config, + state_accumulator_config: self.state_accumulator_config, } } @@ -234,11 +234,8 @@ impl SwarmBuilder { self } - pub fn with_state_accumulator_v2_enabled_config( - mut self, - c: StateAccumulatorV2EnabledConfig, - ) -> Self { - self.state_accumulator_v2_enabled_config = c; + pub fn with_state_accumulator_config(mut self, c: StateAccumulatorV1EnabledConfig) -> Self { + self.state_accumulator_config = c; self } @@ -362,9 +359,7 @@ impl SwarmBuilder { .with_supported_protocol_versions_config( self.supported_protocol_versions_config.clone(), ) - .with_state_accumulator_v2_enabled_config( - self.state_accumulator_v2_enabled_config.clone(), - ) + .with_state_accumulator_config(self.state_accumulator_config.clone()) .build(); // Populate validator genesis by pointing to the blob let genesis_path = dir.join(IOTA_GENESIS_FILENAME); diff --git a/crates/test-cluster/src/lib.rs b/crates/test-cluster/src/lib.rs index 35c385b9133..28b121169e0 100644 --- a/crates/test-cluster/src/lib.rs +++ b/crates/test-cluster/src/lib.rs @@ -56,7 +56,7 @@ use iota_swarm_config::{ genesis_config::{AccountConfig, DEFAULT_GAS_AMOUNT, GenesisConfig, ValidatorGenesisConfig}, network_config::{NetworkConfig, NetworkConfigLight}, network_config_builder::{ - ProtocolVersionsConfig, StateAccumulatorV2EnabledCallback, StateAccumulatorV2EnabledConfig, + ProtocolVersionsConfig, StateAccumulatorV1EnabledCallback, StateAccumulatorV1EnabledConfig, SupportedProtocolVersionsCallback, }, node_config_builder::{FullnodeConfigBuilder, ValidatorConfigBuilder}, @@ -1039,7 +1039,7 @@ pub struct TestClusterBuilder { max_submit_position: Option, submit_delay_step_override_millis: Option, - validator_state_accumulator_v2_enabled_config: StateAccumulatorV2EnabledConfig, + validator_state_accumulator_config: StateAccumulatorV1EnabledConfig, } impl TestClusterBuilder { @@ -1067,9 +1067,7 @@ impl TestClusterBuilder { fullnode_fw_config: None, max_submit_position: None, submit_delay_step_override_millis: None, - validator_state_accumulator_v2_enabled_config: StateAccumulatorV2EnabledConfig::Global( - true, - ), + validator_state_accumulator_config: StateAccumulatorV1EnabledConfig::Global(true), } } @@ -1190,12 +1188,12 @@ impl TestClusterBuilder { self } - pub fn with_state_accumulator_v2_enabled_callback( + pub fn with_state_accumulator_callback( mut self, - func: StateAccumulatorV2EnabledCallback, + func: StateAccumulatorV1EnabledCallback, ) -> Self { - self.validator_state_accumulator_v2_enabled_config = - StateAccumulatorV2EnabledConfig::PerValidator(func); + self.validator_state_accumulator_config = + StateAccumulatorV1EnabledConfig::PerValidator(func); self } @@ -1519,9 +1517,7 @@ impl TestClusterBuilder { .with_supported_protocol_versions_config( self.validator_supported_protocol_versions_config.clone(), ) - .with_state_accumulator_v2_enabled_config( - self.validator_state_accumulator_v2_enabled_config.clone(), - ) + .with_state_accumulator_config(self.validator_state_accumulator_config.clone()) .with_fullnode_count(1) .with_fullnode_supported_protocol_versions_config( self.fullnode_supported_protocol_versions_config