Skip to content

Commit

Permalink
Remove handle_consensus_transaction (MystenLabs#2114)
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind authored May 23, 2022
1 parent 8466e98 commit 93e75a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 46 deletions.
42 changes: 1 addition & 41 deletions sui_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use sui_types::{
storage::{BackingPackageStore, DeleteKind, Storage},
MOVE_STDLIB_ADDRESS, SUI_FRAMEWORK_ADDRESS,
};
use tracing::{debug, error, instrument, log};
use tracing::{debug, error, instrument};
use typed_store::Map;

#[cfg(test)]
Expand Down Expand Up @@ -461,46 +461,6 @@ impl AuthorityState {
})
}

/// Process certificates coming from the consensus. It is crucial that this function is only
/// called by a single task (ie. the task handling consensus outputs).
pub async fn handle_consensus_certificate(
&self,
certificate: CertifiedTransaction,
last_consensus_index: ExecutionIndices,
) -> SuiResult<()> {
// Ensure it is a shared object certificate
if !certificate.contains_shared_object() {
log::debug!(
"Transaction without shared object has been sequenced: {:?}",
certificate
);
return Ok(());
}

// Ensure it is the first time we see this certificate.
let transaction_digest = *certificate.digest();
if self
.database
.sequenced(&transaction_digest, certificate.shared_input_objects())?[0]
.is_some()
{
return Ok(());
}

// Check the certificate.
certificate.verify(&self.committee)?;

// Persist the certificate since we are about to lock one or more shared object.
// We thus need to make sure someone (if not the client) can continue the protocol.
// Also atomically lock the shared objects for this particular transaction and
// increment the last consensus index. Note that a single process can ever call
// this function and that the last consensus index is also kept in memory. It is
// thus ok to only persist now (despite this function may have returned earlier).
// In the worst case, the synchronizer of the consensus client will catch up.
self.database
.persist_certificate_and_lock_shared_objects(certificate, last_consensus_index)
}

/// Check if we need to submit this transaction to consensus. We usually do, unless (i) we already
/// processed the transaction and we can immediately return the effects, or (ii) we already locked
/// all shared-objects of the transaction and can (re-)attempt execution.
Expand Down
4 changes: 2 additions & 2 deletions sui_core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,9 +1541,9 @@ async fn shared_object() {

// Sequence the certificate to assign a sequence number to the shared object.
authority
.handle_consensus_certificate(
certificate,
.handle_consensus_transaction(
/* last_consensus_index */ ExecutionIndices::default(),
ConsensusTransaction::UserTransaction(certificate),
)
.await
.unwrap();
Expand Down
12 changes: 9 additions & 3 deletions sui_core/src/unit_tests/consensus_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::authority::{
AuthorityState,
};
use move_core_types::{account_address::AccountAddress, ident_str};
use narwhal_executor::ExecutionIndices;
use narwhal_executor::{ExecutionIndices, ExecutionState};
use narwhal_types::Transactions;
use narwhal_types::TransactionsServer;
use narwhal_types::{Empty, TransactionProto};
Expand Down Expand Up @@ -107,7 +107,10 @@ async fn listen_to_sequenced_transaction() {

// Set the shared object locks.
state
.handle_consensus_certificate(certificate, ExecutionIndices::default())
.handle_consensus_transaction(
ExecutionIndices::default(),
ConsensusTransaction::UserTransaction(certificate),
)
.await
.unwrap();

Expand Down Expand Up @@ -173,7 +176,10 @@ async fn submit_transaction_to_consensus() {

// Set the shared object locks.
state_guard
.handle_consensus_certificate(certificate.clone(), ExecutionIndices::default())
.handle_consensus_transaction(
ExecutionIndices::default(),
ConsensusTransaction::UserTransaction(certificate.clone()),
)
.await
.unwrap();

Expand Down

0 comments on commit 93e75a3

Please sign in to comment.