mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
move out base fee lowering to api code
This commit is contained in:
parent
9139685944
commit
569a2d7f55
3 changed files with 25 additions and 12 deletions
|
|
@ -117,17 +117,6 @@ type EVM struct {
|
|||
// NewEVM returns a new EVM. The returned EVM is not thread safe and should
|
||||
// only ever be used *once*.
|
||||
func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig *params.ChainConfig, config Config) *EVM {
|
||||
// If basefee tracking is disabled (eth_call, eth_estimateGas, etc), and no
|
||||
// gas prices were specified, lower the basefee to 0 to avoid breaking EVM
|
||||
// invariants (basefee < feecap)
|
||||
if config.NoBaseFee {
|
||||
if txCtx.GasPrice.BitLen() == 0 {
|
||||
blockCtx.BaseFee = new(big.Int)
|
||||
}
|
||||
if txCtx.BlobFeeCap != nil && txCtx.BlobFeeCap.BitLen() == 0 {
|
||||
blockCtx.BlobBaseFee = new(big.Int)
|
||||
}
|
||||
}
|
||||
evm := &EVM{
|
||||
Context: blockCtx,
|
||||
TxContext: txCtx,
|
||||
|
|
|
|||
|
|
@ -211,8 +211,16 @@ func run(ctx context.Context, call *core.Message, opts *Options) (*core.Executio
|
|||
evmContext = core.NewEVMBlockContext(opts.Header, opts.Chain, nil)
|
||||
|
||||
dirtyState = opts.State.Copy()
|
||||
evm = vm.NewEVM(evmContext, msgContext, dirtyState, opts.Config, vm.Config{NoBaseFee: true})
|
||||
)
|
||||
// Lower the basefee to 0 to avoid breaking EVM
|
||||
// invariants (basefee < feecap).
|
||||
if msgContext.GasPrice.Sign() == 0 {
|
||||
evmContext.BaseFee = new(big.Int)
|
||||
}
|
||||
if msgContext.BlobFeeCap != nil && msgContext.BlobFeeCap.BitLen() == 0 {
|
||||
evmContext.BlobBaseFee = new(big.Int)
|
||||
}
|
||||
evm := vm.NewEVM(evmContext, msgContext, dirtyState, opts.Config, vm.Config{NoBaseFee: true})
|
||||
// Monitor the outer context and interrupt the EVM upon cancellation. To avoid
|
||||
// a dangling goroutine until the outer estimation finishes, create an internal
|
||||
// context for the lifetime of this method call.
|
||||
|
|
|
|||
|
|
@ -1156,6 +1156,14 @@ func applyMessage(ctx context.Context, b Backend, args TransactionArgs, state *s
|
|||
return nil, err
|
||||
}
|
||||
msg := args.ToMessage(header.BaseFee, skipChecks)
|
||||
// Lower the basefee to 0 to avoid breaking EVM
|
||||
// invariants (basefee < feecap).
|
||||
if msg.GasPrice.Sign() == 0 {
|
||||
blockContext.BaseFee = new(big.Int)
|
||||
}
|
||||
if msg.BlobGasFeeCap != nil && msg.BlobGasFeeCap.BitLen() == 0 {
|
||||
blockContext.BlobBaseFee = new(big.Int)
|
||||
}
|
||||
evm := b.GetEVM(ctx, msg, state, header, vmConfig, blockContext)
|
||||
if precompiles != nil {
|
||||
evm.SetPrecompiles(precompiles)
|
||||
|
|
@ -1606,6 +1614,14 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
|
|||
tracer := logger.NewAccessListTracer(accessList, args.from(), to, precompiles)
|
||||
config := vm.Config{Tracer: tracer.Hooks(), NoBaseFee: true}
|
||||
vmenv := b.GetEVM(ctx, msg, statedb, header, &config, nil)
|
||||
// Lower the basefee to 0 to avoid breaking EVM
|
||||
// invariants (basefee < feecap).
|
||||
if msg.GasPrice.Sign() == 0 {
|
||||
vmenv.Context.BaseFee = new(big.Int)
|
||||
}
|
||||
if msg.BlobGasFeeCap != nil && msg.BlobGasFeeCap.BitLen() == 0 {
|
||||
vmenv.Context.BlobBaseFee = new(big.Int)
|
||||
}
|
||||
res, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.GasLimit))
|
||||
if err != nil {
|
||||
return nil, 0, nil, fmt.Errorf("failed to apply transaction: %v err: %v", args.ToTransaction(false).Hash(), err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue