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 committed by GitHub
parent 288f5976a8
commit a02f8302d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

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

View File

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