Skip to content

fix(consensus): harden remote input handling - #1442

Merged
lklimek merged 8 commits into
dashpay:v1.7-devfrom
Claudius-Maginificent:fix/security-consensus-remote
Sep 9, 2026
Merged

lklimek merged 8 commits into
dashpay:v1.7-devfrom
Claudius-Maginificent:fix/security-consensus-remote

Conversation

@Claudius-Maginificent

@Claudius-Maginificent Claudius-Maginificent commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR

Nodes keep making progress when peers send inconsistent consensus data or stop receiving large block responses. State sync now installs validator controls only after checking them against locally trusted data.

User story

As a node operator, I want malformed or slow peer traffic to remain contained so that consensus, block sync, and state sync continue without manual recovery.

Scenario

Actual behavior

Certain peer inputs could delay block serving, leave proposal metadata inconsistent, or make state sync accept validator controls that were not covered by the legacy hashes.

Expected behavior

Peer-controlled work is bounded, slow deliveries are isolated to their peer, and remotely supplied validator state is checked against Dash Core, signed header data, and local genesis parameters.

Detailed discussion

Issue being fixed or feature implemented

Remote-input edge cases could make a node lose progress, retain inconsistent metadata, or perform excessive block-serving work. This change makes those paths deterministic and bounded while preserving the v1.7 wire, vote-signing, and block-hash formats.

What was done?

  • Recover threshold vote-extension shares only from a complete ordered group backed by threshold voting power.
  • Reconcile unsigned proposal metadata with the authenticated completed block.
  • Rebuild state-sync validator membership from Dash Core and require a remotely supplied voting-power threshold to match the locally stored genesis value.
  • Reject partially populated validator public-key shares and compare all header fields on primary and witness paths.
  • Bound block preparation globally and per peer while isolating delivery waits so a slow peer cannot occupy the shared preparation workers.
  • Detect delivery stalls from packet progress, bound peer cleanup, and reject delivery tracking for broadcast envelopes.
  • Remove silent block-request rate drops that could stall an honest fast sync; expensive block loads and serialization remain bounded by the fair scheduler.
  • Preserve the existing exported recovery option, align the Dash Core mock with the real RPC representation, and document the state-sync trust requirement.
  • Port and adapt the relevant regression coverage from lklimek/tenderdash#51.

These changes do not alter signature counting, vote sign bytes, header hashes, block hashes, or quorum threshold calculation.

How Has This Been Tested?

  • Race-enabled tests for block sync, state sync, P2P delivery, transport completion, vote recovery, header equality, and light-block validation.
  • Full affected-package tests for dash/core, internal/p2p/client, internal/p2p/conn, internal/blocksync, internal/statesync, types, light, and internal/consensus.
  • golangci-lint v2.13.2 with CI flags against origin/v1.7-dev: 0 issues.
  • gofmt and git diff --check.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Co-authored by Claudius the Magnificent AI Agent

lklimek and others added 2 commits September 8, 2026 11:00
Add failing regression coverage for vote-extension recovery panics,
proposal metadata malleability, validator-set state binding, and
CoreChainLockedHeight omission from the header hash.

Co-Authored-By: Claude GPT-6 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: b1e1a70e-ddae-4578-b10c-34009637ee0b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Sep 8, 2026 •

Copy link
Copy Markdown

🕓 Queued for automated review — 19th in line, estimated start in ~6 h (commit f9cc55f)
Estimated review time once started: ~40 min (two-phase automated review; median of recent runs).

  • Request priority review — tick this box and the review moves to the front of the queue.

@Claudius-Maginificent Claudius-Maginificent changed the title fix(security): harden remote consensus inputs fix(consensus): harden remote input handling Sep 8, 2026
Avoid mutating a proposal that may still be read by gossip workers, and address the static-analysis findings reported by CI.

