Skip to content

Commit

Permalink
Fix RocksDb GetMinRewindHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumagi committed Aug 18, 2021
1 parent fd885da commit 7cffdd8
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,20 @@ public void SaveChanges(IList<UnspentOutput> unspentOutputs, HashHeightPair oldB
/// <inheritdoc />
public int GetMinRewindHeight()
{
HashHeightPair current = this.GetTipHash();
// Find the first row with a rewind table key prefix.
using (var iterator = this.rocksDb.NewIterator())
{
iterator.Seek(new byte[] { rewindTable });
if (!iterator.Valid())
return -1;

int minHeight = current?.Height ?? -1;
byte[] key = iterator.Key();

while (minHeight > 0 && this.rocksDb.Get(new byte[] { rewindTable }.Concat(BitConverter.GetBytes(minHeight)).ToArray()) != null)
minHeight--;
if (key.Length != 5 || key[0] != rewindTable)
return -1;

return minHeight;
return BitConverter.ToInt32(key.SafeSubarray(1, 4).ToArray());
}
}

/// <inheritdoc />
Expand Down

0 comments on commit 7cffdd8

Please sign in to comment.