Repository navigation
fix(consensus): bound catch-up block-part resends and restore round timeouts in reactor test - #1418
Conversation
…etChanges The test drove its 7-node network with newMockTickerFunc(true), which forwards only RoundStepNewHeight timeouts and only the first one; every other scheduled timeout is discarded. That leaves the network without timeoutPropose, without timeoutPrevoteWait/timeoutPrecommitWait and, after the first height, without timeoutNewHeight — so consensus has no way to change round and no way to start a height it committed without receiving a peer commit. Any perturbation is therefore permanent, and the test hangs until its 2-minute context deadline. Both observed CI failure shapes follow from this. A proposal delayed past MessageDelay+Precision makes every validator prevote nil, and the round change that would recover never fires. Separately, a node that applies a commit itself sits at RoundStepNewHeight forever; when it is the next proposer, nobody proposes and nobody times out waiting. Restore the real ticker, which "chore(consensus): stabilize consensus algorithm (#284)" had already established before #1204 reverted it, and give rounds enough wall clock to complete on a loaded runner. Round timeouts only fire when the network stalls, so larger values cost nothing on the healthy path, while 2s/1s makes a starved CI runner abandon rounds it would have completed, leaving it to churn instead of converge. Verified with go test -race -count=10: the old code fails 1/10 on an idle 16-core host, reproducing the CI signature exactly (all seven nodes report a waitForAndValidateBlock deadline, one with "subscription terminated by publisher"); the new code passes 20/20 over two such runs. Under three concurrent copies of the test the pass rate rises from 10/18 to 14/15. Refs #1405 <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RoXmbFrVf1BqVW1BHZv6Va
|
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: Team 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 |
|
🕓 Ready for review — 34 ahead in queue (commit 6eff091) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Codex/Sol only (Phase 2 disabled)
The change is confined to test infrastructure and correctly replaces the liveness-disabling one-shot mock ticker with independent production timeout tickers while increasing only test-local timeout parameters. The focused non-race test passed; the race run on a heavily contended host reached active round changes before its wall-clock deadline, consistent with the documented oversubscription limitation rather than the permanent ticker-induced stall this PR fixes. Source: reviewers gpt-5.6-sol (general and tenderdash-consensus-security); final verifier gpt-5.6-sol. Orchestration-only: openclaw-agent/cliproxy/gpt-5.6-sol (not reviewer evidence).
Validated zero-blocker Codex/Sol precheck evidence was promoted to final because Phase 2 (Sonnet/Opus) is temporarily disabled. This is Codex/Sol-only final validation, not Codex + Sonnet/Opus coverage.
Review provenance
- Codex reviewers:
gpt-5.6-sol— general (completed),gpt-5.6-sol— tenderdash-consensus-security (completed) - Verifier:
gpt-5.6-sol— verifier - Sonnet/Opus: not run (Phase 2 disabled — temporary Codex/Sol-only final)
- Secondary pass: disabled (
temporary_phase2_sonnet_disable)
…erval GossipBlockPartsForCatchup never marks catch-up parts as delivered, so prs.ProposalBlockParts.Not().PickRandom() keeps finding the same index missing and the part is re-sent on every gossip tick. The loop ends only when our own view of the peer's height advances, and the traffic it generates delays exactly the NewRoundStep messages that would advance it. Measured in a 7-node race-enabled reactor test: 1091 height-11 block parts pushed at a node that had already reached height 12, every one discarded, against 9 completed proposal blocks in the same window. The live round cannot assemble its proposal, every validator prevotes nil, and the height churns rounds until the test deadline. The same loop drives the part-set-header mismatch branch, which logs at error level on every tick without sending anything. Bound it to one part-set pass per catchupResendInterval. A pass spends one send per part; once complete, further ticks are skipped until the interval elapses, then a new pass begins. A peer that silently dropped its parts is therefore still served repeatedly for as long as it stays behind, so the wedge fixed in #1365 stays fixed, while a peer we only believe to be lagging costs one pass rather than one send per tick. Parts are still never marked delivered, keeping that guarantee independent of PeerState bookkeeping — which is unreliable here, since SetHasProposalBlockPart ignores updates whose round differs from the peer's current round and catch-up passes the committed block's round. At 4 concurrent race-enabled copies of TestReactorValidatorSetChanges, where the unbounded loop passes 2/16, this passes 16/16 — matching a full revert of the resend behaviour while keeping its protection. Also 18/18 at 3 concurrent copies and 10/10 unloaded. Wasted catch-up parts drop from 164592 to 2845 per batch (a revert scores 2736), and the wedge precondition "Commit came in before proposal" occurs 632 times across those runs with zero wedges. The two tests from #1365 now assert the bounded contract: parts are still never marked delivered, no resend occurs inside the interval, and a resend follows once the clock advances past it. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RoXmbFrVf1BqVW1BHZv6Va
thepastaclaw
left a comment
There was a problem hiding this comment.
Preliminary review — Codex only
Restoring the real timeout ticker is sound, but the catch-up limiter does not enforce its intended resend interval for partially populated part sets. Because the pass budget uses the total part-set size, a peer with one missing part can still receive hundreds or thousands of duplicate copies before the 500 ms backoff begins, so changes are required.
Source: reviewers gpt-5.6-sol (general) and gpt-5.6-sol (tenderdash-consensus-security); final verifier gpt-5.6-sol. Orchestration-only: openclaw-agent/cliproxy/gpt-5.6-sol (not reviewer evidence).
Validated blockers were found in the Codex precheck. Opus is deferred until a fresh Codex revalidation clears the blocker gate.
Review provenance
- Codex reviewers:
gpt-5.6-sol— general (completed),gpt-5.6-sol— tenderdash-consensus-security (completed) - Verifier:
gpt-5.6-sol— verifier - Sonnet: not run (deferred by blocker gate)
🔴 1 blocking
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `internal/consensus/gossiper.go`:
- [BLOCKING] internal/consensus/gossiper.go:243: Limit each catch-up pass to the peer's missing parts
`beginCatchupAttempt` budgets attempts using the total bitmap size, while `PickRandom` at line 194 selects only unset bits and successful catch-up sends deliberately leave those bits unset. A valid partial bitmap containing N-1 set bits therefore causes the sole missing part to be selected and resent N times before the retry interval starts. This state is reachable from an untrusted peer because `NewValidBlockMessage.ValidateBasic` checks the bitmap's size but not its contents, and `ApplyNewValidBlockMessage` installs the supplied bitmap for the matching height. With the production 100 ms gossip cadence, a roughly 337-part default-size block permits about 34 seconds of uninterrupted duplicate sends before a 500 ms pause; the protocol maximum of 1,601 parts permits about 160 seconds. This leaves the flooding behavior that the PR is intended to stop almost unchanged for partial part sets. Count the currently missing bits instead, and add a regression case where every bit except one is set.
…y size beginCatchupAttempt sized a catch-up pass with prs.ProposalBlockParts.Size(), the length of the peer's bit-array, while GossipBlockPartsForCatchup draws indices from prs.ProposalBlockParts.Not().PickRandom() — the unset bits alone. A peer reporting all but one part present therefore had every draw in the pass return that same index, so the one missing part was re-sent once per entry in the array before the interval pause. That bit-array arrives from the network. NewValidBlockMessage. ValidateBasic checks only that its length equals BlockPartSetHeader.Total, never the bit pattern, and PeerState.ApplyNewValidBlockMessage installs it wholesale. A peer can thus pick the amplification factor, up to MaxBlockPartsCount (1601) sends of a single part per interval, which largely defeats the bound. Budget on the number of parts the peer reports missing instead, and return early when none are. CountTrueBits has no nil receiver guard, unlike Size, so the nil bit-array is rejected first; the sole production caller already checks it, but the previous Size call was nil-safe and that property is worth keeping. The bound can now only tighten: missing is at most the array length, and is equal to it in the common case where a lagging peer holds none of the parts, so catch-up throughput for genuinely lagging peers is unchanged. Adds a regression case for a bit-array with a single unset bit, which draws 3 sends per pass before this change and 1 after, plus a case for a peer that reports the complete part set, which must open no pass at all. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RoXmbFrVf1BqVW1BHZv6Va
thepastaclaw
left a comment
There was a problem hiding this comment.
Preliminary review — Codex only
The current head fixes the prior static partial-bitmap amplification, and restoring the real timeout ticker remains appropriate. Two in-scope limiter flaws remain: a peer can extend an active catch-up pass by repeatedly replacing its bitmap, and a malformed header can trigger a maximum-length pass of storage reads and error logs without sending any part.
Source: Codex reviewers gpt-5.6-sol (general and tenderdash-consensus-security); final verifier claude-opus-4-6; orchestration-only openclaw-agent/cliproxy/gpt-5.6-sol (not reviewer evidence).
Validated blockers were found in the Codex precheck. Opus is deferred until a fresh Codex revalidation clears the blocker gate.
Review provenance
- Codex reviewers:
gpt-5.6-sol— general (completed),gpt-5.6-sol— tenderdash-consensus-security (completed) - Verifier:
gpt-5.6-sol— verifier - Sonnet: not run (deferred by blocker gate)
🔴 2 blocking
1 additional finding(s) omitted (not in diff).
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `internal/consensus/gossiper.go`:
- [BLOCKING] internal/consensus/gossiper.go:250-262: Snapshot the missing-part budget for each catch-up pass
`missing` is recalculated from the latest peer-supplied bitmap on every tick, while `catchupAttempts` and `catchupRetryAt` describe an already active pass. After N-1 attempts against N missing parts, the peer can replace the bitmap with one reporting N-1 missing parts. Because `catchupRetryAt` has not yet been initialized, `catchupAttempts >= missing` immediately resets the counter without waiting. Repeating this before each threshold permits N*(N-1)/2 attempts before the first retry interval; for a matching 1,601-part block that is 1,280,800 uninterrupted part-send attempts. This is reachable because `ApplyNewValidBlockMessage` replaces the bitmap wholesale at the peer's matching height and round. Snapshot the missing count when a pass opens, or track a remaining budget that cannot be increased or reset by bitmap updates until the retry interval expires, and add a regression test that decreases the reported missing count immediately before each threshold.
- [BLOCKING] internal/consensus/gossiper.go:207-210: End the catch-up pass after a failed header check
`beginCatchupAttempt` consumes only one slot before the header check, so a failure here does not activate the retry interval until every reported missing-part slot has been consumed. A peer can install an otherwise valid `NewValidBlockMessage` at its catch-up height with an all-zero 1,601-bit array and an arbitrary 32-byte part-set hash. The mismatch then causes a block-meta lookup and an Error log on every default 100 ms gossip tick for about 160 seconds, followed by only a 500 ms pause, without sending a part or requiring another inbound message. Multiple peers can amplify this storage, CPU, and log work while contending with live consensus traffic. A metadata, header, or part-load failure should terminate the current pass and set its retry deadline immediately; add a regression test using a maximum-size missing bitmap and mismatched header.
beginCatchupAttempt derived the pass threshold from prs.ProposalBlockParts on every call while catchupAttempts and catchupRetryAt persisted across calls, so the peer that owns that bit-array could move the threshold out from under the counter. Two ways, both reachable through NewValidBlockMessage, whose ValidateBasic checks only the array's length: Lowering the reported missing count to the number of sends already made takes the "pass spent" branch while catchupRetryAt is still zero, because that field was only assigned once the counter reached the earlier, larger threshold. The wait is then measured against the zero time, the counter resets and sending continues. Repeating one decrement at a time telescopes into roughly N^2/2 sends before any wait applies. Raising it afterwards is simpler still: the counter no longer meets the threshold, so the branch holding the deadline check is skipped entirely and a deadline already set is stepped over. Draw from a remaining-budget counter instead. Opening a pass fixes both the budget and the deadline together, and the budget only counts down, so neither can be re-derived from anything the peer sends mid-pass. There is no longer a state where a pass is spent but no deadline exists. The height reset stays: ApplyNewRoundStepMessage drops any message that does not advance the peer's height/round/step, so a peer cannot replay it to reopen passes, and it can only keep doing so by advancing out of the catch-up window. Removing it would instead make every legitimately advancing peer wait an interval per height. Sends per interval remain bounded by the block's real part count: ensurePeerPartSetHeader rejects a fabricated part-set header, so a peer inflating the count buys early exits rather than sends. The regression test drops the reported count to the sends already made and then raises it again, drawing 5 sends from a 3-send pass before this change and 3 after. TestGossiper, TestPeerGossipWorker and TestReactorValidatorSetChanges pass; 16/16 at 4 concurrent race-enabled copies with wasted catch-up parts at 3002 against 2845 before, so the storm bound is unchanged. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RoXmbFrVf1BqVW1BHZv6Va
thepastaclaw
left a comment
There was a problem hiding this comment.
Preliminary review — Codex only
Restoring production timeout tickers is sound, and the current head fixes the active-pass bitmap manipulation by snapshotting both the missing-part budget and retry deadline when a pass opens. One blocking issue remains: storage and validation failures leave that peer-controlled pass active, enabling continuous reads and error logs and allowing an inflated malformed-header budget to carry into repeated valid part sends. Source: Codex reviewers gpt-5.6-sol (general and tenderdash-consensus-security); final verifier claude-opus-4-6; openclaw-agent/cliproxy/gpt-5.6-sol is orchestration-only and not reviewer evidence.
Validated blockers were found in the Codex precheck. Opus is deferred until a fresh Codex revalidation clears the blocker gate.
Review provenance
- Codex reviewers:
gpt-5.6-sol— general (completed),gpt-5.6-sol— tenderdash-consensus-security (completed) - Verifier:
gpt-5.6-sol— verifier - Sonnet: not run (deferred by blocker gate)
🔴 1 blocking
1 additional finding(s) omitted (not in diff).
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `internal/consensus/gossiper.go`:
- [BLOCKING] internal/consensus/gossiper.go:202-215: End the catch-up pass after a failed header check
`beginCatchupAttempt` consumes a peer-controlled budget slot before loading metadata or validating the part-set header, but each failure here returns without ending the active pass. An unauthenticated peer can announce a stored historical height and install a validly encoded 1,601-bit all-zero `NewValidBlockMessage` with an arbitrary valid-length hash; `ValidateBasic` accepts it and `ApplyNewValidBlockMessage` installs it. The default 100 ms gossip loop then performs a metadata read and emits an Error log on every tick for roughly 160 seconds. Because `catchupRetryAt` was set when the pass opened, it has already expired when the budget is exhausted, so another full pass starts immediately without an effective pause. The same state allows send amplification: after opening the 1,601-slot pass with a mismatched header, the peer can replace its same-height state with the stored block's real header and a bitmap reporting one missing part, and the unchanged remaining budget permits approximately 1,600 duplicate sends of that part. Terminate the active pass and establish a fresh retry deadline after metadata, header, or part-load failures, and add regressions for both a persistent maximum-size mismatch and a malformed-to-valid same-height replacement.
beginCatchupAttempt charged a budget slot before loadMeta, the part-set header check and loadPart, none of which ended the pass when they failed. The peer supplies both the missing bit-array a pass is budgeted from and the part-set header those checks run against, and ValidateBasic accepts any well-formed pair, so it could open a maximum-size pass under a header matching no stored block. That bought two things. A pass that can never send charged a block-store read and an error log to every gossip tick for its whole budget - roughly 160s at the production 100ms cadence - and since the retry deadline was armed when the pass opened, it had long expired by the time the budget ran out, so the next pass began immediately and the interval never throttled anything. The same inflated budget also survived the peer replacing its state, at the same height, with the stored block's real header and a single missing part: the budget is deliberately not re-derived once a pass is open, so the remainder landed as duplicate sends of that one part. Move the send into sendCatchupBlockPart and abandon the pass, arming a fresh retry deadline, whenever it reports that no part reached the peer. A pass now costs at most one failed attempt per interval, and only a pass that got as far as sending keeps its budget. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RoXmbFrVf1BqVW1BHZv6Va
Catch-up pass now ends when it cannot send — fixed in e01f593Answering the blocking finding carried in the review body of 5031834714 and 5039744991 ( Verified independently, not taken on faith. Both exploits reproduce. I wrote them as tests against the pushed head Fix. The send moved into Structuring it as a wrapper plus a helper rather than five calls to On exploit 1, being precise about what the fix is worth: the limiter's contract is one attempt per interval, so wasted reads and error logs drop from one per 100 ms tick to one per 500 ms — 5x, not elimination. That is the ceiling any per-interval bound can offer, and it matches your suggested direction. Exploit 2, the send amplification, is eliminated outright: the inflated budget dies on the first failed attempt, so the fresh pass is budgeted on the single part the peer actually reports. One residual lever I checked rather than assumed. Verification. Targeted group green under The storm bed needed care this time: an unrelated tenant on the measurement host swung an unmodified
The single failure hit both arms in the same round. No liveness or storm-bound regression. Separately: both reviews also report |
thepastaclaw
left a comment
There was a problem hiding this comment.
Preliminary review — Codex only
The current head fixes the prior failure-path pass leak, but successful passes still permit back-to-back replay and allow a previously opened budget to be concentrated on one remaining part. Both issues are in the limiter introduced by this PR and leave sustained duplicate catch-up traffic possible for large multipart blocks, so changes are still required.
Source: reviewers gpt-5.6-sol (Codex general and TenderDash consensus-security); final verifier claude-opus-4-6. Orchestration-only: openclaw-agent/cliproxy/gpt-5.6-sol (not reviewer evidence).
Validated blockers were found in the Codex precheck. Opus is deferred until a fresh Codex revalidation clears the blocker gate.
Review provenance
- Codex reviewers:
gpt-5.6-sol— general (completed),gpt-5.6-sol— tenderdash-consensus-security (completed) - Verifier:
gpt-5.6-sol— verifier - Sonnet: not run (deferred by blocker gate)
🔴 2 blocking
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `internal/consensus/gossiper.go`:
- [BLOCKING] internal/consensus/gossiper.go:280-283: Start the retry interval when the pass finishes
`catchupRetryAt` is armed when a pass opens, although catch-up sends only one part per data-gossip invocation. At the default 100 ms gossip cadence, a pass with six or more missing parts lasts at least the full 500 ms interval. When `catchupRemaining` reaches zero, the deadline has therefore already expired, and the next tick immediately opens another pass. Successful catch-up sends intentionally do not update the peer bitmap, so a peer that remains at the same height can receive block parts on every tick indefinitely, with no quiet interval between passes. This preserves the traffic-starvation behavior the limiter is intended to stop for multipart blocks. Arm the retry deadline when the final attempt is consumed or completed, and add a test that advances the fake clock by the production gossip cadence between sends and verifies a full retry interval after the pass ends.
- [BLOCKING] internal/consensus/gossiper.go:276-283: Tighten an active pass when the missing bitmap shrinks
The pass snapshots its initial missing count, but `sendCatchupBlockPart` selects from the peer's latest bitmap on every tick. An untrusted peer can open a valid N-part pass reporting every part missing, allow one send to succeed, and then send another same-height `NewValidBlockMessage` with the same stored part-set header but only one unset bit. `ValidateBasic` accepts that replacement and `ApplyNewValidBlockMessage` installs it wholesale, while the unchanged `catchupRemaining` funds N-1 successful duplicate sends of the sole missing part. For a 1,601-part block, this permits roughly 160 seconds of uninterrupted duplicates at the default cadence, and `endCatchupPass` never runs because every send succeeds. Consume a snapshot of distinct missing indices or monotonically reduce the active remaining budget when the current missing count decreases; never increase or reopen the active pass from a replacement bitmap.
There was a problem hiding this comment.
Pull request overview
This PR addresses a consensus gossip liveness issue where catch-up block-part resends can become effectively unbounded (starving other consensus messages), and it stabilizes TestReactorValidatorSetChanges by restoring real consensus round timeouts in the test network harness.
Changes:
- Restore real timeout ticker usage in
TestReactorValidatorSetChangesand increase propose/vote timeouts to better tolerate race-detector and single-process contention. - Add per-peer catch-up pass accounting to bound catch-up block-part resends to at most one part-set “pass” per
catchupResendInterval. - Update and extend gossiper unit tests to validate the bounded resend behavior and pass-budget invariants; wire a real clock into the peer gossiper.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/consensus/reactor_test.go | Switches the flaky reactor test back to a real timeout ticker and increases round timeouts to allow recovery under load. |
| internal/consensus/gossiper.go | Implements bounded catch-up block-part resend passes using a clock and per-peer pass bookkeeping. |
| internal/consensus/gossiper_test.go | Updates existing catch-up resend tests and adds new cases for pass budgeting, retry interval behavior, and malformed/mismatched peer state. |
| internal/consensus/gossip_peer_worker.go | Initializes the new gossiper clock with a real clock in production wiring. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…l exploitable Two gaps let a peer defeat the catch-up throttle this PR is adding: - beginCatchupAttempt armed catchupRetryAt when a pass opened. A pass with enough missing parts to span more gossip ticks than catchupResendInterval takes longer than the interval to exhaust its budget, so the deadline had already elapsed by the time the pass finished - the next tick reopened a fresh pass with no quiet gap at all. Arm the deadline when the pass's last attempt is spent instead. - The pass budget was fixed at open and never revisited downward. A peer fully controls ProposalBlockParts over the wire (NewValidBlockMessage. ValidateBasic checks only length, ApplyNewValidBlockMessage installs it wholesale) and can open a pass reporting many parts missing, then swap in a bit-array with only one unset bit — every remaining budgeted attempt then draws that same index, funding repeated duplicate sends of it. Clamp the remaining budget down whenever the peer's current missing count drops below it; never raise it back up. Adds regression tests for both: a 6-part pass ticked across catchupResendInterval to show the deadline is measured from the pass's last send, and a 5-part pass whose bitmap shrinks mid-pass to show the budget clamps to the peer's current report. Both fail against the pre-fix code. Addresses thepastaclaw findings on PR #1418. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]>
…p parts beginCatchupAttempt derived the peer's missing-part count via Not().CountTrueBits(), which allocates and copies the whole (peer-controlled, up to MaxBlockPartsCount) bit-array on every gossip tick just to count it. sendCatchupBlockPart already performs its own Not().PickRandom() when a send actually happens, so this was a second, avoidable full-array allocation on every tick regardless of whether a send occurs. Derive the same count as size minus set bits instead. Addresses a copilot review comment on PR #1418. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]>
…asion Layers on top of review-stream's retryAt-at-close and downward-clamp fix in beginCatchupAttempt. Distinct fixes: - syncProposalBlockPart (pre-existing, untouched elsewhere in this PR) unconditionally returned nil, so a failed send never reached endCatchupPass despite the caller's contract assuming it would. sendCatchupBlockPart now reports success as a bool instead of an error nobody was meant to inspect, and its "no missing part" branch can no longer be hit (the comment claiming otherwise was already false: prs is a fresh per-tick deep copy nothing else can mutate). - A peer's height advancing reset the retry deadline as well as the budget, granting a free pass on every height step; only the budget resets now. - The three catch-up fields were guarded only by a comment claiming a single caller, despite the same *msgGossiper being shared across three concurrent handler goroutines; a mutex now guards them structurally. - Documented the rate limit's actual scope (per gossip worker, not per peer -- a reconnect gets a fresh one) on the Gossiper interface and the actual tick-to-interval relationship on catchupResendInterval, both previously undocumented. Co-Authored-By: Claude Sonnet 5 <[email protected]>
GossipBlockPartsForCatchup is rate-limited and returns without sending on most ticks, so "block parts already delivered" no longer describes what happened before the unconditional GossipCommit call on the same branch. Co-Authored-By: Claude Sonnet 5 <[email protected]>
syncProposalBlockPart unconditionally returned nil regardless of the underlying send's actual result, so sendCatchupBlockPart's error check against it (added in the prior commit) was dead code: a send that never reached the peer was indistinguishable from one that did, and endCatchupPass never fired for that failure mode -- the pass kept spending its budget one failed attempt per tick instead of ending on the first one, exactly the spin endCatchupPass exists to prevent. Fix at the source: return g.sync's result directly and drop the now-redundant local log, since both callers already log a non-nil error themselves. The other caller, GossipProposalBlockParts, only ever logged this error and took no other action, so propagating it for real is behavior-preserving there. Regression test advances a fake clock across many ticks with every send forced to fail and asserts exactly one block-part read per catchupResendInterval, not one per tick; confirmed failing (5 reads instead of 1) against the pre-fix code. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…-validatorset-timing
…nce interrupts a live pass A peer that advances its reported height mid-pass (before the pass exhausts its own budget) reset catchupRemaining to 0 without arming catchupRetryAt, since the deadline was only ever armed when a pass ran its budget down naturally. A peer whose height ticks forward every gossip tick therefore got a fresh full-budget pass every tick forever, completely bypassing catchupResendInterval for the common multi-part-block case. Arm the deadline on the height-change branch too whenever a pass was actually in flight, matching the same invariant beginCatchupAttempt's normal exhaustion path already upholds. Document that invariant on the struct fields it protects. Also, while re-auditing this function for the same iteration: - stop re-deriving the budget from a peer-controlled bit-array once a pass is open (now g.catchupRemaining = min(g.catchupRemaining, missing), replacing an equivalent but more verbose branch) - de-duplicate the block-store-failure error logs in sendCatchupBlockPart; blockRepository.loadMeta/loadPart already log the failure, so the caller's second log was pure noise - correct sendCatchupBlockPart's doc (it reports handoff to the p2p channel, not peer delivery) and give its error log a distinct message from GossipProposalBlockParts's - correct the Gossiper interface, catchupResendInterval, and endCatchupPass doc comments, which described a flat one-send-per- interval bound that does not hold for multi-part blocks Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ak catch-up assertions - Add TestGossipBlockPartsForCatchupHeightAdvanceInterruptingPassIsThrottled, a regression test for the height-advance bug fixed in gossiper.go: confirmed RED (20 sends) against the pre-fix code via git stash, GREEN (1 send) after the fix. - Rename/rewrite TestGossipBlockPartsForCatchupBudgetIsFixedAtPassOpen to TestGossipBlockPartsForCatchupBudgetIsNeverRaisedMidPass: the old sequence never actually drove catchupRemaining below the reported missing count it then 'raised', so the raise-attempt it claimed to guard against was a no-op the test would pass on regardless. The new version forces a real clamp (5-part block, drop to 1 missing after two sends) before attempting to raise the count back up, and asserts the raise is not honored before the interval elapses. - Strengthen TestGossipBlockPartsForCatchupPeerHasEveryPart with an explicit AssertNotCalled, so it fails loudly instead of silently if a send is ever wired in for a peer that already has every part. - Update the two wantLog assertions in TestGossipBlockPartsForCatchup that still expected the removed 'couldn't find a block meta/part' caller-side logs; the block-store-failure messages they should match are now blockRepository's own 'failed to load block meta'/'failed to load block part'. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…pWorker newPeerGossipWorker constructed two independent clockwork.NewRealClock() instances for what is meant to be one gossip worker's shared notion of time. They agree in practice (both wrap wall-clock time), but nothing enforces that, and it defeats point-in-time comparisons in tests that inject a single fake clock expecting both call sites to observe it. Construct one clock and pass it to both. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…t comment The comment described GossipBlockPartsForCatchup as rate-limited and a no-op on most ticks, which held before this PR's changes but not after: a pass now spends one send per tick for as many ticks as the peer reports parts missing, and the quiet gap applies only between passes, not on most individual ticks. Reword to match. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…he catch-up throttle PeerGossipSleepDuration sets the tick rate that internal/consensus/gossiper.go's catchupResendInterval throttle is metered against: configuring it above that fixed interval silently disables the throttle. Document the coupling at both the struct field and the generated TOML template so an operator tuning gossip cadence sees the side effect. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…backed off beginCatchupAttempt computed missing (Size() - CountTrueBits(), an O(bits) scan of the peer-controlled ProposalBlockParts array) unconditionally, even on ticks that are going to return false immediately because the pass is still within catchupRetryAt's backoff. At production defaults most gossip ticks land in backoff (a pass's quiet interval is ~5x the gossip cadence), so this scanned a bit-array up to MaxBlockPartsCount long on nearly every tick for no reason. Move the backoff check ahead of the scan: when no pass is open and the retry deadline hasn't elapsed, return early without touching ProposalBlockParts at all. The scan still runs whenever it can affect the outcome - opening a new pass, or clamping an active one's budget down to a shrunk missing count. Addresses a copilot review comment on PR #1418. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]>
…complete beginCatchupAttempt returned early on missing == 0 without touching catchupRemaining/catchupRetryAt. When that happened mid-pass (catchupRemaining > 0, budget not yet exhausted), the pass stayed open indefinitely: noOpenPass would keep evaluating false forever, so the backoff check above it — which only runs while no pass is open — was skipped on every later tick regardless of elapsed time. A peer could freeze catchupRemaining above zero by reporting a complete part set whenever it liked, then resume sending immediately the next time it reported parts missing, with no retry interval honored at all. Close the pass in that case too: zero the remaining budget and arm the retry deadline, matching what happens when a send fails or a height change interrupts a pass. Only do this when a pass was actually open; a peer that has simply always reported a complete set must not have a wait imposed on it. Also corrects a stale doc comment on PeerGossipSleepDuration added by the same throttle: catchupResendInterval is a fixed quiet gap that does not scale with the gossip tick duration, it only fits more ticks into that same window. Adds a regression test that opens a pass, spends one send, has the peer report complete, then report missing again on the same simulated instant - asserting no send until the retry interval elapses. Fails against the pre-fix code (an immediate second send). Addresses copilot review comments on PR #1418. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]>
thepastaclaw
left a comment
There was a problem hiding this comment.
Preliminary review — Codex only
The current pass accounting fixes both prior resend-budget defects, but panic unwinding still bypasses failure settlement, allowing an unreadable historical record to trigger a long burst of per-tick storage panics and full-stack logs. The focused race command reached the consensus package suite and failed only in the unrelated existing TestLoadHeightProgressUnderSustainedFlood contention assertion; the catch-up panic path has no regression coverage.
Source: reviewers gpt-5.6-sol (Codex general and TenderDash consensus-security); final verifier claude-opus-4-6; openclaw-agent/cliproxy/gpt-5.6-sol is orchestration-only and not reviewer evidence.
Validated blockers were found in the Codex precheck. Opus is deferred until a fresh Codex revalidation clears the blocker gate.
Review provenance
- Codex reviewers:
gpt-5.6-sol— general (completed),gpt-5.6-sol— tenderdash-consensus-security (completed) - Verifier:
gpt-5.6-sol— verifier - Sonnet: not run (deferred by blocker gate)
🔴 1 blocking
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `internal/consensus/gossiper.go`:
- [BLOCKING] internal/consensus/gossiper.go:220-225: End the catch-up pass when block-store access panics
`beginCatchupAttempt` consumes a pass slot before `sendCatchupBlockPart` calls `LoadBlockMeta` or `LoadBlockPart`. Those block-store methods intentionally panic on database read, decode, and validation failures, while `peerGossipWorker.runGossipHandler` recovers the panic, logs a full stack, and continues ticking. Because `endCatchupPass` is reached only when `sendCatchupBlockPart` returns normally with `false`, panic unwinding leaves the remaining budget active. A peer that selects an unreadable historical height and reports a maximum-size 1,601-part missing bitmap can therefore cause a storage panic and full-stack Error log every default 100 ms tick for roughly 160 seconds before the budget expires, then repeat after the backoff. This defeats the PR's explicit invariant that an attempt which cannot send must end its pass. Settle unsuccessful attempts in a defer so panic unwinding also closes the pass, and add a regression using a block-store mock that panics.
…ication, not a throttle bypass df8a6057c's commit message and code comments described the missing==0 mid-pass fix as letting a peer "resume sending... with no retry interval honored at all", which reads as a flooding/throttle-bypass concern. On closer trace (independently by team-lead and grumpy-stream) that's not accurate: catchupRemaining only ever counts down, never up, so total sends per pass are identically bounded by the budget fixed at pass open whether or not this fix exists. Nothing here lets a peer exceed that budget or the one-send-per-tick ceiling. The actual defect is CPU amplification: leaving a pass open indefinitely (via alternating missing==0 reports) keeps noOpenPass false forever, which permanently defeats 3b9463dd0's backoff-skip check - the O(bits) scan of the peer-controlled, up-to-MaxBlockPartsCount bit-array then runs on every single gossip tick instead of being skipped during backoff, for as long as the peer holds the pass open this way. It also predates this PR: grumpy traced the same missing==0 short-circuit in the 5978b27 baseline and both its parent commits, so this isn't new here - it only started costing more once 3b9463dd0 added a backoff-skip path for it to defeat. Also records a deliberate behavior change for honest peers: closing the pass on missing==0 means a peer that legitimately completes its part set and later falls behind again now waits out one catchupResendInterval before catch-up resumes, rather than resuming on its very next report. Accepted: a peer that just reported complete is not starving, and the wait is negligible against block time. No functional change from df8a6057c - comments only, on both the fix and its regression test. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]>
GossipBlockPartsForCatchup only called endCatchupPass() on a normal false return from sendCatchupBlockPart. But sendCatchupBlockPart's block-store reads (blockRepository.loadMeta/loadPart, wrapping LoadBlockMeta/ LoadBlockPart) panic deliberately on a decode or read failure rather than returning an error - runGossipHandler recovers that panic per gossip tick, logs a full stack, and keeps ticking, same as it does for every other peer-facing panic path in the node. A panic there unwinds straight past the if-check, so endCatchupPass() never runs and the pass stays open with its remaining budget intact. Since the peer controls both the height and the missing bitmap a pass is budgeted on, a peer that names a height whose stored record is corrupt or unreadable gets a fresh attempt - and a fresh panic, and a fresh full-stack log - on every tick for the rest of the pass's budget (up to ~160s for a maximum-size 1,601-part report at the default cadence) instead of ending on the first failed attempt like every other failure mode this PR's earlier commits already cover. Settle the attempt in a defer instead of an if-check on the return value, so panic unwinding also reaches it. sendCatchupBlockPart's own return value still selects the fast path (success needs no settlement); the defer only changes what happens when it doesn't get the chance to return at all. Adds a regression test using a block-store mock that panics on LoadBlockMeta, asserting exactly one read (and thus one panic) per pass rather than one per tick for the whole budget - mirrors TestGossipBlockPartsForCatchupSendFailureEndsPass's structure for the already-covered normal-failure case. Confirmed failing (2+ reads instead of 1) against the pre-fix code. Addresses a thepastaclaw blocking finding on PR #1418. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]>
…h-up pass 25da4c2 removed the unconditional catchupRetryAt clear from the height-change branch to close a bypass, and ea2b81498 later armed it properly for a pass genuinely interrupted mid-flight (catchupRemaining > 0). The catchupRemaining == 0 case was never revisited: a deadline armed by the OLD height (by exhausting its own budget, or by the peer reporting complete) silently carried forward and throttled the NEW height's first pass by up to catchupResendInterval, for a peer that isn't replaying anything and owes nothing - it's genuinely further along. Catch-up is the only path offered to a peer at a different height than ours (regular gossip requires equal heights), so this taxes every honestly-advancing lagging peer once per height. This throttle does not exist on origin/v1.7-dev; it's a cost this PR's own commits introduced. Naively clearing catchupRetryAt whenever catchupRemaining == 0 at a height change (the obvious fix) reopens a worse gap than intended, though: it cannot tell "the previous pass genuinely finished" apart from "an INTERMEDIATE height in a rapid chain never got a chance to open a pass at all, and is still serving an earlier interruption's penalty" - both look identical (remaining == 0) at the moment of the next height change. Verified by writing TestGossipBlockPartsForCatchupHeightAdvanceInterruptingPassIsThrottled first: a naive version of this fix turns its pinned 1 send across 20 rapid height-hops into 10, because every OTHER hop's remaining == 0 came from the previous hop being blocked, not from a pass finishing. Track WHY catchupRetryAt is currently armed instead: catchupRetrySticky is true when the deadline covers unrendered service (a pass interrupted before exhausting its own budget, or a failed attempt via endCatchupPass) and must survive a height change - including a chain of several - and false when the pass closed because it had genuinely nothing left to do (spent its own budget in full, or the peer reported complete). The height-change branch only clears catchupRetryAt when it's non-sticky (or already elapsed); otherwise it's left untouched, whatever height change caused it to be checked. This does still leave a bounded gap in the non-sticky case, stated explicitly in the code rather than glossed: a peer can open a pass, let it close cleanly (one real send, e.g. by reporting a single missing part), then immediately claim a new height and repeat, getting one send per gossip tick indefinitely instead of one pass per interval. Bounded to at most 1 send/PeerGossipSleepDuration tick (10/s, ~640KB/s of block parts at production defaults), because CompareHRS enforces monotonic height only (no replay or ping-ponging) and ensurePeerPartSetHeader requires the real, currently-stored PartSetHeader for each claimed height (a mismatch ends the pass via the now-sticky endCatchupPass, costing a full interval rather than a send). Sustaining it requires marching forward through genuine, still-retained history, capped by blockStoreBase - no worse than the pre-#1365 catch-up rate this codebase already tolerated in production. Accepted as strictly cheaper than taxing every honestly-advancing lagging peer by up to 500ms per height; a verified-progress-gated redesign that closes it for real is tracked as follow-up, not done here. Two new regression tests, both proven against the pre-fix code: - TestGossipBlockPartsForCatchupCleanHeightAdvanceIsNotThrottled: a single-part pass closes cleanly, the peer immediately claims a new height with a fresh block - asserts an immediate send, not a catchupResendInterval wait. RED before this fix. - TestGossipBlockPartsForCatchupHeightAdvanceInterruptingPassIsThrottled (existing, extended doc comment): still asserts full throttling across 20 rapid, always-interrupted height hops - GREEN before this fix, and the guard that caught the naive version's regression above. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]>
thepastaclaw
left a comment
There was a problem hiding this comment.
Preliminary review — Codex only
The prior panic-path blocker is fixed by deferred pass settlement and focused regression coverage, but two in-scope throttle defects remain: successful final sends can consume their retry interval while blocked, and peer-asserted height advances can clear the interval entirely. The focused consensus package test reached completion but failed only in the known unrelated TestLoadHeightProgressUnderSustainedFlood contention assertion.
Source: reviewers gpt-5.6-sol (general) and gpt-5.6-sol (tenderdash-consensus-security); final verifier claude-opus-4-6. Orchestration-only: openclaw-agent/cliproxy/gpt-5.6-sol (not reviewer evidence).
Validated blockers were found in the Codex precheck. Opus is deferred until a fresh Codex revalidation clears the blocker gate.
Review provenance
- Codex reviewers:
gpt-5.6-sol— general (completed),gpt-5.6-sol— tenderdash-consensus-security (completed) - Verifier:
gpt-5.6-sol— verifier - Sonnet: not run (deferred by blocker gate)
🔴 2 blocking
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `internal/consensus/gossiper.go`:
- [BLOCKING] internal/consensus/gossiper.go:423-430: Start the retry gap after the final send completes
`beginCatchupAttempt` consumes the final slot and arms `catchupRetryAt` from `now` before `sendCatchupBlockPart` performs the corresponding block-store reads and outbound send. The latter reaches `Channel.Send`, which explicitly blocks until the envelope is enqueued or the context ends (`internal/p2p/channel.go:217-224`). If storage or outbound congestion delays that final successful send by at least 500 ms, the deadline has already expired when the pass actually finishes. After the worker's normal sleep, the next invocation can immediately open another pass, eliminating the promised quiet gap under exactly the congestion where repeated catch-up traffic can interfere with current-round data gossip. Settle successful pass completion and arm the deadline using `g.clock.Now()` after the final send returns; add a regression whose mocked send advances the fake clock by the interval before returning and verify that a full additional interval is still required.
- [BLOCKING] internal/consensus/gossiper.go:330-359: Preserve the retry gap across unverified height advances
The default height-change branch clears every non-sticky retry deadline, including one armed when a one-attempt pass cleanly exhausted its budget. An untrusted connected peer can therefore claim historical height H with `NewRoundStep`, install the real stored `PartSetHeader` and a bitmap with one unset bit through `NewValidBlock`, receive that part, and then claim H+1 before the next gossip tick. `ApplyNewRoundStepMessage` verifies only monotonic HRS progression, while `ApplyNewValidBlockMessage` accepts the replacement at the matching height and round; neither proves that the peer processed the prior part. Repeating this over retained heights yields one historical block part on every gossip tick instead of one pass per 500 ms interval, and reconnecting permits replay of the retained range. This restores sustained data-channel traffic and block-store reads that the PR is intended to suppress. Preserve the pending deadline across peer-asserted height changes, or grant immediate service only after progress the local node can verify.
…re it beginCatchupAttempt armed catchupRetryAt from a timestamp taken on entry, before the caller had even reached sendCatchupBlockPart. The p2p channel applies backpressure on that very goroutine, so a slow send burned its own duration out of the quiet gap it was supposed to precede - the slower the peer's channel, the weaker the throttle. It now reports the pass's last slot to the caller instead of arming the deadline itself, and GossipBlockPartsForCatchup settles the pass from a fresh clock reading once the send returns. endCatchupPass and the new completeCatchupPass share settleCatchupPass, keeping one place where a drawn attempt closes a pass. The window where the pass is spent but its deadline is not yet armed keeps the documented invariant (a stale deadline with catchupRemaining == 0 is legal) and is unobservable: the single per-peer goroutine is inside the send for all of it, so no further attempt and no height change can run before it settles. Co-Authored-By: Claude Opus 5 <[email protected]>
* fix(consensus): bound catch-up block-part resends and restore round timeouts in reactor test (#1418) * test(consensus): restore real timeout ticker in TestReactorValidatorSetChanges The test drove its 7-node network with newMockTickerFunc(true), which forwards only RoundStepNewHeight timeouts and only the first one; every other scheduled timeout is discarded. That leaves the network without timeoutPropose, without timeoutPrevoteWait/timeoutPrecommitWait and, after the first height, without timeoutNewHeight — so consensus has no way to change round and no way to start a height it committed without receiving a peer commit. Any perturbation is therefore permanent, and the test hangs until its 2-minute context deadline. Both observed CI failure shapes follow from this. A proposal delayed past MessageDelay+Precision makes every validator prevote nil, and the round change that would recover never fires. Separately, a node that applies a commit itself sits at RoundStepNewHeight forever; when it is the next proposer, nobody proposes and nobody times out waiting. Restore the real ticker, which "chore(consensus): stabilize consensus algorithm (#284)" had already established before #1204 reverted it, and give rounds enough wall clock to complete on a loaded runner. Round timeouts only fire when the network stalls, so larger values cost nothing on the healthy path, while 2s/1s makes a starved CI runner abandon rounds it would have completed, leaving it to churn instead of converge. Verified with go test -race -count=10: the old code fails 1/10 on an idle 16-core host, reproducing the CI signature exactly (all seven nodes report a waitForAndValidateBlock deadline, one with "subscription terminated by publisher"); the new code passes 20/20 over two such runs. Under three concurrent copies of the test the pass rate rises from 10/18 to 14/15. Refs #1405 <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RoXmbFrVf1BqVW1BHZv6Va * fix(consensus): bound catch-up block-part resends to one pass per interval GossipBlockPartsForCatchup never marks catch-up parts as delivered, so prs.ProposalBlockParts.Not().PickRandom() keeps finding the same index missing and the part is re-sent on every gossip tick. The loop ends only when our own view of the peer's height advances, and the traffic it generates delays exactly the NewRoundStep messages that would advance it. Measured in a 7-node race-enabled reactor test: 1091 height-11 block parts pushed at a node that had already reached height 12, every one discarded, against 9 completed proposal blocks in the same window. The live round cannot assemble its proposal, every validator prevotes nil, and the height churns rounds until the test deadline. The same loop drives the part-set-header mismatch branch, which logs at error level on every tick without sending anything. Bound it to one part-set pass per catchupResendInterval. A pass spends one send per part; once complete, further ticks are skipped until the interval elapses, then a new pass begins. A peer that silently dropped its parts is therefore still served repeatedly for as long as it stays behind, so the wedge fixed in #1365 stays fixed, while a peer we only believe to be lagging costs one pass rather than one send per tick. Parts are still never marked delivered, keeping that guarantee independent of PeerState bookkeeping — which is unreliable here, since SetHasProposalBlockPart ignores updates whose round differs from the peer's current round and catch-up passes the committed block's round. At 4 concurrent race-enabled copies of TestReactorValidatorSetChanges, where the unbounded loop passes 2/16, this passes 16/16 — matching a full revert of the resend behaviour while keeping its protection. Also 18/18 at 3 concurrent copies and 10/10 unloaded. Wasted catch-up parts drop from 164592 to 2845 per batch (a revert scores 2736), and the wedge precondition "Commit came in before proposal" occurs 632 times across those runs with zero wedges. The two tests from #1365 now assert the bounded contract: parts are still never marked delivered, no resend occurs inside the interval, and a resend follows once the clock advances past it. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RoXmbFrVf1BqVW1BHZv6Va * fix(consensus): budget catch-up passes by missing parts, not bit-array size beginCatchupAttempt sized a catch-up pass with prs.ProposalBlockParts.Size(), the length of the peer's bit-array, while GossipBlockPartsForCatchup draws indices from prs.ProposalBlockParts.Not().PickRandom() — the unset bits alone. A peer reporting all but one part present therefore had every draw in the pass return that same index, so the one missing part was re-sent once per entry in the array before the interval pause. That bit-array arrives from the network. NewValidBlockMessage. ValidateBasic checks only that its length equals BlockPartSetHeader.Total, never the bit pattern, and PeerState.ApplyNewValidBlockMessage installs it wholesale. A peer can thus pick the amplification factor, up to MaxBlockPartsCount (1601) sends of a single part per interval, which largely defeats the bound. Budget on the number of parts the peer reports missing instead, and return early when none are. CountTrueBits has no nil receiver guard, unlike Size, so the nil bit-array is rejected first; the sole production caller already checks it, but the previous Size call was nil-safe and that property is worth keeping. The bound can now only tighten: missing is at most the array length, and is equal to it in the common case where a lagging peer holds none of the parts, so catch-up throughput for genuinely lagging peers is unchanged. Adds a regression case for a bit-array with a single unset bit, which draws 3 sends per pass before this change and 1 after, plus a case for a peer that reports the complete part set, which must open no pass at all. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RoXmbFrVf1BqVW1BHZv6Va * fix(consensus): fix the catch-up pass budget against peer bitmap swaps beginCatchupAttempt derived the pass threshold from prs.ProposalBlockParts on every call while catchupAttempts and catchupRetryAt persisted across calls, so the peer that owns that bit-array could move the threshold out from under the counter. Two ways, both reachable through NewValidBlockMessage, whose ValidateBasic checks only the array's length: Lowering the reported missing count to the number of sends already made takes the "pass spent" branch while catchupRetryAt is still zero, because that field was only assigned once the counter reached the earlier, larger threshold. The wait is then measured against the zero time, the counter resets and sending continues. Repeating one decrement at a time telescopes into roughly N^2/2 sends before any wait applies. Raising it afterwards is simpler still: the counter no longer meets the threshold, so the branch holding the deadline check is skipped entirely and a deadline already set is stepped over. Draw from a remaining-budget counter instead. Opening a pass fixes both the budget and the deadline together, and the budget only counts down, so neither can be re-derived from anything the peer sends mid-pass. There is no longer a state where a pass is spent but no deadline exists. The height reset stays: ApplyNewRoundStepMessage drops any message that does not advance the peer's height/round/step, so a peer cannot replay it to reopen passes, and it can only keep doing so by advancing out of the catch-up window. Removing it would instead make every legitimately advancing peer wait an interval per height. Sends per interval remain bounded by the block's real part count: ensurePeerPartSetHeader rejects a fabricated part-set header, so a peer inflating the count buys early exits rather than sends. The regression test drops the reported count to the sends already made and then raises it again, drawing 5 sends from a 3-send pass before this change and 3 after. TestGossiper, TestPeerGossipWorker and TestReactorValidatorSetChanges pass; 16/16 at 4 concurrent race-enabled copies with wasted catch-up parts at 3002 against 2845 before, so the storm bound is unchanged. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RoXmbFrVf1BqVW1BHZv6Va * fix(consensus): end a catch-up pass that cannot send beginCatchupAttempt charged a budget slot before loadMeta, the part-set header check and loadPart, none of which ended the pass when they failed. The peer supplies both the missing bit-array a pass is budgeted from and the part-set header those checks run against, and ValidateBasic accepts any well-formed pair, so it could open a maximum-size pass under a header matching no stored block. That bought two things. A pass that can never send charged a block-store read and an error log to every gossip tick for its whole budget - roughly 160s at the production 100ms cadence - and since the retry deadline was armed when the pass opened, it had long expired by the time the budget ran out, so the next pass began immediately and the interval never throttled anything. The same inflated budget also survived the peer replacing its state, at the same height, with the stored block's real header and a single missing part: the budget is deliberately not re-derived once a pass is open, so the remainder landed as duplicate sends of that one part. Move the send into sendCatchupBlockPart and abandon the pass, arming a fresh retry deadline, whenever it reports that no part reached the peer. A pass now costs at most one failed attempt per interval, and only a pass that got as far as sending keeps its budget. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RoXmbFrVf1BqVW1BHZv6Va * fix(consensus): close catch-up pass gaps thepastaclaw flagged as still exploitable Two gaps let a peer defeat the catch-up throttle this PR is adding: - beginCatchupAttempt armed catchupRetryAt when a pass opened. A pass with enough missing parts to span more gossip ticks than catchupResendInterval takes longer than the interval to exhaust its budget, so the deadline had already elapsed by the time the pass finished - the next tick reopened a fresh pass with no quiet gap at all. Arm the deadline when the pass's last attempt is spent instead. - The pass budget was fixed at open and never revisited downward. A peer fully controls ProposalBlockParts over the wire (NewValidBlockMessage. ValidateBasic checks only length, ApplyNewValidBlockMessage installs it wholesale) and can open a pass reporting many parts missing, then swap in a bit-array with only one unset bit — every remaining budgeted attempt then draws that same index, funding repeated duplicate sends of it. Clamp the remaining budget down whenever the peer's current missing count drops below it; never raise it back up. Adds regression tests for both: a 6-part pass ticked across catchupResendInterval to show the deadline is measured from the pass's last send, and a 5-part pass whose bitmap shrinks mid-pass to show the budget clamps to the peer's current report. Both fail against the pre-fix code. Addresses thepastaclaw findings on PR #1418. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]> * perf(consensus): avoid a full bit-array copy to count missing catch-up parts beginCatchupAttempt derived the peer's missing-part count via Not().CountTrueBits(), which allocates and copies the whole (peer-controlled, up to MaxBlockPartsCount) bit-array on every gossip tick just to count it. sendCatchupBlockPart already performs its own Not().PickRandom() when a send actually happens, so this was a second, avoidable full-array allocation on every tick regardless of whether a send occurs. Derive the same count as size minus set bits instead. Addresses a copilot review comment on PR #1418. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(consensus): honor catch-up send failures, close height-advance evasion Layers on top of review-stream's retryAt-at-close and downward-clamp fix in beginCatchupAttempt. Distinct fixes: - syncProposalBlockPart (pre-existing, untouched elsewhere in this PR) unconditionally returned nil, so a failed send never reached endCatchupPass despite the caller's contract assuming it would. sendCatchupBlockPart now reports success as a bool instead of an error nobody was meant to inspect, and its "no missing part" branch can no longer be hit (the comment claiming otherwise was already false: prs is a fresh per-tick deep copy nothing else can mutate). - A peer's height advancing reset the retry deadline as well as the budget, granting a free pass on every height step; only the budget resets now. - The three catch-up fields were guarded only by a comment claiming a single caller, despite the same *msgGossiper being shared across three concurrent handler goroutines; a mutex now guards them structurally. - Documented the rate limit's actual scope (per gossip worker, not per peer -- a reconnect gets a fresh one) on the Gossiper interface and the actual tick-to-interval relationship on catchupResendInterval, both previously undocumented. Co-Authored-By: Claude Sonnet 5 <[email protected]> * docs(consensus): fix stale catch-up comment in dataGossipHandler GossipBlockPartsForCatchup is rate-limited and returns without sending on most ticks, so "block parts already delivered" no longer describes what happened before the unconditional GossipCommit call on the same branch. Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(consensus): propagate the real send error from syncProposalBlockPart syncProposalBlockPart unconditionally returned nil regardless of the underlying send's actual result, so sendCatchupBlockPart's error check against it (added in the prior commit) was dead code: a send that never reached the peer was indistinguishable from one that did, and endCatchupPass never fired for that failure mode -- the pass kept spending its budget one failed attempt per tick instead of ending on the first one, exactly the spin endCatchupPass exists to prevent. Fix at the source: return g.sync's result directly and drop the now-redundant local log, since both callers already log a non-nil error themselves. The other caller, GossipProposalBlockParts, only ever logged this error and took no other action, so propagating it for real is behavior-preserving there. Regression test advances a fake clock across many ticks with every send forced to fail and asserts exactly one block-part read per catchupResendInterval, not one per tick; confirmed failing (5 reads instead of 1) against the pre-fix code. Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(consensus): arm catch-up retry deadline when a peer's height advance interrupts a live pass A peer that advances its reported height mid-pass (before the pass exhausts its own budget) reset catchupRemaining to 0 without arming catchupRetryAt, since the deadline was only ever armed when a pass ran its budget down naturally. A peer whose height ticks forward every gossip tick therefore got a fresh full-budget pass every tick forever, completely bypassing catchupResendInterval for the common multi-part-block case. Arm the deadline on the height-change branch too whenever a pass was actually in flight, matching the same invariant beginCatchupAttempt's normal exhaustion path already upholds. Document that invariant on the struct fields it protects. Also, while re-auditing this function for the same iteration: - stop re-deriving the budget from a peer-controlled bit-array once a pass is open (now g.catchupRemaining = min(g.catchupRemaining, missing), replacing an equivalent but more verbose branch) - de-duplicate the block-store-failure error logs in sendCatchupBlockPart; blockRepository.loadMeta/loadPart already log the failure, so the caller's second log was pure noise - correct sendCatchupBlockPart's doc (it reports handoff to the p2p channel, not peer delivery) and give its error log a distinct message from GossipProposalBlockParts's - correct the Gossiper interface, catchupResendInterval, and endCatchupPass doc comments, which described a flat one-send-per- interval bound that does not hold for multi-part blocks Co-Authored-By: Claude Sonnet 5 <[email protected]> * test(consensus): pin the height-advance throttle bug and fix stale/weak catch-up assertions - Add TestGossipBlockPartsForCatchupHeightAdvanceInterruptingPassIsThrottled, a regression test for the height-advance bug fixed in gossiper.go: confirmed RED (20 sends) against the pre-fix code via git stash, GREEN (1 send) after the fix. - Rename/rewrite TestGossipBlockPartsForCatchupBudgetIsFixedAtPassOpen to TestGossipBlockPartsForCatchupBudgetIsNeverRaisedMidPass: the old sequence never actually drove catchupRemaining below the reported missing count it then 'raised', so the raise-attempt it claimed to guard against was a no-op the test would pass on regardless. The new version forces a real clamp (5-part block, drop to 1 missing after two sends) before attempting to raise the count back up, and asserts the raise is not honored before the interval elapses. - Strengthen TestGossipBlockPartsForCatchupPeerHasEveryPart with an explicit AssertNotCalled, so it fails loudly instead of silently if a send is ever wired in for a peer that already has every part. - Update the two wantLog assertions in TestGossipBlockPartsForCatchup that still expected the removed 'couldn't find a block meta/part' caller-side logs; the block-store-failure messages they should match are now blockRepository's own 'failed to load block meta'/'failed to load block part'. Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(consensus): share one clock between msgGossiper and its peerGossipWorker newPeerGossipWorker constructed two independent clockwork.NewRealClock() instances for what is meant to be one gossip worker's shared notion of time. They agree in practice (both wrap wall-clock time), but nothing enforces that, and it defeats point-in-time comparisons in tests that inject a single fake clock expecting both call sites to observe it. Construct one clock and pass it to both. Co-Authored-By: Claude Sonnet 5 <[email protected]> * docs(consensus): correct dataGossipHandler's stale catch-up rate-limit comment The comment described GossipBlockPartsForCatchup as rate-limited and a no-op on most ticks, which held before this PR's changes but not after: a pass now spends one send per tick for as many ticks as the peer reports parts missing, and the quiet gap applies only between passes, not on most individual ticks. Reword to match. Co-Authored-By: Claude Sonnet 5 <[email protected]> * docs(config): cross-reference PeerGossipSleepDuration's coupling to the catch-up throttle PeerGossipSleepDuration sets the tick rate that internal/consensus/gossiper.go's catchupResendInterval throttle is metered against: configuring it above that fixed interval silently disables the throttle. Document the coupling at both the struct field and the generated TOML template so an operator tuning gossip cadence sees the side effect. Co-Authored-By: Claude Sonnet 5 <[email protected]> * perf(consensus): skip the missing-part scan while a catch-up pass is backed off beginCatchupAttempt computed missing (Size() - CountTrueBits(), an O(bits) scan of the peer-controlled ProposalBlockParts array) unconditionally, even on ticks that are going to return false immediately because the pass is still within catchupRetryAt's backoff. At production defaults most gossip ticks land in backoff (a pass's quiet interval is ~5x the gossip cadence), so this scanned a bit-array up to MaxBlockPartsCount long on nearly every tick for no reason. Move the backoff check ahead of the scan: when no pass is open and the retry deadline hasn't elapsed, return early without touching ProposalBlockParts at all. The scan still runs whenever it can affect the outcome - opening a new pass, or clamping an active one's budget down to a shrunk missing count. Addresses a copilot review comment on PR #1418. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(consensus): close an open catch-up pass when the peer reports it complete beginCatchupAttempt returned early on missing == 0 without touching catchupRemaining/catchupRetryAt. When that happened mid-pass (catchupRemaining > 0, budget not yet exhausted), the pass stayed open indefinitely: noOpenPass would keep evaluating false forever, so the backoff check above it — which only runs while no pass is open — was skipped on every later tick regardless of elapsed time. A peer could freeze catchupRemaining above zero by reporting a complete part set whenever it liked, then resume sending immediately the next time it reported parts missing, with no retry interval honored at all. Close the pass in that case too: zero the remaining budget and arm the retry deadline, matching what happens when a send fails or a height change interrupts a pass. Only do this when a pass was actually open; a peer that has simply always reported a complete set must not have a wait imposed on it. Also corrects a stale doc comment on PeerGossipSleepDuration added by the same throttle: catchupResendInterval is a fixed quiet gap that does not scale with the gossip tick duration, it only fits more ticks into that same window. Adds a regression test that opens a pass, spends one send, has the peer report complete, then report missing again on the same simulated instant - asserting no send until the retry interval elapses. Fails against the pre-fix code (an immediate second send). Addresses copilot review comments on PR #1418. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]> * docs(consensus): reclassify the missing==0 mid-pass fix as CPU-amplification, not a throttle bypass df8a6057c's commit message and code comments described the missing==0 mid-pass fix as letting a peer "resume sending... with no retry interval honored at all", which reads as a flooding/throttle-bypass concern. On closer trace (independently by team-lead and grumpy-stream) that's not accurate: catchupRemaining only ever counts down, never up, so total sends per pass are identically bounded by the budget fixed at pass open whether or not this fix exists. Nothing here lets a peer exceed that budget or the one-send-per-tick ceiling. The actual defect is CPU amplification: leaving a pass open indefinitely (via alternating missing==0 reports) keeps noOpenPass false forever, which permanently defeats 3b9463dd0's backoff-skip check - the O(bits) scan of the peer-controlled, up-to-MaxBlockPartsCount bit-array then runs on every single gossip tick instead of being skipped during backoff, for as long as the peer holds the pass open this way. It also predates this PR: grumpy traced the same missing==0 short-circuit in the 5978b27 baseline and both its parent commits, so this isn't new here - it only started costing more once 3b9463dd0 added a backoff-skip path for it to defeat. Also records a deliberate behavior change for honest peers: closing the pass on missing==0 means a peer that legitimately completes its part set and later falls behind again now waits out one catchupResendInterval before catch-up resumes, rather than resuming on its very next report. Accepted: a peer that just reported complete is not starving, and the wait is negligible against block time. No functional change from df8a6057c - comments only, on both the fix and its regression test. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(consensus): end a catch-up pass when a block-store read panics GossipBlockPartsForCatchup only called endCatchupPass() on a normal false return from sendCatchupBlockPart. But sendCatchupBlockPart's block-store reads (blockRepository.loadMeta/loadPart, wrapping LoadBlockMeta/ LoadBlockPart) panic deliberately on a decode or read failure rather than returning an error - runGossipHandler recovers that panic per gossip tick, logs a full stack, and keeps ticking, same as it does for every other peer-facing panic path in the node. A panic there unwinds straight past the if-check, so endCatchupPass() never runs and the pass stays open with its remaining budget intact. Since the peer controls both the height and the missing bitmap a pass is budgeted on, a peer that names a height whose stored record is corrupt or unreadable gets a fresh attempt - and a fresh panic, and a fresh full-stack log - on every tick for the rest of the pass's budget (up to ~160s for a maximum-size 1,601-part report at the default cadence) instead of ending on the first failed attempt like every other failure mode this PR's earlier commits already cover. Settle the attempt in a defer instead of an if-check on the return value, so panic unwinding also reaches it. sendCatchupBlockPart's own return value still selects the fast path (success needs no settlement); the defer only changes what happens when it doesn't get the chance to return at all. Adds a regression test using a block-store mock that panics on LoadBlockMeta, asserting exactly one read (and thus one panic) per pass rather than one per tick for the whole budget - mirrors TestGossipBlockPartsForCatchupSendFailureEndsPass's structure for the already-covered normal-failure case. Confirmed failing (2+ reads instead of 1) against the pre-fix code. Addresses a thepastaclaw blocking finding on PR #1418. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(consensus): don't throttle a genuinely-advancing peer's next catch-up pass 25da4c2 removed the unconditional catchupRetryAt clear from the height-change branch to close a bypass, and ea2b81498 later armed it properly for a pass genuinely interrupted mid-flight (catchupRemaining > 0). The catchupRemaining == 0 case was never revisited: a deadline armed by the OLD height (by exhausting its own budget, or by the peer reporting complete) silently carried forward and throttled the NEW height's first pass by up to catchupResendInterval, for a peer that isn't replaying anything and owes nothing - it's genuinely further along. Catch-up is the only path offered to a peer at a different height than ours (regular gossip requires equal heights), so this taxes every honestly-advancing lagging peer once per height. This throttle does not exist on origin/v1.7-dev; it's a cost this PR's own commits introduced. Naively clearing catchupRetryAt whenever catchupRemaining == 0 at a height change (the obvious fix) reopens a worse gap than intended, though: it cannot tell "the previous pass genuinely finished" apart from "an INTERMEDIATE height in a rapid chain never got a chance to open a pass at all, and is still serving an earlier interruption's penalty" - both look identical (remaining == 0) at the moment of the next height change. Verified by writing TestGossipBlockPartsForCatchupHeightAdvanceInterruptingPassIsThrottled first: a naive version of this fix turns its pinned 1 send across 20 rapid height-hops into 10, because every OTHER hop's remaining == 0 came from the previous hop being blocked, not from a pass finishing. Track WHY catchupRetryAt is currently armed instead: catchupRetrySticky is true when the deadline covers unrendered service (a pass interrupted before exhausting its own budget, or a failed attempt via endCatchupPass) and must survive a height change - including a chain of several - and false when the pass closed because it had genuinely nothing left to do (spent its own budget in full, or the peer reported complete). The height-change branch only clears catchupRetryAt when it's non-sticky (or already elapsed); otherwise it's left untouched, whatever height change caused it to be checked. This does still leave a bounded gap in the non-sticky case, stated explicitly in the code rather than glossed: a peer can open a pass, let it close cleanly (one real send, e.g. by reporting a single missing part), then immediately claim a new height and repeat, getting one send per gossip tick indefinitely instead of one pass per interval. Bounded to at most 1 send/PeerGossipSleepDuration tick (10/s, ~640KB/s of block parts at production defaults), because CompareHRS enforces monotonic height only (no replay or ping-ponging) and ensurePeerPartSetHeader requires the real, currently-stored PartSetHeader for each claimed height (a mismatch ends the pass via the now-sticky endCatchupPass, costing a full interval rather than a send). Sustaining it requires marching forward through genuine, still-retained history, capped by blockStoreBase - no worse than the pre-#1365 catch-up rate this codebase already tolerated in production. Accepted as strictly cheaper than taxing every honestly-advancing lagging peer by up to 500ms per height; a verified-progress-gated redesign that closes it for real is tracked as follow-up, not done here. Two new regression tests, both proven against the pre-fix code: - TestGossipBlockPartsForCatchupCleanHeightAdvanceIsNotThrottled: a single-part pass closes cleanly, the peer immediately claims a new height with a fresh block - asserts an immediate send, not a catchupResendInterval wait. RED before this fix. - TestGossipBlockPartsForCatchupHeightAdvanceInterruptingPassIsThrottled (existing, extended doc comment): still asserts full throttling across 20 rapid, always-interrupted height hops - GREEN before this fix, and the guard that caught the naive version's regression above. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(consensus): start the catch-up quiet gap after the send, not before it beginCatchupAttempt armed catchupRetryAt from a timestamp taken on entry, before the caller had even reached sendCatchupBlockPart. The p2p channel applies backpressure on that very goroutine, so a slow send burned its own duration out of the quiet gap it was supposed to precede - the slower the peer's channel, the weaker the throttle. It now reports the pass's last slot to the caller instead of arming the deadline itself, and GossipBlockPartsForCatchup settles the pass from a fresh clock reading once the send returns. endCatchupPass and the new completeCatchupPass share settleCatchupPass, keeping one place where a drawn attempt closes a pass. The window where the pass is spent but its deadline is not yet armed keeps the documented invariant (a stale deadline with catchupRemaining == 0 is legal) and is unobservable: the single per-peer goroutine is inside the send for all of it, so no further attempt and no height change can run before it settles. Co-Authored-By: Claude Opus 5 <[email protected]> --------- Co-authored-by: Claude Opus 5 <[email protected]> (cherry picked from commit 9bf9a0b) * fix(consensus): check that a proposal's block ID describes its block A Proposal carries a BlockID and a proposer signature over it. The BlockID has three fields, and until the block arrives none of them can be checked against anything: PartSetHeader is validated implicitly, because the parts have to assemble under it, but Hash and StateID are taken on the proposer's word. RoundState.BlockID() then hands that BlockID, unexamined, to the prevote signer. So a proposer can gossip a genuine block and sign a BlockID that does not describe it. Every node that receives the block assembles it, finds nothing that disagrees, and signs a prevote for the proposer's value. A commit forms over a BlockID no node ever verified. The height that commit seals is fine: finalization derives the BlockID from the block itself, so the committed state records the real one. The next height is not. Its LastCommit carries the BlockID the votes actually signed, and validation compares that against the previous height's recorded value. They differ, and neither can be revised -- one is persisted state, the other is sealed by a threshold signature over a finalized height. Every proposer at every subsequent round fails the same comparison. The chain does not recover, and restarting does not help. An honest proposer derives its BlockID from the block and the parts it is gossiped in, so once the block is assembled the claim is exactly checkable. Two changes, at the two points that matter: - When the part set completes, compare the Proposal's BlockID against the one derived from the block just assembled. On disagreement the block is kept -- it is the bytes, and they are what they are -- and the Proposal is dropped with its receive time, which leaves the proposal incomplete so the round prevotes nil and moves on. A round is a cheap price; the alternative is signing the value that ends the chain. - RoundState.BlockID() returns the BlockID derived from the block and parts whenever it holds them, and falls back to the Proposal's only when there is no block to derive from. The check above is what reports the lie; this is what keeps an unexamined claim from reaching a signature by some other route. Honest operation is unaffected, and that is measured rather than argued. An instrumented build that compared the two values at every block completion, without acting on the result, recorded 767 agreements and no disagreement across the consensus suite, replay included. Forging one StateID byte in the derived value turned all 778 of them into disagreements, so the comparison was in a position to report one. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019gAC8rAzQagn5sgDxUJNjj (cherry picked from commit 2c2a8f6) * fix(consensus): check a commit's state ID against the block it commits A commit names a block by hash, part set header and state ID. Before applying one, a node checks that the block it holds matches the first two and never looks at the third. A commit that agrees on hash and part set header while naming a different state ID is therefore applied against this block, and then recorded carrying its own BlockID. That record is what the next height is validated against. Its LastCommit holds the BlockID the votes signed; the previous height's committed state holds the one derived from the block. They disagree, and neither side can be revised: one is sealed by a threshold signature over a finalized height, the other is persisted state. Every proposer at every subsequent round fails the same comparison, and restarting changes nothing. Ask the third field. It is asked separately from the other two, rather than as one comparison over the whole BlockID, so an operator is told which field disagreed instead of only that something did. The three checks move into verifyCommitBlock. That is an extraction made for testability and worth naming as such: reaching them previously required an ABCI client, because the surrounding function hands the block to the application immediately afterwards. Separated, each field's rejection is tested directly, with a nil executor so that a test which stops rejecting panics rather than passing quietly. Making the new comparison tautological fails exactly one subtest across the package, and nothing else notices. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019gAC8rAzQagn5sgDxUJNjj (cherry picked from commit 665ff68) * fix(consensus): drop a disagreeing proposal instead of rejecting the block Two checks in addProposalBlockPart detect the same condition -- a Proposal that disagrees with the block just assembled -- and they disagreed about the remedy. The block ID check drops the proposal and keeps the block. The core chain locked height comparison returned an error, which discards the block. Discarding it is terminal. AddPart consumes the part before either check runs, and PartSet.AddPart returns (false, nil) for a part it already holds (types/part_set.go), so the completion branch is guarded by `added && IsComplete()` and is never re-entered. The part that completed the set is spent, the block is never assigned, and nothing assembles it again. Replay feeds the same sequence to the same rejection, so restarting does not clear it. Make the two agree: on disagreement the proposal is dropped and the block is kept. That is what gives the round its way back, and the mechanism is not tidiness. Proposaler.Set returns early while rs.Proposal is non-nil, so a second proposal for the same height and round is discarded unread -- clearing the field is the only thing that lets the honest copy be accepted. Re-delivery is ordinary behaviour rather than luck: shouldProposalBeGossiped sends when `!prs.Proposal`, and that flag is set only by the sender in updatePeerProposal after its own send, so every honest validator that lost the race still believes we lack the proposal and keeps offering it. Dropping is safe because the block is checked without reference to any proposal. StateData.isValidForPrevote calls sm.ValidateBlockChainLock before the node prevotes, comparing the block's own core chain locked height against state, and it guards Proposal == nil explicitly, so a cleared proposal makes the round prevote nil and advance rather than panic. The remedy does not depend on knowing what caused the disagreement, which is the property worth having: a proposer can build the value wrongly, and any peer relaying the message can raise it, because CanonicalizeProposal omits the dash fields from what the proposer signs while state_proposaler.go enforces only a lower bound. One test covers both because the code cannot distinguish them and is not required to. The part set header, not the block hash, decides whether the proposal describes these bytes: CoreChainLockedHeight reaches Header.Hash() through cdcEncode, which has no uint32 case and contributes an empty leaf for every value, so two blocks differing only in that field share a hash. That predicate selects which diagnosis is reported rather than the outcome, and it is commented as such. An earlier version of this change gated the comparison and left it terminal. That closes the cases where the proposal describes different bytes and does nothing when a relayed proposal names this block with the field altered, since the part set header still matches. It is recorded here so the narrower shape is not reintroduced as an obvious hardening. Measured over the consensus suite: the two values agree 778 times and disagree 3, all at height one and off by one. Every disagreement was attributed by capturing a stack at the comparison. One comes from the reactor test that installs a proposer proposing an incorrect chain lock height; the other two are the tests added here, which construct the disagreement deliberately -- including the reversed case, a proposal claiming a higher chain lock than the block it names, which is this commit's own fixture rather than anything arising at genesis. So the pre-existing suite contains exactly one disagreement, produced by a deliberately byzantine proposer, and none from an honest flow. The suite also passes with the mismatch made non-fatal, so nothing depended on the rejection. Dropping discards ProposalReceiveTime with the proposal, so timeliness is re-evaluated against the re-delivered copy and a slow re-delivery can still cost that round. That cost is per round and self-clearing, and keeping the two paths identical is worth more than softening it here. The proposal is cleared inline rather than through a helper shared with the block ID check above. The duplication is deliberate: that check is a cherry pick, and keeping it byte-comparable with the branch it came from is worth more on a release branch than removing four lines. The helper belongs where the code is native. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019gAC8rAzQagn5sgDxUJNjj * test(p2p): draw distinct addresses in TestConnTracker loops TestConnTracker/BaseSmall/AddingMany failed in CI with "expected: 100, actual: 99". It is not a timing flake: randLocalIPv4 returns 127.<r>.<r>.<r> where randByte is rand.Intn(math.MaxUint8), so the three random octets span 255^3 = 16,581,375 addresses. connTrackerImpl.Len is len(rat.cache) and the cache is keyed by address, so two equal draws collapse into one entry and the count comes up short. AddConn also returns an error for the duplicate, but the loop discards it with `_ =`, so nothing reports the real cause. Measured over 1,000,000 simulated runs of the 100-draw loop: 298 collided, i.e. once in ~3,356 runs, matching the analytic 100*99/(2*255^3). Four loops in this test draw that way (AddingMany and Cycle, each under both the BaseSmall and BaseLarge factories), so the observed rate is closer to once in ~840 CI runs. Cycle is the worse of the two — a collision re-adds an address inside the window, so AddConn errors and trips require.NoError directly rather than only skewing a count. VeryShort draws ten and is exposed the same way. The fix already exists in this file: seqIPv4 ("deterministic, distinct IPv4 address for the given index") was added alongside the tests in #1356, which draw 21,000 addresses and would collide with near-certainty, but it was never applied to the pre-existing loops. Use it in all three loops that need distinct addresses. randLocalIPv4 stays for RepeatedAdding and Window, which each need exactly one address and are collision-immune, and its doc comment now states when it is safe to use so the next reader does not reintroduce the defect. Verified by mutation rather than by re-running until green: collapsing the address space to 3^3 = 27 (below the 100 drawn, so a collision is forced by pigeonhole) reproduces the exact CI signature on the pre-fix code — AddingMany "expected: 100, actual: 27" under both factories, plus Cycle and VeryShort — while the post-fix code passes ten consecutive runs at that same collapsed space. Run in an isolated module containing only conn_tracker.go and its test, since the package's BLS cgo dependency is not buildable in this environment. Not changed, but noted: randByte is rand.Intn(math.MaxUint8), which yields 0..254 and never 255. It is inert for the two remaining single-address callers and is left alone to keep this change scoped. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019gAC8rAzQagn5sgDxUJNjj * fix(consensus): validate block IDs across message ordering Check commits against assembled blocks before application and persistence, including commit-first and locally assembled commit paths. Propagate apply errors before broadcasting a commit or advancing the round. Validate late proposals against retained blocks while allowing matching replacements. Add failing-first regressions with signed commits and proposal controls. Co-Authored-By: Codex GPT-6 <[email protected]> <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> --------- Co-authored-by: Claude Opus 5 <[email protected]>
TL;DR: Fixes a consensus bug where a node helping a peer catch up would flood it with block parts it had already moved past, starving the current round — and fixes the CI test that had been hanging because of it.
Detailed discussion
Two commits. The first is internal test infrastructure with no user-observable behaviour change; the second is a production consensus fix.
User storyandScenarioare omitted because the user-visible effect is limited to the second commit and is fully described below.Issue being fixed or feature implemented
Partially addresses #1405.
TestReactorValidatorSetChangesintermittently hangs for its full 2-minute budget, most recently on #1417 (a pure Go-toolchain bump): run 32835423456.It does not close #1405, which also names
TestRouter_EvictPeersininternal/p2p— a separate matter (a hardcoded 1-second wait inp2ptest.RequireUpdateover a mocked transport), sharing no mechanism with this test.Root cause 1 — the test harness disabled consensus recovery
TestReactorValidatorSetChangesdrove its 7-node network withnewMockTickerFunc(true).mockTicker.ScheduleTimeoutforwards onlyRoundStepNewHeighttimeouts, and withonlyOnce=trueonly the first one; every other scheduled timeout is discarded. The network ran with notimeoutPropose, notimeoutPrevoteWait/timeoutPrecommitWait— so round changes were impossible — and, after the first height, notimeoutNewHeight, so a node that assembled a commit itself never started the next height.With recovery disabled, any perturbation wedged the network permanently. Both observed CI shapes follow: a proposal delayed past
MessageDelay + Precisionmakes every validator prevote nil and the round change that would recover never fires; separately, a node that applies a commit itself sits atRoundStepNewHeightforever, and when it is the next proposer nobody proposes and nobody times out waiting.This also explains why #1204 did not fix the flake — it introduced the mock ticker, reverting the deliberate move to a real ticker made by
chore(consensus): stabilize consensus algorithm (#284).Root cause 2 — unbounded catch-up block-part resends
Restoring round changes exposed a second, pre-existing defect.
GossipBlockPartsForCatchupnever marks catch-up parts as delivered, soprs.ProposalBlockParts.Not().PickRandom()keeps finding the same index missing and the part is re-sent on every gossip tick. The loop ends only when our own view of the peer's height advances — and the traffic it generates delays exactly theNewRoundStepmessages that would advance it.Measured in the reactor test: 1091 height-11 block parts pushed at a node that had already reached height 12, every one discarded, against 9 completed proposal blocks in the same window. The live round cannot assemble its proposal, every validator prevotes nil, and the height churns rounds until the deadline. The same loop drives the part-set-header mismatch branch, which logs at error level every tick without sending anything.
This was not caused by the first commit — before it, the network froze at round 0 with every node on the same height, so no peer was ever "behind" and the catch-up path never engaged.
What was done
internal/consensus/reactor_test.go—tickerFun: newTickerFunc()restores real round timeouts, andTimeout.Propose/Timeout.Voteare raised to 5s/2s. Round timeouts only fire when the network stalls, so larger values cost nothing on the healthy path; the previous values made a starved runner abandon rounds it would otherwise have completed.internal/consensus/gossiper.go— catch-up is bounded to one part-set pass percatchupResendInterval(500ms). A pass spends one send per part; once complete, further ticks are skipped until the interval elapses, then a new pass begins.The bound preserves #1365's guarantee. A peer that silently dropped its parts is still served repeatedly for as long as it stays behind, so the wedge that PR fixed stays fixed; only a peer we believe to be lagging is cheap. Parts are still never marked delivered, which keeps that guarantee independent of
PeerStatebookkeeping — deliberately, becauseSetHasProposalBlockPartignores updates whose round differs from the peer's current round, and catch-up passes the committed block's round.Rejected on measurement: widening the test's
Synchronyparams (no benefit), pacing block production viaCreateEmptyBlocksInterval(worse, 4/18), and simply lowering the gossip cadence (5ms → 25ms → 100ms moved 2/16 → 7/16 → 5/16, confirming the cure is stopping after a pass, not sending more slowly).How Has This Been Tested?
Locally,
go test -race, 16-core host. N concurrent copies of the test binary on the same host, same bed throughout:-count=10The unloaded baseline reproduced the CI signature exactly — all seven nodes reporting a
waitForAndValidateBlockdeadline, one withsubscription terminated by publisher.Mechanistic confirmation for commit 1: counting round changes after the last committed block, the old code shows
max_round = 0and oneentering new roundper node — frozen, and no extra time would help. After it, 16–62 events reaching rounds 2 through 11.Mechanistic confirmation for commit 2: wasted catch-up parts per batch drop from 164592 to 2845 (a full revert of the resend behaviour scores 2736, so the bound gives up almost nothing), and part-set mismatch errors fall from 73 to 4. The wedge precondition
Commit came in before proposaloccurs 632 times across those runs with zero wedges.Unit tests: full
TestGossiperandTestPeerGossipWorkersuites pass. The two tests added by #1365 were updated rather than removed — they still assert that catch-up never marks parts delivered, and now additionally assert that no resend happens inside the interval and that one does once the clock advances past it.TestGossipBlockPartsForCatchup's table cases now advance the fake clock between cases, since they are independent occasions at the same height.Breaking Changes
None.
Checklist
For repository code-owners and collaborators only
Follow-ups worth a look (deliberately out of scope)
internal/consensus/init_test.gosetsdeadlock.Opts.DeadlockTimeout = 5s. Under contention that detector fires on a benign lock wait andos.Exit(2)s the entire package test binary.newMockTickerFunc(true)is still used byhelper_test.go:216,replay_test.go:376andbyzantine_test.go:50. Same trap, unexamined.AGENTS.mdstates CI runs tests with-p 1, buttest-group-%in theMakefiledoes not pass it, so up toGOMAXPROCSpackage binaries run concurrently. That is the contention source behind this class of flake.Prior work
waitForAndValidateBlock's failure path; still in place, and what makes these logs legible enough to diagnose.Attribution
🤖 Co-authored by Claudius the Magnificent AI Agent