Skip to content

Commit

Permalink
Use dry run for sample transactions (MystenLabs#17166)
Browse files Browse the repository at this point in the history
  • Loading branch information
mystenmark authored Apr 16, 2024
1 parent 86e0bbd commit 15da915
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
30 changes: 30 additions & 0 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,36 @@ impl AuthorityState {
});
}

self.dry_exec_transaction_impl(&epoch_store, transaction, transaction_digest)
.await
}

pub async fn dry_exec_transaction_for_benchmark(
&self,
transaction: TransactionData,
transaction_digest: TransactionDigest,
) -> SuiResult<(
DryRunTransactionBlockResponse,
BTreeMap<ObjectID, (ObjectRef, Object, WriteKind)>,
TransactionEffects,
Option<ObjectID>,
)> {
let epoch_store = self.load_epoch_store_one_call_per_task();
self.dry_exec_transaction_impl(&epoch_store, transaction, transaction_digest)
.await
}

async fn dry_exec_transaction_impl(
&self,
epoch_store: &AuthorityPerEpochStore,
transaction: TransactionData,
transaction_digest: TransactionDigest,
) -> SuiResult<(
DryRunTransactionBlockResponse,
BTreeMap<ObjectID, (ObjectRef, Object, WriteKind)>,
TransactionEffects,
Option<ObjectID>,
)> {
// Cheap validity checks for a transaction, including input size limits.
transaction.check_version_supported(epoch_store.protocol_config())?;
transaction.validity_check_no_gas_check(epoch_store.protocol_config())?;
Expand Down
14 changes: 7 additions & 7 deletions crates/sui-single-node-benchmark/src/benchmark_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ impl BenchmarkContext {

pub(crate) async fn benchmark_transaction_execution(
&self,
mut transactions: Vec<CertifiedTransaction>,
transactions: Vec<CertifiedTransaction>,
print_sample_tx: bool,
) {
if print_sample_tx {
// We must use remove(0) in case there are shared objects and the transactions
// must be executed in order.
self.execute_sample_transaction(transactions.remove(0))
self.execute_sample_transaction(transactions[0].clone())
.await;
}

Expand Down Expand Up @@ -305,11 +305,11 @@ impl BenchmarkContext {

pub(crate) async fn benchmark_transaction_execution_in_memory(
&self,
mut transactions: Vec<CertifiedTransaction>,
transactions: Vec<CertifiedTransaction>,
print_sample_tx: bool,
) {
if print_sample_tx {
self.execute_sample_transaction(transactions.remove(0))
self.execute_sample_transaction(transactions[0].clone())
.await;
}

Expand Down Expand Up @@ -343,7 +343,7 @@ impl BenchmarkContext {
);
let effects = self
.validator()
.execute_raw_transaction(sample_transaction.into_unsigned())
.execute_dry_run(sample_transaction.into_unsigned())
.await;
info!("Sample effects: {:?}\n\n", effects);
assert!(effects.status().is_ok());
Expand Down Expand Up @@ -373,10 +373,10 @@ impl BenchmarkContext {

pub(crate) async fn benchmark_checkpoint_executor(
&self,
mut transactions: Vec<CertifiedTransaction>,
transactions: Vec<CertifiedTransaction>,
checkpoint_size: usize,
) {
self.execute_sample_transaction(transactions.remove(0))
self.execute_sample_transaction(transactions[0].clone())
.await;

info!("Executing all transactions to generate effects");
Expand Down
14 changes: 14 additions & 0 deletions crates/sui-single-node-benchmark/src/single_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ impl SingleValidator {
effects
}

pub async fn execute_dry_run(&self, transaction: Transaction) -> TransactionEffects {
let effects = self
.get_validator()
.dry_exec_transaction_for_benchmark(
transaction.data().intent_message().value.clone(),
*transaction.digest(),
)
.await
.unwrap()
.2;
assert!(effects.status().is_ok());
effects
}

pub async fn execute_certificate(
&self,
cert: CertifiedTransaction,
Expand Down

0 comments on commit 15da915

Please sign in to comment.