Skip to content

Commit 0af50dd

Browse files
committed
fix: an attempt at making witness generation more stable
1 parent d482b2f commit 0af50dd

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

core/blockchain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
16991699
}
17001700

17011701
// Enable prefetching to pull in trie node paths while processing transactions
1702-
statedb.StartPrefetcher("chain", nil)
1702+
statedb.StartPrefetcher("chain")
17031703
activeState = statedb
17041704

17051705
// If we have a followup block, run that against the current state to pre-cache
@@ -1836,7 +1836,7 @@ func (bc *BlockChain) BuildAndWriteBlock(parentBlock *types.Block, header *types
18361836
return nil, NonStatTy, err
18371837
}
18381838

1839-
statedb.StartPrefetcher("l1sync", nil)
1839+
statedb.StartPrefetcher("l1sync")
18401840
defer statedb.StopPrefetcher()
18411841

18421842
header.ParentHash = parentBlock.Hash()

core/state/statedb.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,20 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
160160
return sdb, nil
161161
}
162162

163+
// WithWitness sets the witness for the state database.
164+
func (s *StateDB) WithWitness(witness *stateless.Witness) {
165+
s.witness = witness
166+
}
167+
163168
// StartPrefetcher initializes a new trie prefetcher to pull in nodes from the
164169
// state trie concurrently while the state is mutated so that when we reach the
165170
// commit phase, most of the needed data is already hot.
166-
func (s *StateDB) StartPrefetcher(namespace string, witness *stateless.Witness) {
171+
func (s *StateDB) StartPrefetcher(namespace string) {
167172
if s.prefetcher != nil {
168173
s.prefetcher.close()
169174
s.prefetcher = nil
170175
}
171176

172-
// Enable witness collection if requested
173-
s.witness = witness
174-
175177
if s.snap != nil {
176178
s.prefetcher = newTriePrefetcher(s.db, s.originalRoot, namespace)
177179
}

eth/api.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,11 @@ func generateWitness(blockchain *core.BlockChain, block *types.Block) (*stateles
354354
if err != nil {
355355
return nil, fmt.Errorf("failed to retrieve parent state: %w", err)
356356
}
357+
statedb.WithWitness(witness)
357358

358359
// Collect storage locations that prover needs but sequencer might not touch necessarily
359360
statedb.GetState(rcfg.L2MessageQueueAddress, rcfg.WithdrawTrieRootSlot)
360361

361-
statedb.StartPrefetcher("debug_execution_witness", witness)
362-
defer statedb.StopPrefetcher()
363-
364362
receipts, _, usedGas, err := blockchain.Processor().Process(block, statedb, *blockchain.GetVMConfig())
365363
if err != nil {
366364
return nil, fmt.Errorf("failed to process block %d: %w", block.Number(), err)

rollup/pipeline/pipeline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func sendCancellable[T any, C comparable](resCh chan T, msg T, cancelCh <-chan C
228228
}
229229

230230
func (p *Pipeline) traceAndApplyStage(txsIn <-chan *types.Transaction) (<-chan error, <-chan *BlockCandidate, error) {
231-
p.state.StartPrefetcher("miner", nil)
231+
p.state.StartPrefetcher("miner")
232232
downstreamCh := make(chan *BlockCandidate, p.downstreamChCapacity())
233233
resCh := make(chan error)
234234
p.wg.Add(1)

0 commit comments

Comments
 (0)