From 907386b70884e370cc247fe54650a87e930a2d90 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 24 May 2019 09:38:09 +0200 Subject: [PATCH 1/2] Refactor checks for disconnected blocks and conflicts in CInstantSendManager::SyncTransaction --- src/llmq/quorums_instantsend.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/llmq/quorums_instantsend.cpp b/src/llmq/quorums_instantsend.cpp index e6d859c714ef..4e82189ff513 100644 --- a/src/llmq/quorums_instantsend.cpp +++ b/src/llmq/quorums_instantsend.cpp @@ -961,11 +961,12 @@ void CInstantSendManager::SyncTransaction(const CTransaction& tx, const CBlockIn } bool inMempool = mempool.get(tx.GetHash()) != nullptr; + bool isDisconnect = pindex && posInBlock == CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK; // Are we called from validation.cpp/MemPoolConflictRemovalTracker? // TODO refactor this when we backport the BlockConnected signal from Bitcoin, as it gives better info about // conflicted TXs - bool isConflictRemoved = !pindex && posInBlock == CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK && !inMempool; + bool isConflictRemoved = isDisconnect && !inMempool; if (isConflictRemoved) { LOCK(cs); @@ -980,7 +981,7 @@ void CInstantSendManager::SyncTransaction(const CTransaction& tx, const CBlockIn // update DB about when an IS lock was mined if (!islockHash.IsNull() && pindex) { - if (posInBlock == CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK) { + if (isDisconnect) { db.RemoveInstantSendLockMined(islockHash, pindex->nHeight); } else { db.WriteInstantSendLockMined(islockHash, pindex->nHeight); @@ -1001,7 +1002,7 @@ void CInstantSendManager::SyncTransaction(const CTransaction& tx, const CBlockIn if (!chainlocked && islockHash.IsNull()) { // TX is not locked, so make sure it is tracked AddNonLockedTx(MakeTransactionRef(tx)); - nonLockedTxs.at(tx.GetHash()).pindexMined = posInBlock != CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK ? pindex : nullptr; + nonLockedTxs.at(tx.GetHash()).pindexMined = !isDisconnect ? pindex : nullptr; } else { // TX is locked, so make sure we don't track it anymore RemoveNonLockedTx(tx.GetHash(), true); From bd8449678228528a9178c3fa888143086e806e49 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 24 May 2019 09:38:32 +0200 Subject: [PATCH 2/2] Fix off-by-one when calling RemoveInstantSendLockMined --- src/llmq/quorums_instantsend.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/llmq/quorums_instantsend.cpp b/src/llmq/quorums_instantsend.cpp index 4e82189ff513..f56e6e3cadfe 100644 --- a/src/llmq/quorums_instantsend.cpp +++ b/src/llmq/quorums_instantsend.cpp @@ -982,7 +982,8 @@ void CInstantSendManager::SyncTransaction(const CTransaction& tx, const CBlockIn // update DB about when an IS lock was mined if (!islockHash.IsNull() && pindex) { if (isDisconnect) { - db.RemoveInstantSendLockMined(islockHash, pindex->nHeight); + // SyncTransaction is called with pprev + db.RemoveInstantSendLockMined(islockHash, pindex->nHeight + 1); } else { db.WriteInstantSendLockMined(islockHash, pindex->nHeight); }