Skip to content

Commit

Permalink
checkpoints: don't reinsert genesis checkpoint if its already present
Browse files Browse the repository at this point in the history
This patch fixes an issue we've seen where a node's
highest_synced_checkpoint watermark ends up getting reset to 0 upon
restarting. This ended up being due to us unconditionally inserting the
genesis cehckpoint and reseting the watermark to 0.
  • Loading branch information
bmwill committed Jan 30, 2023
1 parent 00e2275 commit 754f7dd
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions crates/sui-core/src/checkpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,38 @@ impl CheckpointStore {
contents: CheckpointContents,
epoch_store: &AuthorityPerEpochStore,
) {
if epoch_store.epoch() == checkpoint.summary.epoch {
epoch_store
.put_genesis_checkpoint_in_builder(&checkpoint.summary, &contents)
.unwrap();
} else {
debug!("Not inserting checkpoint builder data for genesis checkpoint, validator epoch {}, genesis epoch {}",
epoch_store.epoch(), checkpoint.summary.epoch,
);
assert_eq!(
checkpoint.epoch(),
0,
"can't call insert_genesis_checkpoint with a checkpoint not in epoch 0"
);
assert_eq!(
checkpoint.sequence_number(),
0,
"can't call insert_genesis_checkpoint with a checkpoint that doesn't have a sequence number of 0"
);

// Only insert the genesis checkpoint if the DB is empty and doesn't have it already
if self
.get_checkpoint_by_digest(&checkpoint.digest())
.unwrap()
.is_none()
{
if epoch_store.epoch() == checkpoint.summary.epoch {
epoch_store
.put_genesis_checkpoint_in_builder(&checkpoint.summary, &contents)
.unwrap();
} else {
debug!(
validator_epoch =% epoch_store.epoch(),
genesis_epoch =% checkpoint.epoch(),
"Not inserting checkpoint builder data for genesis checkpoint",
);
}
self.insert_checkpoint_contents(contents).unwrap();
self.insert_verified_checkpoint(checkpoint.clone()).unwrap();
self.update_highest_synced_checkpoint(&checkpoint).unwrap();
}
self.insert_verified_checkpoint(checkpoint.clone()).unwrap();
self.insert_checkpoint_contents(contents).unwrap();
self.update_highest_synced_checkpoint(&checkpoint).unwrap();
}

pub fn get_checkpoint_by_digest(
Expand Down

0 comments on commit 754f7dd

Please sign in to comment.