Repository navigation
feat(interfaces): look up a Platform quorum at its signed Core height #8069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |
| #include <llmq/blockprocessor.h> | ||
| #include <llmq/commitment.h> | ||
| #include <llmq/context.h> | ||
| #include <llmq/params.h> | ||
| #include <llmq/quorums.h> | ||
| #include <llmq/quorumsman.h> | ||
| #include <llmq/utils.h> | ||
|
|
@@ -86,6 +87,7 @@ | |
| #include <boost/signals2/signal.hpp> | ||
|
|
||
| #include <algorithm> | ||
| #include <limits> | ||
| #include <memory> | ||
| #include <optional> | ||
| #include <ranges> | ||
|
|
@@ -684,44 +686,68 @@ class LLMQImpl : public LLMQ | |
| } | ||
| return stats; | ||
| } | ||
| std::vector<PlatformQuorum> getPlatformQuorums(uint8_t llmq_type) override | ||
| PlatformQuorumResult getPlatformQuorum(uint8_t llmq_type, const uint256& quorum_hash, | ||
| uint32_t core_chain_locked_height) override | ||
| { | ||
| std::vector<PlatformQuorum> ret; | ||
| PlatformQuorumResult invalid{PlatformQuorumStatus::INVALID, {}}; | ||
| const auto type{static_cast<Consensus::LLMQType>(llmq_type)}; | ||
| const auto llmq_params{Params().GetLLMQ(type)}; | ||
| if (type != Params().GetConsensus().llmqTypePlatform || !llmq_params.has_value()) { | ||
| return invalid; | ||
| } | ||
| if (core_chain_locked_height > static_cast<uint32_t>(std::numeric_limits<int32_t>::max())) { | ||
| return invalid; | ||
| } | ||
| const int signed_height{static_cast<int>(core_chain_locked_height)}; | ||
| if (!context().llmq_ctx || !context().llmq_ctx->quorum_block_processor || !context().chainman) { | ||
| return ret; | ||
| return {}; | ||
| } | ||
| const auto* pindex{WITH_LOCK(::cs_main, return context().chainman->ActiveChain().Tip())}; | ||
| if (!pindex) { | ||
| return ret; | ||
| // Only a ChainLock whose block is known can lock part of the active chain; the best height may | ||
| // belong to a block this node has not seen. | ||
| const CBlockIndex* chainlocked_block{nullptr}; | ||
| int32_t best_cl_height{-1}; | ||
| if (const auto& chainlocks{context().chainlocks}) { | ||
| chainlocked_block = chainlocks->GetBestChainlockWithPindex().second; | ||
| best_cl_height = chainlocks->GetBestChainLockHeight(); | ||
| } | ||
| const auto type{static_cast<Consensus::LLMQType>(llmq_type)}; | ||
| const auto llmq_params{Params().GetLLMQ(type)}; | ||
| if (!llmq_params.has_value()) { | ||
| return ret; | ||
|
|
||
| LOCK(::cs_main); | ||
| const CChain& active{context().chainman->ActiveChain()}; | ||
| const CBlockIndex* tip{active.Tip()}; | ||
| if (!tip || signed_height > tip->nHeight) { | ||
| return {}; | ||
| } | ||
| // Drive proofs may be signed by an older Platform quorum while they | ||
| // are still consensus-valid and retained locally. Export the full | ||
| // retained-key window, not only the current signing-active set. | ||
| const auto quorum_count{static_cast<size_t>(std::max(llmq_params->signingActiveQuorumCount, | ||
| llmq_params->keepOldKeys))}; | ||
| // Read mined final commitments directly: they already carry the quorum | ||
| // hash and public key, so there is no need to materialize full CQuorum | ||
| // objects (member lists, vvec/contribution reads, quorum cache inserts) | ||
| // via ScanQuorums. Newest-first, matching ScanQuorums' ordering. | ||
| // A ChainLock can arrive before its block, and without one the tip is the best bound known. | ||
| // A stale height proves nothing against the quorum, so it is not INVALID. | ||
| const int cl_height{best_cl_height >= 0 ? std::min(best_cl_height, tip->nHeight) : tip->nHeight}; | ||
| if (signed_height < llmq::PlatformQuorumMinSignedHeight(*llmq_params, cl_height)) { | ||
| return {}; | ||
| } | ||
|
|
||
| const auto& qbp{*context().llmq_ctx->quorum_block_processor}; | ||
| const auto quorum_base_block_indexes{llmq_params->useRotation | ||
| ? qbp.GetMinedCommitmentsIndexedUntilBlock(type, pindex, quorum_count) | ||
| : qbp.GetMinedCommitmentsUntilBlock(type, pindex, quorum_count)}; | ||
| for (const auto* pQuorumBaseBlockIndex : quorum_base_block_indexes) { | ||
| const auto qc{qbp.GetMinedCommitment(type, pQuorumBaseBlockIndex->GetBlockHash()).first}; | ||
| if (!qc.quorumPublicKey.IsValid()) continue; | ||
| ret.emplace_back(PlatformQuorum{ | ||
| .m_quorum_hash = qc.quorumHash, | ||
| .m_pubkey = qc.quorumPublicKey.ToByteVector(/*specificLegacyScheme=*/false), | ||
| .m_height = pQuorumBaseBlockIndex->nHeight, | ||
| }); | ||
| const CBlockIndex* signed_block{active[signed_height]}; | ||
| const auto window{static_cast<size_t>(llmq::PlatformEligibleQuorumCount(*llmq_params))}; | ||
| const auto bases{llmq_params->useRotation ? qbp.GetMinedCommitmentsIndexedUntilBlock(type, signed_block, window) | ||
| : qbp.GetMinedCommitmentsUntilBlock(type, signed_block, window)}; | ||
|
Comment on lines
+729
to
+731
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: Choose the commitment index format from rotation activation at the signed block
source:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declining: the two predicates cannot differ at a height where a Platform quorum exists.
Threading activation state through the window and staleness helpers would add a code path that no network can reach. 🤖 Posted autonomously by Claude on behalf of pasta.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with the activation argument. For a rotating Platform type, Withdrawing this finding.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Withdrawn (re-reviewed at |
||
| if (std::ranges::none_of(bases, [&](const CBlockIndex* base) { return base->GetBlockHash() == quorum_hash; })) { | ||
|
Comment on lines
+730
to
+732
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🔴 Blocking: Do not return FOUND for a base implicated by an ordering contradiction The existing commitment walkers append every base value read from EvoDB without validating that the bases remain in the expected mined-height order. If a corrupted index entry maps a newer mined commitment to an older base, that base remains in source:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declining: the scenario needs a corrupted local EvoDB, which no peer, RPC or Platform endpoint can cause, and guarding against it here would not make the node safe.
The earlier revision's second walker with ordering, duplicate and retraction logic was removed on purpose: it was the bulk of the PR's complexity for a fault outside the threat model. Index integrity checking, if wanted, belongs in the block processor for every reader, not in this lookup. 🤖 Posted autonomously by Claude on behalf of pasta.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that this scenario requires local EvoDB corruption, which no peer, RPC, or Platform endpoint can induce. Since the quorum manager and other commitment consumers already trust the same index, adding an ordering check only in this interface would not make the node safe; I withdraw this finding. Withdrawing this finding.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The re-review at b8e3318 (review) counts this finding as still blocking, but it was withdrawn in the reply above at 09:30Z and the review itself lists it under "No longer blocking". The head and the code are unchanged since then, so the decline above stands and nothing further is planned for this thread. 🤖 Posted autonomously by Claude on behalf of pasta.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. This requires local EvoDB corruption, and adding an ordering check only to this interface would not make the node safe because other commitment consumers already trust the same index. I withdraw the finding. Withdrawing this finding. |
||
| // Platform verifies a block against its last committed validator set, so the block that | ||
| // first carries a height may be signed by a quorum no longer in the window at that height. | ||
| // A quorum mined at or below the height has its base block on the active chain below it; | ||
| // any other hash could never have signed. | ||
| const CBlockIndex* base{context().chainman->m_blockman.LookupBlockIndex(quorum_hash)}; | ||
| const bool never_mined{!base || base->nHeight >= signed_height || !active.Contains(base)}; | ||
| // That is final only on the part of the active chain a ChainLock locks; beyond it the | ||
| // active chain may be a competing branch. Unlike Chainlocks::HasChainLock, this keeps the | ||
| // lock while spork 19 is off. | ||
| const bool chainlocked{chainlocked_block && chainlocked_block->GetAncestor(signed_height) == signed_block}; | ||
| return never_mined && chainlocked ? invalid : PlatformQuorumResult{}; | ||
| } | ||
| return ret; | ||
|
|
||
| const auto qc{qbp.GetMinedCommitment(type, quorum_hash).first}; | ||
| if (!qc.quorumPublicKey.IsValid()) { | ||
| return {}; | ||
| } | ||
| return {PlatformQuorumStatus::FOUND, qc.quorumPublicKey.ToByteVector(/*specificLegacyScheme=*/false)}; | ||
| } | ||
| std::vector<uint8_t> getInstantSendLock(const uint256& txid) override | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Blocking: Treat an uninitialized ChainLock freshness bound as unavailable
When no ChainLock is known, cl_height falls back to the tip, although the tip does not establish the latest ChainLock height. ChainLockSig initializes its height to -1, so this includes initialization after a restart. With tip 2000, an actual stalled ChainLock at 1000, and the mainnet window of 624 blocks, an authentic proof carrying height 1000 returns INVALID. After this node learns that ChainLock, the same proof at the same tip passes the freshness check and can return FOUND. Local initialization is therefore treated as evidence against an honest endpoint, which can trigger a ban in the intended consumer. Preserve freshness rejection when a ChainLock is known, but return UNAVAILABLE when rejection depends solely on the fallback tip, and add a restart-during-stall regression.
source:
gpt-6.1-sol(phase2-reviewer: general)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. The tip still proves a height fresh, because any ChainLock is at or below it, but it cannot prove one stale. Fixed in c7d30c7 as you suggested: a height below the tip-based bound is
UNAVAILABLEwhile no ChainLock is known, andINVALIDonce one is.Restart-during-stall regression: with no ChainLock, h = 3 at tip 100 is
UNAVAILABLE(it wasINVALID). With a ChainLock on the tip it isINVALID. Once the stalled ChainLock at 50 is learned, the same h = 3 isFOUND. Restoringreturn invalid;fails the first row.🤖 Posted autonomously by Claude on behalf of pasta.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved (re-reviewed at
c7d30c71): Your freshness branch now returns UNAVAILABLE when only the fallback tip establishes staleness, while retaining INVALID when a known ChainLock establishes it. The restart/stall regression checks the same signed height without a ChainLock, with the tip locked, and after learning the stalled lock.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update at b8e3318: a stale height is now
UNAVAILABLEwhether or not a ChainLock is known. If Platform halts for longer than the window while Core keeps ChainLocking, every honest endpoint serves state with a stale height, so staleness is not evidence against the endpoint. Such state is still neverFOUND. The restart-during-stall rows remain ingetPlatformQuorum; the row with a ChainLock on the tip now expectsUNAVAILABLE.🤖 Posted autonomously by Claude on behalf of pasta.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved (re-reviewed at
b8e3318d): The stale-height branch now returns UNAVAILABLE regardless of whether a ChainLock is known, so neither an uninitialized state nor a stalled ChainLock causes staleness alone to classify an endpoint negatively.