fix: using proper quorums for asset unlock validation

This commit is contained in:
Konstantin Akimov 2024-09-18 19:46:45 +07:00
parent 0253438503
commit 27040030e9
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524

View File

@ -12,6 +12,7 @@
#include <chainparams.h> #include <chainparams.h>
#include <consensus/params.h> #include <consensus/params.h>
#include <consensus/validation.h> #include <consensus/validation.h>
#include <deploymentstatus.h>
#include <logging.h> #include <logging.h>
#include <tinyformat.h> #include <tinyformat.h>
#include <util/ranges_set.h> #include <util/ranges_set.h>
@ -113,13 +114,18 @@ bool CAssetUnlockPayload::VerifySig(const llmq::CQuorumManager& qman, const uint
// and at the quorumHash must be active in either the current or previous quorum cycle // and at the quorumHash must be active in either the current or previous quorum cycle
// and the sig must validate against that specific quorumHash. // and the sig must validate against that specific quorumHash.
Consensus::LLMQType llmqType = Params().GetConsensus().llmqTypePlatform; Consensus::LLMQType llmqType = Params().GetConsensus().llmqTypePlatform;
// We check at most 2 quorums const auto& llmq_params_opt = Params().GetLLMQ(llmqType);
const auto quorums = qman.ScanQuorums(llmqType, pindexTip, 2); assert(llmq_params_opt.has_value());
// after deployment WITHDRAWALS activated we check not to quorum, but all active quorums + 1 the latest inactive
const int quorums_to_scan = DeploymentActiveAt(*pindexTip, Params().GetConsensus(), Consensus::DEPLOYMENT_WITHDRAWALS) ? (llmq_params_opt->signingActiveQuorumCount + 1) : 2;
const auto quorums = qman.ScanQuorums(llmqType, pindexTip, quorums_to_scan);
if (bool isActive = std::any_of(quorums.begin(), quorums.end(), [&](const auto &q) { return q->qc->quorumHash == quorumHash; }); !isActive) { if (bool isActive = std::any_of(quorums.begin(), quorums.end(), [&](const auto &q) { return q->qc->quorumHash == quorumHash; }); !isActive) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-assetunlock-not-active-quorum"); return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-assetunlock-too-old-quorum");
} }
if (static_cast<uint32_t>(pindexTip->nHeight) < requestedHeight || pindexTip->nHeight >= getHeightToExpiry()) { if (static_cast<uint32_t>(pindexTip->nHeight) < requestedHeight || pindexTip->nHeight >= getHeightToExpiry()) {