{"id":"XE-0268","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"245","source_url":"https://github.com/xeprotocol/xe/issues/245","reporter_id":121,"title":"net/sync: client apply loop discards dependency-retryable blocks after 10 passes; fresh sync near-livelock under target map order","area":null,"claimed_tier":"medium","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-02T22:50:04.705483+00:00","updated_at":"2026-11-05T04:18:12.201813+00:00","source_created_at":"2026-11-02T22:48:26+00:00","told_at":null,"status_changed_at":"2026-11-05T04:17:39.394942+00:00","url":"https://bounty.xe.network/XE-0268","body":"# net/sync: client apply loop discards dependency-retryable blocks after 10 passes; fresh sync near-livelock under target map order\n\nSuggested tier: **Medium**. Availability only; no funds, finality, state, or\nsupply effect.\n\n## Summary\n\nThe sync server walks accounts in Go map order, sends entire account chains for\naccounts the client does not know, and stops at 10,000 blocks. The client stops\nreading at 10,000 blocks, applies the batch in received order, and retries only\n10 times. An opening receive cannot be applied until its source send is applied.\nThe client records many blocks as retryable dependency errors (`unopened\naccount` / `source send not pending`) and discards them when the 10-pass bound is\nexhausted.\n\n**The unmodified target is a near-livelock on the tested chain, not a proven\npermanent stall.** `r-009` (180 s) reached 62/12,001 blocks and 31/6,001\naccounts; `r-030` (600 s, same chain, no lab knobs) applied 25 net new blocks and\nreached 26/12,001 blocks, 13/6,001 accounts, with 11 capped rounds and 0–10\napplied calls per round. The permanent 0-progress livelock is the in-process\ndeterministic `ORDER=chain_desc` case (`r-021`) only.\n\n## Target\n\n- Pinned commit: `978785929bc17a2f4ab30c383e5fc9cf4d634512`\n- Unmodified binary SHA-256:\n  `c3bbf2612ab282fd31ea9b78eec109e9554a260b4ca6e6aa6e01d9fb04ff1f34`\n- Instrumented node SHA-256:\n  `43f8e71f9d533821fe8f5da7d9fcbf4e6c0301ba08fd7f33b86b279286ba6d9a`\n- In-process test build: source commit above; patch SHA-256\n  `2a05069542446be7e47a5c9566d32c4bdd3ce1111dafb88b6285c6d07022496a`;\n  test binary SHA-256\n  `dae46008c031ab9d84e5c3666b30e66639ce01c9a42fc86b82883f8f737c4488`\n- Network: `t104b-lab` (custom local genesis)\n- Ledger genesis:\n  `be79a8c7fa04ebb76f2fba9d8e9d5311007544029876a3c3e3e534aeb2fa0d16`\n- Statechain genesis:\n  `cdac6a19f67c2a8f38c426570992ed91fd82aceb4dbb4490fcc13452be3fc0fb`\n- Activation state: tip 0, no active features, protocol 1.0.0\n- Store/topology: Badger; single-peer runs use one server and one fresh client;\n  `r-016` uses five servers; loopback API/metrics; `--disable-mdns\n  --no-discovery`\n\n## Preconditions\n\nAn honest server, a valid chain with a dependency path (or a hub whose sends are\noutside the 10k window), and more than 10,000 blocks. The client's frontier map\nis below the 1 MiB request boundary described in the companion F-002 report. No\ninvalid blocks, forged signatures, or attacker are required.\n\n## Invariant\n\nA fresh node with one honest peer reaches the server tip in bounded rounds. The\nsame valid chain must converge regardless of the server's account iteration\norder. Re-submitted retryable blocks must not be permanently discarded after a\nfixed number of passes.\n\n## Unmodified-target observations\n\n- `r-009`: default-PoW 6,001-account / 12,001-block chain, target map order,\n  180 s. Client end state 62/12,001 blocks, 31/6,001 accounts; 5 capped rounds.\n  The `r-009` artifact has no `run-meta`; the node reports `xe/9787859` and the\n  per-run hash is recorded in `r-030`.\n- `r-030`: same chain, 600 s, `INSTRUMENTED=0`, empty `SERVER_ENV`/`CLIENT_ENV`.\n  Start 1/1; end 26/12,001 blocks, 13/6,001 accounts; 11\n  `hit maxTotalBlocks cap` rounds and 11 `could not be added after retries`\n  rounds; applied calls per round 0,0,0,3,4,2,0,10,4,2,8 (the counter includes\n  duplicate no-ops; the final round was in flight at the stop sample); samples\n  plateau at 24→26 blocks in the last two minutes. This is a near-livelock\n  within a 600 s bound, not a permanent-stall claim.\n- Exact unmodified-target command:\n\n```sh\nGOTOOLCHAIN=\"go$(cat target/xe/.go-version)\" \\\n  go run ./lab/scenarios/t-104b/cmd/genchain \\\n  -out /tmp/t104b-default-6k -shape linear -accounts 6000 \\\n  -difficulty default -workers 4\n\nINSTRUMENTED=0 \\\nSERVER_BIN=$PWD/target/xe/xe CLIENT_BIN=$PWD/target/xe/xe \\\n  lab/scenarios/t-104b/run-node.sh /tmp/t104b-default-6k r-repro-f003 600\n```\n\n## Causal controls (instrumented/in-process; not unmodified target)\n\n- `r-021` in-process deterministic descending order on a 12,001-block path:\n  8 rounds, 10,000 received each, **0 new blocks**, client stays at 1 account.\n  This is the permanent livelock case; it is **in-process deterministic\n  `ORDER=chain_desc`**, not unmodified target map order.\n- `r-023`: same chain/order with caps raised to 20k/20k; 21, 22, 22 new blocks\n  in three rounds, exactly 11 accounts/round (10 retry passes plus the final\n  pass).\n- `r-024b`: committed 400-account chain, descending, 1,000 retries; 800/800\n  non-genesis blocks in one round, 401 passes (801/801 including genesis).\n- `r-024c`: same chain, 10 retries; after two rounds 43/800 non-genesis blocks\n  applied, 22/401 accounts, i.e. 11 accounts/round.\n- `r-025`: target-like map order, 20,000 accounts, 10k/10k, 10 retries; ten\n  rounds, 100,000 received, 15 new blocks, 8/20,001 accounts.\n- `r-026`: star control (5 hubs, 6,006 accounts, 12,011 blocks), map order;\n  converged in 2 rounds. `r-020` ascending 6k path converged in 2 rounds.\n- Instrumented node repeats: `r-005` (20,001 accounts, map, one peer, 150 s;\n  end 6/40,001 blocks, 3 accounts), `r-010` (default-PoW 6k, map, 180 s; end\n  68/12,001 blocks, 34/6,001 accounts), `r-011` (same chain ascending; converged\n  in 2 rounds), `r-016` (five peers; end 4/40,001 blocks, 2 accounts, 3 net new;\n  per-round sum 15 is unreliable under concurrency), `r-017` (star; converged to\n  12,011/6,006; use `r-026` for the two-round claim).\n\n## Root cause\n\n- `net/sync.go:682-688`: server accounts come from\n  `for acc := range ourFrontiers`.\n- `net/sync.go:697-699`: an account absent from the client's map sends its\n  entire chain.\n- `net/sync.go:689,724`: the server stops at `maxServerBlocks = 10000`.\n- `net/sync.go:577`: the client stops reading at `maxTotalBlocks = 10000`.\n- `net/sync.go:604-627`: at most 10 retry passes; a pass with no progress breaks\n  early; a final pass applies what it can.\n- `core/ledger.go:1081-1091`: `validateAndAddReceive` calls\n  `getPendingSendOverlay(b.Source)` (line 1086) and returns `source send not\n  pending` when the source is absent.\n- `core/cascade_commit.go:110-122`: `getPendingSendOverlay` reads the cascade\n  overlay or `store.GetPendingSend`; an unapplied source send yields no pending\n  entry.\n- `core/ledger.go:1454-1458`: an unopened account has no declared public key.\n- `core/retryable.go:5-33`: `IsRetryableError` matches `unopened account` and\n  `source send not pending`, so the client keeps such blocks for the next pass.\n\nThe server's map order is randomized per request by Go. A fresh client's only\napplied root is genesis, so a random 10k window may not contain a complete\nancestor closure for a deep account.\n\n## Impact\n\nFresh-node onboarding and post-loss recovery are slow or stalled on the tested\ndependency-shaped chain: 26/12,001 blocks and 13/6,001 accounts after 600 s with\nthe unmodified target. A hostile peer serving the same valid blocks in a\ndependency-hostile order would be expected to produce the permanent\ninstrumented-order case; this was not tested with a separate malicious peer. The\nunmodified target's map order already produces the near-livelock. No funds are\nlost, no invalid block is accepted, and finalized state does not diverge.\n\n## Duplicate cross-references\n\n- **#219 / PR #223** cover the 10,000-block **response** cap's\n  terminal/continuation ambiguity and a readiness false-green. PR #223 does not\n  change the client's fixed 10-pass apply loop or the cross-account dependency\n  retry path. This report is the apply-side mechanism; it does not re-claim\n  #219's readiness/cap result.\n- If maintainers treat this as a duplicate of #219, I accept the dedupe and will\n  not re-file. The F-003 evidence can be added as a comment on #219 only if the\n  XE team requests it.\n- #59 (overlapping sync resource use), #60 (SIGTERM/shutdown), #44 (full-page\n  allocation), and #57 (lease-family blocks) are separate reports. #196 is the\n  statechain response byte cap; #8 finding 4 is nil-block/empty-page\n  amplification.\n\n## Suggested fix\n\nMake the client order-independent: apply batches in dependency rounds until no\nprogress, not a fixed 10 passes; or topologically sort receives by source depth.\nOn the server, send accounts in chain-creation order or include source sends\nbefore recipients. Mark the tracker dirty when a response was capped so the next\nround starts immediately rather than waiting for the 60 s full resync. The\ntracker item is the #219/PR #223 area; complementary, not part of this report's\nnovel mechanism.\n\n## Payout\n\nXE address: `b50f71f5ad1743456550ad7bd7720e18ce3a271f1c73eb90c56a79915404521b`\n","patch_refs":[{"id":243,"repo":"xeprotocol/xe","kind":"pr","ref":"249","title":"fix(core,store,net): atomic genesis final-height commit/repair and sync request/dependency convergence (fixes #244, #245, #246)","url":"https://github.com/xeprotocol/xe/pull/249","note":"","state":"open","author":"Khanhtnq","added_by":"desk","created_at":"2026-11-03T14:28:53.094909+00:00"}],"thread":[]}