internal/ethapi: apply block overrides to header in eth_call (#34842)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

Apply block overrides to header in eth_call so EIP-1559 fee fields
use the correct overridden basefee.
This commit is contained in:
rayoo 2026-05-02 02:32:49 +08:00 committed by GitHub
parent 8656efcf5b
commit 7155c65abb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View file

@ -734,6 +734,10 @@ func doCall(ctx context.Context, b Backend, args TransactionArgs, state *state.S
if err := blockOverrides.Apply(&blockCtx); err != nil {
return nil, err
}
// Override the header so callers that compute gas price from 1559 fee
// fields see the overridden basefee. Otherwise GASPRICE/effectiveTip
// would be derived from the pre-override basefee.
header = blockOverrides.MakeHeader(header)
}
rules := b.ChainConfig().Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time)
precompiles := vm.ActivePrecompiledContracts(rules)

View file

@ -1315,6 +1315,27 @@ func TestCall(t *testing.T) {
},
expectErr: errors.New(`block override "withdrawals" is not supported for this RPC method`),
},
// Verify that an overridden basefee is honored when computing gasPrice
// from the 1559 fee fields. Returning GASPRICE opcode; expected value
// is min(MaxFeePerGas, MaxPriorityFeePerGas + overridden BaseFee).
//
// BaseFee override = 0xa (10); MaxFeePerGas = 0x64 (100);
// MaxPriorityFeePerGas = 0x2 (2); expected GASPRICE = 12.
{
name: "basefee-override-used-in-gasprice",
blockNumber: rpc.LatestBlockNumber,
call: TransactionArgs{
From: &accounts[0].addr,
// Contract: GASPRICE; PUSH1 0; MSTORE; PUSH1 32; PUSH1 0; RETURN
Input: hex2Bytes("3a60005260206000f3"),
MaxFeePerGas: (*hexutil.Big)(big.NewInt(100)),
MaxPriorityFeePerGas: (*hexutil.Big)(big.NewInt(2)),
},
blockOverrides: override.BlockOverrides{
BaseFeePerGas: (*hexutil.Big)(big.NewInt(10)),
},
want: "0x000000000000000000000000000000000000000000000000000000000000000c",
},
}
for _, tc := range testSuite {
result, err := api.Call(context.Background(), tc.call, &rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, &tc.overrides, &tc.blockOverrides)