Skip to content

Commit

Permalink
llmq: Some refactoring in CChainLocksHandler::ProcessNewChainLock (#3…
Browse files Browse the repository at this point in the history
…976)

* llmq: Drop InternalHasConflictingChainLock in ProcessNewChainLock

* llmq: Directly use clsig.blockHash instead of copying it into msgHash

* llmq: Reuse CInv(MSG_CLSIG, hash)

* llmq: Add const in two places
  • Loading branch information
nunumichael committed Feb 16, 2021
1 parent c3d8ca8 commit 6845a7b
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/llmq/quorums_chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ void CChainLocksHandler::ProcessMessage(CNode* pfrom, const std::string& strComm
}
}

void CChainLocksHandler::ProcessNewChainLock(NodeId from, const llmq::CChainLockSig& clsig, const uint256& hash)
void CChainLocksHandler::ProcessNewChainLock(const NodeId from, const llmq::CChainLockSig& clsig, const uint256& hash)
{
CInv clsigInv(MSG_CLSIG, hash);

if (from != -1) {
LOCK(cs_main);
EraseObjectRequest(from, CInv(MSG_CLSIG, hash));
EraseObjectRequest(from, clsigInv);
}

{
Expand All @@ -123,9 +125,8 @@ void CChainLocksHandler::ProcessNewChainLock(NodeId from, const llmq::CChainLock
}
}

uint256 requestId = ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, clsig.nHeight));
uint256 msgHash = clsig.blockHash;
if (!quorumSigningManager->VerifyRecoveredSig(Params().GetConsensus().llmqTypeChainLocks, clsig.nHeight, requestId, msgHash, clsig.sig)) {
const uint256 requestId = ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, clsig.nHeight));
if (!quorumSigningManager->VerifyRecoveredSig(Params().GetConsensus().llmqTypeChainLocks, clsig.nHeight, requestId, clsig.blockHash, clsig.sig)) {
LogPrint(BCLog::CHAINLOCKS, "CChainLocksHandler::%s -- invalid CLSIG (%s), peer=%d\n", __func__, clsig.ToString(), from);
if (from != -1) {
LOCK(cs_main);
Expand All @@ -134,20 +135,7 @@ void CChainLocksHandler::ProcessNewChainLock(NodeId from, const llmq::CChainLock
return;
}

{
LOCK(cs);

if (InternalHasConflictingChainLock(clsig.nHeight, clsig.blockHash)) {
// This should not happen. If it happens, it means that a malicious entity controls a large part of the MN
// network. In this case, we don't allow him to reorg older chainlocks.
LogPrintf("CChainLocksHandler::%s -- new CLSIG (%s) tries to reorg previous CLSIG (%s), peer=%d\n",
__func__, clsig.ToString(), bestChainLock.ToString(), from);
return;
}
}

CInv inv(MSG_CLSIG, hash);
g_connman->RelayInv(inv, LLMQS_PROTO_VERSION);
g_connman->RelayInv(clsigInv, LLMQS_PROTO_VERSION);

{
LOCK2(cs_main, cs);
Expand Down

0 comments on commit 6845a7b

Please sign in to comment.