Fix: Off-by-one error during rewind.

This commit is contained in:
Kevin Gorham 2021-04-22 18:47:58 -04:00
parent 5dd0df7619
commit c60119cd5a
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
2 changed files with 5 additions and 4 deletions

View File

@ -596,7 +596,8 @@ class CompactBlockProcessor(
return if (height < lowerBoundHeight) { return if (height < lowerBoundHeight) {
lowerBoundHeight lowerBoundHeight
} else { } else {
rustBackend.getNearestRewindHeight(height) // tricky: subtract one because we delete ABOVE this block
rustBackend.getNearestRewindHeight(height) - 1
} }
} }

View File

@ -433,7 +433,7 @@ interface TransactionDao {
twig("[cleanup] cleanupCancelledTx found ${it.size} matching transactions to cleanup") twig("[cleanup] cleanupCancelledTx found ${it.size} matching transactions to cleanup")
}.forEach { transactionId -> }.forEach { transactionId ->
hasInitialMatch = true hasInitialMatch = true
removeInvalidTransaction(transactionId) removeInvalidOutboundTransaction(transactionId)
} }
hasFinalMatch = findMatchingTransactionId(rawTransactionId) != null hasFinalMatch = findMatchingTransactionId(rawTransactionId) != null
success = hasInitialMatch && !hasFinalMatch success = hasInitialMatch && !hasFinalMatch
@ -445,7 +445,7 @@ interface TransactionDao {
} }
@Transaction @Transaction
suspend fun removeInvalidTransaction(transactionId: Long): Boolean { suspend fun removeInvalidOutboundTransaction(transactionId: Long): Boolean {
var success = false var success = false
try { try {
twig("[cleanup] removing invalid transactionId:$transactionId") twig("[cleanup] removing invalid transactionId:$transactionId")
@ -474,7 +474,7 @@ interface TransactionDao {
suspend fun deleteExpired(lastHeight: Int): Int { suspend fun deleteExpired(lastHeight: Int): Int {
var count = 0 var count = 0
findExpiredTxs(lastHeight).forEach { transactionId -> findExpiredTxs(lastHeight).forEach { transactionId ->
if (removeInvalidTransaction(transactionId)) count++ if (removeInvalidOutboundTransaction(transactionId)) count++
} }
return count return count
} }