Skip to content

Commit ca62042

Browse files
addressing a few last nits around data gas (ethereum#31)
1 parent dc3740c commit ca62042

File tree

9 files changed

+30
-31
lines changed

9 files changed

+30
-31
lines changed

core/error.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ var (
5959
// by a transaction is higher than what's left in the block.
6060
ErrGasLimitReached = errors.New("gas limit reached")
6161

62+
// ErrDataGasLimitReached is returned by the gas pool if the amount of data gas required by a
63+
// transaction is higher than what's left in the block.
64+
ErrDataGasLimitReached = errors.New("data gas limit reached")
65+
6266
// ErrInsufficientFundsForTransfer is returned if the transaction sender doesn't
6367
// have enough funds for transfer(topmost call only).
6468
ErrInsufficientFundsForTransfer = errors.New("insufficient funds for transfer")

core/gaspool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (gp *GasPool) AddDataGas(amount uint64) *GasPool {
6464
// error otherwise.
6565
func (gp *GasPool) SubDataGas(amount uint64) error {
6666
if gp.dataGas < amount {
67-
return ErrGasLimitReached
67+
return ErrDataGasLimitReached
6868
}
6969
gp.dataGas -= amount
7070
return nil

core/state_transition.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
387387
ret, st.gas, vmerr = st.evm.Call(sender, st.to(), st.data, st.gas, st.value)
388388
}
389389

390-
// TODO: Also refund datagas if tx is rejected
390+
// Note that unlike regular gas, data fee gas is not refunded if the tx is reverted, per
391+
// EIP-4844 spec.
391392
if !rules.IsLondon {
392393
// Before EIP-3529: refunds were capped to gasUsed / 2
393394
st.refundGas(params.RefundQuotient)

eth/api_backend.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,21 @@ func (b *EthAPIBackend) GetTd(ctx context.Context, hash common.Hash) *big.Int {
212212
return nil
213213
}
214214

215-
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) {
215+
func (b *EthAPIBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error) {
216216
vmError := func() error { return nil }
217217
if vmConfig == nil {
218218
vmConfig = b.eth.blockchain.GetVMConfig()
219219
}
220220
txContext := core.NewEVMTxContext(msg)
221+
var excessDataGas *big.Int
222+
ph, err := b.HeaderByHash(ctx, header.ParentHash)
223+
224+
if err != nil {
225+
return nil, vmError, err
226+
}
227+
if ph != nil {
228+
excessDataGas = ph.ExcessDataGas
229+
}
221230
context := core.NewEVMBlockContext(header, excessDataGas, b.eth.BlockChain(), nil)
222231
return vm.NewEVM(context, txContext, state, b.eth.blockchain.Config(), *vmConfig), vmError, nil
223232
}

internal/ethapi/api.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -953,15 +953,7 @@ func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash
953953
if err != nil {
954954
return nil, err
955955
}
956-
var excessDataGas *big.Int
957-
ph, err := b.HeaderByHash(ctx, header.ParentHash)
958-
if err != nil {
959-
return nil, err
960-
}
961-
if ph != nil {
962-
excessDataGas = ph.ExcessDataGas
963-
}
964-
evm, vmError, err := b.GetEVM(ctx, msg, state, header, excessDataGas, &vm.Config{NoBaseFee: true})
956+
evm, vmError, err := b.GetEVM(ctx, msg, state, header, &vm.Config{NoBaseFee: true})
965957
if err != nil {
966958
return nil, err
967959
}
@@ -1454,15 +1446,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
14541446
// Apply the transaction with the access list tracer
14551447
tracer := logger.NewAccessListTracer(accessList, args.from(), to, precompiles)
14561448
config := vm.Config{Tracer: tracer, Debug: true, NoBaseFee: true}
1457-
var excessDataGas *big.Int
1458-
ph, err := b.HeaderByHash(ctx, header.ParentHash)
1459-
if err != nil {
1460-
return nil, 0, nil, err
1461-
}
1462-
if ph != nil {
1463-
excessDataGas = ph.ExcessDataGas
1464-
}
1465-
vmenv, _, err := b.GetEVM(ctx, msg, statedb, header, excessDataGas, &config)
1449+
vmenv, _, err := b.GetEVM(ctx, msg, statedb, header, &config)
14661450
if err != nil {
14671451
return nil, 0, nil, err
14681452
}

internal/ethapi/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type Backend interface {
6868
PendingBlockAndReceipts() (*types.Block, types.Receipts)
6969
GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
7070
GetTd(ctx context.Context, hash common.Hash) *big.Int
71-
GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, excessDataGas *big.Int, vmConfig *vm.Config) (*vm.EVM, func() error, error)
71+
GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error)
7272
SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
7373
SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
7474
SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription

internal/ethapi/transaction_args_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func (b *backendMock) GetLogs(ctx context.Context, blockHash common.Hash, number
302302
return nil, nil
303303
}
304304
func (b *backendMock) GetTd(ctx context.Context, hash common.Hash) *big.Int { return nil }
305-
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) {
305+
func (b *backendMock) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error) {
306306
return nil, nil, nil
307307
}
308308
func (b *backendMock) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription { return nil }

les/api_backend.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,19 @@ func (b *LesApiBackend) GetTd(ctx context.Context, hash common.Hash) *big.Int {
179179
return nil
180180
}
181181

182-
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) {
182+
func (b *LesApiBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error) {
183183
if vmConfig == nil {
184184
vmConfig = new(vm.Config)
185185
}
186186
txContext := core.NewEVMTxContext(msg)
187+
var excessDataGas *big.Int
188+
ph, err := b.HeaderByHash(ctx, header.ParentHash)
189+
if err != nil {
190+
return nil, state.Error, err
191+
}
192+
if ph != nil {
193+
excessDataGas = ph.ExcessDataGas
194+
}
187195
context := core.NewEVMBlockContext(header, excessDataGas, b.eth.blockchain, nil)
188196
return vm.NewEVM(context, txContext, state, b.eth.chainConfig, *vmConfig), state.Error, nil
189197
}

miner/worker.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ type environment struct {
100100
txs []*types.Transaction
101101
receipts []*types.Receipt
102102
uncles map[common.Hash]*types.Header
103-
numBlobs int
104103
}
105104

106105
// copy creates a deep copy of environment.
@@ -837,19 +836,13 @@ func (w *worker) updateSnapshot(env *environment) {
837836
func (w *worker) commitTransaction(env *environment, tx *types.Transaction) ([]*types.Log, error) {
838837
snap := env.state.Snapshot()
839838

840-
txBlobCount := len(tx.DataHashes())
841-
if env.numBlobs+txBlobCount > params.MaxBlobsPerBlock {
842-
return nil, errMaxBlobsReached
843-
}
844-
845839
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())
846840
if err != nil {
847841
env.state.RevertToSnapshot(snap)
848842
return nil, err
849843
}
850844
env.txs = append(env.txs, tx)
851845
env.receipts = append(env.receipts, receipt)
852-
env.numBlobs += txBlobCount
853846

854847
return receipt.Logs, nil
855848
}

0 commit comments

Comments
 (0)