instantsend: Postpone mempool related cleanup fixes until dip0020 activation (#4159)

* instantsend: Upgrade IS db on dip0020 activation

* instantsend: Do not remove islocks for txes removed from mempool until dip0020 is activated

* refactor: introduce fUpgradedDB to avoid excessive locking and checking the state

* llmq: Decouple `fUpgradedDB` from `cs`

* Update src/llmq/quorums_instantsend.cpp

Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com>

* Fix deadlock

Upgrade locks cs_main via GetTransaction

Co-authored-by: xdustinface <xdustinfacex@gmail.com>
Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com>
This commit is contained in:
UdjinM6 2021-05-18 23:29:51 +03:00
parent 0e3aea8c4e
commit 8b831eeb7e
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9
2 changed files with 13 additions and 4 deletions

View File

@ -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) {

View File

@ -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<bool> fUpgradedDB{false};
std::thread workThread;
CThreadInterrupt workInterrupt;