Repository navigation
fix(e2e): restore state sync and fix the p2p startup race that slow the test networks - #1460
Conversation
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]>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
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]>
PR HygieneState: waiting-self-review · commit
Self-review is an author attestation that you have read the diff: This report does not bypass CI or repository protection rules. |
|
✅ 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
left a comment
There was a problem hiding this comment.
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:
criticalbygpt-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; agentastra-verifier - Phase 2 reviewers:
gpt-6-astra— general (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— tenderdash-consensus-security (completed, effort xhigh); agentphase2-reviewer
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
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, aPubKey.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, theninvalid 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 60ssyncTimeoutbefore 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-devpushes: 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.Configgains one exported accessor).Root cause 2 — p2p startup race (production)
Reactors open their channels in
OnStart, afterrouter.Startalready 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 hitsunknown channeland 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 aschain stalled— the known flaky failure mode of therotatejob.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.
AddChannelDescriptorsskips already-registered IDs, andDialnow reads the descriptor slice under the transport mutex, likeAcceptdoes — it previously raced withAddChannelDescriptors.Rejected alternatives, documented so nobody retries them: starting reactors before
router.Startpanics (Router.OpenChannelneeds the queue factory built inRouter.OnStart); deferring listen/dial until reactors are up deadlocks state-sync nodes, which wait for peers inOnStart.Root cause 3 — runner start_at barrier waited for every node (test infra)
The barrier before starting a
start_atnode 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 falsechain stalledfailure. 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 answerNoBlockResponse, 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 lintagainst the base: 0 issues.unknown channeldrops go from 15–16 per run to 0. The local reproduction of thechain stalled at height 1010flake stops reproducing.start_atheight (validator06 at 1010, validator05 at 1007). Coming up exactly atstart_atwas 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 theDiallocking change fixes a genuine pre-existing data race.Three findings were fixed in follow-up commits:
channelDescriptors()emitted 21 descriptors for 13 IDs, becausep2p.ChannelDescriptors(cfg)is already the union including statesync and consensus. Every connection built ~8 orphaned channel objects, andsort.Sliceis not stable, so which duplicate won was arbitrary per process. Now deduplicated, with a stable sort.makeNodeInfo/makeSeedNodeInfo, covers validator/full/seed, and runs as a unit test without starting a node.Two hardening changes came out of the same review, since no test that enumerates today's reactors can catch a reactor added tomorrow:
NodeInfoare now derived from the registered descriptors (minusErrorChannel, 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.AddChannelDescriptorsnow 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.recvinggrowth without an idle timeout (internal/p2p/conn/connection.go, pre-existing, inherited from upstream) andp2pclient.Newbeing 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
Prior work
🤖 Generated with Claude Code