> ## Documentation Index
> Fetch the complete documentation index at: https://ckb.danielasaboro.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Reestablishment, Retry, and Peer Resilience

> Week 15 recovers channels and network synchronization without stale replay, duplicate attempts, or unbounded peer work.

# Reestablishment, Retry, and Peer Resilience

Week 14 made local state durable. That solves only half of restart recovery. A Fiber node must next meet peers whose connection epochs, message queues, commitment progress, and gossip cursors continued on their own timelines.

The Week 15 question is:

`How can a node reconnect without treating every delayed message as current or every ready signal as permission to replay everything?`

The answer combines strict ordering with bounded work. Persisted state determines what is eligible. A verified handshake determines when replay can begin. Exact attempt state determines what may retry. Peer budgets determine how much work any connection may force the node to retain.

## Reestablishment is a protocol phase, not a socket event

A TCP/libp2p connection does not mean the channel is ready. Both sides must compare their durable channel view, restore the relevant commitment/revocation progress, replay required updates in protocol order, and only then admit new TLC work.

Exercise 57 models four phases:

`Disconnected -> AwaitingReestablish -> Replaying -> Ready`

Every connection receives a local epoch. Delayed messages from an older epoch are rejected. `ChannelReady` before state comparison is rejected. A mismatched commitment number or revocation nonce is rejected rather than “fixed” by copying the peer’s value. Once state agrees, the exact persisted replay set runs once for that epoch. Duplicate ready messages are idempotent.

