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`.
This commit is contained in:
dustinface 2021-03-18 00:49:58 +01:00 committed by GitHub
parent d66d52a256
commit ab819ce489
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 10 deletions

View File

@ -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");
}

View File

@ -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;
@ -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);
@ -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");
}

View File

@ -52,7 +52,7 @@ public:
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;