Skip to content

Commit 77b1586

Browse files
pgherveougithub-actions[bot]
authored andcommitted
[pallet-revive] tracing should wrap around call stack execution (#7676)
Fix tracing should wrap around the entire call stack execution --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 1d2353f commit 77b1586

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

prdoc/pr_7676.prdoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title: '[pallet-revive] tracing should wrap around call stack execution'
2+
doc:
3+
- audience: Runtime Dev
4+
description: Fix tracing should wrap around the entire call stack execution
5+
crates:
6+
- name: pallet-revive
7+
bump: minor

substrate/frame/revive/src/exec.rs

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,10 +1015,21 @@ where
10151015
fn run(&mut self, executable: E, input_data: Vec<u8>) -> Result<(), ExecError> {
10161016
let frame = self.top_frame();
10171017
let entry_point = frame.entry_point;
1018-
let is_delegate_call = frame.delegate.is_some();
10191018
let delegated_code_hash =
10201019
if frame.delegate.is_some() { Some(*executable.code_hash()) } else { None };
10211020

1021+
if_tracing(|tracer| {
1022+
tracer.enter_child_span(
1023+
self.caller().account_id().map(T::AddressMapper::to_address).unwrap_or_default(),
1024+
T::AddressMapper::to_address(&frame.account_id),
1025+
frame.delegate.is_some(),
1026+
frame.read_only,
1027+
frame.value_transferred,
1028+
&input_data,
1029+
frame.nested_gas.gas_left(),
1030+
);
1031+
});
1032+
10221033
// The output of the caller frame will be replaced by the output of this run.
10231034
// It is also not accessible from nested frames.
10241035
// Hence we drop it early to save the memory.
@@ -1036,8 +1047,6 @@ where
10361047
let do_transaction = || -> ExecResult {
10371048
let caller = self.caller();
10381049
let frame = top_frame_mut!(self);
1039-
let read_only = frame.read_only;
1040-
let value_transferred = frame.value_transferred;
10411050
let account_id = &frame.account_id.clone();
10421051

10431052
// We need to make sure that the contract's account exists before calling its
@@ -1081,35 +1090,10 @@ where
10811090
)?;
10821091
}
10831092

1084-
let contract_address = T::AddressMapper::to_address(account_id);
1085-
let maybe_caller_address = caller.account_id().map(T::AddressMapper::to_address);
10861093
let code_deposit = executable.code_info().deposit();
1087-
1088-
if_tracing(|tracer| {
1089-
tracer.enter_child_span(
1090-
maybe_caller_address.unwrap_or_default(),
1091-
contract_address,
1092-
is_delegate_call,
1093-
read_only,
1094-
value_transferred,
1095-
&input_data,
1096-
frame.nested_gas.gas_left(),
1097-
);
1098-
});
1099-
1100-
let output = executable.execute(self, entry_point, input_data).map_err(|e| {
1101-
if_tracing(|tracer| {
1102-
tracer.exit_child_span_with_error(
1103-
e.error,
1104-
top_frame_mut!(self).nested_gas.gas_consumed(),
1105-
);
1106-
});
1107-
ExecError { error: e.error, origin: ErrorOrigin::Callee }
1108-
})?;
1109-
1110-
if_tracing(|tracer| {
1111-
tracer.exit_child_span(&output, top_frame_mut!(self).nested_gas.gas_consumed());
1112-
});
1094+
let output = executable
1095+
.execute(self, entry_point, input_data)
1096+
.map_err(|e| ExecError { error: e.error, origin: ErrorOrigin::Callee })?;
11131097

11141098
// Avoid useless work that would be reverted anyways.
11151099
if output.did_revert() {
@@ -1157,10 +1141,27 @@ where
11571141

11581142
let (success, output) = match transaction_outcome {
11591143
// `with_transactional` executed successfully, and we have the expected output.
1160-
Ok((success, output)) => (success, output),
1144+
Ok((success, output)) => {
1145+
if_tracing(|tracer| {
1146+
let gas_consumed = top_frame!(self).nested_gas.gas_consumed();
1147+
match &output {
1148+
Ok(output) => tracer.exit_child_span(&output, gas_consumed),
1149+
Err(e) => tracer.exit_child_span_with_error(e.error.into(), gas_consumed),
1150+
}
1151+
});
1152+
1153+
(success, output)
1154+
},
11611155
// `with_transactional` returned an error, and we propagate that error and note no state
11621156
// has changed.
1163-
Err(error) => (false, Err(error.into())),
1157+
Err(error) => {
1158+
if_tracing(|tracer| {
1159+
let gas_consumed = top_frame!(self).nested_gas.gas_consumed();
1160+
tracer.exit_child_span_with_error(error.into(), gas_consumed);
1161+
});
1162+
1163+
(false, Err(error.into()))
1164+
},
11641165
};
11651166

11661167
if success {

0 commit comments

Comments
 (0)