From cf3caca17cfdc94ee98522929f8451a75465672e Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Tue, 29 Apr 2025 11:44:10 +0530 Subject: [PATCH] updated upstream HFs from time based to block number based --- cmd/evm/internal/t8ntool/execution.go | 4 ++-- consensus/beacon/consensus.go | 2 +- consensus/misc/eip4844/eip4844.go | 14 +++++++------- consensus/misc/eip4844/eip4844_test.go | 8 +++----- core/blockchain.go | 2 +- core/chain_makers.go | 10 +++++----- core/genesis.go | 4 ++-- core/genesis_test.go | 2 +- core/state_processor.go | 2 +- core/txpool/blobpool/blobpool_test.go | 3 +-- core/txpool/validation.go | 2 +- core/types/transaction_signing.go | 4 ++-- eth/catalyst/api_test.go | 7 ++++--- eth/state_accessor.go | 2 +- eth/tracers/internal/tracetest/util.go | 2 +- internal/ethapi/simulate.go | 2 +- internal/ethapi/transaction_args_test.go | 1 - params/config.go | 4 ++-- tests/init.go | 16 ++++++++-------- tests/state_test_util.go | 4 ++-- 20 files changed, 46 insertions(+), 49 deletions(-) diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index 7059d9acfa..84c4db511c 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -364,7 +364,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, // Gather the execution-layer triggered requests. var requests [][]byte - if chainConfig.IsPrague(vmContext.BlockNumber, vmContext.Time) && chainConfig.Bor == nil { + if chainConfig.IsPrague(vmContext.BlockNumber) && chainConfig.Bor == nil { requests = [][]byte{} // EIP-6110 var allLogs []*types.Log @@ -381,7 +381,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, } // Commit block - root, err := statedb.Commit(vmContext.BlockNumber.Uint64(), chainConfig.IsEIP158(vmContext.BlockNumber), chainConfig.IsCancun(vmContext.BlockNumber, vmContext.Time)) + root, err := statedb.Commit(vmContext.BlockNumber.Uint64(), chainConfig.IsEIP158(vmContext.BlockNumber), chainConfig.IsCancun(vmContext.BlockNumber)) if err != nil { return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not commit state: %v", err)) } diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 5e92e8dab5..de28a6a36b 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -79,7 +79,7 @@ func isPostMerge(config *params.ChainConfig, blockNum uint64, timestamp uint64) mergedAtGenesis := config.TerminalTotalDifficulty != nil && config.TerminalTotalDifficulty.Sign() == 0 return mergedAtGenesis || config.MergeNetsplitBlock != nil && blockNum >= config.MergeNetsplitBlock.Uint64() || - config.ShanghaiTime != nil && timestamp >= *config.ShanghaiTime + config.ShanghaiBlock != nil } // Author implements consensus.Engine, returning the verified author of the block. diff --git a/consensus/misc/eip4844/eip4844.go b/consensus/misc/eip4844/eip4844.go index 32b34f4e53..06219623e5 100644 --- a/consensus/misc/eip4844/eip4844.go +++ b/consensus/misc/eip4844/eip4844.go @@ -72,7 +72,7 @@ func CalcExcessBlobGas(config *params.ChainConfig, parent *types.Header, headTim parentBlobGasUsed = *parent.BlobGasUsed } excessBlobGas := parentExcessBlobGas + parentBlobGasUsed - targetGas := uint64(targetBlobsPerBlock(config, headTimestamp)) * params.BlobTxBlobGasPerBlob + targetGas := uint64(targetBlobsPerBlock(config, uint64(0))) * params.BlobTxBlobGasPerBlob if excessBlobGas < targetGas { return 0 } @@ -105,11 +105,11 @@ func MaxBlobsPerBlock(cfg *params.ChainConfig, time uint64) int { s = cfg.BlobScheduleConfig ) switch { - case cfg.IsOsaka(london, time) && s.Osaka != nil: + case cfg.IsOsaka(london) && s.Osaka != nil: return s.Osaka.Max - case cfg.IsPrague(london, time) && s.Prague != nil: + case cfg.IsPrague(london) && s.Prague != nil: return s.Prague.Max - case cfg.IsCancun(london, time) && s.Cancun != nil: + case cfg.IsCancun(london) && s.Cancun != nil: return s.Cancun.Max default: return 0 @@ -150,11 +150,11 @@ func targetBlobsPerBlock(cfg *params.ChainConfig, time uint64) int { s = cfg.BlobScheduleConfig ) switch { - case cfg.IsOsaka(london, time) && s.Osaka != nil: + case cfg.IsOsaka(london) && s.Osaka != nil: return s.Osaka.Target - case cfg.IsPrague(london, time) && s.Prague != nil: + case cfg.IsPrague(london) && s.Prague != nil: return s.Prague.Target - case cfg.IsCancun(london, time) && s.Cancun != nil: + case cfg.IsCancun(london) && s.Cancun != nil: return s.Cancun.Target default: return 0 diff --git a/consensus/misc/eip4844/eip4844_test.go b/consensus/misc/eip4844/eip4844_test.go index 14e6ae88bc..bec97ca8f9 100644 --- a/consensus/misc/eip4844/eip4844_test.go +++ b/consensus/misc/eip4844/eip4844_test.go @@ -28,7 +28,7 @@ import ( func TestCalcExcessBlobGas(t *testing.T) { var ( config = params.MainnetChainConfig - targetBlobs = targetBlobsPerBlock(config, *config.CancunTime) + targetBlobs = targetBlobsPerBlock(config, uint64(0)) targetBlobGas = uint64(targetBlobs) * params.BlobTxBlobGasPerBlob ) var tests = []struct { @@ -61,7 +61,7 @@ func TestCalcExcessBlobGas(t *testing.T) { ExcessBlobGas: &tt.excess, BlobGasUsed: &blobGasUsed, } - result := CalcExcessBlobGas(config, header, *config.CancunTime) + result := CalcExcessBlobGas(config, header, uint64(0)) if result != tt.want { t.Errorf("test %d: excess blob gas mismatch: have %v, want %v", i, result, tt.want) } @@ -71,8 +71,6 @@ func TestCalcExcessBlobGas(t *testing.T) { func TestCalcBlobFee(t *testing.T) { t.Parallel() - zero := uint64(0) - tests := []struct { excessBlobGas uint64 blobfee int64 @@ -83,7 +81,7 @@ func TestCalcBlobFee(t *testing.T) { {10 * 1024 * 1024, 23}, } for i, tt := range tests { - config := ¶ms.ChainConfig{LondonBlock: big.NewInt(0), CancunTime: &zero, BlobScheduleConfig: params.DefaultBlobSchedule} + config := ¶ms.ChainConfig{LondonBlock: big.NewInt(0), CancunBlock: big.NewInt(0), BlobScheduleConfig: params.DefaultBlobSchedule} header := &types.Header{ExcessBlobGas: &tt.excessBlobGas} have := CalcBlobFee(config, header) if have.Int64() != tt.blobfee { diff --git a/core/blockchain.go b/core/blockchain.go index 41e8a889f3..1434eb07fc 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1862,7 +1862,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. log.Crit("Failed to write block into disk", "err", err) } // Commit all cached state changes into underlying memory database. - root, err := statedb.Commit(block.NumberU64(), bc.chainConfig.IsEIP158(block.Number()), bc.chainConfig.IsCancun(block.Number(), block.Time())) + root, err := statedb.Commit(block.NumberU64(), bc.chainConfig.IsEIP158(block.Number()), bc.chainConfig.IsCancun(block.Number())) if err != nil { return []*types.Log{}, err } diff --git a/core/chain_makers.go b/core/chain_makers.go index cdf1d191ed..06ae05b0b0 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -324,7 +324,7 @@ func (b *BlockGen) collectRequests(readonly bool) (requests [][]byte) { statedb = statedb.Copy() } - if b.cm.config.IsPrague(b.header.Number, b.header.Time) { + if b.cm.config.IsPrague(b.header.Number) { requests = [][]byte{} // EIP-6110 deposits var blockLogs []*types.Log @@ -397,7 +397,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse misc.ApplyDAOHardFork(statedb) } - if config.IsPrague(b.header.Number, b.header.Time) || config.IsVerkle(b.header.Number, b.header.Time) { + if config.IsPrague(b.header.Number) || config.IsVerkle(b.header.Number) { // EIP-2935 blockContext := NewEVMBlockContext(b.header, cm, &b.header.Coinbase) blockContext.Random = &common.Hash{} // enable post-merge instruction set @@ -423,7 +423,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse } // Write state changes to db - root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number), config.IsCancun(b.header.Number, b.header.Time)) + root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number), config.IsCancun(b.header.Number)) if err != nil { panic(fmt.Sprintf("state write error: %v", err)) } @@ -535,7 +535,7 @@ func GenerateVerkleChain(config *params.ChainConfig, parent *types.Block, engine } // Write state changes to DB. - root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number), config.IsCancun(b.header.Number, b.header.Time)) + root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number), config.IsCancun(b.header.Number)) if err != nil { panic(fmt.Sprintf("state write error: %v", err)) } @@ -620,7 +620,7 @@ func (cm *chainMaker) makeHeader(parent *types.Block, state *state.StateDB, engi header.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit) } } - if cm.config.IsCancun(header.Number, header.Time) { + if cm.config.IsCancun(header.Number) { excessBlobGas := eip4844.CalcExcessBlobGas(cm.config, parentHeader, time) header.ExcessBlobGas = &excessBlobGas header.BlobGasUsed = new(uint64) diff --git a/core/genesis.go b/core/genesis.go index 3a6d61da2b..2cacb80f5b 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -284,10 +284,10 @@ func (o *ChainOverrides) apply(cfg *params.ChainConfig) error { return nil } if o.OverridePrague != nil { - cfg.PragueTime = o.OverridePrague + cfg.PragueBlock = o.OverridePrague } if o.OverrideVerkle != nil { - cfg.VerkleTime = o.OverrideVerkle + cfg.VerkleBlock = o.OverrideVerkle } return cfg.CheckConfigForkOrder() } diff --git a/core/genesis_test.go b/core/genesis_test.go index 4d6fcb72e4..94ba39485f 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -290,7 +290,7 @@ func TestVerkleGenesisCommit(t *testing.T) { ShanghaiBlock: big.NewInt(0), CancunBlock: big.NewInt(0), PragueBlock: big.NewInt(0), - OsakaTime: big.NewInt(0), + OsakaBlock: big.NewInt(0), VerkleBlock: big.NewInt(0), TerminalTotalDifficulty: big.NewInt(0), EnableVerkleAtGenesis: true, diff --git a/core/state_processor.go b/core/state_processor.go index 9a864d4d5a..e8478d7aab 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -89,7 +89,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg if beaconRoot := block.BeaconRoot(); beaconRoot != nil { ProcessBeaconBlockRoot(*beaconRoot, evm) } - if p.config.IsPrague(block.Number()) || p.config.IsVerkle(block.Number(), block.Time()) { + if p.config.IsPrague(block.Number()) || p.config.IsVerkle(block.Number()) { ProcessParentBlockHash(block.ParentHash(), evm) } diff --git a/core/txpool/blobpool/blobpool_test.go b/core/txpool/blobpool/blobpool_test.go index 3b567704d5..112326b291 100644 --- a/core/txpool/blobpool/blobpool_test.go +++ b/core/txpool/blobpool/blobpool_test.go @@ -1094,12 +1094,11 @@ func TestChangingSlotterSize(t *testing.T) { statedb.Commit(0, true, false) // Make custom chain config where the max blob count changes based on the loop variable. - cancunTime := uint64(0) config := ¶ms.ChainConfig{ ChainID: big.NewInt(1), LondonBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), - CancunTime: &cancunTime, + CancunBlock: big.NewInt(0), BlobScheduleConfig: ¶ms.BlobScheduleConfig{ Cancun: ¶ms.BlobConfig{ Target: maxBlobs / 2, diff --git a/core/txpool/validation.go b/core/txpool/validation.go index 5ac27f9569..967ff78dd4 100644 --- a/core/txpool/validation.go +++ b/core/txpool/validation.go @@ -122,7 +122,7 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types return fmt.Errorf("%w: gas %v, minimum needed %v", core.ErrIntrinsicGas, tx.Gas(), intrGas) } // Ensure the transaction can cover floor data gas. - if opts.Config.IsPrague(head.Number, head.Time) { + if opts.Config.IsPrague(head.Number) { floorDataGas, err := core.FloorDataGas(tx.Data()) if err != nil { return err diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index 4d8d06e2ff..831d1bc3ce 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -42,7 +42,7 @@ type sigCache struct { func MakeSigner(config *params.ChainConfig, blockNumber *big.Int, blockTime uint64) Signer { var signer Signer switch { - case config.IsPrague(blockNumber, blockTime): + case config.IsPrague(blockNumber): signer = NewPragueSigner(config.ChainID) case config.IsCancun(blockNumber): signer = NewCancunSigner(config.ChainID) @@ -71,7 +71,7 @@ func LatestSigner(config *params.ChainConfig) Signer { var signer Signer if config.ChainID != nil { switch { - case config.PragueTime != nil: + case config.PragueBlock != nil: signer = NewPragueSigner(config.ChainID) case config.CancunBlock != nil: signer = NewCancunSigner(config.ChainID) diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index 66498e70a2..ff6e853bf9 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -1533,10 +1533,11 @@ func TestParentBeaconBlockRoot(t *testing.T) { genesis, blocks := generateMergeChain(10, true) + // Bor doesn't allow timebased hardforks // Set cancun time to last block + 5 seconds - time := blocks[len(blocks)-1].Time() + 5 - genesis.Config.ShanghaiTime = &time - genesis.Config.CancunTime = &time + // time := blocks[len(blocks)-1].Time() + 5 + // genesis.Config.ShanghaiTime = &time + // genesis.Config.CancunTime = &time genesis.Config.BlobScheduleConfig = params.DefaultBlobSchedule n, ethservice := startEthService(t, genesis, blocks) diff --git a/eth/state_accessor.go b/eth/state_accessor.go index 75df9ae417..111ea70469 100644 --- a/eth/state_accessor.go +++ b/eth/state_accessor.go @@ -161,7 +161,7 @@ func (eth *Ethereum) hashState(ctx context.Context, block *types.Block, reexec u return nil, nil, fmt.Errorf("processing block %d failed: %v", current.NumberU64(), err) } // Finalize the state so any modifications are written to the trie - root, err := statedb.Commit(current.NumberU64(), eth.blockchain.Config().IsEIP158(current.Number()), eth.blockchain.Config().IsCancun(current.Number(), current.Time())) + root, err := statedb.Commit(current.NumberU64(), eth.blockchain.Config().IsEIP158(current.Number()), eth.blockchain.Config().IsCancun(current.Number())) if err != nil { return nil, nil, fmt.Errorf("stateAtBlock commit failed, number %d root %v: %w", current.NumberU64(), current.Root().Hex(), err) diff --git a/eth/tracers/internal/tracetest/util.go b/eth/tracers/internal/tracetest/util.go index ccc34d8a99..45647e3b71 100644 --- a/eth/tracers/internal/tracetest/util.go +++ b/eth/tracers/internal/tracetest/util.go @@ -73,7 +73,7 @@ func (c *traceContext) toBlockContext(genesis *core.Genesis) vm.BlockContext { } if genesis.ExcessBlobGas != nil && genesis.BlobGasUsed != nil { - header := &types.Header{Number: genesis.Config.LondonBlock, Time: *genesis.Config.CancunTime} + header := &types.Header{Number: genesis.Config.LondonBlock} excess := eip4844.CalcExcessBlobGas(genesis.Config, header, genesis.Timestamp) header.ExcessBlobGas = &excess context.BlobBaseFee = eip4844.CalcBlobFee(genesis.Config, header) diff --git a/internal/ethapi/simulate.go b/internal/ethapi/simulate.go index b6d71a7f74..e19b759259 100644 --- a/internal/ethapi/simulate.go +++ b/internal/ethapi/simulate.go @@ -246,7 +246,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header, if precompiles != nil { evm.SetPrecompiles(precompiles) } - if sim.chainConfig.IsPrague(header.Number, header.Time) || sim.chainConfig.IsVerkle(header.Number, header.Time) { + if sim.chainConfig.IsPrague(header.Number) || sim.chainConfig.IsVerkle(header.Number) { core.ProcessParentBlockHash(header.ParentHash, evm) } if header.ParentBeaconRoot != nil { diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index 466b3d513a..667d34e494 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -279,7 +279,6 @@ func newBackendMock() *backendMock { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(1000), - CancunTime: &cancunTime, BlobScheduleConfig: params.DefaultBlobSchedule, } diff --git a/params/config.go b/params/config.go index da9ed594be..e35df5aad0 100644 --- a/params/config.go +++ b/params/config.go @@ -1102,12 +1102,12 @@ func (c *ChainConfig) IsPrague(num *big.Int) bool { return isBlockForked(c.PragueBlock, num) } -// IsVerkle returns whether num is either equal to the Verkle fork time or greater. +// IsVerkle returns whether num is either equal to the Verkle fork block or greater. func (c *ChainConfig) IsVerkle(num *big.Int) bool { return c.IsLondon(num) && isBlockForked(c.VerkleBlock, num) } -// IsOsaka returns whether time is either equal to the Osaka fork time or greater. +// IsOsaka returns whether num is either equal to the Osaka fork block or greater. func (c *ChainConfig) IsOsaka(num *big.Int) bool { return c.IsLondon(num) && isBlockForked(c.OsakaBlock, num) } diff --git a/tests/init.go b/tests/init.go index 599220ac8c..4cb631e039 100644 --- a/tests/init.go +++ b/tests/init.go @@ -449,10 +449,10 @@ var Forks = map[string]*params.ChainConfig{ ArrowGlacierBlock: big.NewInt(0), MergeNetsplitBlock: big.NewInt(0), TerminalTotalDifficulty: big.NewInt(0), - ShanghaiTime: u64(0), - CancunTime: u64(0), - PragueTime: u64(0), - OsakaTime: u64(0), + ShanghaiBlock: big.NewInt(0), + CancunBlock: big.NewInt(0), + PragueBlock: big.NewInt(0), + OsakaBlock: big.NewInt(0), DepositContractAddress: params.MainnetChainConfig.DepositContractAddress, BlobScheduleConfig: ¶ms.BlobScheduleConfig{ Cancun: params.DefaultCancunBlobConfig, @@ -476,10 +476,10 @@ var Forks = map[string]*params.ChainConfig{ ArrowGlacierBlock: big.NewInt(0), MergeNetsplitBlock: big.NewInt(0), TerminalTotalDifficulty: big.NewInt(0), - ShanghaiTime: u64(0), - CancunTime: u64(0), - PragueTime: u64(0), - OsakaTime: u64(15_000), + ShanghaiBlock: big.NewInt(0), + CancunBlock: big.NewInt(0), + PragueBlock: big.NewInt(0), + OsakaBlock: big.NewInt(0), DepositContractAddress: params.MainnetChainConfig.DepositContractAddress, BlobScheduleConfig: ¶ms.BlobScheduleConfig{ Cancun: params.DefaultCancunBlobConfig, diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 4c238216ec..838e19509f 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -296,7 +296,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh // - the block body is verified against the header in block_validator.go:ValidateBody // Here, we just do this shortcut smaller fix, since state tests do not // utilize those codepaths. - if config.IsCancun(new(big.Int), block.Time()) { + if config.IsCancun(new(big.Int)) { if len(msg.BlobHashes) > eip4844.MaxBlobsPerBlock(config, block.Time()) { return st, common.Hash{}, 0, errors.New("blob gas exceeds maximum") } @@ -363,7 +363,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh st.StateDB.AddBalance(block.Coinbase(), new(uint256.Int), tracing.BalanceChangeUnspecified) // Commit state mutations into database. - root, _ = st.StateDB.Commit(block.NumberU64(), config.IsEIP158(block.Number()), config.IsCancun(block.Number(), block.Time())) + root, _ = st.StateDB.Commit(block.NumberU64(), config.IsEIP158(block.Number()), config.IsCancun(block.Number())) if tracer := evm.Config.Tracer; tracer != nil && tracer.OnTxEnd != nil { receipt := &types.Receipt{GasUsed: vmRet.UsedGas} tracer.OnTxEnd(receipt, nil)