diff --git a/core/error.go b/core/error.go index f06d661fdcde..65844697d4a6 100644 --- a/core/error.go +++ b/core/error.go @@ -59,6 +59,10 @@ var ( // by a transaction is higher than what's left in the block. ErrGasLimitReached = errors.New("gas limit reached") + // ErrDataGasLimitReached is returned by the gas pool if the amount of data gas required by a + // transaction is higher than what's left in the block. + ErrDataGasLimitReached = errors.New("data gas limit reached") + // ErrInsufficientFundsForTransfer is returned if the transaction sender doesn't // have enough funds for transfer(topmost call only). ErrInsufficientFundsForTransfer = errors.New("insufficient funds for transfer") diff --git a/core/gaspool.go b/core/gaspool.go index e3ea3c77e2a2..963a7759a97d 100644 --- a/core/gaspool.go +++ b/core/gaspool.go @@ -64,7 +64,7 @@ func (gp *GasPool) AddDataGas(amount uint64) *GasPool { // error otherwise. func (gp *GasPool) SubDataGas(amount uint64) error { if gp.dataGas < amount { - return ErrGasLimitReached + return ErrDataGasLimitReached } gp.dataGas -= amount return nil diff --git a/core/state_transition.go b/core/state_transition.go index b1024e9113b3..d94f84a6daf6 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -387,7 +387,8 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { ret, st.gas, vmerr = st.evm.Call(sender, st.to(), st.data, st.gas, st.value) } - // TODO: Also refund datagas if tx is rejected + // Note that unlike regular gas, data fee gas is not refunded if the tx is reverted, per + // EIP-4844 spec. if !rules.IsLondon { // Before EIP-3529: refunds were capped to gasUsed / 2 st.refundGas(params.RefundQuotient) diff --git a/eth/api_backend.go b/eth/api_backend.go index df0de9b021ba..d8f6ea7052c5 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -212,12 +212,21 @@ func (b *EthAPIBackend) GetTd(ctx context.Context, hash common.Hash) *big.Int { return nil } -func (b *EthAPIBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, excessDataGas *big.Int, vmConfig *vm.Config) (*vm.EVM, func() error, error) { +func (b *EthAPIBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error) { vmError := func() error { return nil } if vmConfig == nil { vmConfig = b.eth.blockchain.GetVMConfig() } txContext := core.NewEVMTxContext(msg) + var excessDataGas *big.Int + ph, err := b.HeaderByHash(ctx, header.ParentHash) + + if err != nil { + return nil, vmError, err + } + if ph != nil { + excessDataGas = ph.ExcessDataGas + } context := core.NewEVMBlockContext(header, excessDataGas, b.eth.BlockChain(), nil) return vm.NewEVM(context, txContext, state, b.eth.blockchain.Config(), *vmConfig), vmError, nil } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index b0932780732a..829c5169167a 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -953,15 +953,7 @@ func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash if err != nil { return nil, err } - var excessDataGas *big.Int - ph, err := b.HeaderByHash(ctx, header.ParentHash) - if err != nil { - return nil, err - } - if ph != nil { - excessDataGas = ph.ExcessDataGas - } - evm, vmError, err := b.GetEVM(ctx, msg, state, header, excessDataGas, &vm.Config{NoBaseFee: true}) + evm, vmError, err := b.GetEVM(ctx, msg, state, header, &vm.Config{NoBaseFee: true}) if err != nil { return nil, err } @@ -1454,15 +1446,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH // Apply the transaction with the access list tracer tracer := logger.NewAccessListTracer(accessList, args.from(), to, precompiles) config := vm.Config{Tracer: tracer, Debug: true, NoBaseFee: true} - var excessDataGas *big.Int - ph, err := b.HeaderByHash(ctx, header.ParentHash) - if err != nil { - return nil, 0, nil, err - } - if ph != nil { - excessDataGas = ph.ExcessDataGas - } - vmenv, _, err := b.GetEVM(ctx, msg, statedb, header, excessDataGas, &config) + vmenv, _, err := b.GetEVM(ctx, msg, statedb, header, &config) if err != nil { return nil, 0, nil, err } diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 426f69a88e88..5b4ceb631069 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -68,7 +68,7 @@ type Backend interface { PendingBlockAndReceipts() (*types.Block, types.Receipts) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) GetTd(ctx context.Context, hash common.Hash) *big.Int - GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, excessDataGas *big.Int, vmConfig *vm.Config) (*vm.EVM, func() error, error) + GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index c365b12d97ed..28dc561c36e4 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -302,7 +302,7 @@ func (b *backendMock) GetLogs(ctx context.Context, blockHash common.Hash, number return nil, nil } func (b *backendMock) GetTd(ctx context.Context, hash common.Hash) *big.Int { return nil } -func (b *backendMock) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, excessDataGas *big.Int, vmConfig *vm.Config) (*vm.EVM, func() error, error) { +func (b *backendMock) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error) { return nil, nil, nil } func (b *backendMock) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription { return nil } diff --git a/les/api_backend.go b/les/api_backend.go index 946d77afd1bf..f0daeee23860 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -179,11 +179,19 @@ func (b *LesApiBackend) GetTd(ctx context.Context, hash common.Hash) *big.Int { return nil } -func (b *LesApiBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, excessDataGas *big.Int, vmConfig *vm.Config) (*vm.EVM, func() error, error) { +func (b *LesApiBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error) { if vmConfig == nil { vmConfig = new(vm.Config) } txContext := core.NewEVMTxContext(msg) + var excessDataGas *big.Int + ph, err := b.HeaderByHash(ctx, header.ParentHash) + if err != nil { + return nil, state.Error, err + } + if ph != nil { + excessDataGas = ph.ExcessDataGas + } context := core.NewEVMBlockContext(header, excessDataGas, b.eth.blockchain, nil) return vm.NewEVM(context, txContext, state, b.eth.chainConfig, *vmConfig), state.Error, nil } diff --git a/miner/worker.go b/miner/worker.go index c7aecb793c54..e83afe1ecd9a 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -100,7 +100,6 @@ type environment struct { txs []*types.Transaction receipts []*types.Receipt uncles map[common.Hash]*types.Header - numBlobs int } // copy creates a deep copy of environment. @@ -837,11 +836,6 @@ func (w *worker) updateSnapshot(env *environment) { func (w *worker) commitTransaction(env *environment, tx *types.Transaction) ([]*types.Log, error) { snap := env.state.Snapshot() - txBlobCount := len(tx.DataHashes()) - if env.numBlobs+txBlobCount > params.MaxBlobsPerBlock { - return nil, errMaxBlobsReached - } - receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &env.coinbase, env.gasPool, env.state, env.header, env.excessDataGas, tx, &env.header.GasUsed, *w.chain.GetVMConfig()) if err != nil { env.state.RevertToSnapshot(snap) @@ -849,7 +843,6 @@ func (w *worker) commitTransaction(env *environment, tx *types.Transaction) ([]* } env.txs = append(env.txs, tx) env.receipts = append(env.receipts, receipt) - env.numBlobs += txBlobCount return receipt.Logs, nil }