Skip to content

Commit

Permalink
Correctly set lastFlushHash in utxo cache init
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacia committed Mar 9, 2021
1 parent 90684b9 commit 92d3d9b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions blockchain/utxocache.go
Original file line number Diff line number Diff line change
@@ -692,17 +692,13 @@ func (s *utxoCache) InitConsistentState(tip *blockNode, fastSync bool, interrupt
log.Tracef("UTXO cache consistency status from disk: [%d] hash %v",
statusCode, statusHash)

// We can set this variable now already because it will always be valid
// unless an error is returned, in which case the state is entirely invalid.
// Doing it here prevents forgetting it later.
s.lastFlushHash = tip.hash

// If no status was found, the database is old and didn't have a cached utxo
// state yet. In that case, we set the status to the best state and write
// this to the database.
if statusCode == ucsEmpty {
log.Debugf("Database didn't specify UTXO state consistency: consistent "+
"to best chain tip (%v)", tip.hash)
s.lastFlushHash = tip.hash
err := s.db.Update(func(dbTx database.Tx) error {
return dbPutUtxoStateConsistency(dbTx, ucsConsistent, &tip.hash)
})
@@ -713,10 +709,12 @@ func (s *utxoCache) InitConsistentState(tip *blockNode, fastSync bool, interrupt
// If state is consistent, we are done.
if statusCode == ucsConsistent && *statusHash == tip.hash {
log.Debugf("UTXO state consistent (%d:%v)", tip.height, tip.hash)

s.lastFlushHash = tip.hash
return nil
}

s.lastFlushHash = *statusHash

log.Info("Reconstructing UTXO state after unclean shutdown. This may take " +
"a long time...")

0 comments on commit 92d3d9b

Please sign in to comment.