Skip to content

Commit

Permalink
Clean up local execution
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind committed Oct 30, 2024
1 parent e8690c5 commit f24e5de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 88 deletions.
88 changes: 2 additions & 86 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use tap::{TapFallible, TapOptional};
use tokio::sync::mpsc::unbounded_channel;
use tokio::sync::{mpsc, oneshot, RwLock};
use tokio::task::JoinHandle;
use tracing::{debug, error, info, instrument, warn, Instrument};
use tracing::{debug, error, info, instrument, warn};

use self::authority_store::ExecutionLockWriteGuard;
use self::authority_store_pruner::AuthorityStorePruningMetrics;
Expand Down Expand Up @@ -91,7 +91,7 @@ use sui_types::digests::TransactionEventsDigest;
use sui_types::dynamic_field::{DynamicFieldInfo, DynamicFieldName};
use sui_types::effects::{
InputSharedObject, SignedTransactionEffects, TransactionEffects, TransactionEffectsAPI,
TransactionEvents, VerifiedCertifiedTransactionEffects, VerifiedSignedTransactionEffects,
TransactionEvents, VerifiedSignedTransactionEffects,
};
use sui_types::error::{ExecutionError, UserInputError};
use sui_types::event::{Event, EventID};
Expand Down Expand Up @@ -125,7 +125,6 @@ use sui_types::{
committee::Committee,
crypto::AuthoritySignature,
error::{SuiError, SuiResult},
fp_ensure,
object::{Object, ObjectRead},
transaction::*,
SUI_SYSTEM_ADDRESS,
Expand Down Expand Up @@ -239,7 +238,6 @@ pub struct AuthorityMetrics {
execute_certificate_latency_shared_object: Histogram,
await_transaction_latency: Histogram,

execute_certificate_with_effects_latency: Histogram,
internal_execution_latency: Histogram,
execution_load_input_objects_latency: Histogram,
prepare_certificate_latency: Histogram,
Expand Down Expand Up @@ -459,13 +457,6 @@ impl AuthorityMetrics {
registry,
)
.unwrap(),
execute_certificate_with_effects_latency: register_histogram_with_registry!(
"authority_state_execute_certificate_with_effects_latency",
"Latency of executing certificates with effects, including waiting for inputs",
LATENCY_SEC_BUCKETS.to_vec(),
registry,
)
.unwrap(),
internal_execution_latency: register_histogram_with_registry!(
"authority_state_internal_execution_latency",
"Latency of actual certificate executions",
Expand Down Expand Up @@ -1117,81 +1108,6 @@ impl AuthorityState {
.inc();
}

/// Executes a transaction that's known to have correct effects.
/// For such transaction, we don't have to wait for consensus to set shared object
/// locks because we already know the shared object versions based on the effects.
/// This function can be called by a fullnode only.
// TODO: This function is no longer needed. Remove it and cleanup all the
// related functions.
#[instrument(level = "trace", skip_all)]
pub async fn fullnode_execute_certificate_with_effects(
&self,
transaction: &VerifiedExecutableTransaction,
// NOTE: the caller of this must promise to wait until it
// knows for sure this tx is finalized, namely, it has seen a
// CertifiedTransactionEffects or at least f+1 identifical effects
// digests matching this TransactionEffectsEnvelope, before calling
// this function, in order to prevent a byzantine validator from
// giving us incorrect effects.
effects: &VerifiedCertifiedTransactionEffects,
epoch_store: &Arc<AuthorityPerEpochStore>,
) -> SuiResult {
assert!(self.is_fullnode(epoch_store));
// NOTE: the fullnode can change epoch during local execution. It should not cause
// data inconsistency, but can be problematic for certain tests.
// The check below mitigates the issue, but it is not a fundamental solution to
// avoid race between local execution and reconfiguration.
if self.epoch_store.load().epoch() != epoch_store.epoch() {
return Err(SuiError::EpochEnded(epoch_store.epoch()));
}
let _metrics_guard = self
.metrics
.execute_certificate_with_effects_latency
.start_timer();
let digest = *transaction.digest();
debug!("execute_certificate_with_effects");
fp_ensure!(
*effects.data().transaction_digest() == digest,
SuiError::ErrorWhileProcessingCertificate {
err: "effects/tx digest mismatch".to_string()
}
);

if transaction.contains_shared_object() {
epoch_store
.acquire_shared_locks_from_effects(
transaction,
effects.data(),
self.get_object_cache_reader().as_ref(),
)
.await?;
}

let expected_effects_digest = effects.digest();

self.transaction_manager
.enqueue(vec![transaction.clone()], epoch_store);

let observed_effects = self
.get_transaction_cache_reader()
.notify_read_executed_effects(&[digest])
.instrument(tracing::debug_span!(
"notify_read_effects_in_execute_certificate_with_effects"
))
.await?
.pop()
.expect("notify_read_effects should return exactly 1 element");

let observed_effects_digest = observed_effects.digest();
if &observed_effects_digest != expected_effects_digest {
panic!(
"Locally executed effects do not match canonical effects! expected_effects_digest={:?} observed_effects_digest={:?} expected_effects={:?} observed_effects={:?} input_objects={:?}",
expected_effects_digest, observed_effects_digest, effects.data(), observed_effects, transaction.data().transaction_data().input_objects()
);
}
Ok(())
}

/// Executes a certificate for its effects.
#[instrument(level = "trace", skip_all)]
pub async fn execute_certificate(
Expand Down
5 changes: 3 additions & 2 deletions crates/sui-types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,9 @@ pub enum SuiError {
},
#[error("Signatures in a certificate must form a quorum")]
CertificateRequiresQuorum,
#[error("Transaction certificate processing failed: {err}")]
ErrorWhileProcessingCertificate { err: String },
#[allow(non_camel_case_types)]
#[error("DEPRECATED")]
DEPRECATED_ErrorWhileProcessingCertificate,
#[error(
"Failed to get a quorum of signed effects when processing transaction: {effects_map:?}"
)]
Expand Down

0 comments on commit f24e5de

Please sign in to comment.