Skip to content

Commit

Permalink
indexers: fix bug when flushing with utreexoproofindexmaxmemory=-1
Browse files Browse the repository at this point in the history
When keeping everything in memory, the keys that may have already been
deleted may still exist on disk. So the entirety of the database must be
deleted before the in-memory utreexo state is flushed to disk.
  • Loading branch information
kcalvinalvin committed Sep 2, 2024
1 parent 87a8b19 commit de309e2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions blockchain/indexers/utreexobackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,24 @@ func (us *UtreexoState) flush(bestHash *chainhash.Hash) error {
return err
}

// If we're keeping everything in memory, make sure to remove everything from the
// current database before flushing as the keys deleted in memory may still exist
// on disk.
if us.config.MaxMemoryUsage < 0 {
iter := us.utreexoStateDB.NewIterator(nil, nil)
for iter.Next() {
err := ldbTx.Delete(iter.Key(), nil)
if err != nil {
ldbTx.Discard()
return err
}
}
}

// Write the best block hash and the numleaves for the utreexo state.
err = dbWriteUtreexoStateConsistency(ldbTx, bestHash, us.state.GetNumLeaves())
if err != nil {
ldbTx.Discard()
return err
}

Expand Down

0 comments on commit de309e2

Please sign in to comment.