Skip to content

Commit b0c3b43

Browse files
committed
patch runtimes 3600, 3601 and 3700
1 parent 759e0d0 commit b0c3b43

File tree

28 files changed

+543
-1814
lines changed

28 files changed

+543
-1814
lines changed

tracing/3600/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tracing/3600/runtime/common/src/apis.rs

Lines changed: 99 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -147,75 +147,63 @@ macro_rules! impl_runtime_apis_plus_common {
147147
> {
148148
#[cfg(feature = "evm-tracing")]
149149
{
150-
use moonbeam_evm_tracer::tracer::EvmTracer;
151-
use xcm_primitives::{
152-
ETHEREUM_XCM_TRACING_STORAGE_KEY,
153-
EthereumXcmTracingStatus
154-
};
150+
use moonbeam_evm_tracer::tracer::{EthereumTracingStatus, EvmTracer};
151+
use xcm_primitives::EthereumXcmTracingStatus;
155152
use frame_support::storage::unhashed;
156153
use frame_system::pallet_prelude::BlockNumberFor;
157154

158155
// Tell the CallDispatcher we are tracing a specific Transaction.
159-
unhashed::put::<EthereumXcmTracingStatus>(
160-
ETHEREUM_XCM_TRACING_STORAGE_KEY,
161-
&EthereumXcmTracingStatus::Transaction(traced_transaction.hash()),
162-
);
163-
164-
// Initialize block: calls the "on_initialize" hook on every pallet
165-
// in AllPalletsWithSystem.
166-
// After pallet message queue was introduced, this must be done only after
167-
// enabling XCM tracing by setting ETHEREUM_XCM_TRACING_STORAGE_KEY
168-
// in the storage
169-
Executive::initialize_block(header);
170-
171-
// Apply the a subset of extrinsics: all the substrate-specific or ethereum
172-
// transactions that preceded the requested transaction.
173-
for ext in extrinsics.into_iter() {
174-
let _ = match &ext.0.function {
175-
RuntimeCall::Ethereum(transact { transaction }) => {
176-
177-
// Reset the previously consumed weight when tracing ethereum transactions.
178-
// This is necessary because EVM tracing introduces additional
179-
// (ref_time) overhead, which differs from the production runtime behavior.
180-
// Without resetting the block weight, the extra tracing overhead could
181-
// leading to some transactions to incorrectly fail during tracing.
182-
frame_system::BlockWeight::<Runtime>::kill();
183-
184-
if transaction == traced_transaction {
185-
EvmTracer::new().trace(|| Executive::apply_extrinsic(ext));
186-
return Ok(());
187-
} else {
188-
Executive::apply_extrinsic(ext)
156+
EthereumTracingStatus::wrap(EthereumXcmTracingStatus::Transaction(traced_transaction.hash()), || {
157+
// Initialize block: calls the "on_initialize" hook on every pallet
158+
// in AllPalletsWithSystem.
159+
// After pallet message queue was introduced, this must be done only after
160+
// enabling XCM tracing by setting ETHEREUM_XCM_TRACING_STORAGE_KEY
161+
// in the storage
162+
Executive::initialize_block(header);
163+
164+
// Apply the a subset of extrinsics: all the substrate-specific or ethereum
165+
// transactions that preceded the requested transaction.
166+
for ext in extrinsics.into_iter() {
167+
let _ = match &ext.0.function {
168+
RuntimeCall::Ethereum(transact { transaction }) => {
169+
// Reset the previously consumed weight when tracing ethereum transactions.
170+
// This is necessary because EVM tracing introduces additional
171+
// (ref_time) overhead, which differs from the production runtime behavior.
172+
// Without resetting the block weight, the extra tracing overhead could
173+
// leading to some transactions to incorrectly fail during tracing.
174+
frame_system::BlockWeight::<Runtime>::kill();
175+
176+
if transaction == traced_transaction {
177+
EvmTracer::new().trace(|| Executive::apply_extrinsic(ext));
178+
return Ok(());
179+
} else {
180+
Executive::apply_extrinsic(ext)
181+
}
189182
}
183+
_ => Executive::apply_extrinsic(ext),
184+
};
185+
186+
if let Some(EthereumXcmTracingStatus::TransactionExited) = EthereumTracingStatus::state() {
187+
return Ok(());
190188
}
191-
_ => Executive::apply_extrinsic(ext),
192-
};
193-
if let Some(EthereumXcmTracingStatus::TransactionExited) = unhashed::get(
194-
ETHEREUM_XCM_TRACING_STORAGE_KEY
195-
) {
196-
return Ok(());
197189
}
198-
}
199190

200-
if let Some(EthereumXcmTracingStatus::Transaction(_)) = unhashed::get(
201-
ETHEREUM_XCM_TRACING_STORAGE_KEY
202-
) {
203-
// If the transaction was not found, it might be
204-
// an eth-xcm transaction that was executed at on_idle
205-
replay_on_idle();
206-
}
191+
if let Some(EthereumXcmTracingStatus::Transaction(_)) = EthereumTracingStatus::state() {
192+
// If the transaction was not found, it might be
193+
// an eth-xcm transaction that was executed at on_idle
194+
replay_on_idle();
195+
}
207196

208-
if let Some(EthereumXcmTracingStatus::TransactionExited) = unhashed::get(
209-
ETHEREUM_XCM_TRACING_STORAGE_KEY
210-
) {
211-
// The transaction was found
212-
Ok(())
213-
} else {
214-
// The transaction was not-found
215-
Err(sp_runtime::DispatchError::Other(
216-
"Failed to find Ethereum transaction among the extrinsics.",
217-
))
218-
}
197+
if let Some(EthereumXcmTracingStatus::TransactionExited) = EthereumTracingStatus::state() {
198+
// The transaction was found
199+
Ok(())
200+
} else {
201+
// The transaction was not-found
202+
Err(sp_runtime::DispatchError::Other(
203+
"Failed to find Ethereum transaction among the extrinsics.",
204+
))
205+
}
206+
})
219207
}
220208
#[cfg(not(feature = "evm-tracing"))]
221209
Err(sp_runtime::DispatchError::Other(
@@ -233,80 +221,77 @@ macro_rules! impl_runtime_apis_plus_common {
233221
> {
234222
#[cfg(feature = "evm-tracing")]
235223
{
236-
use moonbeam_evm_tracer::tracer::EvmTracer;
224+
use moonbeam_evm_tracer::tracer::{EthereumTracingStatus, EvmTracer};
237225
use frame_system::pallet_prelude::BlockNumberFor;
238226
use xcm_primitives::EthereumXcmTracingStatus;
239227

240228
// Tell the CallDispatcher we are tracing a full Block.
241-
frame_support::storage::unhashed::put::<EthereumXcmTracingStatus>(
242-
xcm_primitives::ETHEREUM_XCM_TRACING_STORAGE_KEY,
243-
&EthereumXcmTracingStatus::Block,
244-
);
245-
246-
let mut config = <Runtime as pallet_evm::Config>::config().clone();
247-
config.estimate = true;
248-
249-
// Initialize block: calls the "on_initialize" hook on every pallet
250-
// in AllPalletsWithSystem.
251-
// After pallet message queue was introduced, this must be done only after
252-
// enabling XCM tracing by setting ETHEREUM_XCM_TRACING_STORAGE_KEY
253-
// in the storage
254-
Executive::initialize_block(header);
255-
256-
// Apply all extrinsics. Ethereum extrinsics are traced.
257-
for ext in extrinsics.into_iter() {
258-
match &ext.0.function {
259-
RuntimeCall::Ethereum(transact { transaction }) => {
260-
261-
// Reset the previously consumed weight when tracing multiple transactions.
262-
// This is necessary because EVM tracing introduces additional
263-
// (ref_time) overhead, which differs from the production runtime behavior.
264-
// Without resetting the block weight, the extra tracing overhead could
265-
// leading to some transactions to incorrectly fail during tracing.
266-
frame_system::BlockWeight::<Runtime>::kill();
267-
268-
let tx_hash = &transaction.hash();
269-
if known_transactions.contains(&tx_hash) {
270-
// Each known extrinsic is a new call stack.
271-
EvmTracer::emit_new();
272-
EvmTracer::new().trace(|| {
229+
EthereumTracingStatus::wrap(EthereumXcmTracingStatus::Block, || {
230+
let mut config = <Runtime as pallet_evm::Config>::config().clone();
231+
config.estimate = true;
232+
233+
// Initialize block: calls the "on_initialize" hook on every pallet
234+
// in AllPalletsWithSystem.
235+
// After pallet message queue was introduced, this must be done only after
236+
// enabling XCM tracing by setting ETHEREUM_XCM_TRACING_STORAGE_KEY
237+
// in the storage
238+
Executive::initialize_block(header);
239+
240+
// Apply all extrinsics. Ethereum extrinsics are traced.
241+
for ext in extrinsics.into_iter() {
242+
match &ext.0.function {
243+
RuntimeCall::Ethereum(transact { transaction }) => {
244+
245+
// Reset the previously consumed weight when tracing multiple transactions.
246+
// This is necessary because EVM tracing introduces additional
247+
// (ref_time) overhead, which differs from the production runtime behavior.
248+
// Without resetting the block weight, the extra tracing overhead could
249+
// leading to some transactions to incorrectly fail during tracing.
250+
frame_system::BlockWeight::<Runtime>::kill();
251+
252+
let tx_hash = &transaction.hash();
253+
if known_transactions.contains(&tx_hash) {
254+
// Each known extrinsic is a new call stack.
255+
EvmTracer::emit_new();
256+
EvmTracer::new().trace(|| {
257+
if let Err(err) = Executive::apply_extrinsic(ext) {
258+
log::debug!(
259+
target: "tracing",
260+
"Could not trace eth transaction (hash: {}): {:?}",
261+
&tx_hash,
262+
err
263+
);
264+
}
265+
});
266+
} else {
273267
if let Err(err) = Executive::apply_extrinsic(ext) {
274268
log::debug!(
275269
target: "tracing",
276-
"Could not trace eth transaction (hash: {}): {:?}",
270+
"Failed to apply eth extrinsic (hash: {}): {:?}",
277271
&tx_hash,
278272
err
279273
);
280274
}
281-
});
282-
} else {
275+
}
276+
}
277+
_ => {
283278
if let Err(err) = Executive::apply_extrinsic(ext) {
284279
log::debug!(
285280
target: "tracing",
286-
"Failed to apply eth extrinsic (hash: {}): {:?}",
287-
&tx_hash,
281+
"Failed to apply non-eth extrinsic: {:?}",
288282
err
289283
);
290284
}
291285
}
292-
}
293-
_ => {
294-
if let Err(err) = Executive::apply_extrinsic(ext) {
295-
log::debug!(
296-
target: "tracing",
297-
"Failed to apply non-eth extrinsic: {:?}",
298-
err
299-
);
300-
}
301-
}
302-
};
303-
}
286+
};
287+
}
304288

305-
// Replay on_idle
306-
// Some XCM messages with eth-xcm transaction might be executed at on_idle
307-
replay_on_idle();
289+
// Replay on_idle
290+
// Some XCM messages with eth-xcm transaction might be executed at on_idle
291+
replay_on_idle();
308292

309-
Ok(())
293+
Ok(())
294+
})
310295
}
311296
#[cfg(not(feature = "evm-tracing"))]
312297
Err(sp_runtime::DispatchError::Other(

tracing/3600/runtime/common/src/impl_moonbeam_xcm_call_tracing.rs

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#[macro_export]
1818
macro_rules! impl_moonbeam_xcm_call_tracing {
1919
{} => {
20-
20+
use moonbeam_evm_tracer::tracer::EthereumTracingStatus;
2121
type CallResult =
2222
Result<
2323
PostDispatchInfoOf<RuntimeCall>,
@@ -43,8 +43,7 @@ macro_rules! impl_moonbeam_xcm_call_tracing {
4343
use moonbeam_evm_tracer::tracer::EvmTracer;
4444
use xcm_primitives::{
4545
XcmToEthereum,
46-
EthereumXcmTracingStatus,
47-
ETHEREUM_XCM_TRACING_STORAGE_KEY
46+
EthereumXcmTracingStatus
4847
};
4948
use frame_support::storage::unhashed;
5049
use frame_support::traits::Get;
@@ -63,53 +62,50 @@ macro_rules! impl_moonbeam_xcm_call_tracing {
6362
)
6463
};
6564

66-
return match unhashed::get(
67-
ETHEREUM_XCM_TRACING_STORAGE_KEY
68-
) {
65+
return match EthereumTracingStatus::state() {
6966
// This runtime instance is used for tracing.
70-
Some(tracing_status) => match tracing_status {
71-
// Tracing a block, all calls are done using environmental.
72-
EthereumXcmTracingStatus::Block => {
73-
// Each known extrinsic is a new call stack.
74-
EvmTracer::emit_new();
75-
let mut res: Option<CallResult> = None;
76-
EvmTracer::new().trace(|| {
77-
res = Some(dispatch_call());
78-
});
79-
res.expect("Invalid dispatch result")
80-
},
81-
// Tracing a transaction, the one matching the trace request
82-
// is done using environmental, the rest dispatched normally.
83-
EthereumXcmTracingStatus::Transaction(traced_transaction_hash) => {
84-
let transaction_hash = xcm_transaction.into_transaction_v2(
85-
EthereumXcm::nonce(),
86-
<Runtime as pallet_evm::Config>::ChainId::get(),
87-
false
88-
)
89-
.expect("Invalid transaction conversion")
90-
.hash();
91-
if transaction_hash == traced_transaction_hash {
67+
Some(tracing_status) => {
68+
match tracing_status {
69+
// Tracing a block, all calls are done using environmental.
70+
EthereumXcmTracingStatus::Block => {
71+
// Each known extrinsic is a new call stack.
72+
EvmTracer::emit_new();
9273
let mut res: Option<CallResult> = None;
9374
EvmTracer::new().trace(|| {
9475
res = Some(dispatch_call());
9576
});
96-
// Tracing runtime work is done, just signal instance exit.
97-
unhashed::put::<EthereumXcmTracingStatus>(
98-
xcm_primitives::ETHEREUM_XCM_TRACING_STORAGE_KEY,
99-
&EthereumXcmTracingStatus::TransactionExited,
100-
);
101-
return res.expect("Invalid dispatch result");
102-
}
103-
dispatch_call()
104-
},
105-
// Tracing a transaction that has already been found and
106-
// executed. There's no need to dispatch the rest of the
107-
// calls.
108-
EthereumXcmTracingStatus::TransactionExited => Ok(crate::PostDispatchInfo {
109-
actual_weight: None,
110-
pays_fee: frame_support::pallet_prelude::Pays::No,
111-
}),
112-
},
77+
res.expect("Invalid dispatch result")
78+
},
79+
// Tracing a transaction, the one matching the trace request
80+
// is done using environmental, the rest dispatched normally.
81+
EthereumXcmTracingStatus::Transaction(traced_transaction_hash) => {
82+
let transaction_hash = xcm_transaction.into_transaction_v2(
83+
EthereumXcm::nonce(),
84+
<Runtime as pallet_evm::Config>::ChainId::get(),
85+
false
86+
)
87+
.expect("Invalid transaction conversion")
88+
.hash();
89+
if transaction_hash == traced_transaction_hash {
90+
let mut res: Option<CallResult> = None;
91+
EvmTracer::new().trace(|| {
92+
res = Some(dispatch_call());
93+
});
94+
// Tracing runtime work is done, just signal instance exit.
95+
EthereumTracingStatus::update(EthereumXcmTracingStatus::TransactionExited);
96+
return res.expect("Invalid dispatch result");
97+
}
98+
dispatch_call()
99+
},
100+
// Tracing a transaction that has already been found and
101+
// executed. There's no need to dispatch the rest of the
102+
// calls.
103+
EthereumXcmTracingStatus::TransactionExited => Ok(crate::PostDispatchInfo {
104+
actual_weight: None,
105+
pays_fee: frame_support::pallet_prelude::Pays::No,
106+
}),
107+
}
108+
}
113109
// This runtime instance is importing a block.
114110
None => dispatch_call()
115111
};

0 commit comments

Comments
 (0)