Skip to content

Commit 85a4b82

Browse files
authored
all: tie timestamp based forks to the passage of London (ethereum#27279)
1 parent 6a6318b commit 85a4b82

File tree

14 files changed

+31
-29
lines changed

14 files changed

+31
-29
lines changed

cmd/evm/internal/t8ntool/transaction.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func Transaction(ctx *cli.Context) error {
140140
}
141141
// Check intrinsic gas
142142
if gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil,
143-
chainConfig.IsHomestead(new(big.Int)), chainConfig.IsIstanbul(new(big.Int)), chainConfig.IsShanghai(0)); err != nil {
143+
chainConfig.IsHomestead(new(big.Int)), chainConfig.IsIstanbul(new(big.Int)), chainConfig.IsShanghai(new(big.Int), 0)); err != nil {
144144
r.Error = err
145145
results = append(results, r)
146146
continue
@@ -172,7 +172,7 @@ func Transaction(ctx *cli.Context) error {
172172
r.Error = errors.New("gas * maxFeePerGas exceeds 256 bits")
173173
}
174174
// Check whether the init code size has been exceeded.
175-
if chainConfig.IsShanghai(0) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
175+
if chainConfig.IsShanghai(new(big.Int), 0) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
176176
r.Error = errors.New("max initcode size exceeded")
177177
}
178178
results = append(results, r)

