5
5
"errors"
6
6
"fmt"
7
7
"math/big"
8
- "slices "
8
+ "strings "
9
9
10
10
"github.com/goccy/go-json"
11
11
"github.com/onflow/flow-go/fvm/evm/offchain/query"
@@ -29,6 +29,8 @@ import (
29
29
"github.com/onflow/flow-evm-gateway/storage/pebble"
30
30
flowEVM "github.com/onflow/flow-go/fvm/evm"
31
31
32
+ offchain "github.com/onflow/flow-go/fvm/evm/offchain/storage"
33
+
32
34
// this import is needed for side-effects, because the
33
35
// tracers.DefaultDirectory is relying on the init function
34
36
_ "github.com/onflow/go-ethereum/eth/tracers/js"
@@ -302,15 +304,7 @@ func (d *DebugAPI) traceTransaction(
302
304
return nil , err
303
305
}
304
306
305
- // We need to re-execute the given transaction and all the
306
- // transactions that precede it in the same block, based on
307
- // the previous block state, to generate the correct trace.
308
- previousBlock , err := d .blocks .GetByHeight (block .Height - 1 )
309
- if err != nil {
310
- return nil , err
311
- }
312
-
313
- blockExecutor , err := d .executorAtBlock (previousBlock )
307
+ blockExecutor , err := d .executorAtBlock (block )
314
308
if err != nil {
315
309
return nil , err
316
310
}
@@ -383,14 +377,7 @@ func (d *DebugAPI) traceBlockByNumber(
383
377
return results , nil
384
378
}
385
379
386
- // We need to re-execute all the transactions from the given block,
387
- // on top of the previous block state, to generate the correct traces.
388
- previousBlock , err := d .blocks .GetByHeight (block .Height - 1 )
389
- if err != nil {
390
- return nil , err
391
- }
392
-
393
- blockExecutor , err := d .executorAtBlock (previousBlock )
380
+ blockExecutor , err := d .executorAtBlock (block )
394
381
if err != nil {
395
382
return nil , err
396
383
}
@@ -424,19 +411,28 @@ func (d *DebugAPI) traceBlockByNumber(
424
411
}
425
412
426
413
func (d * DebugAPI ) executorAtBlock (block * models.Block ) (* evm.BlockExecutor , error ) {
427
- snapshot , err := d .registerStore .GetSnapshotAt (block .Height )
414
+ previousBlock , err := d .blocks .GetByHeight (block .Height - 1 )
415
+ if err != nil {
416
+ return nil , err
417
+ }
418
+
419
+ // We need to re-execute all the transactions from the given block,
420
+ // on top of the previous block state, to generate the correct traces.
421
+ snapshot , err := d .registerStore .GetSnapshotAt (previousBlock .Height )
428
422
if err != nil {
429
423
return nil , fmt .Errorf (
430
424
"failed to get register snapshot at block height %d: %w" ,
431
- block .Height ,
425
+ previousBlock .Height ,
432
426
err ,
433
427
)
434
428
}
435
- ledger := storage .NewRegisterDelta (snapshot )
429
+
430
+ // create storage
431
+ state := offchain .NewEphemeralStorage (offchain .NewReadOnlyStorage (snapshot ))
436
432
437
433
return evm .NewBlockExecutor (
438
434
block ,
439
- ledger ,
435
+ state ,
440
436
d .config .FlowNetworkID ,
441
437
d .blocks ,
442
438
d .receipts ,
@@ -484,6 +480,6 @@ func isDefaultCallTracer(config *tracers.TraceConfig) bool {
484
480
return false
485
481
}
486
482
487
- tracerConfig := json . RawMessage ( replayer .TracerConfig )
488
- return slices . Equal ( config . TracerConfig , tracerConfig )
483
+ trimmedConfig := strings . ReplaceAll ( string ( config .TracerConfig ), " " , "" )
484
+ return trimmedConfig == replayer . TracerConfig
489
485
}
0 commit comments