Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --trace option to replay CLIs #1638

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion radix-engine-stores/src/rocks_db_with_merkle_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::path::PathBuf;

mod state_tree;
use crate::rocks_db::{decode_from_rocksdb_bytes, encode_to_rocksdb_bytes};
use state_tree::*;
pub use state_tree::*;

const META_CF: &str = "meta";
const SUBSTATES_CF: &str = "substates";
Expand Down
6 changes: 6 additions & 0 deletions simulator/src/replay/cmd_alloc_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ pub struct TxnAllocDump {
/// Include round update type of transactions in output data
#[clap(short = 'r', long)]
pub include_round_update_transaction: bool,

/// Trace transaction execution
#[clap(long)]
pub trace: bool,
}

impl TxnAllocDump {
Expand Down Expand Up @@ -116,6 +120,7 @@ impl TxnAllocDump {
self.include_generic_transaction,
self.include_round_update_transaction,
);
let trace = self.trace;
let txn_write_thread_handle = thread::spawn(move || {
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();
let iter = rx.iter();
Expand All @@ -130,6 +135,7 @@ impl TxnAllocDump {
&scrypto_vm,
&network,
&prepared,
trace,
);

let (heap_allocations_sum, heap_current_level, heap_peak_memory) =
Expand Down
14 changes: 12 additions & 2 deletions simulator/src/replay/cmd_execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub struct TxnExecute {
/// The max version to execute
#[clap(short, long)]
pub max_version: Option<u64>,

/// Trace transaction execution
#[clap(long)]
pub trace: bool,
}

impl TxnExecute {
Expand Down Expand Up @@ -69,12 +73,18 @@ impl TxnExecute {

// txn executor
let mut database = RocksDBWithMerkleTreeSubstateStore::standard(self.database_dir.clone());
let trace = self.trace;
let txn_write_thread_handle = thread::spawn(move || {
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();
let iter = rx.iter();
for tx_payload in iter {
let state_updates =
execute_ledger_transaction(&database, &scrypto_vm, &network, &tx_payload);
let state_updates = execute_ledger_transaction(
&database,
&scrypto_vm,
&network,
&tx_payload,
trace,
);
let database_updates =
state_updates.create_database_updates::<SpreadPrefixKeyMapper>();
database.commit(&database_updates);
Expand Down
14 changes: 12 additions & 2 deletions simulator/src/replay/cmd_execute_in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub struct TxnExecuteInMemory {
/// State hash breakpoints, in format of comma separated `<version>:<hash>`
#[clap(short, long)]
pub breakpoints: Option<String>,

/// Trace transaction execution
#[clap(long)]
pub trace: bool,
}

impl TxnExecuteInMemory {
Expand Down Expand Up @@ -81,12 +85,18 @@ impl TxnExecuteInMemory {
// txn executor
let substate_database = InMemorySubstateDatabase::standard();
let mut database = HashTreeUpdatingDatabase::new(substate_database);
let trace = self.trace;
let txn_write_thread_handle = thread::spawn(move || {
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();
let iter = rx.iter();
for tx_payload in iter {
let state_updates =
execute_ledger_transaction(&database, &scrypto_vm, &network, &tx_payload);
let state_updates = execute_ledger_transaction(
&database,
&scrypto_vm,
&network,
&tx_payload,
trace,
);
let database_updates =
state_updates.create_database_updates::<SpreadPrefixKeyMapper>();
database.commit(&database_updates);
Expand Down
6 changes: 6 additions & 0 deletions simulator/src/replay/cmd_measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ pub struct TxnMeasure {
/// The max version to execute
#[clap(short, long)]
pub max_version: Option<u64>,

/// Trace transaction execution
#[clap(long)]
pub trace: bool,
}

impl TxnMeasure {
Expand Down Expand Up @@ -91,6 +95,7 @@ impl TxnMeasure {
.map_err(Error::IOError)?;
}

let trace = self.trace;
let txn_write_thread_handle = thread::spawn(move || {
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();
let iter = rx.iter();
Expand All @@ -102,6 +107,7 @@ impl TxnMeasure {
&scrypto_vm,
&network,
&prepared,
trace,
);
let execution_cost_units = receipt
.fee_summary()
Expand Down
28 changes: 22 additions & 6 deletions simulator/src/replay/cmd_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub struct TxnSync {
/// The max version to execute
#[clap(short, long)]
pub max_version: Option<u64>,

/// Trace transaction execution
#[clap(long)]
pub trace: bool,
}

impl TxnSync {
Expand Down Expand Up @@ -62,25 +66,37 @@ impl TxnSync {

// txn executor
let mut database = RocksDBWithMerkleTreeSubstateStore::standard(self.database_dir.clone());
let trace = self.trace;
let txn_write_thread_handle = thread::spawn(move || {
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();
let iter = rx.iter();
for (tx_payload, expected_state_root_hash) in iter {
let state_updates =
execute_ledger_transaction(&database, &scrypto_vm, &network, &tx_payload);
let state_updates = execute_ledger_transaction(
&database,
&scrypto_vm,
&network,
&tx_payload,
trace,
);
let database_updates =
state_updates.create_database_updates::<SpreadPrefixKeyMapper>();
database.commit(&database_updates);

let new_state_root_hash = database.get_current_root_hash();
let new_version = database.get_current_version();

let current_version = database.get_current_version();
let new_version = current_version + 1;
// TODO: avoid redundant computation?
let (_, new_state_root_hash) =
radix_engine_stores::rocks_db_with_merkle_tree::compute_state_tree_update(
&database,
current_version,
&database_updates,
);
if new_state_root_hash != expected_state_root_hash {
panic!(
"State hash mismatch at version {}. Expected {} Actual {}",
new_version, expected_state_root_hash, new_state_root_hash
);
}
database.commit(&database_updates);

// print progress
if new_version < 1000 || new_version % 1000 == 0 {
Expand Down
16 changes: 12 additions & 4 deletions simulator/src/replay/ledger_transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ pub fn execute_ledger_transaction<S: SubstateDatabase>(
scrypto_vm: &ScryptoVm<DefaultWasmEngine>,
network: &NetworkDefinition,
tx_payload: &[u8],
trace: bool,
) -> StateUpdates {
let prepared = prepare_ledger_transaction(tx_payload);
execute_prepared_ledger_transaction(database, scrypto_vm, network, &prepared)
execute_prepared_ledger_transaction(database, scrypto_vm, network, &prepared, trace)
.into_state_updates()
}

Expand All @@ -63,6 +64,7 @@ pub fn execute_prepared_ledger_transaction<S: SubstateDatabase>(
scrypto_vm: &ScryptoVm<DefaultWasmEngine>,
network: &NetworkDefinition,
prepared: &PreparedLedgerTransaction,
trace: bool,
) -> LedgerTransactionReceipt {
match &prepared.inner {
PreparedLedgerTransactionInner::Genesis(prepared_genesis_tx) => {
Expand All @@ -79,7 +81,9 @@ pub fn execute_prepared_ledger_transaction<S: SubstateDatabase>(
native_vm: DefaultNativeVm::new(),
},
&CostingParameters::default(),
&ExecutionConfig::for_genesis_transaction(network.clone()),
&ExecutionConfig::for_genesis_transaction(network.clone())
.with_kernel_trace(trace)
.with_cost_breakdown(trace),
&tx.get_executable(btreeset!(AuthAddresses::system_role())),
);
LedgerTransactionReceipt::Standard(receipt)
Expand All @@ -94,7 +98,9 @@ pub fn execute_prepared_ledger_transaction<S: SubstateDatabase>(
native_vm: DefaultNativeVm::new(),
},
&CostingParameters::default(),
&ExecutionConfig::for_notarized_transaction(network.clone()),
&ExecutionConfig::for_notarized_transaction(network.clone())
.with_kernel_trace(trace)
.with_cost_breakdown(trace),
&NotarizedTransactionValidator::new(ValidationConfig::default(network.id))
.validate(tx.as_ref().clone())
.expect("Transaction validation failure")
Expand All @@ -110,7 +116,9 @@ pub fn execute_prepared_ledger_transaction<S: SubstateDatabase>(
native_vm: DefaultNativeVm::new(),
},
&CostingParameters::default(),
&ExecutionConfig::for_system_transaction(network.clone()),
&ExecutionConfig::for_system_transaction(network.clone())
.with_kernel_trace(trace)
.with_cost_breakdown(trace),
&tx.get_executable(),
);
LedgerTransactionReceipt::Standard(receipt)
Expand Down
Loading