Skip to content

Commit

Permalink
Cheaper/Faster bailout from TrySignChainTip when already signed before
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Mar 7, 2019
1 parent 0a5e8eb commit 96291e7
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/llmq/quorums_chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ void CChainLocksHandler::TrySignChainTip()
// This will fail when multiple blocks compete, but we accept this for the initial implementation.
// Later, we'll add the multiple attempts process.

uint256 requestId = ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, pindex->nHeight));
uint256 msgHash = pindex->GetBlockHash();

{
LOCK(cs);

Expand All @@ -244,6 +241,16 @@ void CChainLocksHandler::TrySignChainTip()
return;
}

if (pindex->nHeight == lastSignedHeight) {
// already signed this one
return;
}

if (bestChainLock.nHeight >= pindex->nHeight) {
// already got the same CLSIG or a better one
return;
}

if (InternalHasConflictingChainLock(pindex->nHeight, pindex->GetBlockHash())) {
if (!inEnforceBestChainLock) {
// we accepted this block when there was no lock yet, but now a conflicting lock appeared. Invalidate it.
Expand All @@ -253,14 +260,15 @@ void CChainLocksHandler::TrySignChainTip()
}
return;
}
}

if (bestChainLock.nHeight >= pindex->nHeight) {
// already got the same CLSIG or a better one
return;
}
uint256 requestId = ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, pindex->nHeight));
uint256 msgHash = pindex->GetBlockHash();

if (pindex->nHeight == lastSignedHeight) {
// already signed this one
{
LOCK(cs);
if (bestChainLock.nHeight >= pindex->nHeight) {
// might have happened while we didn't hold cs
return;
}
lastSignedHeight = pindex->nHeight;
Expand Down

0 comments on commit 96291e7

Please sign in to comment.