Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,22 @@ class LLMQ
int32_t m_expiry_height{0};
};
virtual std::vector<QuorumInfo> getQuorumStats() = 0;
struct PlatformQuorum {
uint256 m_quorum_hash{};
std::vector<uint8_t> m_pubkey{}; //!< serialized BLS public key (basic scheme)
int32_t m_height{0};
enum class PlatformQuorumStatus { FOUND, INVALID, UNAVAILABLE };
struct PlatformQuorumResult {
PlatformQuorumStatus status{PlatformQuorumStatus::UNAVAILABLE};
std::vector<uint8_t> public_key; //!< 48-byte basic-scheme key for FOUND; empty otherwise
};
//! Locally retained quorums of the given LLMQ type with their public
//! keys. Used by the GUI Platform client to verify Platform state-root
//! quorum signatures against locally synced quorum data. This includes
//! retained signing quorums that are no longer in the active signing set.
virtual std::vector<PlatformQuorum> getPlatformQuorums(uint8_t llmq_type) = 0;
//! Whether `quorum_hash` (Core internal byte order) could sign Platform state whose signed metadata
//! carries `core_chain_locked_height`, judged from this node's active chain. FOUND means it is among
//! the quorums eligible at that height. INVALID means the local chain proves it could not: the
//! hash is no block of the active chain below that height, so no quorum with it was mined by then,
//! which counts only if the active chain's block at that height is, or is an ancestor of, the block
//! of the best ChainLock whose block this node knows. UNAVAILABLE means this node proves neither and
//! says nothing against whoever served the state: the height is above the tip or too far below the
//! best ChainLock to verify, or the quorum is an older one, which may still sign the one Platform
//! block that first carries a height after a jump.
virtual PlatformQuorumResult getPlatformQuorum(uint8_t llmq_type, const uint256& quorum_hash,
uint32_t core_chain_locked_height) = 0;
//! Serialized InstantSend lock for the given txid, or empty if the
//! transaction has no islock (used to build asset lock proofs).
virtual std::vector<uint8_t> getInstantSendLock(const uint256& txid) = 0;
Expand Down
30 changes: 30 additions & 0 deletions src/llmq/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef BITCOIN_LLMQ_PARAMS_H
#define BITCOIN_LLMQ_PARAMS_H

#include <algorithm>
#include <array>
#include <cstdint>
#include <string_view>
Expand Down Expand Up @@ -512,6 +513,35 @@ static constexpr std::array<LLMQParams, 14> available_llmqs = {

} // namespace Consensus

namespace llmq {
//! DKG intervals beyond its signing-active period during which a Platform quorum is still accepted
//! as the signer of Platform state.
static constexpr int PLATFORM_QUORUM_SLACK{2};

//! DKG intervals during which a Platform quorum may sign Platform state. A quorum of a non-rotating
//! type is signing-active for signingActiveQuorumCount intervals, one of a rotating type for one.
[[nodiscard]] constexpr int PlatformEligibleIntervals(const Consensus::LLMQParams& params)
{
return (params.useRotation ? 1 : params.signingActiveQuorumCount) + PLATFORM_QUORUM_SLACK;
}

//! How many of the newest mined Platform quorums may sign Platform state. A non-rotating type mines
//! one quorum per DKG interval, a rotating type one per quorum index.
[[nodiscard]] constexpr int PlatformEligibleQuorumCount(const Consensus::LLMQParams& params)
{
return PlatformEligibleIntervals(params) * (params.useRotation ? params.signingActiveQuorumCount : 1);
}

//! Lowest Core chain-locked height that Platform state may carry for this node to verify its
//! quorum signature, given the node's ChainLock height. Bounding by the ChainLock rather than the
//! tip keeps state signed before a ChainLock stall verifiable while the tip keeps moving.
[[nodiscard]] constexpr int PlatformQuorumMinSignedHeight(const Consensus::LLMQParams& params, int cl_height)
{
const int64_t window{int64_t{PlatformEligibleIntervals(params)} * params.dkgInterval};
return static_cast<int>(std::max<int64_t>(0, int64_t{cl_height} - window));
}
} // namespace llmq

// This must be outside of all namespaces. We must also duplicate the forward declaration of is_serializable_enum to
// avoid inclusion of serialize.h here.
template<typename T> struct is_serializable_enum;
Expand Down
88 changes: 57 additions & 31 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -86,6 +87,7 @@
#include <boost/signals2/signal.hpp>

#include <algorithm>
#include <limits>
#include <memory>
#include <optional>
#include <ranges>
Expand Down Expand Up @@ -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 {};
}
Comment on lines +723 to +725

@thepastaclaw thepastaclaw Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Resolved at b8e3318d; see the replies below.

🔴 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.

