Fix potential deadlock in CInstantSendDb::Upgrade() (#4548)

This commit is contained in:
UdjinM6 2021-10-26 22:50:09 +03:00 committed by GitHub
parent db77905703
commit 95262de6b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,8 +58,11 @@ CInstantSendDb::CInstantSendDb(bool unitTests, bool fWipe)
db = std::make_unique<CDBWrapper>(unitTests ? "" : (GetDataDir() / "llmq/isdb"), 32 << 20, unitTests, fWipe);
}
void CInstantSendDb::Upgrade()
void CInstantSendDb::Upgrade() EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs)
{
AssertLockHeld(cs_main);
AssertLockHeld(::mempool.cs);
LOCK(cs_db);
int v{0};
if (!db->Read(DB_VERSION, v) || v < CInstantSendDb::CURRENT_VERSION) {
@ -1267,7 +1270,7 @@ void CInstantSendManager::NotifyChainLock(const CBlockIndex* pindexChainLock)
void CInstantSendManager::UpdatedBlockTip(const CBlockIndex* pindexNew)
{
if (!fUpgradedDB) {
LOCK(cs_main);
LOCK2(cs_main, ::mempool.cs); // for GetTransaction in Upgrade
if (VersionBitsState(pindexNew, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0020, versionbitscache) == ThresholdState::ACTIVE) {
db.Upgrade();
fUpgradedDB = true;