Skip to content

Commit

Permalink
Add option to AsyncSignIfMember to allow signing same requestID on di…
Browse files Browse the repository at this point in the history
…fferent msgHashes

codereview suggestions

continued
  • Loading branch information
knst committed Aug 5, 2024
1 parent ee5cec1 commit 6466132
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/llmq/ehf_signals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void CEHFSignalsHandler::trySignEHFSignal(int bit, const CBlockIndex* const pind
LogPrint(BCLog::EHF, "CEHFSignalsHandler::trySignEHFSignal: msgHash=%s quorum=%s id=%s\n", msgHash.ToString(), quorum->qc->quorumHash.ToString(), requestId.ToString());

WITH_LOCK(cs, ids.insert(requestId));
sigman.AsyncSignIfMember(llmqType, shareman, requestId, msgHash);
sigman.AsyncSignIfMember(llmqType, shareman, requestId, msgHash, quorum->qc->quorumHash, false, true);
}

void CEHFSignalsHandler::HandleNewRecoveredSig(const CRecoveredSig& recoveredSig)
Expand Down
16 changes: 12 additions & 4 deletions src/llmq/signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,9 @@ void CSigningManager::UnregisterRecoveredSigsListener(CRecoveredSigsListener* l)
recoveredSigsListeners.erase(itRem, recoveredSigsListeners.end());
}

bool CSigningManager::AsyncSignIfMember(Consensus::LLMQType llmqType, CSigSharesManager& shareman, const uint256& id, const uint256& msgHash, const uint256& quorumHash, bool allowReSign)
bool CSigningManager::AsyncSignIfMember(Consensus::LLMQType llmqType, CSigSharesManager& shareman, const uint256& id,
const uint256& msgHash, const uint256& quorumHash, bool allowReSign,
bool allowDiffMsgHashSigning)
{
LogPrintf("CSigningManager::AsyncSignIfMember id=%s\n", id.ToString());
if (m_mn_activeman == nullptr) return false;
Expand Down Expand Up @@ -917,9 +919,15 @@ bool CSigningManager::AsyncSignIfMember(Consensus::LLMQType llmqType, CSigShares
uint256 prevMsgHash;
db.GetVoteForId(llmqType, id, prevMsgHash);
if (msgHash != prevMsgHash) {
LogPrintf("CSigningManager::%s -- already voted for id=%s and msgHash=%s. Not voting on conflicting msgHash=%s\n", __func__,
id.ToString(), prevMsgHash.ToString(), msgHash.ToString());
return false;
if (allowDiffMsgHashSigning) {
LogPrintf("CSigningManager::%s -- already voted for id=%s and msgHash=%s. Signing for different msgHash=%s\n",
__func__, id.ToString(), prevMsgHash.ToString(), msgHash.ToString());
hasVoted = false;
} else {
LogPrintf("CSigningManager::%s -- already voted for id=%s and msgHash=%s. Not voting on conflicting msgHash=%s\n",
__func__, id.ToString(), prevMsgHash.ToString(), msgHash.ToString());
return false;
}
} else if (allowReSign) {
LogPrint(BCLog::LLMQ, "CSigningManager::%s -- already voted for id=%s and msgHash=%s. Resigning!\n", __func__,
id.ToString(), prevMsgHash.ToString());
Expand Down
4 changes: 3 additions & 1 deletion src/llmq/signing.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ class CSigningManager
void RegisterRecoveredSigsListener(CRecoveredSigsListener* l);
void UnregisterRecoveredSigsListener(CRecoveredSigsListener* l);

bool AsyncSignIfMember(Consensus::LLMQType llmqType, CSigSharesManager& shareman, const uint256& id, const uint256& msgHash, const uint256& quorumHash = uint256(), bool allowReSign = false);
bool AsyncSignIfMember(Consensus::LLMQType llmqType, CSigSharesManager& shareman, const uint256& id,
const uint256& msgHash, const uint256& quorumHash = uint256(), bool allowReSign = false,
bool allowDiffMsgHashSigning = false);
bool HasRecoveredSig(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash) const;
bool HasRecoveredSigForId(Consensus::LLMQType llmqType, const uint256& id) const;
bool HasRecoveredSigForSession(const uint256& signHash) const;
Expand Down

0 comments on commit 6466132

Please sign in to comment.