From 418106538e846fb85b90ca57cdd691a0ff6d53a3 Mon Sep 17 00:00:00 2001 From: Kevin Gorham Date: Thu, 29 Apr 2021 03:34:35 -0400 Subject: [PATCH] Fix: Full rescan should not go beyond the checkpoint. Otherwise, it gets interpreted as a reorg and can throw the wallet into an infinite rewind loop. --- .../cash/z/ecc/android/sdk/block/CompactBlockProcessor.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/cash/z/ecc/android/sdk/block/CompactBlockProcessor.kt b/src/main/java/cash/z/ecc/android/sdk/block/CompactBlockProcessor.kt index e90d94a8..0db8c720 100644 --- a/src/main/java/cash/z/ecc/android/sdk/block/CompactBlockProcessor.kt +++ b/src/main/java/cash/z/ecc/android/sdk/block/CompactBlockProcessor.kt @@ -594,8 +594,10 @@ class CompactBlockProcessor( } suspend fun getNearestRewindHeight(height: Int): Int { - return if (height < lowerBoundHeight) { - lowerBoundHeight + // TODO: add a concept of original checkpoint height to the processor. For now, derive it + val originalCheckpoint = lowerBoundHeight + MAX_REORG_SIZE + 2 // add one because we already have the checkpoint. Add one again because we delete ABOVE the block + return if (height < originalCheckpoint) { + originalCheckpoint } else { // tricky: subtract one because we delete ABOVE this block rustBackend.getNearestRewindHeight(height) - 1