Skip to content

Commit

Permalink
Use dedicated table for determining if transaction was executed in cu…
Browse files Browse the repository at this point in the history
…rrent epoch
  • Loading branch information
mystenmark committed Jun 25, 2024
1 parent 74bf5b8 commit 9fb19fe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
49 changes: 31 additions & 18 deletions crates/sui-core/src/authority/authority_per_epoch_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ pub struct AuthorityPerEpochStore {
pub(crate) metrics: Arc<EpochMetrics>,
epoch_start_configuration: Arc<EpochStartConfiguration>,

executed_in_epoch_table_enabled: once_cell::sync::OnceCell<bool>,

/// Execution state that has to restart at each epoch change
execution_component: ExecutionComponents,

Expand Down Expand Up @@ -348,7 +350,10 @@ pub struct AuthorityEpochTables {
effects_signatures: DBMap<TransactionDigest, AuthoritySignInfo>,

/// Signatures of transaction certificates that are executed locally.
pub(crate) transaction_cert_signatures: DBMap<TransactionDigest, AuthorityStrongQuorumSignInfo>,
transaction_cert_signatures: DBMap<TransactionDigest, AuthorityStrongQuorumSignInfo>,

/// Transactions that were executed in the current epoch.
executed_in_epoch: DBMap<TransactionDigest, ()>,

/// The tables below manage shared object locks / versions. There are three ways they can be
/// updated:
Expand Down Expand Up @@ -818,6 +823,7 @@ impl AuthorityPerEpochStore {
epoch_close_time: Default::default(),
metrics,
epoch_start_configuration,
executed_in_epoch_table_enabled: once_cell::sync::OnceCell::new(),
execution_component,
chain_identifier,
jwk_aggregator,
Expand Down Expand Up @@ -921,6 +927,14 @@ impl AuthorityPerEpochStore {
.contains(&EpochFlag::StateAccumulatorV2Enabled)
}

pub fn executed_in_epoch_table_enabled(&self) -> bool {
*self.executed_in_epoch_table_enabled.get_or_init(|| {
self.epoch_start_configuration
.flags()
.contains(&EpochFlag::ExecutedInEpochTable)
})
}

/// Returns `&Arc<EpochStartConfiguration>`
/// User can treat this `Arc` as `&EpochStartConfiguration`, or clone the Arc to pass as owned object
pub fn epoch_start_config(&self) -> &Arc<EpochStartConfiguration> {
Expand Down Expand Up @@ -1142,24 +1156,21 @@ impl AuthorityPerEpochStore {
cert_sig: Option<&AuthorityStrongQuorumSignInfo>,
effects_signature: Option<&AuthoritySignInfo>,
) -> SuiResult {
let tables = self.tables()?;
let mut batch = self.tables()?.effects_signatures.batch();
if let Some(cert_sig) = cert_sig {
batch.insert_batch(
&self.tables()?.transaction_cert_signatures,
[(tx_digest, cert_sig)],
)?;
batch.insert_batch(&tables.transaction_cert_signatures, [(tx_digest, cert_sig)])?;
}

if self.executed_in_epoch_table_enabled() {
batch.insert_batch(&tables.executed_in_epoch, [(tx_digest, ())])?;
}

if let Some(effects_signature) = effects_signature {
batch.insert_batch(
&self.tables()?.effects_signatures,
[(tx_digest, effects_signature)],
)?;
batch.insert_batch(&tables.effects_signatures, [(tx_digest, effects_signature)])?;
}
if !matches!(tx_key, TransactionKey::Digest(_)) {
batch.insert_batch(
&self.tables()?.transaction_key_to_digest,
[(tx_key, tx_digest)],
)?;
batch.insert_batch(&tables.transaction_key_to_digest, [(tx_key, tx_digest)])?;
}
batch.write()?;

Expand All @@ -1169,14 +1180,16 @@ impl AuthorityPerEpochStore {
Ok(())
}

pub fn effects_signatures_exists<'a>(
pub fn transactions_executed_in_cur_epoch<'a>(
&self,
digests: impl IntoIterator<Item = &'a TransactionDigest>,
) -> SuiResult<Vec<bool>> {
Ok(self
.tables()?
.effects_signatures
.multi_contains_keys(digests)?)
let tables = self.tables()?;
if self.executed_in_epoch_table_enabled() {
Ok(tables.executed_in_epoch.multi_contains_keys(digests)?)
} else {
Ok(tables.effects_signatures.multi_contains_keys(digests)?)
}
}

pub fn get_effects_signature(
Expand Down
4 changes: 3 additions & 1 deletion crates/sui-core/src/authority/epoch_start_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub enum EpochFlag {

WritebackCacheEnabled,
StateAccumulatorV2Enabled,
ExecutedInEpochTable,
}

impl EpochFlag {
Expand All @@ -68,7 +69,7 @@ impl EpochFlag {
cache_config: &ExecutionCacheConfig,
enable_state_accumulator_v2: bool,
) -> Vec<Self> {
let mut new_flags = vec![];
let mut new_flags = vec![EpochFlag::ExecutedInEpochTable];

if matches!(
choose_execution_cache(cache_config),
Expand Down Expand Up @@ -100,6 +101,7 @@ impl fmt::Display for EpochFlag {
}
EpochFlag::WritebackCacheEnabled => write!(f, "WritebackCacheEnabled"),
EpochFlag::StateAccumulatorV2Enabled => write!(f, "StateAccumulatorV2Enabled"),
EpochFlag::ExecutedInEpochTable => write!(f, "ExecutedInEpochTable"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-core/src/checkpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ impl CheckpointBuilder {

let existing_effects = self
.epoch_store
.effects_signatures_exists(effect.dependencies().iter())?;
.transactions_executed_in_cur_epoch(effect.dependencies().iter())?;

for (dependency, effects_signature_exists) in
effect.dependencies().iter().zip(existing_effects.iter())
Expand Down

0 comments on commit 9fb19fe

Please sign in to comment.