Skip to content

Commit

Permalink
Enable tracing in the execution layer (#21165)
Browse files Browse the repository at this point in the history
## Description 

The main idea here is that we have a client (e.g., the upcoming replay
tool) at some point calling the `execute_transaction_to_effects` from
the `Executor` trait defined in `sui/sui-execution/src/executor.rs` to
execute a PTB. We want execution of a PTB to be traced, the trace
"returned" to the client which is responsible for delivering this trace
to the user (e.g., by storing in to disk). In other words, we want the
executor to be responsible for execution and tracing itself, and the
client to be responsible for all the remaining handling of the generated
trace (e.g., I/O operations). There are arguably many ways to accomplish
this and this PR proposes one of them - passing optional
`MoveTraceBuilder` as an additional argument to
`execute_transaction_to_effects`.

Ultimately, we want execution of the entire PTB to be traced, but in
this PR we only trace execution of Move calls. Tracing of the remaining
PTB commands will be added at a later time via external `TraceEvent`s,
without further changing the interface being modified in this PR.

`MoveTraceBuilder` creates an instance of `MoveTrace`, which contains a
list of trace events including `TraceEvent::External`. This type of
event can represent an arbitrary value, including arguments and return
values of PTB commands.
  • Loading branch information
awelc authored Feb 13, 2025
1 parent 07ae422 commit fd40b0f
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 28 deletions.
7 changes: 2 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ exclude = [
"external-crates/move/crates/move-stdlib-natives",
"external-crates/move/crates/move-symbol-pool",
"external-crates/move/crates/move-transactional-test-runner",
"external-crates/move/crates/move-trace-format",
"external-crates/move/crates/move-unit-test",
"external-crates/move/crates/move-vm-config",
"external-crates/move/crates/move-vm-integration-tests",
Expand Down Expand Up @@ -584,6 +585,7 @@ move-symbol-pool = { path = "external-crates/move/crates/move-symbol-pool" }
move-abstract-interpreter = { path = "external-crates/move/crates/move-abstract-interpreter" }
move-abstract-stack = { path = "external-crates/move/crates/move-abstract-stack" }
move-analyzer = { path = "external-crates/move/crates/move-analyzer" }
move-trace-format = { path = "external-crates/move/crates/move-trace-format" }

fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "69d496c71fb37e3d22fe85e5bbfd4256d61422b9" }
fastcrypto-tbls = { git = "https://github.com/MystenLabs/fastcrypto", rev = "69d496c71fb37e3d22fe85e5bbfd4256d61422b9" }
Expand Down
1 change: 1 addition & 0 deletions crates/simulacrum/src/epoch_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl EpochState {
kind,
signer,
tx_digest,
&mut None,
);
Ok((inner_temp_store, gas_status, effects, result))
}
Expand Down
3 changes: 3 additions & 0 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,7 @@ impl AuthorityState {
kind,
signer,
tx_digest,
&mut None,
);

fail_point_if!("cp_execution_nondeterminism", || {
Expand Down Expand Up @@ -1880,6 +1881,7 @@ impl AuthorityState {
kind,
signer,
transaction_digest,
&mut None,
);
let tx_digest = *effects.transaction_digest();

Expand Down Expand Up @@ -2070,6 +2072,7 @@ impl AuthorityState {
kind,
signer,
transaction.digest(),
&mut None,
);

Ok(SimulateTransactionResult {
Expand Down
1 change: 1 addition & 0 deletions crates/sui-genesis-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ fn create_genesis_transaction(
kind,
signer,
genesis_digest,
&mut None,
);
assert!(inner_temp_store.input_objects.is_empty());
assert!(inner_temp_store.mutable_inputs.is_empty());
Expand Down
2 changes: 2 additions & 0 deletions crates/sui-replay/src/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ impl LocalExec {
transaction_kind.clone(),
tx_info.sender,
*tx_digest,
&mut None,
);

if let Err(err) = self.pretty_print_for_tracing(
Expand Down Expand Up @@ -939,6 +940,7 @@ impl LocalExec {
kind,
signer,
*executable.digest(),
&mut None,
);

let effects =
Expand Down
1 change: 1 addition & 0 deletions crates/sui-single-node-benchmark/src/single_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl SingleValidator {
kind,
signer,
*executable.digest(),
&mut None,
);
assert!(effects.status().is_ok());
store.commit_objects(inner_temp_store);
Expand Down
1 change: 1 addition & 0 deletions crates/sui-swarm-config/src/network_config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ mod test {
kind,
signer,
genesis_digest,
&mut None,
);

assert_eq!(&effects, genesis.effects());
Expand Down
17 changes: 1 addition & 16 deletions external-crates/move/crates/move-trace-format/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,15 @@ version = "0.0.1"
authors = ["Move Core Contributors"]
description = "Move Trace Format"
license = "Apache-2.0"
publish = false
edition = "2021"

[dependencies]
anyhow.workspace = true
proptest = { workspace = true, optional = true }
proptest-derive = { workspace = true, optional = true }
ref-cast.workspace = true
variant_count.workspace = true
move-core-types.workspace = true
serde.workspace = true
enum-compat-util.workspace = true
move-proc-macros.workspace = true
move-binary-format.workspace = true

# wasm support (requires js feature of getrandom)
getrandom = { workspace = true, features = ["js"], optional = true }
serde_json = { workspace = true, features = ["arbitrary_precision"] }

[dev-dependencies]
proptest.workspace = true
proptest-derive.workspace = true
move-core-types = { workspace = true, features = ["fuzzing" ] }

[features]
default = []
fuzzing = ["proptest", "proptest-derive", "move-core-types/fuzzing"]
wasm = ["getrandom"]
12 changes: 12 additions & 0 deletions external-crates/move/crates/move-trace-format/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ impl MoveTrace {
}
}

impl Default for MoveTrace {
fn default() -> Self {
Self::new()
}
}

impl MoveTraceBuilder {
/// Create a new `MoveTraceBuilder` with no additional tracing.
pub fn new() -> Self {
Expand Down Expand Up @@ -314,6 +320,12 @@ impl MoveTraceBuilder {
}
}

impl Default for MoveTraceBuilder {
fn default() -> Self {
Self::new()
}
}

impl Display for TraceValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ impl TraceState {
}
}

impl Default for TraceState {
fn default() -> Self {
Self::new()
}
}

impl Tracer for TraceState {
fn notify(&mut self, event: &TraceEvent, mut write: Writer<'_>) {
self.apply_event(event);
Expand Down
1 change: 1 addition & 0 deletions sui-execution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sui-types.workspace = true

move-binary-format.workspace = true
move-bytecode-verifier-meter.workspace = true
move-trace-format.workspace = true
move-vm-config.workspace = true

sui-adapter-latest = { path = "latest/sui-adapter" }
Expand Down
1 change: 1 addition & 0 deletions sui-execution/latest/sui-adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ move-binary-format.workspace = true
move-bytecode-utils.workspace = true
move-bytecode-verifier-meter.workspace = true
move-core-types.workspace = true
move-trace-format.workspace = true
move-vm-config.workspace = true
move-vm-types.workspace = true
mysten-metrics.workspace = true
Expand Down
Loading

0 comments on commit fd40b0f

Please sign in to comment.