diff --git a/src/llmq/quorums_instantsend.cpp b/src/llmq/quorums_instantsend.cpp index 2d1e26557b..a6e96aca84 100644 --- a/src/llmq/quorums_instantsend.cpp +++ b/src/llmq/quorums_instantsend.cpp @@ -52,7 +52,6 @@ uint256 CInstantSendLock::GetRequestId() const CInstantSendDb::CInstantSendDb(CDBWrapper& _db) : db(_db) { - Upgrade(); } void CInstantSendDb::Upgrade() @@ -1072,7 +1071,7 @@ void CInstantSendManager::TransactionAddedToMempool(const CTransactionRef& tx) void CInstantSendManager::TransactionRemovedFromMempool(const CTransactionRef& tx) { - if (tx->vin.empty()) { + if (tx->vin.empty() || !fUpgradedDB) { return; } @@ -1217,6 +1216,14 @@ void CInstantSendManager::NotifyChainLock(const CBlockIndex* pindexChainLock) void CInstantSendManager::UpdatedBlockTip(const CBlockIndex* pindexNew) { + if (!fUpgradedDB) { + LOCK(cs_main); + if (VersionBitsState(pindexNew, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0020, versionbitscache) == ThresholdState::ACTIVE) { + db.Upgrade(); + fUpgradedDB = true; + } + } + bool fDIP0008Active = pindexNew->pprev && pindexNew->pprev->nHeight >= Params().GetConsensus().DIP0008Height; if (AreChainLocksEnabled() && fDIP0008Active) { diff --git a/src/llmq/quorums_instantsend.h b/src/llmq/quorums_instantsend.h index f7850a582d..7b963ab36d 100644 --- a/src/llmq/quorums_instantsend.h +++ b/src/llmq/quorums_instantsend.h @@ -55,11 +55,11 @@ private: void WriteInstantSendLockMined(CDBBatch& batch, const uint256& hash, int nHeight); void RemoveInstantSendLockMined(CDBBatch& batch, const uint256& hash, int nHeight); - void Upgrade(); - public: explicit CInstantSendDb(CDBWrapper& _db); + void Upgrade(); + void WriteNewInstantSendLock(const uint256& hash, const CInstantSendLock& islock); void RemoveInstantSendLock(CDBBatch& batch, const uint256& hash, CInstantSendLockPtr islock, bool keep_cache = true); @@ -87,6 +87,8 @@ private: mutable CCriticalSection cs; CInstantSendDb db; + std::atomic fUpgradedDB{false}; + std::thread workThread; CThreadInterrupt workInterrupt;