Skip to content

Commit 40e07af

Browse files
committed
chore(all): remove Timestamp() method on Block types
- `Time()` does the same as `Timestamp()` - `Time()` is present upstream, not `Timestamp()`
1 parent 0d522e7 commit 40e07af

File tree

12 files changed

+35
-36
lines changed

12 files changed

+35
-36
lines changed

core/chain_makers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ func (b *BlockGen) Number() *big.Int {
187187
return new(big.Int).Set(b.header.Number)
188188
}
189189

190-
// Timestamp returns the timestamp of the block being generated.
191-
func (b *BlockGen) Timestamp() uint64 {
190+
// Time returns the time of the block being generated.
191+
func (b *BlockGen) Time() uint64 {
192192
return b.header.Time
193193
}
194194

core/state_processor.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat
210210
// This function is called within genesis setup to configure the starting state for precompiles enabled at genesis.
211211
// In block processing and building, ApplyUpgrades is called instead which also applies state upgrades.
212212
func ApplyPrecompileActivations(c *params.ChainConfig, parentTimestamp *uint64, blockContext contract.ConfigurationBlockContext, statedb *state.StateDB) error {
213-
blockTimestamp := blockContext.Timestamp()
213+
blockTimestamp := blockContext.Time()
214214
// Note: RegisteredModules returns precompiles sorted by module addresses.
215215
// This ensures that the order we call Configure for each precompile is consistent.
216216
// 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,
261261
func applyStateUpgrades(c *params.ChainConfig, parentTimestamp *uint64, blockContext contract.ConfigurationBlockContext, statedb *state.StateDB) error {
262262
// Apply state upgrades
263263
configExtra := params.GetExtra(c)
264-
for _, upgrade := range configExtra.GetActivatingStateUpgrades(parentTimestamp, blockContext.Timestamp(), configExtra.StateUpgrades) {
264+
for _, upgrade := range configExtra.GetActivatingStateUpgrades(parentTimestamp, blockContext.Time(), configExtra.StateUpgrades) {
265265
log.Info("Applying state upgrade", "blockNumber", blockContext.Number(), "upgrade", upgrade)
266266
if err := stateupgrade.Configure(&upgrade, c, statedb, blockContext); err != nil {
267267
return fmt.Errorf("could not configure state upgrade: %w", err)
@@ -284,16 +284,16 @@ func ApplyUpgrades(c *params.ChainConfig, parentTimestamp *uint64, blockContext
284284
}
285285

286286
type blockContext struct {
287-
number *big.Int
288-
timestamp uint64
287+
number *big.Int
288+
time uint64
289289
}
290290

291-
func NewBlockContext(number *big.Int, timestamp uint64) *blockContext {
291+
func NewBlockContext(number *big.Int, time uint64) *blockContext {
292292
return &blockContext{
293-
number: number,
294-
timestamp: timestamp,
293+
number: number,
294+
time: time,
295295
}
296296
}
297297

298-
func (bc *blockContext) Number() *big.Int { return bc.number }
299-
func (bc *blockContext) Timestamp() uint64 { return bc.timestamp }
298+
func (bc *blockContext) Number() *big.Int { return bc.number }
299+
func (bc *blockContext) Time() uint64 { return bc.time }

core/types/block.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ func (b *Block) GasLimit() uint64 { return b.header.GasLimit }
317317
func (b *Block) GasUsed() uint64 { return b.header.GasUsed }
318318
func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) }
319319
func (b *Block) Time() uint64 { return b.header.Time }
320-
func (b *Block) Timestamp() uint64 { return b.header.Time }
321320

322321
func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
323322
func (b *Block) MixDigest() common.Hash { return b.header.MixDigest }

params/hooks_libevm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (p *precompileBlockContext) Number() *big.Int {
141141
return p.number
142142
}
143143

144-
func (p *precompileBlockContext) Timestamp() uint64 {
144+
func (p *precompileBlockContext) Time() uint64 {
145145
return p.time
146146
}
147147

plugin/evm/block.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (b *Block) Accept(context.Context) error {
6363
// Call Accept for relevant precompile logs. Note we do this prior to
6464
// calling Accept on the blockChain so any side effects (eg warp signatures)
6565
// take place before the accepted log is emitted to subscribers.
66-
rules := b.vm.chainConfig.Rules(b.ethBlock.Number(), params.IsMergeTODO, b.ethBlock.Timestamp())
66+
rules := b.vm.chainConfig.Rules(b.ethBlock.Number(), params.IsMergeTODO, b.ethBlock.Time())
6767
if err := b.handlePrecompileAccept(*params.GetRulesExtra(rules)); err != nil {
6868
return err
6969
}
@@ -154,7 +154,7 @@ func (b *Block) Verify(context.Context) error {
154154

155155
// ShouldVerifyWithContext implements the block.WithVerifyContext interface
156156
func (b *Block) ShouldVerifyWithContext(context.Context) (bool, error) {
157-
rules := params.GetRulesExtra(b.vm.chainConfig.Rules(b.ethBlock.Number(), params.IsMergeTODO, b.ethBlock.Timestamp()))
157+
rules := params.GetRulesExtra(b.vm.chainConfig.Rules(b.ethBlock.Number(), params.IsMergeTODO, b.ethBlock.Time()))
158158
predicates := rules.Predicaters
159159
// Short circuit early if there are no predicates to verify
160160
if len(predicates) == 0 {
@@ -221,7 +221,7 @@ func (b *Block) verify(predicateContext *precompileconfig.PredicateContext, writ
221221

222222
// verifyPredicates verifies the predicates in the block are valid according to predicateContext.
223223
func (b *Block) verifyPredicates(predicateContext *precompileconfig.PredicateContext) error {
224-
rules := b.vm.chainConfig.Rules(b.ethBlock.Number(), params.IsMergeTODO, b.ethBlock.Timestamp())
224+
rules := b.vm.chainConfig.Rules(b.ethBlock.Number(), params.IsMergeTODO, b.ethBlock.Time())
225225
rulesExtra := params.GetRulesExtra(rules)
226226

227227
switch {

plugin/evm/vm_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,7 +2403,7 @@ func TestTxAllowListDisablePrecompile(t *testing.T) {
24032403
require.Equal(t, signedTx0.Hash(), txs[0].Hash())
24042404

24052405
// verify the issued block is after the network upgrade
2406-
require.GreaterOrEqual(t, int64(block.Timestamp()), disableAllowListTimestamp.Unix())
2406+
require.GreaterOrEqual(t, int64(block.Time()), disableAllowListTimestamp.Unix())
24072407

24082408
<-newTxPoolHeadChan // wait for new head in tx pool
24092409

@@ -2783,7 +2783,7 @@ func TestRewardManagerPrecompileSetRewardAddress(t *testing.T) {
27832783
// to determine the coinbase for this block before full deactivation in the
27842784
// next block.
27852785
require.Equal(t, testAddr, ethBlock.Coinbase())
2786-
require.GreaterOrEqual(t, int64(ethBlock.Timestamp()), disableTime.Unix())
2786+
require.GreaterOrEqual(t, int64(ethBlock.Time()), disableTime.Unix())
27872787

27882788
vm.clock.Set(vm.clock.Time().Add(3 * time.Hour)) // let time pass to decrease gas price
27892789
// issue another block to verify that the reward manager is disabled
@@ -2803,7 +2803,7 @@ func TestRewardManagerPrecompileSetRewardAddress(t *testing.T) {
28032803
// reward manager was disabled at previous block
28042804
// so this block should revert back to enabling fee recipients
28052805
require.Equal(t, etherBase, ethBlock.Coinbase())
2806-
require.GreaterOrEqual(t, int64(ethBlock.Timestamp()), disableTime.Unix())
2806+
require.GreaterOrEqual(t, int64(ethBlock.Time()), disableTime.Unix())
28072807

28082808
// Verify that Blackhole has received fees
28092809
blkState, err = vm.blockChain.StateAt(ethBlock.Root())
@@ -2917,7 +2917,7 @@ func TestRewardManagerPrecompileAllowFeeRecipients(t *testing.T) {
29172917
require.Equal(t, newHead.Head.Hash(), common.Hash(blk.ID()))
29182918
ethBlock = blk.(*chain.BlockWrapper).Block.(*Block).ethBlock
29192919
require.Equal(t, etherBase, ethBlock.Coinbase()) // reward address was activated at previous block
2920-
require.GreaterOrEqual(t, int64(ethBlock.Timestamp()), disableTime.Unix())
2920+
require.GreaterOrEqual(t, int64(ethBlock.Time()), disableTime.Unix())
29212921

29222922
vm.clock.Set(vm.clock.Time().Add(3 * time.Hour)) // let time pass so that gas price is reduced
29232923
tx2 = types.NewTransaction(uint64(2), testEthAddrs[0], big.NewInt(2), 21000, big.NewInt(testMinGasPrice), nil)
@@ -2934,7 +2934,7 @@ func TestRewardManagerPrecompileAllowFeeRecipients(t *testing.T) {
29342934
require.Equal(t, newHead.Head.Hash(), common.Hash(blk.ID()))
29352935
ethBlock = blk.(*chain.BlockWrapper).Block.(*Block).ethBlock
29362936
require.Equal(t, constants.BlackholeAddr, ethBlock.Coinbase()) // reward address was activated at previous block
2937-
require.Greater(t, int64(ethBlock.Timestamp()), disableTime.Unix())
2937+
require.Greater(t, int64(ethBlock.Time()), disableTime.Unix())
29382938

29392939
// Verify that Blackhole has received fees
29402940
blkState, err = vm.blockChain.StateAt(ethBlock.Root())

plugin/evm/vm_upgrade_bytes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func TestVMUpgradeBytesPrecompile(t *testing.T) {
145145
assert.Equal(t, signedTx0.Hash(), txs[0].Hash())
146146

147147
// verify the issued block is after the network upgrade
148-
assert.GreaterOrEqual(t, int64(block.Timestamp()), disableAllowListTimestamp.Unix())
148+
assert.GreaterOrEqual(t, int64(block.Time()), disableAllowListTimestamp.Unix())
149149

150150
<-newTxPoolHeadChan // wait for new head in tx pool
151151

precompile/contract/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type AccessibleState interface {
6262
// ConfigurationBlockContext defines the interface required to configure a precompile.
6363
type ConfigurationBlockContext interface {
6464
Number() *big.Int
65-
Timestamp() uint64
65+
Time() uint64
6666
}
6767

6868
type BlockContext interface {

precompile/contract/mocks.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

precompile/contract/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ func ParseABI(rawABI string) abi.ABI {
6060
}
6161

6262
func IsDurangoActivated(evm AccessibleState) bool {
63-
return evm.GetChainConfig().IsDurango(evm.GetBlockContext().Timestamp())
63+
return evm.GetChainConfig().IsDurango(evm.GetBlockContext().Time())
6464
}

precompile/contracts/feemanager/contract_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ var (
144144
ExpectedRes: []byte{},
145145
SetupBlockContext: func(mbc *contract.MockBlockContext) {
146146
mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes()
147-
mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes()
147+
mbc.EXPECT().Time().Return(uint64(0)).AnyTimes()
148148
},
149149
AfterHook: func(t testing.TB, state contract.StateDB) {
150150
feeConfig := GetStoredFeeConfig(state)
@@ -321,7 +321,7 @@ var (
321321
ExpectedErr: ErrInvalidLen.Error(),
322322
SetupBlockContext: func(mbc *contract.MockBlockContext) {
323323
mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes()
324-
mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes()
324+
mbc.EXPECT().Time().Return(uint64(0)).AnyTimes()
325325
},
326326
},
327327
"set config with extra padded bytes should succeed with Durango": {
@@ -344,7 +344,7 @@ var (
344344
ExpectedRes: []byte{},
345345
SetupBlockContext: func(mbc *contract.MockBlockContext) {
346346
mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes()
347-
mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes()
347+
mbc.EXPECT().Time().Return(uint64(0)).AnyTimes()
348348
},
349349
AfterHook: func(t testing.TB, state contract.StateDB) {
350350
feeConfig := GetStoredFeeConfig(state)
@@ -371,7 +371,7 @@ var (
371371
ReadOnly: false,
372372
SetupBlockContext: func(mbc *contract.MockBlockContext) {
373373
mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes()
374-
mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes()
374+
mbc.EXPECT().Time().Return(uint64(0)).AnyTimes()
375375
},
376376
},
377377
"setFeeConfig regression test should succeed after Durango": {
@@ -388,7 +388,7 @@ var (
388388
ExpectedRes: []byte{},
389389
SetupBlockContext: func(mbc *contract.MockBlockContext) {
390390
mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes()
391-
mbc.EXPECT().Timestamp().Return(uint64(0)).AnyTimes()
391+
mbc.EXPECT().Time().Return(uint64(0)).AnyTimes()
392392
},
393393
AfterHook: func(t testing.TB, state contract.StateDB) {
394394
feeConfig := GetStoredFeeConfig(state)

precompile/testutils/test_precompile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (test PrecompileTest) setup(t testing.TB, module modules.Module, state cont
106106
test.SetupBlockContext(blockContext)
107107
} else {
108108
blockContext.EXPECT().Number().Return(big.NewInt(0)).AnyTimes()
109-
blockContext.EXPECT().Timestamp().Return(uint64(time.Now().Unix())).AnyTimes()
109+
blockContext.EXPECT().Time().Return(uint64(time.Now().Unix())).AnyTimes()
110110
}
111111
snowContext := utils.TestSnowContext()
112112

0 commit comments

Comments
 (0)