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 #749

Open
wants to merge 1 commit into
base: libevm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -185,8 +185,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
2 changes: 1 addition & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,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
1 change: 0 additions & 1 deletion core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,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 @@ -185,7 +185,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 @@ -151,7 +151,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 @@ -279,7 +279,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 @@ -360,7 +360,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
2 changes: 1 addition & 1 deletion precompile/contract/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type AccessibleState interface {
// ConfigurationBlockContext defines the interface required to configure a precompile.
type ConfigurationBlockContext interface {
Number() *big.Int
Timestamp() uint64
Time() uint64
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this is non-breaking given the types.Block already implements Time()

}

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/testutils/test_precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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