From 40e07af980abc07901414c869203980976ac5bc5 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Thu, 6 Feb 2025 09:50:13 +0100 Subject: [PATCH 1/4] chore(all): remove Timestamp() method on Block types - `Time()` does the same as `Timestamp()` - `Time()` is present upstream, not `Timestamp()` --- core/chain_makers.go | 4 ++-- core/state_processor.go | 18 +++++++++--------- core/types/block.go | 1 - params/hooks_libevm.go | 2 +- plugin/evm/block.go | 6 +++--- plugin/evm/vm_test.go | 10 +++++----- plugin/evm/vm_upgrade_bytes_test.go | 2 +- precompile/contract/interfaces.go | 2 +- precompile/contract/mocks.go | 12 ++++++------ precompile/contract/utils.go | 2 +- .../contracts/feemanager/contract_test.go | 10 +++++----- precompile/testutils/test_precompile.go | 2 +- 12 files changed, 35 insertions(+), 36 deletions(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index 68e3c0a562..5cb68528cb 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -187,8 +187,8 @@ func (b *BlockGen) Number() *big.Int { return new(big.Int).Set(b.header.Number) } -// Timestamp returns the timestamp of the block being generated. -func (b *BlockGen) Timestamp() uint64 { +// Time returns the time of the block being generated. +func (b *BlockGen) Time() uint64 { return b.header.Time } diff --git a/core/state_processor.go b/core/state_processor.go index 4a97a631c0..b98cffebae 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -210,7 +210,7 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat // This function is called within genesis setup to configure the starting state for precompiles enabled at genesis. // In block processing and building, ApplyUpgrades is called instead which also applies state upgrades. func ApplyPrecompileActivations(c *params.ChainConfig, parentTimestamp *uint64, blockContext contract.ConfigurationBlockContext, statedb *state.StateDB) error { - blockTimestamp := blockContext.Timestamp() + blockTimestamp := blockContext.Time() // Note: RegisteredModules returns precompiles sorted by module addresses. // This ensures that the order we call Configure for each precompile is consistent. // This ensures even if precompiles read/write state other than their own they will observe @@ -261,7 +261,7 @@ func ApplyPrecompileActivations(c *params.ChainConfig, parentTimestamp *uint64, func applyStateUpgrades(c *params.ChainConfig, parentTimestamp *uint64, blockContext contract.ConfigurationBlockContext, statedb *state.StateDB) error { // Apply state upgrades configExtra := params.GetExtra(c) - for _, upgrade := range configExtra.GetActivatingStateUpgrades(parentTimestamp, blockContext.Timestamp(), configExtra.StateUpgrades) { + for _, upgrade := range configExtra.GetActivatingStateUpgrades(parentTimestamp, blockContext.Time(), configExtra.StateUpgrades) { log.Info("Applying state upgrade", "blockNumber", blockContext.Number(), "upgrade", upgrade) if err := stateupgrade.Configure(&upgrade, c, statedb, blockContext); err != nil { return fmt.Errorf("could not configure state upgrade: %w", err) @@ -284,16 +284,16 @@ func ApplyUpgrades(c *params.ChainConfig, parentTimestamp *uint64, blockContext } type blockContext struct { - number *big.Int - timestamp uint64 + number *big.Int + time uint64 } -func NewBlockContext(number *big.Int, timestamp uint64) *blockContext { +func NewBlockContext(number *big.Int, time uint64) *blockContext { return &blockContext{ - number: number, - timestamp: timestamp, + number: number, + time: time, } } -func (bc *blockContext) Number() *big.Int { return bc.number } -func (bc *blockContext) Timestamp() uint64 { return bc.timestamp } +func (bc *blockContext) Number() *big.Int { return bc.number } +func (bc *blockContext) Time() uint64 { return bc.time } diff --git a/core/types/block.go b/core/types/block.go index 29963da626..fa234d9326 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -317,7 +317,6 @@ func (b *Block) GasLimit() uint64 { return b.header.GasLimit } func (b *Block) GasUsed() uint64 { return b.header.GasUsed } func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) } func (b *Block) Time() uint64 { return b.header.Time } -func (b *Block) Timestamp() uint64 { return b.header.Time } func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() } func (b *Block) MixDigest() common.Hash { return b.header.MixDigest } diff --git a/params/hooks_libevm.go b/params/hooks_libevm.go index 41fc856053..6a2ffae274 100644 --- a/params/hooks_libevm.go +++ b/params/hooks_libevm.go @@ -141,7 +141,7 @@ func (p *precompileBlockContext) Number() *big.Int { return p.number } -func (p *precompileBlockContext) Timestamp() uint64 { +func (p *precompileBlockContext) Time() uint64 { return p.time } diff --git a/plugin/evm/block.go b/plugin/evm/block.go index 684ca5a363..6818779dc9 100644 --- a/plugin/evm/block.go +++ b/plugin/evm/block.go @@ -63,7 +63,7 @@ func (b *Block) Accept(context.Context) error { // Call Accept for relevant precompile logs. Note we do this prior to // calling Accept on the blockChain so any side effects (eg warp signatures) // take place before the accepted log is emitted to subscribers. - rules := b.vm.chainConfig.Rules(b.ethBlock.Number(), params.IsMergeTODO, b.ethBlock.Timestamp()) + rules := b.vm.chainConfig.Rules(b.ethBlock.Number(), params.IsMergeTODO, b.ethBlock.Time()) if err := b.handlePrecompileAccept(*params.GetRulesExtra(rules)); err != nil { return err } @@ -154,7 +154,7 @@ func (b *Block) Verify(context.Context) error { // ShouldVerifyWithContext implements the block.WithVerifyContext interface func (b *Block) ShouldVerifyWithContext(context.Context) (bool, error) { - rules := params.GetRulesExtra(b.vm.chainConfig.Rules(b.ethBlock.Number(), params.IsMergeTODO, b.ethBlock.Timestamp())) + rules := params.GetRulesExtra(b.vm.chainConfig.Rules(b.ethBlock.Number(), params.IsMergeTODO, b.ethBlock.Time())) predicates := rules.Predicaters // Short circuit early if there are no predicates to verify if len(predicates) == 0 { @@ -221,7 +221,7 @@ func (b *Block) verify(predicateContext *precompileconfig.PredicateContext, writ // verifyPredicates verifies the predicates in the block are valid according to predicateContext. func (b *Block) verifyPredicates(predicateContext *precompileconfig.PredicateContext) error { - rules := b.vm.chainConfig.Rules(b.ethBlock.Number(), params.IsMergeTODO, b.ethBlock.Timestamp()) + rules := b.vm.chainConfig.Rules(b.ethBlock.Number(), params.IsMergeTODO, b.ethBlock.Time()) rulesExtra := params.GetRulesExtra(rules) switch { diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index d617ff824f..8e25e18591 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -2403,7 +2403,7 @@ func TestTxAllowListDisablePrecompile(t *testing.T) { require.Equal(t, signedTx0.Hash(), txs[0].Hash()) // verify the issued block is after the network upgrade - require.GreaterOrEqual(t, int64(block.Timestamp()), disableAllowListTimestamp.Unix()) + require.GreaterOrEqual(t, int64(block.Time()), disableAllowListTimestamp.Unix()) <-newTxPoolHeadChan // wait for new head in tx pool @@ -2783,7 +2783,7 @@ func TestRewardManagerPrecompileSetRewardAddress(t *testing.T) { // to determine the coinbase for this block before full deactivation in the // next block. require.Equal(t, testAddr, ethBlock.Coinbase()) - require.GreaterOrEqual(t, int64(ethBlock.Timestamp()), disableTime.Unix()) + require.GreaterOrEqual(t, int64(ethBlock.Time()), disableTime.Unix()) vm.clock.Set(vm.clock.Time().Add(3 * time.Hour)) // let time pass to decrease gas price // issue another block to verify that the reward manager is disabled @@ -2803,7 +2803,7 @@ func TestRewardManagerPrecompileSetRewardAddress(t *testing.T) { // reward manager was disabled at previous block // so this block should revert back to enabling fee recipients require.Equal(t, etherBase, ethBlock.Coinbase()) - require.GreaterOrEqual(t, int64(ethBlock.Timestamp()), disableTime.Unix()) + require.GreaterOrEqual(t, int64(ethBlock.Time()), disableTime.Unix()) // Verify that Blackhole has received fees blkState, err = vm.blockChain.StateAt(ethBlock.Root()) @@ -2917,7 +2917,7 @@ func TestRewardManagerPrecompileAllowFeeRecipients(t *testing.T) { require.Equal(t, newHead.Head.Hash(), common.Hash(blk.ID())) ethBlock = blk.(*chain.BlockWrapper).Block.(*Block).ethBlock require.Equal(t, etherBase, ethBlock.Coinbase()) // reward address was activated at previous block - require.GreaterOrEqual(t, int64(ethBlock.Timestamp()), disableTime.Unix()) + require.GreaterOrEqual(t, int64(ethBlock.Time()), disableTime.Unix()) vm.clock.Set(vm.clock.Time().Add(3 * time.Hour)) // let time pass so that gas price is reduced tx2 = types.NewTransaction(uint64(2), testEthAddrs[0], big.NewInt(2), 21000, big.NewInt(testMinGasPrice), nil) @@ -2934,7 +2934,7 @@ func TestRewardManagerPrecompileAllowFeeRecipients(t *testing.T) { require.Equal(t, newHead.Head.Hash(), common.Hash(blk.ID())) ethBlock = blk.(*chain.BlockWrapper).Block.(*Block).ethBlock require.Equal(t, constants.BlackholeAddr, ethBlock.Coinbase()) // reward address was activated at previous block - require.Greater(t, int64(ethBlock.Timestamp()), disableTime.Unix()) + require.Greater(t, int64(ethBlock.Time()), disableTime.Unix()) // Verify that Blackhole has received fees blkState, err = vm.blockChain.StateAt(ethBlock.Root()) diff --git a/plugin/evm/vm_upgrade_bytes_test.go b/plugin/evm/vm_upgrade_bytes_test.go index c40e80db1b..00fd99fb8b 100644 --- a/plugin/evm/vm_upgrade_bytes_test.go +++ b/plugin/evm/vm_upgrade_bytes_test.go @@ -145,7 +145,7 @@ func TestVMUpgradeBytesPrecompile(t *testing.T) { assert.Equal(t, signedTx0.Hash(), txs[0].Hash()) // verify the issued block is after the network upgrade - assert.GreaterOrEqual(t, int64(block.Timestamp()), disableAllowListTimestamp.Unix()) + assert.GreaterOrEqual(t, int64(block.Time()), disableAllowListTimestamp.Unix()) <-newTxPoolHeadChan // wait for new head in tx pool diff --git a/precompile/contract/interfaces.go b/precompile/contract/interfaces.go index a4174fb5a4..1798e675e5 100644 --- a/precompile/contract/interfaces.go +++ b/precompile/contract/interfaces.go @@ -62,7 +62,7 @@ type AccessibleState interface { // ConfigurationBlockContext defines the interface required to configure a precompile. type ConfigurationBlockContext interface { Number() *big.Int - Timestamp() uint64 + Time() uint64 } type BlockContext interface { diff --git a/precompile/contract/mocks.go b/precompile/contract/mocks.go index eb8d371e75..cf48cc0cea 100644 --- a/precompile/contract/mocks.go +++ b/precompile/contract/mocks.go @@ -73,18 +73,18 @@ func (mr *MockBlockContextMockRecorder) Number() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Number", reflect.TypeOf((*MockBlockContext)(nil).Number)) } -// Timestamp mocks base method. -func (m *MockBlockContext) Timestamp() uint64 { +// Time mocks base method. +func (m *MockBlockContext) Time() uint64 { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Timestamp") + ret := m.ctrl.Call(m, "Time") ret0, _ := ret[0].(uint64) return ret0 } -// Timestamp indicates an expected call of Timestamp. -func (mr *MockBlockContextMockRecorder) Timestamp() *gomock.Call { +// Time indicates an expected call of Time. +func (mr *MockBlockContextMockRecorder) Time() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Timestamp", reflect.TypeOf((*MockBlockContext)(nil).Timestamp)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Time", reflect.TypeOf((*MockBlockContext)(nil).Time)) } // MockAccessibleState is a mock of AccessibleState interface. diff --git a/precompile/contract/utils.go b/precompile/contract/utils.go index 5a8fb39c40..709ef5b274 100644 --- a/precompile/contract/utils.go +++ b/precompile/contract/utils.go @@ -60,5 +60,5 @@ func ParseABI(rawABI string) abi.ABI { } func IsDurangoActivated(evm AccessibleState) bool { - return evm.GetChainConfig().IsDurango(evm.GetBlockContext().Timestamp()) + return evm.GetChainConfig().IsDurango(evm.GetBlockContext().Time()) } diff --git a/precompile/contracts/feemanager/contract_test.go b/precompile/contracts/feemanager/contract_test.go index 01382383be..88c0ab7ef9 100644 --- a/precompile/contracts/feemanager/contract_test.go +++ b/precompile/contracts/feemanager/contract_test.go @@ -144,7 +144,7 @@ var ( ExpectedRes: []byte{}, SetupBlockContext: func(mbc *contract.MockBlockContext) { mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes() - mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes() + mbc.EXPECT().Time().Return(uint64(0)).AnyTimes() }, AfterHook: func(t testing.TB, state contract.StateDB) { feeConfig := GetStoredFeeConfig(state) @@ -321,7 +321,7 @@ var ( ExpectedErr: ErrInvalidLen.Error(), SetupBlockContext: func(mbc *contract.MockBlockContext) { mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes() - mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes() + mbc.EXPECT().Time().Return(uint64(0)).AnyTimes() }, }, "set config with extra padded bytes should succeed with Durango": { @@ -344,7 +344,7 @@ var ( ExpectedRes: []byte{}, SetupBlockContext: func(mbc *contract.MockBlockContext) { mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes() - mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes() + mbc.EXPECT().Time().Return(uint64(0)).AnyTimes() }, AfterHook: func(t testing.TB, state contract.StateDB) { feeConfig := GetStoredFeeConfig(state) @@ -371,7 +371,7 @@ var ( ReadOnly: false, SetupBlockContext: func(mbc *contract.MockBlockContext) { mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes() - mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes() + mbc.EXPECT().Time().Return(uint64(0)).AnyTimes() }, }, "setFeeConfig regression test should succeed after Durango": { @@ -388,7 +388,7 @@ var ( ExpectedRes: []byte{}, SetupBlockContext: func(mbc *contract.MockBlockContext) { mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes() - mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes() + mbc.EXPECT().Time().Return(uint64(0)).AnyTimes() }, AfterHook: func(t testing.TB, state contract.StateDB) { feeConfig := GetStoredFeeConfig(state) diff --git a/precompile/testutils/test_precompile.go b/precompile/testutils/test_precompile.go index d345f9ada8..ad762f0bff 100644 --- a/precompile/testutils/test_precompile.go +++ b/precompile/testutils/test_precompile.go @@ -106,7 +106,7 @@ func (test PrecompileTest) setup(t testing.TB, module modules.Module, state cont test.SetupBlockContext(blockContext) } else { blockContext.EXPECT().Number().Return(big.NewInt(0)).AnyTimes() - blockContext.EXPECT().Timestamp().Return(uint64(time.Now().Unix())).AnyTimes() + blockContext.EXPECT().Time().Return(uint64(time.Now().Unix())).AnyTimes() } snowContext := utils.TestSnowContext() From 7a882f9708bdda1d512d215af88446a35d33aa56 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Thu, 6 Feb 2025 15:06:15 +0100 Subject: [PATCH 2/4] use core.NewBlockContext to avoid breaking changes --- core/chain_makers.go | 3 ++- core/genesis.go | 3 ++- core/state_processor.go | 11 ++++++----- eth/state_accessor.go | 3 ++- eth/tracers/api_test.go | 3 ++- miner/worker.go | 3 ++- params/hooks_libevm.go | 2 +- precompile/contract/interfaces.go | 2 +- precompile/contract/mocks.go | 12 ++++++------ precompile/contract/utils.go | 2 +- precompile/contracts/feemanager/contract_test.go | 10 +++++----- precompile/testutils/test_precompile.go | 2 +- 12 files changed, 31 insertions(+), 25 deletions(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index 5cb68528cb..b258087734 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -284,7 +284,8 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse b := &BlockGen{i: i, cm: cm, parent: parent, statedb: statedb, engine: engine} b.header = cm.makeHeader(parent, gap, statedb, b.engine) - err := ApplyUpgrades(config, &parent.Header().Time, b, statedb) + blockContext := NewBlockContext(b.header.Number, b.header.Time) + err := ApplyUpgrades(config, &parent.Header().Time, blockContext, statedb) if err != nil { return nil, nil, fmt.Errorf("failed to configure precompiles %w", err) } diff --git a/core/genesis.go b/core/genesis.go index a918057248..4339c80613 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -277,7 +277,8 @@ func (g *Genesis) toBlock(db ethdb.Database, triedb *triedb.Database) *types.Blo } // Configure any stateful precompiles that should be enabled in the genesis. - err = ApplyPrecompileActivations(g.Config, nil, types.NewBlockWithHeader(head), statedb) + blockContext := NewBlockContext(head.Number, head.Time) + err = ApplyPrecompileActivations(g.Config, nil, blockContext, statedb) if err != nil { panic(fmt.Sprintf("unable to configure precompiles in genesis block: %v", err)) } diff --git a/core/state_processor.go b/core/state_processor.go index b98cffebae..4d8ea51291 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -83,7 +83,8 @@ func (p *StateProcessor) Process(block *types.Block, parent *types.Header, state ) // Configure any upgrades that should go into effect during this block. - err := ApplyUpgrades(p.config, &parent.Time, block, statedb) + blockContext := NewBlockContext(block.Number(), block.Time()) + err := ApplyUpgrades(p.config, &parent.Time, blockContext, statedb) if err != nil { log.Error("failed to configure precompiles processing block", "hash", block.Hash(), "number", block.NumberU64(), "timestamp", block.Time(), "err", err) return nil, nil, 0, err @@ -210,7 +211,7 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat // This function is called within genesis setup to configure the starting state for precompiles enabled at genesis. // In block processing and building, ApplyUpgrades is called instead which also applies state upgrades. func ApplyPrecompileActivations(c *params.ChainConfig, parentTimestamp *uint64, blockContext contract.ConfigurationBlockContext, statedb *state.StateDB) error { - blockTimestamp := blockContext.Time() + blockTimestamp := blockContext.Timestamp() // Note: RegisteredModules returns precompiles sorted by module addresses. // This ensures that the order we call Configure for each precompile is consistent. // This ensures even if precompiles read/write state other than their own they will observe @@ -261,7 +262,7 @@ func ApplyPrecompileActivations(c *params.ChainConfig, parentTimestamp *uint64, func applyStateUpgrades(c *params.ChainConfig, parentTimestamp *uint64, blockContext contract.ConfigurationBlockContext, statedb *state.StateDB) error { // Apply state upgrades configExtra := params.GetExtra(c) - for _, upgrade := range configExtra.GetActivatingStateUpgrades(parentTimestamp, blockContext.Time(), configExtra.StateUpgrades) { + for _, upgrade := range configExtra.GetActivatingStateUpgrades(parentTimestamp, blockContext.Timestamp(), configExtra.StateUpgrades) { log.Info("Applying state upgrade", "blockNumber", blockContext.Number(), "upgrade", upgrade) if err := stateupgrade.Configure(&upgrade, c, statedb, blockContext); err != nil { return fmt.Errorf("could not configure state upgrade: %w", err) @@ -295,5 +296,5 @@ func NewBlockContext(number *big.Int, time uint64) *blockContext { } } -func (bc *blockContext) Number() *big.Int { return bc.number } -func (bc *blockContext) Time() uint64 { return bc.time } +func (bc *blockContext) Number() *big.Int { return bc.number } +func (bc *blockContext) Timestamp() uint64 { return bc.time } diff --git a/eth/state_accessor.go b/eth/state_accessor.go index cd9a661a08..9e83f25424 100644 --- a/eth/state_accessor.go +++ b/eth/state_accessor.go @@ -284,7 +284,8 @@ func (eth *Ethereum) StateAtNextBlock(ctx context.Context, parent *types.Block, } // Apply upgrades here for the [nextBlock] - err = core.ApplyUpgrades(eth.blockchain.Config(), &parent.Header().Time, nextBlock, statedb) + blockContext := core.NewBlockContext(nextBlock.Number(), nextBlock.Time()) + err = core.ApplyUpgrades(eth.blockchain.Config(), &parent.Header().Time, blockContext, statedb) if err != nil { release() return nil, nil, err diff --git a/eth/tracers/api_test.go b/eth/tracers/api_test.go index 75babfc3ed..7bb989d28d 100644 --- a/eth/tracers/api_test.go +++ b/eth/tracers/api_test.go @@ -181,7 +181,8 @@ func (b *testBackend) StateAtNextBlock(ctx context.Context, parent, nextBlock *t return nil, nil, err } // Apply upgrades to the parent state - err = core.ApplyUpgrades(b.chainConfig, &parent.Header().Time, nextBlock, statedb) + blockContext := core.NewBlockContext(nextBlock.Number(), nextBlock.Time()) + err = core.ApplyUpgrades(b.chainConfig, &parent.Header().Time, blockContext, statedb) if err != nil { release() return nil, nil, err diff --git a/miner/worker.go b/miner/worker.go index 178dd3f9b7..000c82650d 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -228,7 +228,8 @@ func (w *worker) commitNewWork(predicateContext *precompileconfig.PredicateConte env.state.StopPrefetcher() }() // Configure any upgrades that should go into effect during this block. - err = core.ApplyUpgrades(w.chainConfig, &parent.Time, types.NewBlockWithHeader(header), env.state) + blockContext := core.NewBlockContext(header.Number, header.Time) + err = core.ApplyUpgrades(w.chainConfig, &parent.Time, blockContext, env.state) if err != nil { log.Error("failed to configure precompiles mining new block", "parent", parent.Hash(), "number", header.Number, "timestamp", header.Time, "err", err) return nil, err diff --git a/params/hooks_libevm.go b/params/hooks_libevm.go index 6a2ffae274..41fc856053 100644 --- a/params/hooks_libevm.go +++ b/params/hooks_libevm.go @@ -141,7 +141,7 @@ func (p *precompileBlockContext) Number() *big.Int { return p.number } -func (p *precompileBlockContext) Time() uint64 { +func (p *precompileBlockContext) Timestamp() uint64 { return p.time } diff --git a/precompile/contract/interfaces.go b/precompile/contract/interfaces.go index 1798e675e5..a4174fb5a4 100644 --- a/precompile/contract/interfaces.go +++ b/precompile/contract/interfaces.go @@ -62,7 +62,7 @@ type AccessibleState interface { // ConfigurationBlockContext defines the interface required to configure a precompile. type ConfigurationBlockContext interface { Number() *big.Int - Time() uint64 + Timestamp() uint64 } type BlockContext interface { diff --git a/precompile/contract/mocks.go b/precompile/contract/mocks.go index cf48cc0cea..eb8d371e75 100644 --- a/precompile/contract/mocks.go +++ b/precompile/contract/mocks.go @@ -73,18 +73,18 @@ func (mr *MockBlockContextMockRecorder) Number() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Number", reflect.TypeOf((*MockBlockContext)(nil).Number)) } -// Time mocks base method. -func (m *MockBlockContext) Time() uint64 { +// Timestamp mocks base method. +func (m *MockBlockContext) Timestamp() uint64 { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Time") + ret := m.ctrl.Call(m, "Timestamp") ret0, _ := ret[0].(uint64) return ret0 } -// Time indicates an expected call of Time. -func (mr *MockBlockContextMockRecorder) Time() *gomock.Call { +// Timestamp indicates an expected call of Timestamp. +func (mr *MockBlockContextMockRecorder) Timestamp() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Time", reflect.TypeOf((*MockBlockContext)(nil).Time)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Timestamp", reflect.TypeOf((*MockBlockContext)(nil).Timestamp)) } // MockAccessibleState is a mock of AccessibleState interface. diff --git a/precompile/contract/utils.go b/precompile/contract/utils.go index 709ef5b274..5a8fb39c40 100644 --- a/precompile/contract/utils.go +++ b/precompile/contract/utils.go @@ -60,5 +60,5 @@ func ParseABI(rawABI string) abi.ABI { } func IsDurangoActivated(evm AccessibleState) bool { - return evm.GetChainConfig().IsDurango(evm.GetBlockContext().Time()) + return evm.GetChainConfig().IsDurango(evm.GetBlockContext().Timestamp()) } diff --git a/precompile/contracts/feemanager/contract_test.go b/precompile/contracts/feemanager/contract_test.go index 88c0ab7ef9..01382383be 100644 --- a/precompile/contracts/feemanager/contract_test.go +++ b/precompile/contracts/feemanager/contract_test.go @@ -144,7 +144,7 @@ var ( ExpectedRes: []byte{}, SetupBlockContext: func(mbc *contract.MockBlockContext) { mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes() - mbc.EXPECT().Time().Return(uint64(0)).AnyTimes() + mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes() }, AfterHook: func(t testing.TB, state contract.StateDB) { feeConfig := GetStoredFeeConfig(state) @@ -321,7 +321,7 @@ var ( ExpectedErr: ErrInvalidLen.Error(), SetupBlockContext: func(mbc *contract.MockBlockContext) { mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes() - mbc.EXPECT().Time().Return(uint64(0)).AnyTimes() + mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes() }, }, "set config with extra padded bytes should succeed with Durango": { @@ -344,7 +344,7 @@ var ( ExpectedRes: []byte{}, SetupBlockContext: func(mbc *contract.MockBlockContext) { mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes() - mbc.EXPECT().Time().Return(uint64(0)).AnyTimes() + mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes() }, AfterHook: func(t testing.TB, state contract.StateDB) { feeConfig := GetStoredFeeConfig(state) @@ -371,7 +371,7 @@ var ( ReadOnly: false, SetupBlockContext: func(mbc *contract.MockBlockContext) { mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes() - mbc.EXPECT().Time().Return(uint64(0)).AnyTimes() + mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes() }, }, "setFeeConfig regression test should succeed after Durango": { @@ -388,7 +388,7 @@ var ( ExpectedRes: []byte{}, SetupBlockContext: func(mbc *contract.MockBlockContext) { mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes() - mbc.EXPECT().Time().Return(uint64(0)).AnyTimes() + mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes() }, AfterHook: func(t testing.TB, state contract.StateDB) { feeConfig := GetStoredFeeConfig(state) diff --git a/precompile/testutils/test_precompile.go b/precompile/testutils/test_precompile.go index ad762f0bff..d345f9ada8 100644 --- a/precompile/testutils/test_precompile.go +++ b/precompile/testutils/test_precompile.go @@ -106,7 +106,7 @@ func (test PrecompileTest) setup(t testing.TB, module modules.Module, state cont test.SetupBlockContext(blockContext) } else { blockContext.EXPECT().Number().Return(big.NewInt(0)).AnyTimes() - blockContext.EXPECT().Time().Return(uint64(time.Now().Unix())).AnyTimes() + blockContext.EXPECT().Timestamp().Return(uint64(time.Now().Unix())).AnyTimes() } snowContext := utils.TestSnowContext() From 77ff91257d55d3f73299af69180756a800727990 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Thu, 6 Feb 2025 17:37:47 +0100 Subject: [PATCH 3/4] Revert core.BlockGen Time -> Timestamp --- core/chain_makers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index b258087734..aafb287f4b 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -187,8 +187,8 @@ func (b *BlockGen) Number() *big.Int { return new(big.Int).Set(b.header.Number) } -// Time returns the time of the block being generated. -func (b *BlockGen) Time() uint64 { +// Timestamp returns the timestamp of the block being generated. +func (b *BlockGen) Timestamp() uint64 { return b.header.Time } From 4a1d80534bbc83e282a5bfa682afd171f26bef14 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Fri, 7 Feb 2025 08:30:04 +0100 Subject: [PATCH 4/4] Revert core.blockContext internal field name change --- core/state_processor.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/state_processor.go b/core/state_processor.go index 4d8ea51291..1c5f1cebf7 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -285,16 +285,16 @@ func ApplyUpgrades(c *params.ChainConfig, parentTimestamp *uint64, blockContext } type blockContext struct { - number *big.Int - time uint64 + number *big.Int + timestamp uint64 } -func NewBlockContext(number *big.Int, time uint64) *blockContext { +func NewBlockContext(number *big.Int, timestamp uint64) *blockContext { return &blockContext{ - number: number, - time: time, + number: number, + timestamp: timestamp, } } func (bc *blockContext) Number() *big.Int { return bc.number } -func (bc *blockContext) Timestamp() uint64 { return bc.time } +func (bc *blockContext) Timestamp() uint64 { return bc.timestamp }