Skip to content

fix(e2e): restore state sync and fix the p2p startup race that slow the test networks - #1460

Merged
lklimek merged 11 commits into
v1.8-devfrom
chore/e2e-startup-diag
Sep 14, 2026
Merged

lklimek merged 11 commits into
v1.8-devfrom
chore/e2e-startup-diag

Conversation

@lklimek

@lklimek lklimek commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: End-to-end test networks take minutes to start because a test helper feeds nodes malformed quorum data (so state sync never works) and because a node can be left without peers for a full minute at startup. This fixes both, cutting several minutes per CI run and removing a known source of random failures.

User story

As a contributor waiting on CI, I want the end-to-end runs to start their test networks quickly and not fail at random, so I get trustworthy results sooner.

Scenario

Base flow

An end-to-end run starts a test network, waits for nodes that join later to catch up, then perturbs the network and tests it.

Actual behavior

  • Nodes that are supposed to catch up from a snapshot never do: they silently fall back to replaying the chain, after waiting a full minute. So the snapshot path, one of the things the test is meant to cover, has not actually been exercised since 2026-09-09.
  • Some nodes find no peers at startup and sit idle for a minute, which delays the whole run and sometimes makes the runner declare a healthy chain "stalled" and fail the job.

Expected behavior

Nodes restore from a snapshot in seconds, nodes find peers immediately, and the run neither wastes minutes nor fails at random.

Detailed discussion

Full diagnosis with evidence: root causes, refuted hypotheses, and local experiment results are summarized below; every timing quoted comes from CI logs or local runs with node containers pinned to 4 CPUs.

Root cause 1 — regression since #1442: e2e mock Dash Core returns malformed quorum info (test infra)

#1442 made state sync authenticate a light block's validator set against Dash Core quorum info (internal/statesync/stateprovider.go). The e2e mock Core answers in a shape real Dash Core never produces: a numeric quorum type ("100") instead of the LLMQ name, a PubKey.String() rendering instead of a hex threshold key, and only the local member instead of the whole quorum.

Every e2e state sync therefore rejects every snapshot (quorum type "100" returned by Dash Core does not match light block 100, then invalid Dash Core threshold public key), falls back to block sync at height 1 — which nobody serves, since these chains start at height 1000 — and stalls for the full 60s syncTimeout before catching up through consensus.

The production code is correct: real Dash Core returns the LLMQ name and a hex quorumPublicKey. Only the mock was wrong.

Cost, from "Run CI" step durations on v1.8-dev pushes: rotate 646–691s before #1442 vs 818–1002s after; dashcore 330–355s vs 461–520s. The snapshot restore/backfill path has been silently untested in CI since #1442.

Fix: the mock now serves Dash-Core-shaped quorum info for every quorum in the validator-set schedule, with all members and their pubkey shares (kvstore.Config gains one exported accessor).

Root cause 2 — p2p startup race (production)

Reactors open their channels in OnStart, after router.Start already accepts and dials peers, and an MConn connection only knows the channel descriptors registered when it was created. A seed's PEX request arriving in that window hits unknown channel and the connection is killed as a protocol violation. Behind a connection-capped, rate-limiting seed the node can then stay peerless until block sync's 60s timeout, which delays the first heights (a peerless proposer costs a full round every fifth height) and makes the runner report a healthy chain as chain stalled — the known flaky failure mode of the rotate job.

Fix: create the transport with every descriptor the node's reactors will open (a seed node: PEX only). A message for a channel no reactor has opened yet is dropped by the router instead of killing the connection; a message for a channel that is genuinely unknown still is a protocol violation. AddChannelDescriptors skips already-registered IDs, and Dial now reads the descriptor slice under the transport mutex, like Accept does — it previously raced with AddChannelDescriptors.

Rejected alternatives, documented so nobody retries them: starting reactors before router.Start panics (Router.OpenChannel needs the queue factory built in Router.OnStart); deferring listen/dial until reactors are up deadlocks state-sync nodes, which wait for peers in OnStart.

Root cause 3 — runner start_at barrier waited for every node (test infra)

The barrier before starting a start_at node waited for every running node to reach the height, so one peerless node held back all later nodes, and its 60s no-progress window turned into a false chain stalled failure. It now waits for the chain — any started node with state at that height. Coverage is unchanged: the same nodes start at the same heights with the same sync paths, and the runner still waits for every node before perturbing and testing.

Not fixed here (follow-up)

After restoring a snapshot, block sync may send its first requests to a peer that has pruned those heights (retain_blocks=10); that peer never answers and is evicted only after 5 consecutive failures (~59s). The pruned peer should answer NoBlockResponse, or block sync should skip peers whose base is above the requested height.

