Skip to content

Commit 989ae1d

Browse files
authored
Merge branch 'master' into fix-rewinding
2 parents 6289f4d + 3083ee8 commit 989ae1d

File tree

11 files changed

+41
-14
lines changed

11 files changed

+41
-14
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
216216
if beaconRoot := pre.Env.ParentBeaconBlockRoot; beaconRoot != nil {
217217
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
218218
}
219-
if pre.Env.BlockHashes != nil && chainConfig.IsPrague(new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp, vmContext.ArbOSVersion) {
219+
if !chainConfig.IsArbitrum() && pre.Env.BlockHashes != nil && chainConfig.IsPrague(new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp, vmContext.ArbOSVersion) {
220220
var (
221221
prevNumber = pre.Env.Number - 1
222222
prevHash = pre.Env.BlockHashes[math.HexOrDecimal64(prevNumber)]

core/blockchain.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ type CacheConfig struct {
160160
SnapshotRestoreMaxGas uint64 // Rollback up to this much gas to restore snapshot (otherwise snapshot recalculated from nothing)
161161

162162
// Arbitrum: configure GC window
163-
TriesInMemory uint64 // Height difference before which a trie may not be garbage-collected
164-
TrieRetention time.Duration // Time limit before which a trie may not be garbage-collected
163+
TriesInMemory uint64 // Height difference before which a trie may not be garbage-collected
164+
TrieRetention time.Duration // Time limit before which a trie may not be garbage-collected
165+
TrieTimeLimitRandomOffset time.Duration // Range of random offset of each commit due to TrieTimeLimit period
165166

166167
MaxNumberOfBlocksToSkipStateSaving uint32
167168
MaxAmountOfGasToSkipStateSaving uint64
@@ -203,6 +204,7 @@ var defaultCacheConfig = &CacheConfig{
203204
// Arbitrum Config Options
204205
TriesInMemory: state.DefaultTriesInMemory,
205206
TrieRetention: 30 * time.Minute,
207+
TrieTimeLimitRandomOffset: 0,
206208
MaxNumberOfBlocksToSkipStateSaving: 0,
207209
MaxAmountOfGasToSkipStateSaving: 0,
208210

@@ -295,8 +297,10 @@ type BlockChain struct {
295297
vmConfig vm.Config
296298
logger *tracing.Hooks
297299

300+
// Arbitrum:
298301
numberOfBlocksToSkipStateSaving uint32
299302
amountOfGasInBlocksToSkipStateSaving uint64
303+
gcprocRandOffset time.Duration // random offset for gcproc time
300304
}
301305

302306
type trieGcEntry struct {
@@ -376,6 +380,8 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
376380
bc.prefetcher = newStatePrefetcher(chainConfig, bc.hc)
377381
bc.processor = NewStateProcessor(chainConfig, bc.hc)
378382

383+
bc.gcprocRandOffset = bc.generateGcprocRandOffset()
384+
379385
bc.genesisBlock = bc.GetBlockByNumber(0)
380386
if bc.genesisBlock == nil {
381387
return nil, ErrNoGenesis
@@ -1627,8 +1633,9 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
16271633
}
16281634
flushInterval := time.Duration(bc.flushInterval.Load())
16291635
// If we exceeded out time allowance, flush an entire trie to disk
1636+
// The time threshold can be offset by gcprocRandOffset if TrieTimeLimitRandomOffset > 0; the offset is re-generated after each full trie flush
16301637
// In case of archive node that skips some trie commits we don't flush tries here
1631-
if bc.gcproc > flushInterval && prevEntry != nil && !archiveNode {
1638+
if bc.gcproc+bc.gcprocRandOffset > flushInterval && prevEntry != nil && !archiveNode {
16321639
// If the header is missing (canonical chain behind), we're reorging a low
16331640
// diff sidechain. Suspend committing until this operation is completed.
16341641
header := bc.GetHeaderByNumber(prevNum)
@@ -1644,6 +1651,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
16441651
bc.triedb.Commit(header.Root, true)
16451652
bc.lastWrite = prevNum
16461653
bc.gcproc = 0
1654+
bc.gcprocRandOffset = bc.generateGcprocRandOffset()
16471655
}
16481656
}
16491657
if prevEntry != nil {

core/blockchain_arbitrum.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package core
1919

2020
import (
2121
"fmt"
22+
"math/rand/v2"
2223
"time"
2324

2425
"github.com/ethereum/go-ethereum/common"
@@ -29,6 +30,13 @@ import (
2930
"github.com/ethereum/go-ethereum/rpc"
3031
)
3132

33+
func (bc *BlockChain) generateGcprocRandOffset() time.Duration {
34+
if bc.cacheConfig.TrieTimeLimitRandomOffset > 0 {
35+
return time.Duration(rand.Int64N(int64(bc.cacheConfig.TrieTimeLimitRandomOffset)))
36+
}
37+
return 0
38+
}
39+
3240
func (bc *BlockChain) FlushTrieDB(capLimit common.StorageSize) error {
3341
if bc.triedb.Scheme() == rawdb.PathScheme {
3442
return nil
@@ -53,6 +61,7 @@ func (bc *BlockChain) FlushTrieDB(capLimit common.StorageSize) error {
5361
}
5462

5563
bc.gcproc = 0
64+
bc.gcprocRandOffset = bc.generateGcprocRandOffset()
5665
bc.lastWrite = blockNumber
5766
}
5867
}

core/chain_makers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
390390
}
391391

392392
blockContext := NewEVMBlockContext(b.header, cm, &b.header.Coinbase)
393-
if config.IsPrague(b.header.Number, b.header.Time, blockContext.ArbOSVersion) || config.IsVerkle(b.header.Number, b.header.Time) {
393+
if !config.IsArbitrum() && config.IsPrague(b.header.Number, b.header.Time, blockContext.ArbOSVersion) || config.IsVerkle(b.header.Number, b.header.Time) {
394394
// EIP-2935
395395
blockContext.Random = &common.Hash{} // enable post-merge instruction set
396396
evm := vm.NewEVM(blockContext, statedb, cm.config, vm.Config{})

core/state_processor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
8585
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
8686
ProcessBeaconBlockRoot(*beaconRoot, evm)
8787
}
88-
if p.config.IsPrague(block.Number(), block.Time(), context.ArbOSVersion) || p.config.IsVerkle(block.Number(), block.Time()) {
88+
// We do not need to process the parent block hash if we are on Arbitrum.
89+
// This is taken care of in the while we process the arbitrum internal transaction.
90+
if !p.config.IsArbitrum() && (p.config.IsPrague(block.Number(), block.Time(), context.ArbOSVersion) || p.config.IsVerkle(block.Number(), block.Time())) {
8991
ProcessParentBlockHash(block.ParentHash(), evm)
9092
}
9193

eth/state_accessor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (eth *Ethereum) stateAtTransaction(ctx context.Context, block *types.Block,
261261
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
262262
}
263263
// If prague hardfork, insert parent block hash in the state as per EIP-2935.
264-
if eth.blockchain.Config().IsPrague(block.Number(), block.Time(), context.ArbOSVersion) {
264+
if !eth.blockchain.Config().IsArbitrum() && eth.blockchain.Config().IsPrague(block.Number(), block.Time(), context.ArbOSVersion) {
265265
core.ProcessParentBlockHash(block.ParentHash(), evm)
266266
}
267267
if txIndex == 0 && len(block.Transactions()) == 0 {

eth/tracers/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func (api *API) traceChain(start, end *types.Block, config *TraceConfig, closed
389389
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
390390
}
391391
// Insert parent hash in history contract.
392-
if api.backend.ChainConfig().IsPrague(next.Number(), next.Time(), context.ArbOSVersion) {
392+
if !api.backend.ChainConfig().IsArbitrum() && api.backend.ChainConfig().IsPrague(next.Number(), next.Time(), context.ArbOSVersion) {
393393
core.ProcessParentBlockHash(next.ParentHash(), evm)
394394
}
395395
// Clean out any pending release functions of trace state. Note this
@@ -544,7 +544,7 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config
544544
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
545545
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
546546
}
547-
if chainConfig.IsPrague(block.Number(), block.Time(), vmctx.ArbOSVersion) {
547+
if !chainConfig.IsArbitrum() && chainConfig.IsPrague(block.Number(), block.Time(), vmctx.ArbOSVersion) {
548548
core.ProcessParentBlockHash(block.ParentHash(), evm)
549549
}
550550
for i, tx := range block.Transactions() {
@@ -608,7 +608,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
608608
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
609609
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
610610
}
611-
if api.backend.ChainConfig().IsPrague(block.Number(), block.Time(), blockCtx.ArbOSVersion) {
611+
if !api.backend.ChainConfig().IsArbitrum() && api.backend.ChainConfig().IsPrague(block.Number(), block.Time(), blockCtx.ArbOSVersion) {
612612
core.ProcessParentBlockHash(block.ParentHash(), evm)
613613
}
614614

@@ -787,7 +787,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
787787
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
788788
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
789789
}
790-
if chainConfig.IsPrague(block.Number(), block.Time(), vmctx.ArbOSVersion) {
790+
if !chainConfig.IsArbitrum() && chainConfig.IsPrague(block.Number(), block.Time(), vmctx.ArbOSVersion) {
791791
core.ProcessParentBlockHash(block.ParentHash(), evm)
792792
}
793793
for i, tx := range block.Transactions() {

internal/ethapi/simulate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
208208
if precompiles != nil {
209209
evm.SetPrecompiles(precompiles)
210210
}
211-
if sim.chainConfig.IsPrague(header.Number, header.Time, parentArbOSVersion) || sim.chainConfig.IsVerkle(header.Number, header.Time) {
211+
if !sim.chainConfig.IsArbitrum() && sim.chainConfig.IsPrague(header.Number, header.Time, parentArbOSVersion) || sim.chainConfig.IsVerkle(header.Number, header.Time) {
212212
core.ProcessParentBlockHash(header.ParentHash, evm)
213213
}
214214
var allLogs []*types.Log

metrics/sliding_time_window_array_sample.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ func (s *SlidingTimeWindowArraySample) Snapshot() *sampleSnapshot {
104104

105105
// Update samples a new value.
106106
func (s *SlidingTimeWindowArraySample) Update(v int64) {
107+
if !metricsEnabled {
108+
return
109+
}
107110
s.mutex.Lock()
108111
defer s.mutex.Unlock()
109112
var newTick int64

miner/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (miner *Miner) prepareWork(genParams *generateParams, witness bool) (*envir
230230
if header.ParentBeaconRoot != nil {
231231
core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, env.evm)
232232
}
233-
if miner.chainConfig.IsPrague(header.Number, header.Time, prevArbosVersion) {
233+
if !miner.chainConfig.IsArbitrum() && miner.chainConfig.IsPrague(header.Number, header.Time, prevArbosVersion) {
234234
core.ProcessParentBlockHash(header.ParentHash, env.evm)
235235
}
236236
return env, nil

0 commit comments

Comments
 (0)