@@ -147,75 +147,63 @@ macro_rules! impl_runtime_apis_plus_common {
147
147
> {
148
148
#[ cfg( feature = "evm-tracing" ) ]
149
149
{
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 ;
155
152
use frame_support:: storage:: unhashed;
156
153
use frame_system:: pallet_prelude:: BlockNumberFor ;
157
154
158
155
// 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
+ }
189
182
}
183
+ _ => Executive :: apply_extrinsic( ext) ,
184
+ } ;
185
+
186
+ if let Some ( EthereumXcmTracingStatus :: TransactionExited ) = EthereumTracingStatus :: state( ) {
187
+ return Ok ( ( ) ) ;
190
188
}
191
- _ => Executive :: apply_extrinsic( ext) ,
192
- } ;
193
- if let Some ( EthereumXcmTracingStatus :: TransactionExited ) = unhashed:: get(
194
- ETHEREUM_XCM_TRACING_STORAGE_KEY
195
- ) {
196
- return Ok ( ( ) ) ;
197
189
}
198
- }
199
190
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
+ }
207
196
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
+ } )
219
207
}
220
208
#[ cfg( not( feature = "evm-tracing" ) ) ]
221
209
Err ( sp_runtime:: DispatchError :: Other (
@@ -233,80 +221,77 @@ macro_rules! impl_runtime_apis_plus_common {
233
221
> {
234
222
#[ cfg( feature = "evm-tracing" ) ]
235
223
{
236
- use moonbeam_evm_tracer:: tracer:: EvmTracer ;
224
+ use moonbeam_evm_tracer:: tracer:: { EthereumTracingStatus , EvmTracer } ;
237
225
use frame_system:: pallet_prelude:: BlockNumberFor ;
238
226
use xcm_primitives:: EthereumXcmTracingStatus ;
239
227
240
228
// 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 {
273
267
if let Err ( err) = Executive :: apply_extrinsic( ext) {
274
268
log:: debug!(
275
269
target: "tracing" ,
276
- "Could not trace eth transaction (hash: {}): {:?}" ,
270
+ "Failed to apply eth extrinsic (hash: {}): {:?}" ,
277
271
& tx_hash,
278
272
err
279
273
) ;
280
274
}
281
- } ) ;
282
- } else {
275
+ }
276
+ }
277
+ _ => {
283
278
if let Err ( err) = Executive :: apply_extrinsic( ext) {
284
279
log:: debug!(
285
280
target: "tracing" ,
286
- "Failed to apply eth extrinsic (hash: {}): {:?}" ,
287
- & tx_hash,
281
+ "Failed to apply non-eth extrinsic: {:?}" ,
288
282
err
289
283
) ;
290
284
}
291
285
}
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
+ }
304
288
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( ) ;
308
292
309
- Ok ( ( ) )
293
+ Ok ( ( ) )
294
+ } )
310
295
}
311
296
#[ cfg( not( feature = "evm-tracing" ) ) ]
312
297
Err ( sp_runtime:: DispatchError :: Other (
0 commit comments