@@ -376,6 +376,13 @@ func (api *API) traceChain(start, end *types.Block, config *TraceConfig, closed
376
376
failed = err
377
377
break
378
378
}
379
+ // Insert block's parent beacon block root in the state
380
+ // as per EIP-4788.
381
+ if beaconRoot := next .BeaconRoot (); beaconRoot != nil {
382
+ context := core .NewEVMBlockContext (next .Header (), api .chainContext (ctx ), nil )
383
+ vmenv := vm .NewEVM (context , vm.TxContext {}, statedb , api .backend .ChainConfig (), vm.Config {})
384
+ core .ProcessBeaconBlockRoot (* beaconRoot , vmenv , statedb )
385
+ }
379
386
// Clean out any pending release functions of trace state. Note this
380
387
// step must be done after constructing tracing state, because the
381
388
// tracing state of block next depends on the parent state and construction
@@ -517,14 +524,17 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config
517
524
return nil , err
518
525
}
519
526
defer release ()
520
-
521
527
var (
522
528
roots []common.Hash
523
529
signer = types .MakeSigner (api .backend .ChainConfig (), block .Number (), block .Time ())
524
530
chainConfig = api .backend .ChainConfig ()
525
531
vmctx = core .NewEVMBlockContext (block .Header (), api .chainContext (ctx ), nil )
526
532
deleteEmptyObjects = chainConfig .IsEIP158 (block .Number ())
527
533
)
534
+ if beaconRoot := block .BeaconRoot (); beaconRoot != nil {
535
+ vmenv := vm .NewEVM (vmctx , vm.TxContext {}, statedb , chainConfig , vm.Config {})
536
+ core .ProcessBeaconBlockRoot (* beaconRoot , vmenv , statedb )
537
+ }
528
538
for i , tx := range block .Transactions () {
529
539
if err := ctx .Err (); err != nil {
530
540
return nil , err
@@ -584,7 +594,6 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
584
594
return nil , err
585
595
}
586
596
defer release ()
587
-
588
597
// JS tracers have high overhead. In this case run a parallel
589
598
// process that generates states in one thread and traces txes
590
599
// in separate worker threads.
@@ -601,6 +610,10 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
601
610
signer = types .MakeSigner (api .backend .ChainConfig (), block .Number (), block .Time ())
602
611
results = make ([]* txTraceResult , len (txs ))
603
612
)
613
+ if beaconRoot := block .BeaconRoot (); beaconRoot != nil {
614
+ vmenv := vm .NewEVM (blockCtx , vm.TxContext {}, statedb , api .backend .ChainConfig (), vm.Config {})
615
+ core .ProcessBeaconBlockRoot (* beaconRoot , vmenv , statedb )
616
+ }
604
617
for i , tx := range txs {
605
618
// Generate the next state snapshot fast without tracing
606
619
msg , _ := core .TransactionToMessage (tx , signer , block .BaseFee ())
@@ -727,7 +740,6 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
727
740
return nil , err
728
741
}
729
742
defer release ()
730
-
731
743
// Retrieve the tracing configurations, or use default values
732
744
var (
733
745
logConfig logger.Config
@@ -756,6 +768,10 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
756
768
// Note: This copies the config, to not screw up the main config
757
769
chainConfig , canon = overrideConfig (chainConfig , config .Overrides )
758
770
}
771
+ if beaconRoot := block .BeaconRoot (); beaconRoot != nil {
772
+ vmenv := vm .NewEVM (vmctx , vm.TxContext {}, statedb , chainConfig , vm.Config {})
773
+ core .ProcessBeaconBlockRoot (* beaconRoot , vmenv , statedb )
774
+ }
759
775
for i , tx := range block .Transactions () {
760
776
// Prepare the transaction for un-traced execution
761
777
var (
0 commit comments