From b897505f8584c0dae8e18b9a2315c379ab990ebe Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 5 Apr 2019 06:59:50 +0200 Subject: [PATCH] Remove the need for maintaining the last ChainLocked block in the DB --- src/llmq/quorums_instantsend.cpp | 34 ++++++-------------------------- src/llmq/quorums_instantsend.h | 3 --- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/src/llmq/quorums_instantsend.cpp b/src/llmq/quorums_instantsend.cpp index 172055e2248fc..7f9b054958778 100644 --- a/src/llmq/quorums_instantsend.cpp +++ b/src/llmq/quorums_instantsend.cpp @@ -201,18 +201,6 @@ CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByInput(const COutPoint& o return GetInstantSendLockByHash(islockHash); } -void CInstantSendDb::WriteLastChainLockBlock(const uint256& hash) -{ - db.Write(std::make_tuple(std::string("is_lcb")), hash); -} - -uint256 CInstantSendDb::GetLastChainLockBlock() -{ - uint256 hashBlock; - db.Read(std::make_tuple(std::string("is_lcb")), hashBlock); - return hashBlock; -} - //////////////// CInstantSendManager::CInstantSendManager(CScheduler* _scheduler, CDBWrapper& _llmqDb) : @@ -820,11 +808,6 @@ void CInstantSendManager::SyncTransaction(const CTransaction& tx, const CBlockIn void CInstantSendManager::NotifyChainLock(const CBlockIndex* pindexChainLock) { - { - LOCK(cs); - db.WriteLastChainLockBlock(pindexChainLock->GetBlockHash()); - } - HandleFullyConfirmedBlock(pindexChainLock); } @@ -913,26 +896,21 @@ void CInstantSendManager::RetryLockTxs(const uint256& lockedParentTx) } } - uint256 lastChainLockBlock; - const CBlockIndex* pindexLastChainLockBlock = nullptr; const CBlockIndex* pindexWalk = nullptr; - { - LOCK(cs); - lastChainLockBlock = db.GetLastChainLockBlock(); - } { LOCK(cs_main); - if (!lastChainLockBlock.IsNull()) { - pindexLastChainLockBlock = mapBlockIndex.at(lastChainLockBlock); - pindexWalk = chainActive.Tip(); - } + pindexWalk = chainActive.Tip(); } // scan blocks until we hit the last chainlocked block we know of. Also stop scanning after a depth of 6 to avoid // signing thousands of TXs at once. Also, after a depth of 6, blocks get eligible for ChainLocking even if unsafe // TXs are included, so there is no need to retroactively sign these. int depth = 0; - while (pindexWalk && pindexWalk != pindexLastChainLockBlock && depth < 6) { + while (pindexWalk && depth < 6) { + if (chainLocksHandler->HasChainLock(pindexWalk->nHeight, pindexWalk->GetBlockHash())) { + break; + } + CBlock block; { LOCK(cs_main); diff --git a/src/llmq/quorums_instantsend.h b/src/llmq/quorums_instantsend.h index b4c2d009c1e4d..2355b984a9ebe 100644 --- a/src/llmq/quorums_instantsend.h +++ b/src/llmq/quorums_instantsend.h @@ -66,9 +66,6 @@ class CInstantSendDb uint256 GetInstantSendLockHashByTxid(const uint256& txid); CInstantSendLockPtr GetInstantSendLockByTxid(const uint256& txid); CInstantSendLockPtr GetInstantSendLockByInput(const COutPoint& outpoint); - - void WriteLastChainLockBlock(const uint256& hashBlock); - uint256 GetLastChainLockBlock(); }; class CInstantSendManager : public CRecoveredSigsListener