Skip to content

Commit

Permalink
[core] Cleanup StateAccumulatorV1
Browse files Browse the repository at this point in the history
  • Loading branch information
williampsmith committed Jul 24, 2024
1 parent 8c51fa7 commit 8d33916
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 430 deletions.
23 changes: 0 additions & 23 deletions crates/sui-benchmark/tests/simtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,6 @@ mod test {
test_simulated_load(test_cluster, 60).await;
}

// Ensure that with half the committee enabling v2 and half not,
// we still arrive at the same root state hash (we do not split brain
// fork).
#[sim_test(config = "test_config()")]
async fn test_simulated_load_with_accumulator_v2_partial_upgrade() {
sui_protocol_config::ProtocolConfig::poison_get_for_min_version();
let test_cluster = init_test_cluster_builder(4, 1000)
.with_authority_overload_config(AuthorityOverloadConfig {
// Disable system overload checks for the test - during tests with crashes,
// it is possible for overload protection to trigger due to validators
// having queued certs which are missing dependencies.
check_system_overload_at_execution: false,
check_system_overload_at_signing: false,
..Default::default()
})
.with_submit_delay_step_override_millis(3000)
.with_state_accumulator_v2_enabled_callback(Arc::new(|idx| idx % 2 == 0))
.build()
.await
.into();
test_simulated_load(test_cluster, 60).await;
}

#[sim_test(config = "test_config()")]
async fn test_simulated_load_with_reconfig_and_correlated_crashes() {
sui_protocol_config::ProtocolConfig::poison_get_for_min_version();
Expand Down
9 changes: 0 additions & 9 deletions crates/sui-core/src/authority/authority_per_epoch_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,15 +940,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)
}

pub fn executed_in_epoch_table_enabled(&self) -> bool {
*self.executed_in_epoch_table_enabled.get_or_init(|| {
self.epoch_start_configuration
Expand Down
3 changes: 1 addition & 2 deletions crates/sui-core/src/authority/authority_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ pub async fn execute_certificate_with_execution_error(
// for testing and regression detection.
// We must do this before sending to consensus, otherwise consensus may already
// lead to transaction execution and state change.
let state_acc =
StateAccumulator::new_for_tests(authority.get_accumulator_store().clone(), &epoch_store);
let state_acc = StateAccumulator::new_for_tests(authority.get_accumulator_store().clone());
let include_wrapped_tombstone = !authority
.epoch_store_for_testing()
.protocol_config()
Expand Down
26 changes: 9 additions & 17 deletions crates/sui-core/src/authority/epoch_start_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,23 @@ pub enum EpochFlag {
// This flag was "burned" because it was deployed with a broken version of the code. The
// new flags below are required to enable state accumulator v2
_StateAccumulatorV2EnabledDeprecated = 4,
StateAccumulatorV2EnabledTestnet = 5,
StateAccumulatorV2EnabledMainnet = 6,
_StateAccumulatorV2EnabledTestnetDeprecated = 5,
_StateAccumulatorV2EnabledMainnetDeprecated = 6,

ExecutedInEpochTable = 7,
}

impl EpochFlag {
pub fn default_flags_for_new_epoch(config: &NodeConfig) -> Vec<Self> {
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> {
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<Self> {
fn default_flags_impl(cache_config: &ExecutionCacheConfig) -> Vec<Self> {
let mut new_flags = vec![EpochFlag::ExecutedInEpochTable];

if matches!(
Expand All @@ -92,11 +89,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
}
}
Expand All @@ -119,11 +111,11 @@ impl fmt::Display for EpochFlag {
write!(f, "StateAccumulatorV2EnabledDeprecated (DEPRECATED)")
}
EpochFlag::ExecutedInEpochTable => write!(f, "ExecutedInEpochTable"),
EpochFlag::StateAccumulatorV2EnabledTestnet => {
write!(f, "StateAccumulatorV2EnabledTestnet")
EpochFlag::_StateAccumulatorV2EnabledTestnetDeprecated => {
write!(f, "StateAccumulatorV2EnabledTestnet (DEPRECATED)")
}
EpochFlag::StateAccumulatorV2EnabledMainnet => {
write!(f, "StateAccumulatorV2EnabledMainnet")
EpochFlag::_StateAccumulatorV2EnabledMainnetDeprecated => {
write!(f, "StateAccumulatorV2EnabledMainnet (DEPRECATED)")
}
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/sui-core/src/checkpoints/checkpoint_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ impl CheckpointExecutor {
.expect("Failed to accumulate running root");
self.accumulator
.accumulate_epoch(epoch_store.clone(), *checkpoint.sequence_number())
.await
.expect("Accumulating epoch cannot fail");

self.bump_highest_executed_checkpoint(checkpoint);
Expand Down
7 changes: 3 additions & 4 deletions crates/sui-core/src/checkpoints/checkpoint_executor/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,10 @@ async fn init_executor_test(

let (checkpoint_sender, _): (Sender<VerifiedCheckpoint>, Receiver<VerifiedCheckpoint>) =
broadcast::channel(buffer_size);
let epoch_store = state.epoch_store_for_testing();

let accumulator =
StateAccumulator::new_for_tests(state.get_accumulator_store().clone(), &epoch_store);
let accumulator = Arc::new(accumulator);
let accumulator = Arc::new(StateAccumulator::new_for_tests(
state.get_accumulator_store().clone(),
));

let executor = CheckpointExecutor::new_for_tests(
checkpoint_sender.subscribe(),
Expand Down
5 changes: 1 addition & 4 deletions crates/sui-core/src/checkpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,9 +1452,7 @@ impl CheckpointBuilder {
state_acc
.accumulate_running_root(&self.epoch_store, sequence_number, Some(acc))
.await?;
state_acc
.digest_epoch(self.epoch_store.clone(), sequence_number)
.await?
state_acc.digest_epoch(self.epoch_store.clone(), sequence_number)?
};
self.metrics.highest_accumulated_epoch.set(epoch as i64);
info!("Epoch {epoch} root state hash digest: {root_state_digest:?}");
Expand Down Expand Up @@ -2520,7 +2518,6 @@ mod tests {

let accumulator = Arc::new(StateAccumulator::new_for_tests(
state.get_accumulator_store().clone(),
&epoch_store,
));

let (checkpoint_service, _exit) = CheckpointService::spawn(
Expand Down
Loading

0 comments on commit 8d33916

Please sign in to comment.