Skip to content

Commit

Permalink
Merge pull request #201 from kcalvinalvin/2024-09-02-fix-utreexoproof…
Browse files Browse the repository at this point in the history
…index-max-memory-bug

indexers: fix bug when flushing with utreexoproofindexmaxmemory=-1
  • Loading branch information
kcalvinalvin authored Sep 3, 2024
2 parents 87a8b19 + de309e2 commit ad04fea
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 ad04fea

Please sign in to comment.