Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(core/types): remove Blocks's Timestamp() method #1429

Merged
merged 5 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 9 additions & 9 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 All @@ -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 }
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
2 changes: 1 addition & 1 deletion params/hooks_libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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/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
Loading