apply block header overrides to enable get the correct blockhash

This commit is contained in:
shantichanal 2025-07-10 19:26:34 +02:00
parent 355228b011
commit 78c435f590
2 changed files with 31 additions and 1 deletions

View file

@ -953,7 +953,14 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
}
defer release()
vmctx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
hdr := *block.Header()
if config != nil {
if err := config.BlockOverrides.ApplyHeader(&hdr); err != nil {
return nil, err
}
}
vmctx := core.NewEVMBlockContext(&hdr, api.chainContext(ctx), nil)
// Apply the customization rules if required.
if config != nil {
if overrideErr := config.BlockOverrides.Apply(&vmctx); overrideErr != nil {

View file

@ -171,6 +171,29 @@ func (o *BlockOverrides) Apply(blockCtx *vm.BlockContext) error {
return nil
}
func (o *BlockOverrides) ApplyHeader(h *types.Header) error {
if o == nil {
return nil
}
if o.Number != nil {
h.Number = o.Number.ToInt()
}
if o.Time != nil {
h.Time = uint64(*o.Time)
}
if o.GasLimit != nil {
h.GasLimit = uint64(*o.GasLimit)
}
if o.Difficulty != nil {
h.Difficulty = o.Difficulty.ToInt()
}
if o.BaseFeePerGas != nil {
h.BaseFee = o.BaseFeePerGas.ToInt()
}
return nil
}
// MakeHeader returns a new header object with the overridden
// fields.
// Note: MakeHeader ignores BlobBaseFee if set. That's because