@@ -414,7 +414,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
414
414
// Make sure the state associated with the block is available, or log out
415
415
// if there is no available state, waiting for state sync.
416
416
head := bc .CurrentBlock ()
417
- if ! bc .NoTries () && ! bc . HasState (head .Root ) {
417
+ if ! bc .HasState (head .Root ) {
418
418
if head .Number .Uint64 () == 0 {
419
419
// The genesis state is missing, which is only possible in the path-based
420
420
// scheme. This situation occurs when the initial state sync is not finished
@@ -430,7 +430,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
430
430
if bc .cacheConfig .SnapshotLimit > 0 {
431
431
diskRoot = rawdb .ReadSnapshotRoot (bc .db )
432
432
}
433
- if bc .triedb .Scheme () == rawdb .PathScheme {
433
+ if bc .triedb .Scheme () == rawdb .PathScheme && ! bc . NoTries () {
434
434
recoverable , _ := bc .triedb .Recoverable (diskRoot )
435
435
if ! bc .HasState (diskRoot ) && ! recoverable {
436
436
diskRoot = bc .triedb .Head ()
@@ -993,7 +993,7 @@ func (bc *BlockChain) rewindPathHead(head *types.Header, root common.Hash) (*typ
993
993
// then block number zero is returned, indicating that snapshot recovery is disabled
994
994
// and the whole snapshot should be auto-generated in case of head mismatch.
995
995
func (bc * BlockChain ) rewindHead (head * types.Header , root common.Hash ) (* types.Header , uint64 ) {
996
- if bc .triedb .Scheme () == rawdb .PathScheme {
996
+ if bc .triedb .Scheme () == rawdb .PathScheme && ! bc . NoTries () {
997
997
return bc .rewindPathHead (head , root )
998
998
}
999
999
return bc .rewindHashHead (head , root )
@@ -1030,6 +1030,19 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha
1030
1030
// block. Note, depth equality is permitted to allow using SetHead as a
1031
1031
// chain reparation mechanism without deleting any data!
1032
1032
if currentBlock := bc .CurrentBlock (); currentBlock != nil && header .Number .Uint64 () <= currentBlock .Number .Uint64 () {
1033
+ // load bc.snaps for the judge `HasState`
1034
+ if bc .NoTries () {
1035
+ if bc .cacheConfig .SnapshotLimit > 0 {
1036
+ snapconfig := snapshot.Config {
1037
+ CacheSize : bc .cacheConfig .SnapshotLimit ,
1038
+ NoBuild : bc .cacheConfig .SnapshotNoBuild ,
1039
+ AsyncBuild : ! bc .cacheConfig .SnapshotWait ,
1040
+ }
1041
+ bc .snaps , _ = snapshot .New (snapconfig , bc .db , bc .triedb , header .Root , int (bc .cacheConfig .TriesInMemory ), bc .NoTries ())
1042
+ }
1043
+ defer func () { bc .snaps = nil }()
1044
+ }
1045
+
1033
1046
var newHeadBlock * types.Header
1034
1047
newHeadBlock , rootNumber = bc .rewindHead (header , root )
1035
1048
rawdb .WriteHeadBlockHash (db , newHeadBlock .Hash ())
0 commit comments