Skip to content

Commit 7a882f9

Browse files
committed
use core.NewBlockContext to avoid breaking changes
1 parent 40e07af commit 7a882f9

File tree

12 files changed

+31
-25
lines changed

12 files changed

+31
-25
lines changed

core/chain_makers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
284284
b := &BlockGen{i: i, cm: cm, parent: parent, statedb: statedb, engine: engine}
285285
b.header = cm.makeHeader(parent, gap, statedb, b.engine)
286286

287-
err := ApplyUpgrades(config, &parent.Header().Time, b, statedb)
287+
blockContext := NewBlockContext(b.header.Number, b.header.Time)
288+
err := ApplyUpgrades(config, &parent.Header().Time, blockContext, statedb)
288289
if err != nil {
289290
return nil, nil, fmt.Errorf("failed to configure precompiles %w", err)
290291
}

core/genesis.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ func (g *Genesis) toBlock(db ethdb.Database, triedb *triedb.Database) *types.Blo
277277
}
278278

279279
// Configure any stateful precompiles that should be enabled in the genesis.
280-
err = ApplyPrecompileActivations(g.Config, nil, types.NewBlockWithHeader(head), statedb)
280+
blockContext := NewBlockContext(head.Number, head.Time)
281+
err = ApplyPrecompileActivations(g.Config, nil, blockContext, statedb)
281282
if err != nil {
282283
panic(fmt.Sprintf("unable to configure precompiles in genesis block: %v", err))
283284
}

core/state_processor.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ func (p *StateProcessor) Process(block *types.Block, parent *types.Header, state
8383
)
8484

8585
// Configure any upgrades that should go into effect during this block.
86-
err := ApplyUpgrades(p.config, &parent.Time, block, statedb)
86+
blockContext := NewBlockContext(block.Number(), block.Time())
87+
err := ApplyUpgrades(p.config, &parent.Time, blockContext, statedb)
8788
if err != nil {
8889
log.Error("failed to configure precompiles processing block", "hash", block.Hash(), "number", block.NumberU64(), "timestamp", block.Time(), "err", err)
8990
return nil, nil, 0, err
@@ -210,7 +211,7 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat
210211
// This function is called within genesis setup to configure the starting state for precompiles enabled at genesis.
211212
// In block processing and building, ApplyUpgrades is called instead which also applies state upgrades.
212213
func ApplyPrecompileActivations(c *params.ChainConfig, parentTimestamp *uint64, blockContext contract.ConfigurationBlockContext, statedb *state.StateDB) error {
213-
blockTimestamp := blockContext.Time()
214+
blockTimestamp := blockContext.Timestamp()
214215
// Note: RegisteredModules returns precompiles sorted by module addresses.
215216
// This ensures that the order we call Configure for each precompile is consistent.
216217
// This ensures even if precompiles read/write state other than their own they will observe
@@ -261,7 +262,7 @@ func ApplyPrecompileActivations(c *params.ChainConfig, parentTimestamp *uint64,
261262
func applyStateUpgrades(c *params.ChainConfig, parentTimestamp *uint64, blockContext contract.ConfigurationBlockContext, statedb *state.StateDB) error {
262263
// Apply state upgrades
263264
configExtra := params.GetExtra(c)
264-
for _, upgrade := range configExtra.GetActivatingStateUpgrades(parentTimestamp, blockContext.Time(), configExtra.StateUpgrades) {
265+
for _, upgrade := range configExtra.GetActivatingStateUpgrades(parentTimestamp, blockContext.Timestamp(), configExtra.StateUpgrades) {
265266
log.Info("Applying state upgrade", "blockNumber", blockContext.Number(), "upgrade", upgrade)
266267
if err := stateupgrade.Configure(&upgrade, c, statedb, blockContext); err != nil {
267268
return fmt.Errorf("could not configure state upgrade: %w", err)
@@ -295,5 +296,5 @@ func NewBlockContext(number *big.Int, time uint64) *blockContext {
295296
}
296297
}
297298

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

eth/state_accessor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ func (eth *Ethereum) StateAtNextBlock(ctx context.Context, parent *types.Block,
284284
}
285285

286286
// Apply upgrades here for the [nextBlock]
287-
err = core.ApplyUpgrades(eth.blockchain.Config(), &parent.Header().Time, nextBlock, statedb)
287+
blockContext := core.NewBlockContext(nextBlock.Number(), nextBlock.Time())
288+
err = core.ApplyUpgrades(eth.blockchain.Config(), &parent.Header().Time, blockContext, statedb)
288289
if err != nil {
289290
release()
290291
return nil, nil, err

eth/tracers/api_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ func (b *testBackend) StateAtNextBlock(ctx context.Context, parent, nextBlock *t
181181
return nil, nil, err
182182
}
183183
// Apply upgrades to the parent state
184-
err = core.ApplyUpgrades(b.chainConfig, &parent.Header().Time, nextBlock, statedb)
184+
blockContext := core.NewBlockContext(nextBlock.Number(), nextBlock.Time())
185+
err = core.ApplyUpgrades(b.chainConfig, &parent.Header().Time, blockContext, statedb)
185186
if err != nil {
186187
release()
187188
return nil, nil, err

miner/worker.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ func (w *worker) commitNewWork(predicateContext *precompileconfig.PredicateConte
228228
env.state.StopPrefetcher()
229229
}()
230230
// Configure any upgrades that should go into effect during this block.
231-
err = core.ApplyUpgrades(w.chainConfig, &parent.Time, types.NewBlockWithHeader(header), env.state)
231+
blockContext := core.NewBlockContext(header.Number, header.Time)
232+
err = core.ApplyUpgrades(w.chainConfig, &parent.Time, blockContext, env.state)
232233
if err != nil {
233234
log.Error("failed to configure precompiles mining new block", "parent", parent.Hash(), "number", header.Number, "timestamp", header.Time, "err", err)
234235
return nil, err

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) Time() uint64 {
144+
func (p *precompileBlockContext) Timestamp() uint64 {
145145
return p.time
146146
}
147147

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-
Time() uint64
65+
Timestamp() 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().Time())
63+
return evm.GetChainConfig().IsDurango(evm.GetBlockContext().Timestamp())
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().Time().Return(uint64(0)).AnyTimes()
147+
mbc.EXPECT().Timestamp().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().Time().Return(uint64(0)).AnyTimes()
324+
mbc.EXPECT().Timestamp().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().Time().Return(uint64(0)).AnyTimes()
347+
mbc.EXPECT().Timestamp().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().Time().Return(uint64(0)).AnyTimes()
374+
mbc.EXPECT().Timestamp().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().Time().Return(uint64(0)).AnyTimes()
391+
mbc.EXPECT().Timestamp().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().Time().Return(uint64(time.Now().Unix())).AnyTimes()
109+
blockContext.EXPECT().Timestamp().Return(uint64(time.Now().Unix())).AnyTimes()
110110
}
111111
snowContext := utils.TestSnowContext()
112112

0 commit comments

Comments
 (0)