Skip to content

Commit ce2498e

Browse files
committed
Use blocktime not blocknumber
1 parent a39317a commit ce2498e

File tree

20 files changed

+48
-43
lines changed

20 files changed

+48
-43
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
640640
vmEnv := vm.NewEVM(evmContext, txContext, stateDB, b.config, vm.Config{NoBaseFee: true})
641641
gasPool := new(core.GasPool).AddGas(math.MaxUint64)
642642
signer := types.MakeSigner(b.blockchain.Config(), head.Number, head.Time)
643-
l1DataFee, err := fees.EstimateL1DataFeeForMessage(msg, head.BaseFee, b.blockchain.Config(), signer, stateDB, head.Number)
643+
l1DataFee, err := fees.EstimateL1DataFeeForMessage(msg, head.BaseFee, b.blockchain.Config(), signer, stateDB, head.Number, head.Time)
644644
if err != nil {
645645
return nil, err
646646
}

cmd/evm/internal/t8ntool/execution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
180180
snapshot := statedb.Snapshot()
181181
evm := vm.NewEVM(vmContext, txContext, statedb, chainConfig, vmConfig)
182182

183-
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, chainConfig, new(big.Int).SetUint64(pre.Env.Number))
183+
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, chainConfig, new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp)
184184
if err != nil {
185185
log.Info("rejected tx due to fees.CalculateL1DataFee", "index", i, "hash", tx.Hash(), "from", msg.From(), "error", err)
186186
rejectedTxs = append(rejectedTxs, &rejectedTx{i, err.Error()})

core/state_prefetcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c
7171
}
7272
statedb.SetTxContext(tx.Hash(), i)
7373

74-
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, p.config, block.Number())
74+
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, p.config, block.Number(), block.Time())
7575
if err != nil {
7676
return
7777
}

core/state_processor.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
8080
header = block.Header()
8181
blockHash = block.Hash()
8282
blockNumber = block.Number()
83+
blockTime = block.Time()
8384
allLogs []*types.Log
8485
gp = new(GasPool).AddGas(block.GasLimit())
8586
)
@@ -105,7 +106,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
105106
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
106107
}
107108
statedb.SetTxContext(tx.Hash(), i)
108-
receipt, err := applyTransaction(msg, p.config, p.bc, nil, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv)
109+
receipt, err := applyTransaction(msg, p.config, p.bc, nil, gp, statedb, blockNumber, blockTime, blockHash, tx, usedGas, vmenv)
109110
if err != nil {
110111
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
111112
}
@@ -120,7 +121,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
120121
return receipts, allLogs, *usedGas, nil
121122
}
122123

123-
func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, error) {
124+
func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockTime uint64, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, error) {
124125
defer func(t0 time.Time) {
125126
applyTransactionTimer.Update(time.Since(t0))
126127
}(time.Now())
@@ -129,7 +130,7 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
129130
txContext := NewEVMTxContext(msg)
130131
evm.Reset(txContext, statedb)
131132

132-
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, config, blockNumber)
133+
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, config, blockNumber, blockTime)
133134
if err != nil {
134135
return nil, err
135136
}
@@ -201,7 +202,7 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
201202
// Create a new context to be used in the EVM environment
202203
blockContext := NewEVMBlockContext(header, bc, config, author)
203204
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg)
204-
return applyTransaction(msg, config, bc, author, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv)
205+
return applyTransaction(msg, config, bc, author, gp, statedb, header.Number, header.Time, header.Hash(), tx, usedGas, vmenv)
205206
}
206207

207208
// ProcessParentBlockHash stores the parent block hash in the history storage contract

