Skip to content

Commit

Permalink
feat: update IS database instantly, no more dependency on DIP0020
Browse files Browse the repository at this point in the history
This fork is activated long time ago, no more possible conflicts
  • Loading branch information
knst committed Nov 16, 2024
1 parent 9bfb700 commit a7f193a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
12 changes: 3 additions & 9 deletions src/llmq/instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ CInstantSendDb::CInstantSendDb(bool unitTests, bool fWipe) :

CInstantSendDb::~CInstantSendDb() = default;

void CInstantSendDb::Upgrade(const CTxMemPool& mempool)
void CInstantSendDb::Upgrade()
{
LOCK2(cs_main, mempool.cs);
LOCK(cs_db);
LOCK2(cs_main, cs_db);
int v{0};
if (!db->Read(DB_VERSION, v) || v < CInstantSendDb::CURRENT_VERSION) {
CDBBatch batch(*db);
Expand Down Expand Up @@ -1103,7 +1102,7 @@ void CInstantSendManager::TransactionAddedToMempool(const CTransactionRef& tx)

void CInstantSendManager::TransactionRemovedFromMempool(const CTransactionRef& tx)
{
if (tx->vin.empty() || !fUpgradedDB) {
if (tx->vin.empty()) {
return;
}

Expand Down Expand Up @@ -1252,11 +1251,6 @@ void CInstantSendManager::NotifyChainLock(const CBlockIndex* pindexChainLock)

void CInstantSendManager::UpdatedBlockTip(const CBlockIndex* pindexNew)
{
if (!fUpgradedDB && pindexNew->nHeight + 1 >= Params().GetConsensus().DIP0020Height) {
db.Upgrade(mempool);
fUpgradedDB = true;
}

bool fDIP0008Active = pindexNew->pprev && pindexNew->pprev->nHeight >= Params().GetConsensus().DIP0008Height;

if (AreChainLocksEnabled(spork_manager) && fDIP0008Active) {
Expand Down
4 changes: 2 additions & 2 deletions src/llmq/instantsend.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class CInstantSendDb
explicit CInstantSendDb(bool unitTests, bool fWipe);
~CInstantSendDb();

void Upgrade(const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(!cs_db);
void Upgrade() EXCLUSIVE_LOCKS_REQUIRED(!cs_db);

/**
* This method is called when an InstantSend Lock is processed and adds the lock to the database
Expand Down Expand Up @@ -209,7 +209,6 @@ class CInstantSendManager : public CRecoveredSigsListener
const std::unique_ptr<PeerManager>& m_peerman;

const bool m_is_masternode;
std::atomic<bool> fUpgradedDB{false};

std::thread workThread;
CThreadInterrupt workInterrupt;
Expand Down Expand Up @@ -264,6 +263,7 @@ class CInstantSendManager : public CRecoveredSigsListener
shareman(_shareman), spork_manager(sporkman), mempool(_mempool), m_mn_sync(mn_sync), m_peerman(peerman),
m_is_masternode{is_masternode}
{
Upgrade(); // Upgrade DB if need to do it
workInterrupt.reset();
}
~CInstantSendManager() = default;
Expand Down

0 comments on commit a7f193a

Please sign in to comment.