From de8192e857d6f33d59f50465ac11a457b5c84359 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 27 Jan 2021 01:06:04 +0300 Subject: [PATCH 1/3] instantsend: Bail out early on disabled IS in more places --- src/llmq/quorums_instantsend.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/llmq/quorums_instantsend.cpp b/src/llmq/quorums_instantsend.cpp index c84e00603025..5e25ebe31b0b 100644 --- a/src/llmq/quorums_instantsend.cpp +++ b/src/llmq/quorums_instantsend.cpp @@ -214,7 +214,7 @@ size_t CInstantSendDb::GetInstantSendLockCount() const CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByHash(const uint256& hash) const { - if (hash.IsNull()) { + if (hash.IsNull() || !IsInstantSendEnabled()) { return nullptr; } @@ -234,6 +234,9 @@ CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByHash(const uint256& hash uint256 CInstantSendDb::GetInstantSendLockHashByTxid(const uint256& txid) const { + if (!IsInstantSendEnabled()) { + return {}; + } uint256 islockHash; if (!txidCache.get(txid, islockHash)) { db.Read(std::make_tuple(std::string(DB_HASH_BY_TXID), txid), islockHash); @@ -249,6 +252,9 @@ CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByTxid(const uint256& txid CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByInput(const COutPoint& outpoint) const { + if (!IsInstantSendEnabled()) { + return nullptr; + } uint256 islockHash; if (!outpointCache.get(outpoint, islockHash)) { db.Read(std::make_tuple(std::string(DB_HASH_BY_OUTPOINT), outpoint), islockHash); @@ -1146,6 +1152,10 @@ void CInstantSendManager::UpdatedBlockTip(const CBlockIndex* pindexNew) void CInstantSendManager::HandleFullyConfirmedBlock(const CBlockIndex* pindex) { + if (!IsInstantSendEnabled()) { + return; + } + LOCK(cs); auto& consensusParams = Params().GetConsensus(); From 852e67164ba0747fb8db551628e29d44732ace14 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 27 Jan 2021 01:07:48 +0300 Subject: [PATCH 2/3] instantsend: Disable InstantSend while reindexing and importing blocks --- src/llmq/quorums_instantsend.cpp | 4 ++-- src/validation.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/llmq/quorums_instantsend.cpp b/src/llmq/quorums_instantsend.cpp index 5e25ebe31b0b..cc7f086082d7 100644 --- a/src/llmq/quorums_instantsend.cpp +++ b/src/llmq/quorums_instantsend.cpp @@ -1520,12 +1520,12 @@ void CInstantSendManager::WorkThreadMain() bool IsInstantSendEnabled() { - return sporkManager.IsSporkActive(SPORK_2_INSTANTSEND_ENABLED); + return !fReindex && !fImporting && sporkManager.IsSporkActive(SPORK_2_INSTANTSEND_ENABLED); } bool RejectConflictingBlocks() { - return sporkManager.IsSporkActive(SPORK_3_INSTANTSEND_BLOCK_FILTERING); + return !fReindex && !fImporting && sporkManager.IsSporkActive(SPORK_3_INSTANTSEND_BLOCK_FILTERING); } } // namespace llmq diff --git a/src/validation.cpp b/src/validation.cpp index 7e6c797fe633..89be636df084 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2386,7 +2386,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl REJECT_INVALID, "conflict-tx-lock"); } } - } else { + } else if (!fReindex && !fImporting) { LogPrintf("ConnectBlock(DASH): spork is off, skipping transaction locking checks\n"); } From a394e9abe11fbb920e7e17d623e21513f461a5e1 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 17 Feb 2021 18:50:57 +0300 Subject: [PATCH 3/3] Drop extra checks in GetInstantSendLockHashByTxid, GetInstantSendLockByInput and GetInstantSendLockByHash --- src/llmq/quorums_instantsend.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/llmq/quorums_instantsend.cpp b/src/llmq/quorums_instantsend.cpp index cc7f086082d7..6d5cd3cd4fad 100644 --- a/src/llmq/quorums_instantsend.cpp +++ b/src/llmq/quorums_instantsend.cpp @@ -214,7 +214,7 @@ size_t CInstantSendDb::GetInstantSendLockCount() const CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByHash(const uint256& hash) const { - if (hash.IsNull() || !IsInstantSendEnabled()) { + if (hash.IsNull()) { return nullptr; } @@ -234,9 +234,6 @@ CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByHash(const uint256& hash uint256 CInstantSendDb::GetInstantSendLockHashByTxid(const uint256& txid) const { - if (!IsInstantSendEnabled()) { - return {}; - } uint256 islockHash; if (!txidCache.get(txid, islockHash)) { db.Read(std::make_tuple(std::string(DB_HASH_BY_TXID), txid), islockHash); @@ -252,9 +249,6 @@ CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByTxid(const uint256& txid CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByInput(const COutPoint& outpoint) const { - if (!IsInstantSendEnabled()) { - return nullptr; - } uint256 islockHash; if (!outpointCache.get(outpoint, islockHash)) { db.Read(std::make_tuple(std::string(DB_HASH_BY_OUTPOINT), outpoint), islockHash);