diff --git a/src/llmq/quorums_instantsend.cpp b/src/llmq/quorums_instantsend.cpp index 1d38360d7b..391de939ab 100644 --- a/src/llmq/quorums_instantsend.cpp +++ b/src/llmq/quorums_instantsend.cpp @@ -49,7 +49,6 @@ uint256 CInstantSendLock::GetRequestId() const CInstantSendDb::CInstantSendDb(CDBWrapper& _db) : db(_db) { - Upgrade(); } void CInstantSendDb::Upgrade() @@ -1069,7 +1068,7 @@ void CInstantSendManager::TransactionAddedToMempool(const CTransactionRef& tx) void CInstantSendManager::TransactionRemovedFromMempool(const CTransactionRef& tx) { - if (tx->vin.empty()) { + if (tx->vin.empty() || !fUpgradedDB) { return; } @@ -1214,6 +1213,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 b684960381..49810c4a73 100644 --- a/src/llmq/quorums_instantsend.h +++ b/src/llmq/quorums_instantsend.h @@ -54,11 +54,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); @@ -86,6 +86,8 @@ private: mutable CCriticalSection cs; CInstantSendDb db; + std::atomic fUpgradedDB{false}; + std::thread workThread; CThreadInterrupt workInterrupt;