Skip to content

Commit

Permalink
llmq: Move GetAllQuorumMembers into CFinalCommitment::Verify (#4032)
Browse files Browse the repository at this point in the history
Instead of calling `CLLMQUtils::GetAllQuorumMembers` before each `CFinalCommitment::Verify` call to get the quorum members, just get them inside `CFinalCommitment::Verify`.
  • Loading branch information
xdustinface authored Mar 17, 2021
1 parent d66d52a commit ab819ce
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
7 changes: 2 additions & 5 deletions src/llmq/quorums_blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& strC
}
}

auto members = CLLMQUtils::GetAllQuorumMembers(type, pquorumIndex);

if (!qc.Verify(members, true)) {
if (!qc.Verify(pquorumIndex, true)) {
LOCK(cs_main);
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- commitment for quorum %s:%d is not valid, peer=%d\n", __func__,
qc.quorumHash.ToString(), qc.llmqType, pfrom->GetId());
Expand Down Expand Up @@ -219,9 +217,8 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH
}

auto quorumIndex = LookupBlockIndex(qc.quorumHash);
auto members = CLLMQUtils::GetAllQuorumMembers(params.type, quorumIndex);

if (!qc.Verify(members, true)) {
if (!qc.Verify(quorumIndex, true)) {
return state.DoS(100, false, REJECT_INVALID, "bad-qc-invalid");
}

Expand Down
7 changes: 3 additions & 4 deletions src/llmq/quorums_commitment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CFinalCommitment::CFinalCommitment(const Consensus::LLMQParams& params, const ui
LogPrintStr(strprintf("CFinalCommitment::%s -- %s", __func__, tinyformat::format(__VA_ARGS__))); \
} while(0)

bool CFinalCommitment::Verify(const std::vector<CDeterministicMNCPtr>& members, bool checkSigs) const
bool CFinalCommitment::Verify(const CBlockIndex* pQuorumIndex, bool checkSigs) const
{
if (nVersion == 0 || nVersion > CURRENT_VERSION) {
return false;
Expand Down Expand Up @@ -65,6 +65,7 @@ bool CFinalCommitment::Verify(const std::vector<CDeterministicMNCPtr>& members,
return false;
}

auto members = CLLMQUtils::GetAllQuorumMembers(llmqType, pQuorumIndex);
for (size_t i = members.size(); i < params.size; i++) {
if (validMembers[i]) {
LogPrintfFinalCommitment("invalid validMembers bitset. bit %d should not be set\n", i);
Expand Down Expand Up @@ -159,7 +160,6 @@ bool CheckLLMQCommitment(const CTransaction& tx, const CBlockIndex* pindexPrev,
if (!Params().GetConsensus().llmqs.count((Consensus::LLMQType)qcTx.commitment.llmqType)) {
return state.DoS(100, false, REJECT_INVALID, "bad-qc-type");
}
const auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)qcTx.commitment.llmqType);

if (qcTx.commitment.IsNull()) {
if (!qcTx.commitment.VerifyNull()) {
Expand All @@ -168,8 +168,7 @@ bool CheckLLMQCommitment(const CTransaction& tx, const CBlockIndex* pindexPrev,
return true;
}

auto members = CLLMQUtils::GetAllQuorumMembers(params.type, pindexQuorum);
if (!qcTx.commitment.Verify(members, false)) {
if (!qcTx.commitment.Verify(pindexQuorum, false)) {
return state.DoS(100, false, REJECT_INVALID, "bad-qc-invalid");
}

Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums_commitment.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CFinalCommitment
return (int)std::count(validMembers.begin(), validMembers.end(), true);
}

bool Verify(const std::vector<CDeterministicMNCPtr>& members, bool checkSigs) const;
bool Verify(const CBlockIndex* pQuorumIndex, bool checkSigs) const;
bool VerifyNull() const;
bool VerifySizes(const Consensus::LLMQParams& params) const;

Expand Down

0 comments on commit ab819ce

Please sign in to comment.