@@ -1349,16 +1349,6 @@ func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
1349
1349
blockContentValidationTimer .Inc (time .Since (substart ).Milliseconds ())
1350
1350
1351
1351
// No validation errors for the block
1352
- var activeState * state.StateDB
1353
- defer func () {
1354
- // The chain importer is starting and stopping trie prefetchers. If a bad
1355
- // block or other error is hit however, an early return may not properly
1356
- // terminate the background threads. This defer ensures that we clean up
1357
- // and dangling prefetcher, without deferring each and holding on live refs.
1358
- if activeState != nil {
1359
- activeState .StopPrefetcher ()
1360
- }
1361
- }()
1362
1352
1363
1353
// Retrieve the parent block to determine which root to build state on
1364
1354
substart = time .Now ()
@@ -1377,8 +1367,8 @@ func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
1377
1367
blockStateInitTimer .Inc (time .Since (substart ).Milliseconds ())
1378
1368
1379
1369
// Enable prefetching to pull in trie node paths while processing transactions
1380
- statedb .StartPrefetcher ("chain" , bc .cacheConfig .TriePrefetcherParallelism )
1381
- activeState = statedb
1370
+ statedb .StartPrefetcher ("chain" , state . WithConcurrentWorkers ( bc .cacheConfig .TriePrefetcherParallelism ) )
1371
+ defer statedb . StopPrefetcher ()
1382
1372
1383
1373
// Process block using the parent state as reference point
1384
1374
pstart := time .Now ()
@@ -1736,10 +1726,8 @@ func (bc *BlockChain) reprocessBlock(parent *types.Block, current *types.Block)
1736
1726
}
1737
1727
1738
1728
// Enable prefetching to pull in trie node paths while processing transactions
1739
- statedb .StartPrefetcher ("chain" , bc .cacheConfig .TriePrefetcherParallelism )
1740
- defer func () {
1741
- statedb .StopPrefetcher ()
1742
- }()
1729
+ statedb .StartPrefetcher ("chain" , state .WithConcurrentWorkers (bc .cacheConfig .TriePrefetcherParallelism ))
1730
+ defer statedb .StopPrefetcher ()
1743
1731
1744
1732
// Process previously stored block
1745
1733
receipts , _ , usedGas , err := bc .processor .Process (current , parent .Header (), statedb , vm.Config {})
0 commit comments