From d6e7758519417aad9b6e311d521f905aa5f24176 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 5 Apr 2019 06:35:39 +0200 Subject: [PATCH] Keep track of when IS locks were mined --- src/llmq/quorums_instantsend.cpp | 28 ++++++++++++++++++++++++++-- src/llmq/quorums_instantsend.h | 3 +++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/llmq/quorums_instantsend.cpp b/src/llmq/quorums_instantsend.cpp index 9a323f57ea6c7..623ee43e08dbe 100644 --- a/src/llmq/quorums_instantsend.cpp +++ b/src/llmq/quorums_instantsend.cpp @@ -85,6 +85,16 @@ void CInstantSendDb::RemoveInstantSendLock(const uint256& hash, CInstantSendLock } } +void CInstantSendDb::WriteInstantSendLockMined(const uint256& hash, int nHeight) +{ + db.Write(std::make_tuple(std::string("is_m"), std::numeric_limits::max() - nHeight, hash), true); +} + +void CInstantSendDb::RemoveInstantSendLockMined(const uint256& hash, int nHeight) +{ + db.Erase(std::make_tuple(std::string("is_m"), std::numeric_limits::max() - nHeight, hash)); +} + CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByHash(const uint256& hash) { CInstantSendLockPtr ret; @@ -743,9 +753,23 @@ void CInstantSendManager::SyncTransaction(const CTransaction& tx, const CBlockIn return; } - bool locked = IsLocked(tx.GetHash()); + uint256 islockHash; + { + LOCK(cs); + islockHash = db.GetInstantSendLockHashByTxid(tx.GetHash()); + + // update DB about when an IS lock was mined + if (!islockHash.IsNull() && pindex) { + if (posInBlock == CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK) { + db.RemoveInstantSendLockMined(islockHash, pindex->nHeight); + } else { + db.WriteInstantSendLockMined(islockHash, pindex->nHeight); + } + } + } + bool chainlocked = pindex && chainLocksHandler->HasChainLock(pindex->nHeight, pindex->GetBlockHash()); - if (locked || chainlocked) { + if (!islockHash.IsNull() || chainlocked) { RetryLockTxs(tx.GetHash()); } else { ProcessTx(tx, Params().GetConsensus()); diff --git a/src/llmq/quorums_instantsend.h b/src/llmq/quorums_instantsend.h index 3254595fdf651..d36b214e03dcb 100644 --- a/src/llmq/quorums_instantsend.h +++ b/src/llmq/quorums_instantsend.h @@ -57,6 +57,9 @@ class CInstantSendDb void WriteNewInstantSendLock(const uint256& hash, const CInstantSendLock& islock); void RemoveInstantSendLock(const uint256& hash, CInstantSendLockPtr islock); + void WriteInstantSendLockMined(const uint256& hash, int nHeight); + void RemoveInstantSendLockMined(const uint256& hash, int nHeight); + CInstantSendLockPtr GetInstantSendLockByHash(const uint256& hash); uint256 GetInstantSendLockHashByTxid(const uint256& txid); CInstantSendLockPtr GetInstantSendLockByTxid(const uint256& txid);