Skip to content

Commit

Permalink
Remove EpochFlag::WritebackCacheEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mystenmark committed Jan 22, 2025
1 parent f751a0d commit 143322d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 90 deletions.
46 changes: 13 additions & 33 deletions crates/sui-core/src/authority/epoch_start_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use enum_dispatch::enum_dispatch;
use serde::{Deserialize, Serialize};
use sui_config::{ExecutionCacheConfig, NodeConfig};
use sui_config::NodeConfig;

use std::fmt;
use sui_types::authenticator_state::get_authenticator_state_obj_initial_shared_version;
Expand All @@ -19,8 +19,6 @@ use sui_types::sui_system_state::epoch_start_sui_system_state::{
EpochStartSystemState, EpochStartSystemStateTrait,
};

use crate::execution_cache::{choose_execution_cache, ExecutionCacheConfigType};

#[enum_dispatch]
pub trait EpochStartConfigTrait {
fn epoch_digest(&self) -> CheckpointDigest;
Expand All @@ -32,14 +30,6 @@ pub trait EpochStartConfigTrait {
fn bridge_obj_initial_shared_version(&self) -> Option<SequenceNumber>;
fn bridge_committee_initiated(&self) -> bool;

fn execution_cache_type(&self) -> ExecutionCacheConfigType {
if self.flags().contains(&EpochFlag::WritebackCacheEnabled) {
ExecutionCacheConfigType::WritebackCache
} else {
ExecutionCacheConfigType::PassthroughCache
}
}

fn use_version_assignment_tables_v3(&self) -> bool {
self.flags()
.contains(&EpochFlag::UseVersionAssignmentTablesV3)
Expand All @@ -57,46 +47,34 @@ pub trait EpochStartConfigTrait {
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
pub enum EpochFlag {
// The deprecated flags have all been in production for long enough that
// we can have deleted the old code paths they were guarding.
// we have deleted the old code paths they were guarding.
// We retain them here in order not to break deserialization.
_InMemoryCheckpointRootsDeprecated = 0,
_PerEpochFinalizedTransactionsDeprecated = 1,
_ObjectLockSplitTablesDeprecated = 2,

WritebackCacheEnabled = 3,

// 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
_WritebackCacheEnabledDeprecated = 3,
_StateAccumulatorV2EnabledDeprecated = 4,
_StateAccumulatorV2EnabledTestnetDeprecated = 5,
_StateAccumulatorV2EnabledMainnetDeprecated = 6,

_ExecutedInEpochTableDeprecated = 7,

UseVersionAssignmentTablesV3 = 8,
}

impl EpochFlag {
pub fn default_flags_for_new_epoch(config: &NodeConfig) -> Vec<Self> {
Self::default_flags_impl(&config.execution_cache)
pub fn default_flags_for_new_epoch(_config: &NodeConfig) -> Vec<Self> {
// NodeConfig arg is not currently used, but we keep it here for future
// flags that might depend on the config.
Self::default_flags_impl()
}

/// 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())
Self::default_flags_impl()
}

fn default_flags_impl(cache_config: &ExecutionCacheConfig) -> Vec<Self> {
let mut new_flags = vec![EpochFlag::UseVersionAssignmentTablesV3];

if matches!(
choose_execution_cache(cache_config),
ExecutionCacheConfigType::WritebackCache
) {
new_flags.push(EpochFlag::WritebackCacheEnabled);
}

new_flags
fn default_flags_impl() -> Vec<Self> {
vec![EpochFlag::UseVersionAssignmentTablesV3]
}
}

Expand All @@ -113,7 +91,9 @@ impl fmt::Display for EpochFlag {
EpochFlag::_ObjectLockSplitTablesDeprecated => {
write!(f, "ObjectLockSplitTables (DEPRECATED)")
}
EpochFlag::WritebackCacheEnabled => write!(f, "WritebackCacheEnabled"),
EpochFlag::_WritebackCacheEnabledDeprecated => {
write!(f, "WritebackCacheEnabled (DEPRECATED)")
}
EpochFlag::_StateAccumulatorV2EnabledDeprecated => {
write!(f, "StateAccumulatorV2EnabledDeprecated (DEPRECATED)")
}
Expand Down
1 change: 0 additions & 1 deletion crates/sui-core/src/authority/test_authority_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ impl<'a> TestAuthorityBuilder<'a> {

let cache_traits = build_execution_cache(
&Default::default(),
&epoch_start_configuration,
&registry,
&authority_store,
backpressure_manager.clone(),
Expand Down
65 changes: 10 additions & 55 deletions crates/sui-core/src/execution_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use crate::authority::authority_per_epoch_store::AuthorityPerEpochStore;
use crate::authority::authority_store::{ExecutionLockWriteGuard, SuiLockResult};
use crate::authority::backpressure::BackpressureManager;
use crate::authority::epoch_start_configuration::EpochFlag;
use crate::authority::epoch_start_configuration::EpochStartConfiguration;
use crate::authority::epoch_start_configuration::{EpochFlag, EpochStartConfigTrait};
use crate::authority::AuthorityStore;
use crate::state_accumulator::AccumulatorStore;
use crate::transaction_outputs::TransactionOutputs;
Expand Down Expand Up @@ -36,7 +36,7 @@ use sui_types::{
object::Owner,
storage::InputKey,
};
use tracing::{error, instrument};
use tracing::instrument;

pub(crate) mod cache_types;
pub mod metrics;
Expand Down Expand Up @@ -101,68 +101,23 @@ impl ExecutionCacheTraitPointers {
}
}

static DISABLE_WRITEBACK_CACHE_ENV_VAR: &str = "DISABLE_WRITEBACK_CACHE";

#[derive(Debug)]
pub enum ExecutionCacheConfigType {
WritebackCache,
PassthroughCache,
}

pub fn choose_execution_cache(_: &ExecutionCacheConfig) -> ExecutionCacheConfigType {
if std::env::var(DISABLE_WRITEBACK_CACHE_ENV_VAR).is_ok() {
error!("DISABLE_WRITEBACK_CACHE is no longer respected. WritebackCache is the default.");
}

ExecutionCacheConfigType::WritebackCache
}

pub fn build_execution_cache(
cache_config: &ExecutionCacheConfig,
epoch_start_config: &EpochStartConfiguration,
prometheus_registry: &Registry,
store: &Arc<AuthorityStore>,
backpressure_manager: Arc<BackpressureManager>,
) -> ExecutionCacheTraitPointers {
let execution_cache_metrics = Arc::new(ExecutionCacheMetrics::new(prometheus_registry));

match epoch_start_config.execution_cache_type() {
ExecutionCacheConfigType::WritebackCache => ExecutionCacheTraitPointers::new(
WritebackCache::new(
cache_config,
store.clone(),
execution_cache_metrics,
backpressure_manager,
)
.into(),
),
ExecutionCacheConfigType::PassthroughCache => {
fatal!("PassthroughCache is no longer supported")
}
}
}

/// Should only be used for sui-tool or tests. Nodes must use build_execution_cache which
/// uses the epoch_start_config to prevent cache impl from switching except at epoch boundaries.
pub fn build_execution_cache_from_env(
prometheus_registry: &Registry,
store: &Arc<AuthorityStore>,
) -> ExecutionCacheTraitPointers {
let execution_cache_metrics = Arc::new(ExecutionCacheMetrics::new(prometheus_registry));

if std::env::var(DISABLE_WRITEBACK_CACHE_ENV_VAR).is_ok() {
fatal!("PassthroughCache is no longer supported");
} else {
ExecutionCacheTraitPointers::new(
WritebackCache::new(
&Default::default(),
store.clone(),
execution_cache_metrics,
BackpressureManager::new_for_tests(),
)
.into(),
ExecutionCacheTraitPointers::new(
WritebackCache::new(
cache_config,
store.clone(),
execution_cache_metrics,
backpressure_manager,
)
}
.into(),
)
}

pub trait ExecutionCacheCommit: Send + Sync {
Expand Down
1 change: 0 additions & 1 deletion crates/sui-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ impl SuiNode {

let cache_traits = build_execution_cache(
&config.execution_cache,
&epoch_start_configuration,
&prometheus_registry,
&store,
backpressure_manager.clone(),
Expand Down

0 comments on commit 143322d

Please sign in to comment.