Skip to content

Commit b293e6d

Browse files
codablockUdjinM6
authored andcommitted
[v0.14.0.x] Fix off-by-one error in InstantSend mining info removal when disconnecting blocks (dashpay#2951)
* Refactor checks for disconnected blocks and conflicts in CInstantSendManager::SyncTransaction * Fix off-by-one when calling RemoveInstantSendLockMined
1 parent 276b6e3 commit b293e6d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/llmq/quorums_instantsend.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -937,11 +937,12 @@ void CInstantSendManager::SyncTransaction(const CTransaction& tx, const CBlockIn
937937
}
938938

939939
bool inMempool = mempool.get(tx.GetHash()) != nullptr;
940+
bool isDisconnect = pindex && posInBlock == CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK;
940941

941942
// Are we called from validation.cpp/MemPoolConflictRemovalTracker?
942943
// TODO refactor this when we backport the BlockConnected signal from Bitcoin, as it gives better info about
943944
// conflicted TXs
944-
bool isConflictRemoved = !pindex && posInBlock == CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK && !inMempool;
945+
bool isConflictRemoved = isDisconnect && !inMempool;
945946

946947
if (isConflictRemoved) {
947948
LOCK(cs);
@@ -956,8 +957,9 @@ void CInstantSendManager::SyncTransaction(const CTransaction& tx, const CBlockIn
956957

957958
// update DB about when an IS lock was mined
958959
if (!islockHash.IsNull() && pindex) {
959-
if (posInBlock == CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK) {
960-
db.RemoveInstantSendLockMined(islockHash, pindex->nHeight);
960+
if (isDisconnect) {
961+
// SyncTransaction is called with pprev
962+
db.RemoveInstantSendLockMined(islockHash, pindex->nHeight + 1);
961963
} else {
962964
db.WriteInstantSendLockMined(islockHash, pindex->nHeight);
963965
}
@@ -977,7 +979,7 @@ void CInstantSendManager::SyncTransaction(const CTransaction& tx, const CBlockIn
977979
if (!chainlocked && islockHash.IsNull()) {
978980
// TX is not locked, so make sure it is tracked
979981
AddNonLockedTx(MakeTransactionRef(tx));
980-
nonLockedTxs.at(tx.GetHash()).pindexMined = posInBlock != CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK ? pindex : nullptr;
982+
nonLockedTxs.at(tx.GetHash()).pindexMined = !isDisconnect ? pindex : nullptr;
981983
} else {
982984
// TX is locked, so make sure we don't track it anymore
983985
RemoveNonLockedTx(tx.GetHash(), true);

0 commit comments

Comments
 (0)