This captures the safety lesson behind Fiber’s reconnect fixes without copying its wire messages. Fiber v0.9.0 includes replaying `ChannelReady` safely, pacing reestablishment traffic, persisted commitment replay, and fixes around reconnect ordering and revocation nonce rollover. [PR #1590](https://github.com/nervosnetwork/fiber/pull/1590) is especially useful implementation history: it describes a stalled nonce rollover reached through a valid commitment exchange and fixes the normal signed exchange rather than weakening verification.

## Retry the failed attempt, not the payment-shaped neighborhood

A payment may contain several attempts. Some may have succeeded, some may still be in flight, and one may have failed on the channel that just recovered. Retrying by payment ID alone can duplicate work or disturb a sibling attempt.

Exercise 58 keys authority by tenant, payment, and attempt. A channel-ready event selects only failed attempts for that same channel, below their retry limit. It leaves successful, in-flight, exhausted, cross-channel, and cross-tenant attempts unchanged. Replaying the same ready event schedules nothing twice.

This is the application-level lesson from Fiber’s “retry only failed payment attempts” work in [PR #1511](https://github.com/nervosnetwork/fiber/pull/1511). The fixture’s exact counters and scheduler are teaching policy; the verified behavior is the narrower retry selection reported in the v0.9.0 release cycle.

## Gossip recovery needs a trustworthy cursor

A gossip cursor is a claim: everything through this point has been received and accepted. Advancing it over a gap, invalid signature, bad chain reference, or locally generated message can permanently hide remote data after restart.

Exercise 59 advances only through verified, contiguous, remote messages. One invalid sequence stops the checkpoint before later entries. A stalled active peer receives a bounded retry budget and then rotates to another connected peer. Disconnect clears peer-scoped outbound/retry state but preserves the last verified durable cursor.

Fiber v0.9.0 includes active-sync peer rotation, outbound-state cleanup on disconnect, validation hardening, and a fix for locally generated messages polluting startup sync cursors. Relevant implementation history includes [PR #1553](https://github.com/nervosnetwork/fiber/pull/1553), [PR #1534](https://github.com/nervosnetwork/fiber/pull/1534), the cursor fix in [PR #1227](https://github.com/nervosnetwork/fiber/pull/1227), and validation work in [PR #1400](https://github.com/nervosnetwork/fiber/pull/1400) and [PR #1441](https://github.com/nervosnetwork/fiber/pull/1441).

## Bound the work before doing expensive work

An authenticated peer can still be buggy or abusive. A system that accepts an unlimited inbound queue before validation has already lost the resource-exhaustion fight.

Exercise 60 checks an envelope and byte ceiling before queue admission, then applies both per-peer and global item budgets. Backpressure is a normal `Throttled` result, not an excuse to let queues grow. Round-robin draining preserves an honest peer’s progress even when another peer fills its allowance. Rejected oversized or malformed inputs occupy no work slot.

Fiber v0.9.0 reports bounded inbound processing and broader protection from malformed messages and resource exhaustion; [PR #1554](https://github.com/nervosnetwork/fiber/pull/1554) is the direct implementation reference. The exercise also demonstrates a three-strike ban, but that threshold and lifecycle are explicitly experimental teaching policy. Repeated-invalid-channel-message banning was still described as follow-up direction in the release report, including [PR #1532](https://github.com/nervosnetwork/fiber/pull/1532); it must not be presented as a stable protocol guarantee.

## Where CKB still matters

Reestablishment messages are off-chain protocol traffic. They cannot rewrite confirmed CKB history. If peers disagree about a funding outpoint, close transaction, or exact on-chain TLC settlement, the chain-side evidence boundary from Weeks 12–14 still applies. CKB’s cell transition and transaction witness model is described in [How CKB Works](https://docs.nervos.org/docs/getting-started/how-ckb-works).

Local channel readiness is therefore not proof that a close disappeared, and a gossip announcement is not proof that an output is live. A production operator correlates peer claims with trusted CKB RPC/indexer evidence where the claim crosses the settlement boundary.

## Verified behavior versus teaching model

| Classification | Week 15 claim |
| - | - |
| CKB consensus/transaction behavior | Confirmed on-chain cells/transactions remain authoritative when reconnect claims cross into funding or settlement. |
| Verified Fiber v0.9.0 behavior | Channel/restart recovery, safe ready replay, paced reestablishment, failed-attempt retry, bounded inbound work, stalled-sync rotation, disconnect cleanup, and gossip validation improved. |
| Fiber implementation history | PRs #1590, #1595, #1562, #1511, #1554, #1553, and #1534 explain individual ordering, pacing, retry, and gossip changes. |
| Future/experimental direction | The exact repeated-invalid-message ban policy and threshold are not treated as a released protocol contract. |
| Simplified local teaching model | Integer connection epochs, queue sizes, strike counts, scheduler keys, and gossip sequence fixtures are local exercises. |

The release anchor is [Fiber v0.9.0](https://github.com/nervosnetwork/fiber/releases/tag/v0.9.0), supported by the [August 2026 Fiber development report](https://github.com/nervosnetwork/fiber/discussions/1610). The official [Fiber architectural overview](https://www.nervos.org/knowledge-base/what_is_fiber) supplies the broader channel and routing context.

## Run the exercises

```bash theme={null}
cd week15/reestablishment-and-peer-resilience
npm test
```

* `57-channel-reestablishment-ordering.ts` rejects early, stale, duplicate, and state-mismatched traffic across rapid reconnects.
* `58-attempt-scoped-retry.ts` schedules only exact eligible failed attempts and proves duplicate ready events are harmless.
* `59-gossip-sync-recovery.ts` protects the verified cursor, rotates stalled peers, and clears disconnect-scoped state.
* `60-adversarial-peer-budgets.ts` enforces byte/item budgets, fair draining, early rejection, and a clearly experimental ban policy.

The visible checkpoints follow [CKB Quest](https://ckb-quest.vercel.app/), while [Nervos Nation](https://nervosnation.com/) provides ecosystem discovery rather than protocol authority.

Week 15 leaves one final architectural step. Durable, reestablished nodes work for always-online operators; Week 16 asks how a hosted LSP can serve intermittently connected mobile clients without collapsing tenant identity, signing authority, or settlement evidence into the host.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.