cmd/evm/internal/t8ntool/transition.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func Transition(ctx *cli.Context) error {
261261
return NewError(ErrorConfig, errors.New("EIP-1559 config but missing 'currentBaseFee' in env section"))
262262
}
263263
}
264-
if chainConfig.IsShanghai(prestate.Env.Number) && prestate.Env.Withdrawals == nil {
264+
if chainConfig.IsShanghai(big.NewInt(int64(prestate.Env.Number)), prestate.Env.Timestamp) && prestate.Env.Withdrawals == nil {
265265
return NewError(ErrorConfig, errors.New("Shanghai config but missing 'withdrawals' in env section"))
266266
}
267267
isMerged := chainConfig.TerminalTotalDifficulty != nil && chainConfig.TerminalTotalDifficulty.BitLen() == 0

consensus/beacon/consensus.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,15 @@ func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, pa
261261
return err
262262
}
263263
// Verify existence / non-existence of withdrawalsHash.
264-
shanghai := chain.Config().IsShanghai(header.Time)
264+
shanghai := chain.Config().IsShanghai(header.Number, header.Time)
265265
if shanghai && header.WithdrawalsHash == nil {
266266
return errors.New("missing withdrawalsHash")
267267
}
268268
if !shanghai && header.WithdrawalsHash != nil {
269269
return fmt.Errorf("invalid withdrawalsHash: have %x, expected nil", header.WithdrawalsHash)
270270
}
271271
// Verify the existence / non-existence of excessDataGas
272-
cancun := chain.Config().IsCancun(header.Time)
272+
cancun := chain.Config().IsCancun(header.Number, header.Time)
273273
if cancun && header.ExcessDataGas == nil {
274274
return errors.New("missing excessDataGas")
275275
}
@@ -356,7 +356,7 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea
356356
if !beacon.IsPoSHeader(header) {
357357
return beacon.ethone.FinalizeAndAssemble(chain, header, state, txs, uncles, receipts, nil)
358358
}
359-
shanghai := chain.Config().IsShanghai(header.Time)
359+
shanghai := chain.Config().IsShanghai(header.Number, header.Time)
360360
if shanghai {
361361
// All blocks after Shanghai must include a withdrawals root.
362362
if withdrawals == nil {

consensus/clique/clique.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
298298
if header.GasLimit > params.MaxGasLimit {
299299
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, params.MaxGasLimit)
300300
}
301-
if chain.Config().IsShanghai(header.Time) {
301+
if chain.Config().IsShanghai(header.Number, header.Time) {
302302
return fmt.Errorf("clique does not support shanghai fork")
303303
}
304-
if chain.Config().IsCancun(header.Time) {
304+
if chain.Config().IsCancun(header.Number, header.Time) {
305305
return fmt.Errorf("clique does not support cancun fork")
306306
}
307307
// All basic checks passed, verify cascading fields

consensus/ethash/consensus.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa
262262
if diff := new(big.Int).Sub(header.Number, parent.Number); diff.Cmp(big.NewInt(1)) != 0 {
263263
return consensus.ErrInvalidNumber
264264
}
265-
if chain.Config().IsShanghai(header.Time) {
265+
if chain.Config().IsShanghai(header.Number, header.Time) {
266266
return fmt.Errorf("ethash does not support shanghai fork")
267267
}
268-
if chain.Config().IsCancun(header.Time) {
268+
if chain.Config().IsCancun(header.Number, header.Time) {
269269
return fmt.Errorf("ethash does not support cancun fork")
270270
}
271271
// Add some fake checks for tests

core/genesis.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ func (g *Genesis) ToBlock() *types.Block {
463463
}
464464
}
465465
var withdrawals []*types.Withdrawal
466-
if g.Config != nil && g.Config.IsShanghai(g.Timestamp) {
466+
if g.Config != nil && g.Config.IsShanghai(big.NewInt(int64(g.Number)), g.Timestamp) {
467467
head.WithdrawalsHash = &types.EmptyWithdrawalsHash
468468
withdrawals = make([]*types.Withdrawal, 0)
469469
}

core/state_processor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
9191
}
9292
// Fail if Shanghai not enabled and len(withdrawals) is non-zero.
9393
withdrawals := block.Withdrawals()
94-
if len(withdrawals) > 0 && !p.config.IsShanghai(block.Time()) {
94+
if len(withdrawals) > 0 && !p.config.IsShanghai(block.Number(), block.Time()) {
9595
return nil, nil, 0, fmt.Errorf("withdrawals before shanghai")
9696
}
9797
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)

core/state_processor_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
403403
if config.IsLondon(header.Number) {
404404
header.BaseFee = misc.CalcBaseFee(config, parent.Header())
405405
}
406-
if config.IsShanghai(header.Time) {
406+
if config.IsShanghai(header.Number, header.Time) {
407407
header.WithdrawalsHash = &types.EmptyWithdrawalsHash
408408
}
409409
var receipts []*types.Receipt
@@ -423,7 +423,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
423423
}
424424
header.Root = common.BytesToHash(hasher.Sum(nil))
425425
// Assemble and return the final block for sealing
426-
if config.IsShanghai(header.Time) {
426+
if config.IsShanghai(header.Number, header.Time) {
427427
return types.NewBlockWithWithdrawals(header, txs, nil, receipts, []*types.Withdrawal{}, trie.NewStackTrie(nil))
428428
}
429429
return types.NewBlock(header, txs, nil, receipts, trie.NewStackTrie(nil))

core/txpool/txpool.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
13971397
pool.istanbul.Store(pool.chainconfig.IsIstanbul(next))
13981398
pool.eip2718.Store(pool.chainconfig.IsBerlin(next))
13991399
pool.eip1559.Store(pool.chainconfig.IsLondon(next))
1400-
pool.shanghai.Store(pool.chainconfig.IsShanghai(uint64(time.Now().Unix())))
1400+
pool.shanghai.Store(pool.chainconfig.IsShanghai(next, uint64(time.Now().Unix())))
14011401
}
14021402

14031403
// promoteExecutables moves transactions that have become processable from the

core/types/transaction_signing.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type sigCache struct {
4040
func MakeSigner(config *params.ChainConfig, blockNumber *big.Int, blockTime uint64) Signer {
4141
var signer Signer
4242
switch {
43-
case config.IsCancun(blockTime):
43+
case config.IsCancun(blockNumber, blockTime):
4444
signer = NewCancunSigner(config.ChainID)
4545
case config.IsLondon(blockNumber):
4646
signer = NewLondonSigner(config.ChainID)

eth/catalyst/api.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package catalyst
2020
import (
2121
"errors"
2222
"fmt"
23+
"math/big"
2324
"sync"
2425
"time"
2526

@@ -167,7 +168,7 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV1(update engine.ForkchoiceStateV1, pa
167168
if payloadAttributes.Withdrawals != nil {
168169
return engine.STATUS_INVALID, engine.InvalidParams.With(fmt.Errorf("withdrawals not supported in V1"))
169170
}
170-
if api.eth.BlockChain().Config().IsShanghai(payloadAttributes.Timestamp) {
171+
if api.eth.BlockChain().Config().IsShanghai(api.eth.BlockChain().Config().LondonBlock, payloadAttributes.Timestamp) {
171172
return engine.STATUS_INVALID, engine.InvalidParams.With(fmt.Errorf("forkChoiceUpdateV1 called post-shanghai"))
172173
}
173174
}
@@ -185,7 +186,7 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV2(update engine.ForkchoiceStateV1, pa
185186
}
186187

187188
func (api *ConsensusAPI) verifyPayloadAttributes(attr *engine.PayloadAttributes) error {
188-
if !api.eth.BlockChain().Config().IsShanghai(attr.Timestamp) {
189+
if !api.eth.BlockChain().Config().IsShanghai(api.eth.BlockChain().Config().LondonBlock, attr.Timestamp) {
189190
// Reject payload attributes with withdrawals before shanghai
190191
if attr.Withdrawals != nil {
191192
return errors.New("withdrawals before shanghai")
@@ -423,7 +424,7 @@ func (api *ConsensusAPI) NewPayloadV1(params engine.ExecutableData) (engine.Payl
423424

424425
// NewPayloadV2 creates an Eth1 block, inserts it in the chain, and returns the status of the chain.
425426
func (api *ConsensusAPI) NewPayloadV2(params engine.ExecutableData) (engine.PayloadStatusV1, error) {
426-
if api.eth.BlockChain().Config().IsShanghai(params.Timestamp) {
427+
if api.eth.BlockChain().Config().IsShanghai(new(big.Int).SetUint64(params.Number), params.Timestamp) {
427428
if params.Withdrawals == nil {
428429
return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(fmt.Errorf("nil withdrawals post-shanghai"))
429430
}

light/txpool.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func (pool *TxPool) setNewHead(head *types.Header) {
318318
next := new(big.Int).Add(head.Number, big.NewInt(1))
319319
pool.istanbul = pool.config.IsIstanbul(next)
320320
pool.eip2718 = pool.config.IsBerlin(next)
321-
pool.shanghai = pool.config.IsShanghai(uint64(time.Now().Unix()))
321+
pool.shanghai = pool.config.IsShanghai(next, uint64(time.Now().Unix()))
322322
}
323323

324324
// Stop stops the light transaction pool

params/config.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -492,18 +492,18 @@ func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *bi
492492
}
493493

494494
// IsShanghai returns whether time is either equal to the Shanghai fork time or greater.
495-
func (c *ChainConfig) IsShanghai(time uint64) bool {
496-
return isTimestampForked(c.ShanghaiTime, time)
495+
func (c *ChainConfig) IsShanghai(num *big.Int, time uint64) bool {
496+
return c.IsLondon(num) && isTimestampForked(c.ShanghaiTime, time)
497497
}
498498

499499
// IsCancun returns whether num is either equal to the Cancun fork time or greater.
500-
func (c *ChainConfig) IsCancun(time uint64) bool {
501-
return isTimestampForked(c.CancunTime, time)
500+
func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool {
501+
return c.IsLondon(num) && isTimestampForked(c.CancunTime, time)
502502
}
503503

504504
// IsPrague returns whether num is either equal to the Prague fork time or greater.
505-
func (c *ChainConfig) IsPrague(time uint64) bool {
506-
return isTimestampForked(c.PragueTime, time)
505+
func (c *ChainConfig) IsPrague(num *big.Int, time uint64) bool {
506+
return c.IsLondon(num) && isTimestampForked(c.PragueTime, time)
507507
}
508508

509509
// CheckCompatible checks whether scheduled fork transitions have been imported
@@ -829,8 +829,8 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
829829
IsBerlin: c.IsBerlin(num),
830830
IsLondon: c.IsLondon(num),
831831
IsMerge: isMerge,
832-
IsShanghai: c.IsShanghai(timestamp),
833-
IsCancun: c.IsCancun(timestamp),
834-
IsPrague: c.IsPrague(timestamp),
832+
IsShanghai: c.IsShanghai(num, timestamp),
833+
IsCancun: c.IsCancun(num, timestamp),
834+
IsPrague: c.IsPrague(num, timestamp),
835835
}
836836
}

params/config_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func TestCheckCompatible(t *testing.T) {
121121

122122
func TestConfigRules(t *testing.T) {
123123
c := &ChainConfig{
124+
LondonBlock: new(big.Int),
124125
ShanghaiTime: newUint64(500),
125126
}
126127
var stamp uint64

0 commit comments

Comments
 (0)