Skip to content

Commit

Permalink
chore(all): remove Timestamp() method on Block types
Browse files Browse the repository at this point in the history
- `Time()` does the same as `Timestamp()`
- `Time()` is present upstream, not `Timestamp()`
  • Loading branch information
qdm12 committed Feb 6, 2025
1 parent 0d522e7 commit 40167aa
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 3 additions & 3 deletions plugin/evm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions plugin/evm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/vm_upgrade_bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion precompile/allowlist/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion precompile/contract/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions precompile/contract/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion precompile/contract/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
10 changes: 5 additions & 5 deletions precompile/contracts/feemanager/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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": {
Expand All @@ -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)
Expand All @@ -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": {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion precompile/testutils/test_precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 40167aa

Please sign in to comment.