Testing

  • go build ./...; go test -tags deadlock ./node/ ./internal/p2p/; go test ./test/e2e/pkg/mockcoreserver/ ./abci/example/kvstore/ — all pass. New tests were mutation-checked (each fails with its fix reverted). make lint against the base: 0 issues.
  • Local runs (16-core host, node containers pinned to 4 CPUs, approximating the CI runner) — rotate start phase: 3m28s on the base, 2m13s with the mock and p2p fixes, 1m01s with all three; dashcore: 33s. unknown channel drops go from 15–16 per run to 0. The local reproduction of the chain stalled at height 1010 flake stops reproducing.
  • CI reference points for the same phase: rotate 6m07s today vs 1m57s before fix(consensus): harden remote input handling #1442; dashcore 2m53s vs 41s.
  • Confirmed in CI on this PR (both legs green): the start phase drops from 6m07s to 2m30s on rotate and from ~2m51s to 28s on dashcore. "Run CI" step: rotate 735s (baseline 808–1002s), dashcore 316s (baseline 452–520s).
  • State sync demonstrably restores again: the state-sync nodes come up above their start_at height (validator06 at 1010, validator05 at 1007). Coming up exactly at start_at was the signature of the block-sync fallback this PR removes.
  • E2E_CPUSET (optional, local only) pins node containers to host CPUs so a 4-vCPU runner can be approximated locally.

Review round

A security review of the p2p commit (ee62b65f8) found no critical or high issues and confirmed the change does not weaken peer-misbehaviour handling: genuinely unknown channel IDs still disconnect the peer, payloads for a registered-but-unopened channel are dropped before unmarshalling, and the disconnect that is given up carried no scoring or eviction penalty. It also confirmed the Dial locking change fixes a genuine pre-existing data race.

Three findings were fixed in follow-up commits:

  • channelDescriptors() emitted 21 descriptors for 13 IDs, because p2p.ChannelDescriptors(cfg) is already the union including statesync and consensus. Every connection built ~8 orphaned channel objects, and sort.Slice is not stable, so which duplicate won was arbitrary per process. Now deduplicated, with a stable sort.
  • The node-info test compared two hand-maintained lists in the same file and never covered seed mode. It now derives its expectation from makeNodeInfo/makeSeedNodeInfo, covers validator/full/seed, and runs as a unit test without starting a node.
  • The transport test's copy-on-write assertion could not fail; it now asserts pointer identity with spare capacity.
    Two hardening changes came out of the same review, since no test that enumerates today's reactors can catch a reactor added tomorrow:
  • The channels a node advertises in NodeInfo are now derived from the registered descriptors (minus ErrorChannel, which is never sent to a peer and is documented as such), so three hand-maintained lists collapse into one. The advertised IDs are unchanged in every mode: the same 12 for a full node, {PEX} for a seed.
  • AddChannelDescriptors now logs a warning when a channel is registered after the transport was created — the exact moment this defect exists, and otherwise invisible, since opening the channel still succeeds.
    Each new test was mutation-checked: reverting the corresponding fix turns it red (7 mutations, all red).

Known follow-ups deliberately left out of this PR: unbounded channel.recving growth without an idle timeout (internal/p2p/conn/connection.go, pre-existing, inherited from upstream) and p2pclient.New being seeded with channel IDs its own reactors open.

Breaking changes

None. One production behaviour change: during the startup window, a message for a channel whose reactor has not opened yet is dropped instead of disconnecting the peer.

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 (n/a)

Prior work

🤖 Generated with Claude Code

lklimek and others added 5 commits September 11, 2026 14:43
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]>
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]>
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]>
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]>
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]>
@coderabbitai

coderabbitai Bot commented Sep 12, 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: 97595d9a-f136-463a-b796-e3b54a6cbd37

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.

lklimek and others added 4 commits September 12, 2026 08:36
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]>
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]>
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]>
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]>
@github-actions

github-actions Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

PR Hygiene

State: waiting-self-review · commit e10f89fe13a13a4df2d110db2e9a6cfbd2a75bfc

  • Author must post /self-reviewed e10f89f after bot completion

Self-review is an author attestation that you have read the diff:
/self-reviewed — covers everything pushed so far; post it again after a new push.
Post it after this report appears for commit e10f89fe13a13a4df2d110db2e9a6cfbd2a75bfc, or name the commit explicitly with /self-reviewed e10f89fe13a13a4df2d110db2e9a6cfbd2a75bfc.

This report does not bypass CI or repository protection rules.

@lklimek
lklimek marked this pull request as ready for review September 14, 2026 09:31
@lklimek
lklimek requested a review from shumkov as a code owner September 14, 2026 09:31
@thepastaclaw

thepastaclaw commented Sep 14, 2026 •

Copy link
Copy Markdown

✅ Final review complete — no blockers (commit e10f89f) · triage: critical · Phase 2 only (queue backlog)

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]>

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Final validation — Phase 2 only (queue backlog)

The reviewed changes address the stated e2e state-sync, p2p startup race, and start_at barrier issues without introducing actionable defects. The transport descriptor handling, NodeInfo advertisement, typed NoBlockResponse behavior, and mock quorum data are consistent with surrounding invariants and are covered by targeted tests.

Review provenance

Source: reviewer 1: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: critical by gpt-6-astra (effort low) — This is a large, cross-cutting change that modifies peer-facing network transport behavior and channel validation in internal/p2p/transport_mconn.go, client dialing, and node setup, a critical network surface requiring deeper review.
  • Phase 1 reviewers: not run (skipped for throughput: 14 PRs queued, above the 10 limit)
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — tenderdash-consensus-security (completed, effort xhigh); agent phase2-reviewer

@lklimek
lklimek merged commit ec25cf7 into v1.8-dev Sep 14, 2026
26 of 27 checks passed
@lklimek
lklimek deleted the chore/e2e-startup-diag branch September 14, 2026 14:05
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.

2 participants