Skip to content

Commit

Permalink
Remove the need for maintaining the last ChainLocked block in the DB
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Apr 5, 2019
1 parent 8e7083c commit b897505
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
34 changes: 6 additions & 28 deletions src/llmq/quorums_instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,6 @@ CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByInput(const COutPoint& o
return GetInstantSendLockByHash(islockHash);
}

void CInstantSendDb::WriteLastChainLockBlock(const uint256& hash)
{
db.Write(std::make_tuple(std::string("is_lcb")), hash);
}

uint256 CInstantSendDb::GetLastChainLockBlock()
{
uint256 hashBlock;
db.Read(std::make_tuple(std::string("is_lcb")), hashBlock);
return hashBlock;
}

////////////////

CInstantSendManager::CInstantSendManager(CScheduler* _scheduler, CDBWrapper& _llmqDb) :
Expand Down Expand Up @@ -820,11 +808,6 @@ void CInstantSendManager::SyncTransaction(const CTransaction& tx, const CBlockIn

void CInstantSendManager::NotifyChainLock(const CBlockIndex* pindexChainLock)
{
{
LOCK(cs);
db.WriteLastChainLockBlock(pindexChainLock->GetBlockHash());
}

HandleFullyConfirmedBlock(pindexChainLock);
}

Expand Down Expand Up @@ -913,26 +896,21 @@ void CInstantSendManager::RetryLockTxs(const uint256& lockedParentTx)
}
}

uint256 lastChainLockBlock;
const CBlockIndex* pindexLastChainLockBlock = nullptr;
const CBlockIndex* pindexWalk = nullptr;
{
LOCK(cs);
lastChainLockBlock = db.GetLastChainLockBlock();
}
{
LOCK(cs_main);
if (!lastChainLockBlock.IsNull()) {
pindexLastChainLockBlock = mapBlockIndex.at(lastChainLockBlock);
pindexWalk = chainActive.Tip();
}
pindexWalk = chainActive.Tip();
}

// scan blocks until we hit the last chainlocked block we know of. Also stop scanning after a depth of 6 to avoid
// signing thousands of TXs at once. Also, after a depth of 6, blocks get eligible for ChainLocking even if unsafe
// TXs are included, so there is no need to retroactively sign these.
int depth = 0;
while (pindexWalk && pindexWalk != pindexLastChainLockBlock && depth < 6) {
while (pindexWalk && depth < 6) {
if (chainLocksHandler->HasChainLock(pindexWalk->nHeight, pindexWalk->GetBlockHash())) {
break;
}

CBlock block;
{
LOCK(cs_main);
Expand Down
3 changes: 0 additions & 3 deletions src/llmq/quorums_instantsend.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ class CInstantSendDb
uint256 GetInstantSendLockHashByTxid(const uint256& txid);
CInstantSendLockPtr GetInstantSendLockByTxid(const uint256& txid);
CInstantSendLockPtr GetInstantSendLockByInput(const COutPoint& outpoint);

void WriteLastChainLockBlock(const uint256& hashBlock);
uint256 GetLastChainLockBlock();
};

class CInstantSendManager : public CRecoveredSigsListener
Expand Down

0 comments on commit b897505

Please sign in to comment.