Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 4 additions & 3 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 Expand Up @@ -284,7 +284,8 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
b := &BlockGen{i: i, cm: cm, parent: parent, statedb: statedb, engine: engine}
b.header = cm.makeHeader(parent, gap, statedb, b.engine)

err := ApplyUpgrades(config, &parent.Header().Time, b, statedb)
blockContext := NewBlockContext(b.header.Number, b.header.Time)
err := ApplyUpgrades(config, &parent.Header().Time, blockContext, statedb)
if err != nil {
return nil, nil, fmt.Errorf("failed to configure precompiles %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ func (g *Genesis) toBlock(db ethdb.Database, triedb *triedb.Database) *types.Blo
}

// Configure any stateful precompiles that should be enabled in the genesis.
err = ApplyPrecompileActivations(g.Config, nil, types.NewBlockWithHeader(head), statedb)
blockContext := NewBlockContext(head.Number, head.Time)
err = ApplyPrecompileActivations(g.Config, nil, blockContext, statedb)
if err != nil {
panic(fmt.Sprintf("unable to configure precompiles in genesis block: %v", err))
}
Expand Down
15 changes: 8 additions & 7 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func (p *StateProcessor) Process(block *types.Block, parent *types.Header, state
)

// Configure any upgrades that should go into effect during this block.
err := ApplyUpgrades(p.config, &parent.Time, block, statedb)
blockContext := NewBlockContext(block.Number(), block.Time())
err := ApplyUpgrades(p.config, &parent.Time, blockContext, statedb)
if err != nil {
log.Error("failed to configure precompiles processing block", "hash", block.Hash(), "number", block.NumberU64(), "timestamp", block.Time(), "err", err)
return nil, nil, 0, err
Expand Down Expand Up @@ -284,16 +285,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) Timestamp() 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
3 changes: 2 additions & 1 deletion eth/state_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ func (eth *Ethereum) StateAtNextBlock(ctx context.Context, parent *types.Block,
}

// Apply upgrades here for the [nextBlock]
err = core.ApplyUpgrades(eth.blockchain.Config(), &parent.Header().Time, nextBlock, statedb)
blockContext := core.NewBlockContext(nextBlock.Number(), nextBlock.Time())
err = core.ApplyUpgrades(eth.blockchain.Config(), &parent.Header().Time, blockContext, statedb)
if err != nil {
release()
return nil, nil, err
Expand Down
3 changes: 2 additions & 1 deletion eth/tracers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ func (b *testBackend) StateAtNextBlock(ctx context.Context, parent, nextBlock *t
return nil, nil, err
}
// Apply upgrades to the parent state
err = core.ApplyUpgrades(b.chainConfig, &parent.Header().Time, nextBlock, statedb)
blockContext := core.NewBlockContext(nextBlock.Number(), nextBlock.Time())
err = core.ApplyUpgrades(b.chainConfig, &parent.Header().Time, blockContext, statedb)
if err != nil {
release()
return nil, nil, err
Expand Down
3 changes: 2 additions & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ func (w *worker) commitNewWork(predicateContext *precompileconfig.PredicateConte
env.state.StopPrefetcher()
}()
// Configure any upgrades that should go into effect during this block.
err = core.ApplyUpgrades(w.chainConfig, &parent.Time, types.NewBlockWithHeader(header), env.state)
blockContext := core.NewBlockContext(header.Number, header.Time)
err = core.ApplyUpgrades(w.chainConfig, &parent.Time, blockContext, env.state)
if err != nil {
log.Error("failed to configure precompiles mining new block", "parent", parent.Hash(), "number", header.Number, "timestamp", header.Time, "err", err)
return nil, err
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
Loading