Co-Authored-By: Codex GPT-6 <[email protected]>
@lklimek
lklimek changed the base branch from v1.7-dev to v1.8-dev September 9, 2026 13:13
@lklimek
lklimek changed the base branch from v1.8-dev to v1.7-dev September 9, 2026 13:14
@lklimek
lklimek enabled auto-merge (squash) September 9, 2026 13:23
@lklimek
lklimek merged commit edf4bab into dashpay:v1.7-dev Sep 9, 2026
18 of 20 checks passed
lklimek added a commit that referenced this pull request Sep 14, 2026
…he test networks (#1460)

* chore(e2e): allow pinning node containers to host CPUs via E2E_CPUSET

Lets a developer approximate the 4 vCPU CI runner on a larger host when
measuring e2e timing. Unset (default) leaves the compose file unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(e2e): report quorum type by LLMQ name in the mock Dash Core

The e2e mock Core server answered `quorum info` with the numeric LLMQ type
("100"), while Dash Core returns the LLMQ name ("llmq_test"). Since #1442,
state sync authenticates the light block validator set against `quorum info`
and parses the type with btcjson.GetLLMQType, so every e2e state sync
rejected every snapshot, fell back to block sync at height 1, stalled there
for the 60s sync timeout and only then caught up through consensus. That
added minutes to every CI run and left the state sync restore path untested.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(e2e): serve complete quorum info from the mock Dash Core

State sync (#1442) authenticates a light block's validator set against
Dash Core `quorum info`: the threshold public key as hex and every member
with its public key share, the signed proposer included. The e2e mock only
knew the local node's own share and printed the threshold key in the PubKey
String() form, so authentication still failed after the quorum type fix.

Build every quorum of the validator set schedule the runner already writes
to app.toml and serve it in full, the way Dash Core would. The FilePV path,
kept for quorums outside the schedule, reports the threshold key as hex.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(p2p): register every reactor channel with the transport up front

Reactors open their channels in OnStart, after the router already accepts
and dials peers, and an MConn connection is created with the channel
descriptors registered at that moment. A peer that spoke early on a channel
the connection did not know - typically a seed sending a PEX request right
after the handshake - was dropped with "unknown channel". Behind a
rate-limited, connection-capped seed this left nodes peerless until block
sync's 60s timeout, stalled the first heights and failed e2e runs.

Create the transport with every descriptor the node's reactors open (the
seed: PEX only). Until a reactor opens its channel the router drops that
channel's messages instead of the connection. AddChannelDescriptors skips
channel IDs already registered, and Dial reads the descriptors under the
transport mutex like Accept does.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* test(e2e): start a start_at node once the chain reaches its height

The start_at barrier waited for every running node to reach the height. A
node still looking for peers - common behind the connection-capped seed in
the CI networks - held back every later node for up to block sync's 60s
timeout, and when it made no progress for 60s the runner reported the
healthy chain as "stalled" and failed the run.

Wait for the chain instead: any started node with state at the height. The
lagging nodes keep catching up in the background, and the runner still
waits for every node to reach the target height before perturbing and
testing, so the same nodes, modes and sync paths are exercised.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(node): register each p2p channel descriptor exactly once

p2p.ChannelDescriptors already merges the consensus and state sync
descriptor sets, so also iterating those two sets handed the transport
21 descriptors for 13 channel IDs. Every connection then built two
conn.MConnection channels per duplicated ID, of which channelsIdx keeps
whichever the non-stable sort left last - the other one is allocated,
counted against the connection's send queues, and never receives.

Pull in only p2p.ChannelDescriptors, and sort with slices.SortFunc to
match the package's import style.

Rework the accompanying test into a unit test that no longer starts a
node: it derives the expectation from makeNodeInfo / makeSeedNodeInfo
rather than a second hand-kept channel list, covers validator, full and
seed mode, and asserts the descriptor set is exactly the advertised set
(plus p2p.ErrorChannel, which the p2p client opens lazily and which is
deliberately never advertised) with no ID registered twice.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* test(p2p): pin descriptor identity in AddChannelDescriptors

The previous assertions could not fail: the transport was constructed
with a len == cap slice literal, so any append - in place or not - would
have reallocated and left the snapshot untouched, and assert.Equal
compares descriptors by value, so keeping the duplicate instead of the
first registration went unnoticed.

Give the initial slice spare capacity, so an in-place append really
would write into the array the snapshot shares, and assert pointer
identity with assert.Same for both the retained first registration and
the snapshot's element.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* refactor(node): derive the advertised channels from the registered ones

makeNodeInfo listed the advertised channels by hand, so the node kept
three hand-maintained channel lists (up-front descriptors, validator
NodeInfo, seed NodeInfo) that matched only because each was edited in
step. They fail closed but silently when they drift: Router.OpenChannel
never consults the transport's list, it only adds to it, so a channel
missing up front still opens and only peers that speak on it over a
connection established earlier get dropped.

Derive both NodeInfo channel lists from channelDescriptors and document
why p2p.ErrorChannel is left out - nothing is ever sent to a peer on it,
it only carries p2p.PeerError to the router, which evicts the peer
locally. The advertised IDs are unchanged in every mode.

Assert the invariant per mode (validator, full, seed) against the
descriptor sets the p2p client and the consensus, state sync, evidence
and PEX reactors actually pass to OpenChannel, instead of against a
literal maintained in the test file.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* feat(p2p): warn when a channel is registered after transport creation

A channel the transport was not created with is a gap in the node's
up-front channel list, and it is otherwise invisible: opening the channel
succeeds, no test fails, and only peers that speak on it over a
connection established earlier are dropped as protocol violators.

Log it as a warning - not an error - since the legacy p2p test harness
opens channels ad hoc, and MemoryTransport.AddChannelDescriptors is a
no-op, so nothing else changes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(blocksync): retry missing blocks without waiting for peer timeout

Resolve NoBlockResponse as a typed request failure and retain a peer's
unavailable history across status refreshes. Requeue the missing height
without penalizing or disconnecting the peer, allowing another source to
serve it immediately.

Cover immediate response handling, retry selection, request accounting,
status refreshes, reordered replies, and mismatched heights.

Co-Authored-By: Codex <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Codex <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants