From 40167aa752d8fed1b077d3882f49e4f9b57cda54 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Thu, 6 Feb 2025 09:46:42 +0100 Subject: [PATCH] chore(all): remove Timestamp() method on Block types - `Time()` does the same as `Timestamp()` - `Time()` is present upstream, not `Timestamp()` --- core/state_processor.go | 4 ++-- core/types/block.go | 1 - plugin/evm/block.go | 6 +++--- plugin/evm/vm_test.go | 10 +++++----- plugin/evm/vm_upgrade_bytes_test.go | 2 +- precompile/allowlist/config.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 +- 11 files changed, 26 insertions(+), 27 deletions(-) diff --git a/core/state_processor.go b/core/state_processor.go index 4a97a631c0..be6632eceb 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) 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/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/allowlist/config.go b/precompile/allowlist/config.go index 3b147019ee..35f1326d94 100644 --- a/precompile/allowlist/config.go +++ b/precompile/allowlist/config.go @@ -21,7 +21,7 @@ type AllowListConfig struct { } // Configure initializes the address space of [precompileAddr] by initializing the role of each of -// the addresses in [AllowListAdmins]. +// the addresses in [AllowListConfig]. func (c *AllowListConfig) Configure(chainConfig precompileconfig.ChainConfig, precompileAddr common.Address, state contract.StateDB, blockContext contract.ConfigurationBlockContext) error { for _, enabledAddr := range c.EnabledAddresses { SetAllowListRole(state, precompileAddr, enabledAddr, EnabledRole) 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()