@@ -225,16 +225,10 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
225225 futureBlocks , _ := lru .New (maxFutureBlocks )
226226
227227 bc := & BlockChain {
228- chainConfig : chainConfig ,
229- cacheConfig : cacheConfig ,
230- db : db ,
231- triegc : prque .New (nil ),
232- stateCache : state .NewDatabaseWithConfig (db , & trie.Config {
233- Cache : cacheConfig .TrieCleanLimit ,
234- Journal : cacheConfig .TrieCleanJournal ,
235- Preimages : cacheConfig .Preimages ,
236- UseVerkle : chainConfig .UseVerkle ,
237- }),
228+ chainConfig : chainConfig ,
229+ cacheConfig : cacheConfig ,
230+ db : db ,
231+ triegc : prque .New (nil ),
238232 quit : make (chan struct {}),
239233 shouldPreserve : shouldPreserve ,
240234 bodyCache : bodyCache ,
@@ -279,8 +273,16 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
279273 if err := bc .loadLastState (); err != nil {
280274 return nil , err
281275 }
276+
282277 // Make sure the state associated with the block is available
283278 head := bc .CurrentBlock ()
279+ bc .stateCache = state .NewDatabaseWithConfig (db , & trie.Config {
280+ Cache : cacheConfig .TrieCleanLimit ,
281+ Journal : cacheConfig .TrieCleanJournal ,
282+ Preimages : cacheConfig .Preimages ,
283+ UseVerkle : chainConfig .IsCancun (head .Header ().Number ),
284+ })
285+
284286 if _ , err := state .New (head .Root (), bc .stateCache , bc .snaps ); err != nil {
285287 // Head state is missing, before the state recovery, find out the
286288 // disk layer point of snapshot(if it's enabled). Make sure the
@@ -371,7 +373,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
371373 log .Warn ("Enabling snapshot recovery" , "chainhead" , head .NumberU64 (), "diskbase" , * layer )
372374 recover = true
373375 }
374- bc .snaps , _ = snapshot .New (bc .db , bc .stateCache .TrieDB (), bc .cacheConfig .SnapshotLimit , head .Root (), ! bc .cacheConfig .SnapshotWait , true , recover , bc . Config (). UseVerkle )
376+ bc .snaps , _ = snapshot .New (bc .db , bc .stateCache .TrieDB (), bc .cacheConfig .SnapshotLimit , head .Root (), ! bc .cacheConfig .SnapshotWait , true , recover , chainConfig . IsCancun ( head . Header (). Number ) )
375377 }
376378 // Take ownership of this particular state
377379 go bc .update ()
0 commit comments