Suggested change
if (signed_height < llmq::PlatformQuorumMinSignedHeight(*llmq_params, cl_height)) {
return invalid;
}
if (signed_height < llmq::PlatformQuorumMinSignedHeight(*llmq_params, cl_height)) {
return best_cl_height >= 0 ? invalid : PlatformQuorumResult{};
}

source: gpt-6.1-sol (phase2-reviewer: general)

Copy link
Copy Markdown
Member Author

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 UNAVAILABLE while no ChainLock is known, and INVALID once one is.

Restart-during-stall regression: with no ChainLock, h = 3 at tip 100 is UNAVAILABLE (it was INVALID). With a ChainLock on the tip it is INVALID. Once the stalled ChainLock at 50 is learned, the same h = 3 is FOUND. Restoring return invalid; fails the first row.


🤖 Posted autonomously by Claude on behalf of pasta.

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Member Author

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 UNAVAILABLE whether 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 never FOUND. The restart-during-stall rows remain in getPlatformQuorum; the row with a ChainLock on the tip now expects UNAVAILABLE.


🤖 Posted autonomously by Claude on behalf of pasta.

Copy link
Copy Markdown
Collaborator

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.


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

@thepastaclaw thepastaclaw Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Withdrawn at b8e3318d; see the replies below.

🟡 Suggestion: Choose the commitment index format from rotation activation at the signed block

llmq_params->useRotation identifies a type that supports rotation; it does not indicate that DIP0024 rotation is active at signed_block. Commitment processing writes the indexed EvoDB key only when IsQuorumRotationEnabled(params, pindex) is true, and the quorum-manager path makes the same height-specific choice. Therefore, before activation, this lookup can search the indexed key for commitments stored under the non-indexed key and report UNAVAILABLE. The eligible-count and staleness helpers also currently apply the rotating policy across the entire history. Determine rotation from the activation state at the signed height, then use that effective policy both to select the walker and to calculate the window and signed-height bound.

source: gpt-6.1-sol (phase2-reviewer: general)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

  • A rotating Platform type is only selectable on devnets (-llmqplatform), and devnets set DIP0024Height = 2 (src/kernel/chainparams.cpp:597). IsQuorumRotationEnabled (src/llmq/utils.cpp:576) is therefore false only inside the first DKG interval, before any quorum of the type can have been mined. The lookup returns UNAVAILABLE there, which is correct. Mainnet, testnet and regtest Platform types do not rotate.
  • CQuorumManager::ScanQuorums selects between the same two walkers with static useRotation (src/llmq/quorumsman.cpp:273), so this matches how quorums are scanned for signature verification.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the activation argument. For a rotating Platform type, IsQuorumRotationEnabled remains false through the initial interval, before a valid quorum of that type can be mined; subsequent valid commitments are processed with the indexed format. The static useRotation selection therefore matches the reachable cases here, so I withdraw this suggestion.

Withdrawing this finding.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Withdrawn (re-reviewed at b8e3318d): The activation mismatch does not occur in a reachable Platform-quorum configuration: rotating Platform types are devnet-only and DIP0024 activates before their first usable quorum, while the other Platform types do not rotate.

if (std::ranges::none_of(bases, [&](const CBlockIndex* base) { return base->GetBlockHash() == quorum_hash; })) {
Comment on lines +730 to +732

@thepastaclaw thepastaclaw Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Withdrawn at b8e3318d; see the replies below.

🔴 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 bases; a matching quorum hash then passes the membership check and the readable commitment at line 746 produces FOUND even though the base is outside the real eligibility window. Removing the former corruption-detecting walkers only removes the detection—it does not make this new externally consumed FOUND result safe. Have the walker propagate ordering-integrity information or exclude bases implicated by contradictions and return UNAVAILABLE, while preserving FOUND for an unaffected prefix before an unrelated unreadable suffix.

source: gpt-6.1-sol (phase2-reviewer: general)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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 index value is a quorum base height written only by ProcessCommitment for a consensus-validated block, in the same EvoDB transaction as the commitment record. The walkers resolve it with pindex->GetAncestor(quorumHeight) (src/llmq/blockprocessor.cpp:751, :794), so a wrong base requires on-disk corruption that passes LevelDB's checksums, or a consensus bug.
  • Even then FOUND returns the key from a real mined commitment record (GetMinedCommitment), so the consumer still needs a valid threshold signature from a genuine quorum. The worst case is accepting a genuine quorum that is older than the window.
  • CQuorumManager::ScanQuorums reads the same walkers with no ordering check (src/llmq/quorumsman.cpp:273) to pick the quorums that verify ChainLocks and InstantSend locks. A node with a contradictory index is already wrong about those, and a check in this one interface would not change that.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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
{
Expand Down
Loading
Loading