From e43ca6243a2dc5243ebffec680e6d0c7459d47d0 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 28 Oct 2024 22:25:11 +0700 Subject: [PATCH] feat: replace assert to error in p2p code of Asset Lock It is impossible situation which will never happen. But better to change it to exception for better error-prune implementation in case someone will decide to change this code: 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) { return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-assetunlock-too-old-quorum"); } ... const auto quorum = qman.GetQuorum(llmqType, quorumHash); assert(quorum); <-- for sure exist because we just scanned quorums --- src/evo/assetlocktx.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/evo/assetlocktx.cpp b/src/evo/assetlocktx.cpp index 27e53e0b24..bd3a7e7581 100644 --- a/src/evo/assetlocktx.cpp +++ b/src/evo/assetlocktx.cpp @@ -138,7 +138,10 @@ bool CAssetUnlockPayload::VerifySig(const llmq::CQuorumManager& qman, const uint } const auto quorum = qman.GetQuorum(llmqType, quorumHash); - assert(quorum); + // quorum must be valid at this point. Let's check and throw error just in case + if (!quorum) { + return state.Invalid(TxValidationResult::TX_CONSENSUS, "internal-error"); + } const uint256 requestId = ::SerializeHash(std::make_pair(ASSETUNLOCK_REQUESTID_PREFIX, index));