core/tx_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (l *txList) Overlaps(tx *types.Transaction) bool {
282282
//
283283
// If the new transaction is accepted into the list, the lists' cost and gas
284284
// thresholds are also potentially updated.
285-
func (l *txList) Add(tx *types.Transaction, state *state.StateDB, priceBump uint64, chainconfig *params.ChainConfig, blockNumber *big.Int) (bool, *types.Transaction) {
285+
func (l *txList) Add(tx *types.Transaction, state *state.StateDB, priceBump uint64, chainconfig *params.ChainConfig, blockNumber *big.Int, blockTime uint64) (bool, *types.Transaction) {
286286
// If there's an older better transaction, abort
287287
old := l.txs.Get(tx.Nonce())
288288
if old != nil {
@@ -310,7 +310,7 @@ func (l *txList) Add(tx *types.Transaction, state *state.StateDB, priceBump uint
310310
l1DataFee := big.NewInt(0)
311311
if state != nil && chainconfig != nil {
312312
var err error
313-
l1DataFee, err = fees.CalculateL1DataFee(tx, state, chainconfig, blockNumber)
313+
l1DataFee, err = fees.CalculateL1DataFee(tx, state, chainconfig, blockNumber, blockTime)
314314
if err != nil {
315315
log.Error("Failed to calculate L1 data fee", "err", err, "tx", tx)
316316
return false, nil

core/tx_list_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestStrictTxListAdd(t *testing.T) {
3838
// Insert the transactions in a random order
3939
list := newTxList(true)
4040
for _, v := range rand.Perm(len(txs)) {
41-
list.Add(txs[v], nil, DefaultTxPoolConfig.PriceBump, nil, nil)
41+
list.Add(txs[v], nil, DefaultTxPoolConfig.PriceBump, nil, nil, 0)
4242
}
4343
// Verify internal state
4444
if len(list.txs.items) != len(txs) {
@@ -65,7 +65,7 @@ func BenchmarkTxListAdd(b *testing.B) {
6565
for i := 0; i < b.N; i++ {
6666
list := newTxList(true)
6767
for _, v := range rand.Perm(len(txs)) {
68-
list.Add(txs[v], nil, DefaultTxPoolConfig.PriceBump, nil, nil)
68+
list.Add(txs[v], nil, DefaultTxPoolConfig.PriceBump, nil, nil, 0)
6969
list.Filter(priceLimit, DefaultTxPoolConfig.PriceBump)
7070
}
7171
}

core/tx_pool.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ type TxPool struct {
301301

302302
currentState *state.StateDB // Current state in the blockchain head
303303
currentHead *big.Int // Current blockchain head
304+
currentTime uint64 // Current blockchain head time
304305
pendingNonces *txNoncer // Pending state tracking virtual nonces
305306
currentMaxGas uint64 // Current gas limit for transaction caps
306307

@@ -838,7 +839,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
838839
// 2. If FeeVault is enabled, perform an additional check for L1 data fees.
839840
if pool.chainconfig.Scroll.FeeVaultEnabled() {
840841
// Get L1 data fee in current state
841-
l1DataFee, err := fees.CalculateL1DataFee(tx, pool.currentState, pool.chainconfig, pool.currentHead)
842+
l1DataFee, err := fees.CalculateL1DataFee(tx, pool.currentState, pool.chainconfig, pool.currentHead, pool.currentTime)
842843
if err != nil {
843844
return fmt.Errorf("failed to calculate L1 data fee, err: %w", err)
844845
}
@@ -947,7 +948,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
947948
from, _ := types.Sender(pool.signer, tx) // already validated
948949
if list := pool.pending[from]; list != nil && list.Overlaps(tx) {
949950
// Nonce already pending, check if required price bump is met
950-
inserted, old := list.Add(tx, pool.currentState, pool.config.PriceBump, pool.chainconfig, pool.currentHead)
951+
inserted, old := list.Add(tx, pool.currentState, pool.config.PriceBump, pool.chainconfig, pool.currentHead, pool.currentTime)
951952
if !inserted {
952953
log.Debug("Discarding underpriced pending transaction", "hash", hash.Hex(), "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap())
953954
pendingDiscardMeter.Mark(1)
@@ -1001,7 +1002,7 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction, local boo
10011002
pool.queue[from] = newTxList(false)
10021003
}
10031004

1004-
inserted, old := pool.queue[from].Add(tx, pool.currentState, pool.config.PriceBump, pool.chainconfig, pool.currentHead)
1005+
inserted, old := pool.queue[from].Add(tx, pool.currentState, pool.config.PriceBump, pool.chainconfig, pool.currentHead, pool.currentTime)
10051006
if !inserted {
10061007
// An older transaction was better, discard this
10071008
log.Debug("Discarding underpriced queued transaction", "hash", hash.Hex(), "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap())
@@ -1068,7 +1069,7 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
10681069
return false
10691070
}
10701071

1071-
inserted, old := list.Add(tx, pool.currentState, pool.config.PriceBump, pool.chainconfig, pool.currentHead)
1072+
inserted, old := list.Add(tx, pool.currentState, pool.config.PriceBump, pool.chainconfig, pool.currentHead, pool.currentTime)
10721073
if !inserted {
10731074
// An older transaction was better, discard this
10741075
log.Debug("Discarding underpriced pending transaction", "hash", hash.Hex(), "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap())
@@ -1603,6 +1604,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
16031604

16041605
// Update current head
16051606
pool.currentHead = next
1607+
pool.currentTime = newHead.Time
16061608
}
16071609

16081610
// promoteExecutables moves transactions that have become processable from the
@@ -1690,7 +1692,7 @@ func (pool *TxPool) executableTxFilter(costLimit *big.Int) func(tx *types.Transa
16901692

16911693
if pool.chainconfig.Scroll.FeeVaultEnabled() {
16921694
// recheck L1 data fee, as the oracle price may have changed
1693-
l1DataFee, err := fees.CalculateL1DataFee(tx, pool.currentState, pool.chainconfig, pool.currentHead)
1695+
l1DataFee, err := fees.CalculateL1DataFee(tx, pool.currentState, pool.chainconfig, pool.currentHead, pool.currentTime)
16941696
if err != nil {
16951697
log.Error("Failed to calculate L1 data fee", "err", err, "tx", tx)
16961698
return false

eth/state_accessor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (eth *Ethereum) stateAtTransaction(block *types.Block, txIndex int, reexec
198198
// Not yet the searched for transaction, execute on top of the current state
199199
vmenv := vm.NewEVM(context, txContext, statedb, eth.blockchain.Config(), vm.Config{})
200200
statedb.SetTxContext(tx.Hash(), idx)
201-
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, eth.blockchain.Config(), block.Number())
201+
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, eth.blockchain.Config(), block.Number(), block.Time())
202202
if err != nil {
203203
return nil, vm.BlockContext{}, nil, err
204204
}

eth/tracers/api.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config
292292
TxHash: tx.Hash(),
293293
}
294294

295-
l1DataFee, err := fees.CalculateL1DataFee(tx, task.statedb, api.backend.ChainConfig(), task.block.Number())
295+
l1DataFee, err := fees.CalculateL1DataFee(tx, task.statedb, api.backend.ChainConfig(), task.block.Number(), task.block.Time())
296296
if err != nil {
297297
// though it's not a "tracing error", we still need to put it here
298298
task.results[i] = &txTraceResult{Error: err.Error()}
@@ -557,7 +557,7 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config
557557
)
558558
statedb.SetTxContext(tx.Hash(), i)
559559

560-
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, api.backend.ChainConfig(), block.Number())
560+
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, api.backend.ChainConfig(), block.Number(), block.Time())
561561
if err != nil {
562562
log.Warn("Tracing intermediate roots did not complete due to fees.CalculateL1DataFee", "txindex", i, "txhash", tx.Hash(), "err", err)
563563
return nil, err
@@ -645,7 +645,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
645645
TxHash: txs[task.index].Hash(),
646646
}
647647

648-
l1DataFee, err := fees.CalculateL1DataFee(txs[task.index], task.statedb, api.backend.ChainConfig(), block.Number())
648+
l1DataFee, err := fees.CalculateL1DataFee(txs[task.index], task.statedb, api.backend.ChainConfig(), block.Number(), block.Time())
649649
if err != nil {
650650
// though it's not a "tracing error", we still need to put it here
651651
results[task.index] = &txTraceResult{
@@ -679,7 +679,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
679679
msg, _ := tx.AsMessage(signer, block.BaseFee())
680680
statedb.SetTxContext(tx.Hash(), i)
681681
vmenv := vm.NewEVM(blockCtx, core.NewEVMTxContext(msg), statedb, api.backend.ChainConfig(), vm.Config{})
682-
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, api.backend.ChainConfig(), block.Number())
682+
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, api.backend.ChainConfig(), block.Number(), block.Time())
683683
if err != nil {
684684
failed = err
685685
break
@@ -804,7 +804,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
804804
// Execute the transaction and flush any traces to disk
805805
vmenv := vm.NewEVM(vmctx, txContext, statedb, chainConfig, vmConf)
806806
statedb.SetTxContext(tx.Hash(), i)
807-
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, api.backend.ChainConfig(), block.Number())
807+
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, api.backend.ChainConfig(), block.Number(), block.Time())
808808
if err == nil {
809809
_, err = core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas()), l1DataFee)
810810
}
@@ -869,7 +869,7 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *
869869
TxIndex: int(index),
870870
TxHash: hash,
871871
}
872-
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, api.backend.ChainConfig(), block.Number())
872+
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, api.backend.ChainConfig(), block.Number(), block.Time())
873873
if err != nil {
874874
return nil, err
875875
}
@@ -929,7 +929,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
929929
}
930930

931931
signer := types.MakeSigner(api.backend.ChainConfig(), block.Number(), block.Time())
932-
l1DataFee, err := fees.EstimateL1DataFeeForMessage(msg, block.BaseFee(), api.backend.ChainConfig(), signer, statedb, block.Number())
932+
l1DataFee, err := fees.EstimateL1DataFeeForMessage(msg, block.BaseFee(), api.backend.ChainConfig(), signer, statedb, block.Number(), block.Time())
933933
if err != nil {
934934
return nil, err
935935
}

eth/tracers/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (b *testBackend) StateAtTransaction(ctx context.Context, block *types.Block
173173
return msg, context, statedb, nil
174174
}
175175
vmenv := vm.NewEVM(context, txContext, statedb, b.chainConfig, vm.Config{})
176-
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, b.chainConfig, block.Number())
176+
l1DataFee, err := fees.CalculateL1DataFee(tx, statedb, b.chainConfig, block.Number(), block.Time())
177177
if err != nil {
178178
return nil, vm.BlockContext{}, nil, err
179179
}

0 commit comments

Comments
 (0)