Skip to content

Commit 453a74f

Browse files
UdjinM6Duddino
authored andcommitted
Fix two potential issues in the way pending islocks are processed (dashpay#3678)
* Always check for previous quorum set in llmq IS * Refactor SelectQuorumForSigning and related code Should have no changes in behaviour * Do not use SIGN_HEIGHT_OFFSET when checking pending IS locks, use actual chain tip This commit actually changes the behaviour
1 parent 902809c commit 453a74f

File tree

3 files changed

+11
-25
lines changed

3 files changed

+11
-25
lines changed

src/llmq/quorums_signing.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -764,18 +764,12 @@ bool CSigningManager::AsyncSignIfMember(Consensus::LLMQType llmqType, const uint
764764
}
765765
}
766766

767-
int tipHeight;
768-
{
769-
LOCK(cs_main);
770-
tipHeight = chainActive.Height();
771-
}
772-
773767
// This might end up giving different results on different members
774768
// This might happen when we are on the brink of confirming a new quorum
775769
// This gives a slight risk of not getting enough shares to recover a signature
776770
// But at least it shouldn't be possible to get conflicting recovered signatures
777771
// TODO fix this by re-signing when the next block arrives, but only when that block results in a change of the quorum list and no recovered signature has been created in the mean time
778-
CQuorumCPtr quorum = SelectQuorumForSigning(llmqType, tipHeight, id);
772+
CQuorumCPtr quorum = SelectQuorumForSigning(llmqType, id);
779773
if (!quorum) {
780774
LogPrint(BCLog::LLMQ, "CSigningManager::%s -- failed to select quorum. id=%s, msgHash=%s\n", __func__, id.ToString(), msgHash.ToString());
781775
return false;
@@ -835,27 +829,25 @@ bool CSigningManager::GetVoteForId(Consensus::LLMQType llmqType, const uint256&
835829
return db.GetVoteForId(llmqType, id, msgHashRet);
836830
}
837831

838-
std::vector<CQuorumCPtr> CSigningManager::GetActiveQuorumSet(Consensus::LLMQType llmqType, int signHeight)
832+
CQuorumCPtr CSigningManager::SelectQuorumForSigning(Consensus::LLMQType llmqType, const uint256& selectionHash, int signHeight, int signOffset)
839833
{
840834
auto& llmqParams = Params().GetConsensus().llmqs.at(llmqType);
841835
size_t poolSize = (size_t)llmqParams.signingActiveQuorumCount;
842836

843837
CBlockIndex* pindexStart;
844838
{
845839
LOCK(cs_main);
846-
int startBlockHeight = signHeight - SIGN_HEIGHT_OFFSET;
840+
if (signHeight == -1) {
841+
signHeight = chainActive.Height();
842+
}
843+
int startBlockHeight = signHeight - signOffset;
847844
if (startBlockHeight > chainActive.Height()) {
848845
return {};
849846
}
850847
pindexStart = chainActive[startBlockHeight];
851848
}
852849

853-
return quorumManager->ScanQuorums(llmqType, pindexStart, poolSize);
854-
}
855-
856-
CQuorumCPtr CSigningManager::SelectQuorumForSigning(Consensus::LLMQType llmqType, int signHeight, const uint256& selectionHash)
857-
{
858-
auto quorums = GetActiveQuorumSet(llmqType, signHeight);
850+
auto quorums = quorumManager->ScanQuorums(llmqType, pindexStart, poolSize);
859851
if (quorums.empty()) {
860852
return nullptr;
861853
}
@@ -875,7 +867,7 @@ CQuorumCPtr CSigningManager::SelectQuorumForSigning(Consensus::LLMQType llmqType
875867

876868
bool CSigningManager::VerifyRecoveredSig(Consensus::LLMQType llmqType, int signedAtHeight, const uint256& id, const uint256& msgHash, const CBLSSignature& sig)
877869
{
878-
auto quorum = SelectQuorumForSigning(llmqType, signedAtHeight, id);
870+
auto quorum = SelectQuorumForSigning(llmqType, id, signedAtHeight);
879871
if (!quorum) {
880872
return false;
881873
}

src/llmq/quorums_signing.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class CSigningManager
165165
bool GetVoteForId(Consensus::LLMQType llmqType, const uint256& id, uint256& msgHashRet);
166166

167167
std::vector<CQuorumCPtr> GetActiveQuorumSet(Consensus::LLMQType llmqType, int signHeight);
168-
CQuorumCPtr SelectQuorumForSigning(Consensus::LLMQType llmqType, int signHeight, const uint256& selectionHash);
168+
CQuorumCPtr SelectQuorumForSigning(Consensus::LLMQType llmqType, const uint256& selectionHash, int signHeight = -1 /*chain tip*/, int signOffset = SIGN_HEIGHT_OFFSET);
169169
// Verifies a recovered sig that was signed while the chain tip was at signedAtTip
170170
bool VerifyRecoveredSig(Consensus::LLMQType llmqType, int signedAtHeight, const uint256& id, const uint256& msgHash, const CBLSSignature& sig);
171171
};
@@ -174,4 +174,4 @@ extern std::unique_ptr<CSigningManager> quorumSigningManager;
174174

175175
} // namespace llmq
176176

177-
#endif // PIVX_LLMQ_QUORUMS_SIGNING_H
177+
#endif // PIVX_LLMQ_QUORUMS_SIGNING_H

src/rpc/rpcquorums.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,9 @@ UniValue quorumselectquorum(const JSONRPCRequest& request)
362362

363363
uint256 id = ParseHashV(request.params[1], "id");
364364

365-
int tipHeight;
366-
{
367-
LOCK(cs_main);
368-
tipHeight = chainActive.Height();
369-
}
370-
371365
UniValue ret(UniValue::VOBJ);
372366

373-
auto quorum = llmq::quorumSigningManager->SelectQuorumForSigning(llmqType, tipHeight, id);
367+
auto quorum = llmq::quorumSigningManager->SelectQuorumForSigning(llmqType, id);
374368
if (!quorum) {
375369
throw JSONRPCError(RPC_MISC_ERROR, "no quorums active");
376370
}

0 commit comments

Comments
 (0)