Skip to content

Commit

Permalink
Prepose consensus commit prologue in checkpoint (MystenLabs#18023)
Browse files Browse the repository at this point in the history
## Description 

This PR moves consensus commit prologue to the beginning of the
checkpoint if it presents. This is to make sure
that the consensus commit prologue is before all the cancelled
transactions in the checkpoint, and hence
when doing sequential replay, we know which transactions are cancelled.

This is achieved by finding the consensus commit prologue in the pending
checkpoint, and always
places it the first before all other sorted transactions.

It also builds on several assumptions:
- There is at most one consensus commit prologue transactions in a
pending checkpoint.
- The consensus commit prologue shouldn't have any dependencies that
aren't in any previous checkpoints.

## Test plan 

Added consensus commit prologue invariant check for all integration
simtests.

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
halfprice authored Jun 12, 2024
1 parent 738c473 commit 7e33c3f
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 31 deletions.
57 changes: 41 additions & 16 deletions crates/sui-core/src/authority/authority_per_epoch_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2612,7 +2612,13 @@ impl AuthorityPerEpochStore {
.chain(sequenced_randomness_transactions)
.collect();

let (transactions_to_schedule, notifications, lock, final_round) = self
let (
transactions_to_schedule,
notifications,
lock,
final_round,
consensus_commit_prologue_root,
) = self
.process_consensus_transactions(
&mut batch,
&consensus_transactions,
Expand Down Expand Up @@ -2653,8 +2659,23 @@ impl AuthorityPerEpochStore {
} else {
consensus_commit_info.round
};

let mut checkpoint_roots: Vec<TransactionKey> = Vec::with_capacity(roots.len() + 1);

if let Some(consensus_commit_prologue_root) = consensus_commit_prologue_root {
if self
.protocol_config()
.prepend_prologue_tx_in_consensus_commit_in_checkpoints()
{
// Put consensus commit prologue root at the beginning of the checkpoint roots.
checkpoint_roots.push(consensus_commit_prologue_root);
} else {
roots.insert(consensus_commit_prologue_root);
}
}
checkpoint_roots.extend(roots.into_iter());
let pending_checkpoint = PendingCheckpointV2::V2(PendingCheckpointV2Contents {
roots: roots.into_iter().collect(),
roots: checkpoint_roots,
details: PendingCheckpointInfo {
timestamp_ms: consensus_commit_info.timestamp,
last_of_epoch: final_round && randomness_round.is_none(),
Expand Down Expand Up @@ -2725,18 +2746,18 @@ impl AuthorityPerEpochStore {

// Adds the consensus commit prologue transaction to the beginning of input `transactions` to update
// the system clock used in all transactions in the current consensus commit.
// Returns the root of the consensus commit prologue transaction if it was added to the input.
fn add_consensus_commit_prologue_transaction(
&self,
batch: &mut DBBatch,
transactions: &mut VecDeque<VerifiedExecutableTransaction>,
consensus_commit_info: &ConsensusCommitInfo,
roots: &mut BTreeSet<TransactionKey>,
cancelled_txns: &BTreeMap<TransactionDigest, CancelConsensusCertificateReason>,
) -> SuiResult {
) -> SuiResult<Option<TransactionKey>> {
#[cfg(any(test, feature = "test-utils"))]
{
if consensus_commit_info.skip_consensus_commit_prologue_in_test() {
return Ok(());
return Ok(None);
}
}

Expand Down Expand Up @@ -2773,20 +2794,20 @@ impl AuthorityPerEpochStore {
self.protocol_config(),
version_assignment,
);
match self.process_consensus_system_transaction(&transaction) {
let consensus_commit_prologue_root = match self.process_consensus_system_transaction(&transaction) {
ConsensusCertificateResult::SuiTransaction(processed_tx) => {
roots.insert(processed_tx.key());
transactions.push_front(processed_tx);
transactions.push_front(processed_tx.clone());
Some(processed_tx.key())
}
ConsensusCertificateResult::IgnoredSystem => (),
ConsensusCertificateResult::IgnoredSystem => None,
_ => unreachable!("process_consensus_system_transaction returned unexpected ConsensusCertificateResult."),
};

self.record_consensus_message_processed(
batch,
SequencedConsensusTransactionKey::System(*transaction.digest()),
)?;
Ok(())
Ok(consensus_commit_prologue_root)
}

// Assigns shared object versions to transactions and updates the shared object version state.
Expand Down Expand Up @@ -2910,7 +2931,8 @@ impl AuthorityPerEpochStore {
Vec<VerifiedExecutableTransaction>, // transactions to schedule
Vec<SequencedConsensusTransactionKey>, // keys to notify as complete
Option<RwLockWriteGuard<ReconfigState>>,
bool, // true if final round
bool, // true if final round
Option<TransactionKey>, // consensus commit prologue root
)> {
if randomness_round.is_some() {
assert!(!dkg_failed); // invariant check
Expand Down Expand Up @@ -3046,14 +3068,11 @@ impl AuthorityPerEpochStore {
}
}

// TODO: once transaction cancellation is implemented, we need to add cancelled transaction info to
// the created consensus commit prologue transactions.
// Add the consensus commit prologue transaction to the beginning of `verified_certificates`.
self.add_consensus_commit_prologue_transaction(
let consensus_commit_prologue_root = self.add_consensus_commit_prologue_transaction(
batch,
&mut verified_certificates,
consensus_commit_info,
roots,
&cancelled_txns,
)?;

Expand All @@ -3074,7 +3093,13 @@ impl AuthorityPerEpochStore {
commit_has_deferred_txns,
)?;

Ok((verified_certificates, notifications, lock, final_round))
Ok((
verified_certificates,
notifications,
lock,
final_round,
consensus_commit_prologue_root,
))
}

fn process_end_of_publish_transactions_and_reconfig(
Expand Down
Loading

0 comments on commit 7e33c3f

Please sign in to comment.