55	"errors" 
66	"fmt" 
77	"math/big" 
8- 	"slices " 
8+ 	"strings " 
99
1010	"github.com/goccy/go-json" 
1111	"github.com/onflow/flow-go/fvm/evm/offchain/query" 
@@ -29,6 +29,8 @@ import (
2929	"github.com/onflow/flow-evm-gateway/storage/pebble" 
3030	flowEVM "github.com/onflow/flow-go/fvm/evm" 
3131
32+ 	offchain "github.com/onflow/flow-go/fvm/evm/offchain/storage" 
33+ 
3234	// this import is needed for side-effects, because the 
3335	// tracers.DefaultDirectory is relying on the init function 
3436	_ "github.com/onflow/go-ethereum/eth/tracers/js" 
@@ -302,15 +304,7 @@ func (d *DebugAPI) traceTransaction(
302304		return  nil , err 
303305	}
304306
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 )
314308	if  err  !=  nil  {
315309		return  nil , err 
316310	}
@@ -383,14 +377,7 @@ func (d *DebugAPI) traceBlockByNumber(
383377		return  results , nil 
384378	}
385379
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 )
394381	if  err  !=  nil  {
395382		return  nil , err 
396383	}
@@ -424,19 +411,28 @@ func (d *DebugAPI) traceBlockByNumber(
424411}
425412
426413func  (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 )
428422	if  err  !=  nil  {
429423		return  nil , fmt .Errorf (
430424			"failed to get register snapshot at block height %d: %w" ,
431- 			block .Height ,
425+ 			previousBlock .Height ,
432426			err ,
433427		)
434428	}
435- 	ledger  :=  storage .NewRegisterDelta (snapshot )
429+ 
430+ 	// create storage 
431+ 	state  :=  offchain .NewEphemeralStorage (offchain .NewReadOnlyStorage (snapshot ))
436432
437433	return  evm .NewBlockExecutor (
438434		block ,
439- 		ledger ,
435+ 		state ,
440436		d .config .FlowNetworkID ,
441437		d .blocks ,
442438		d .receipts ,
@@ -484,6 +480,6 @@ func isDefaultCallTracer(config *tracers.TraceConfig) bool {
484480		return  false 
485481	}
486482
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 
489485}
0 commit comments