From ab819ce489abecb81f58686a67b1d68921082b79 Mon Sep 17 00:00:00 2001 From: dustinface <35775977+xdustinface@users.noreply.github.com> Date: Thu, 18 Mar 2021 00:49:58 +0100 Subject: [PATCH] llmq: Move GetAllQuorumMembers into CFinalCommitment::Verify (#4032) Instead of calling `CLLMQUtils::GetAllQuorumMembers` before each `CFinalCommitment::Verify` call to get the quorum members, just get them inside `CFinalCommitment::Verify`. --- src/llmq/quorums_blockprocessor.cpp | 7 ++----- src/llmq/quorums_commitment.cpp | 7 +++---- src/llmq/quorums_commitment.h | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/llmq/quorums_blockprocessor.cpp b/src/llmq/quorums_blockprocessor.cpp index 3754faf889..c917ff39ca 100644 --- a/src/llmq/quorums_blockprocessor.cpp +++ b/src/llmq/quorums_blockprocessor.cpp @@ -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()); @@ -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"); } diff --git a/src/llmq/quorums_commitment.cpp b/src/llmq/quorums_commitment.cpp index 007ab063f5..c7584f7e68 100644 --- a/src/llmq/quorums_commitment.cpp +++ b/src/llmq/quorums_commitment.cpp @@ -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& members, bool checkSigs) const +bool CFinalCommitment::Verify(const CBlockIndex* pQuorumIndex, bool checkSigs) const { if (nVersion == 0 || nVersion > CURRENT_VERSION) { return false; @@ -65,6 +65,7 @@ bool CFinalCommitment::Verify(const std::vector& 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); @@ -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()) { @@ -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"); } diff --git a/src/llmq/quorums_commitment.h b/src/llmq/quorums_commitment.h index 6d02eed11e..62cb3034d3 100644 --- a/src/llmq/quorums_commitment.h +++ b/src/llmq/quorums_commitment.h @@ -52,7 +52,7 @@ public: return (int)std::count(validMembers.begin(), validMembers.end(), true); } - bool Verify(const std::vector& members, bool checkSigs) const; + bool Verify(const CBlockIndex* pQuorumIndex, bool checkSigs) const; bool VerifyNull() const; bool VerifySizes(const Consensus::LLMQParams& params) const;