Skip to content

Commit

Permalink
Prune erroneously lingering pending randomness rounds from `Authority…
Browse files Browse the repository at this point in the history
…PerEpochStore` tables on startup (#18041)

The underlying race issue causing these not to be removed properly will
be fixed in a future change.
  • Loading branch information
aschran authored Jun 3, 2024
1 parent 880222c commit 94c8418
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions crates/sui-core/src/authority/authority_per_epoch_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,31 @@ impl AuthorityEpochTables {
batch.write()?;
Ok(())
}

pub fn check_and_fix_consistency(&self) {
if let Some(randomness_highest_completed_round) = self
.randomness_highest_completed_round
.get(&crate::epoch::randomness::SINGLETON_KEY)
.expect("typed_store should not fail")
{
let old_randomness_rounds = self
.randomness_rounds_pending
.unbounded_iter()
.map(|(round, _)| round)
.take_while(|round| *round <= randomness_highest_completed_round)
.collect::<Vec<_>>();
// TODO: enable this debug_assert once race is fixed.
// debug_assert!(old_randomness_rounds.is_empty());
if !old_randomness_rounds.is_empty() {
error!("Found {} pending randomness rounds that are older than the highest completed round {randomness_highest_completed_round}. Removing them now.", old_randomness_rounds.len());
};
for round in old_randomness_rounds {
self.randomness_rounds_pending
.remove(&round)
.expect("typed_store should not fail");
}
}
}
}

pub(crate) const MUTEX_TABLE_SIZE: usize = 1024;
Expand All @@ -681,6 +706,8 @@ impl AuthorityPerEpochStore {
let epoch_id = committee.epoch;

let tables = AuthorityEpochTables::open(epoch_id, parent_path, db_options.clone());
tables.check_and_fix_consistency();

let end_of_publish =
StakeAggregator::from_iter(committee.clone(), tables.end_of_publish.unbounded_iter());
let reconfig_state = tables
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-core/src/epoch/randomness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::consensus_adapter::ConsensusAdapter;
type PkG = bls12381::G2Element;
type EncG = bls12381::G2Element;

const SINGLETON_KEY: u64 = 0;
pub const SINGLETON_KEY: u64 = 0;

// State machine for randomness DKG and generation.
//
Expand Down

0 comments on commit 94c8418

Please sign in to comment.