net/sync: frontiers request above 1 MiB is truncated; fresh sync stalls at ~7,800 accounts
Report
net/sync: frontiers request above 1 MiB is truncated; fresh sync stalls at ~7,800 accounts
Suggested tier: High (Medium fallback). Availability/recovery only; no state, finality, or supply divergence.
Summary
A net/sync request carries the requester's entire frontiers map as one JSON
object. The server reads at most maxSyncRequestBytes = 1<<20 (1 MiB) and then
decodes JSON. If the map crosses 7,824 entries (first failing wire size 7,825
including json.Encoder.Encode's trailing newline; wire size is the
json.Marshal length + 1 B) while the requester still has missing blocks, the
request is truncated mid-object, json.Decoder returns unexpected EOF, and
handleSyncStream returns without sending a response. The requester cannot
fetch the remaining blocks through that path.
This is conditional, not universal. r-013 (8,501 accounts) converges because
its final batch fits before the boundary. It does not depend on dependency
order; ascending order still stalls at the crossing (r-015).
Target
- Pinned commit:
978785929bc17a2f4ab30c383e5fc9cf4d634512 - Unmodified binary SHA-256:
c3bbf2612ab282fd31ea9b78eec109e9554a260b4ca6e6aa6e01d9fb04ff1f34 - Network:
t104b-lab(custom local genesis) - Ledger genesis:
be79a8c7fa04ebb76f2fba9d8e9d5311007544029876a3c3e3e534aeb2fa0d16 - Statechain genesis:
cdac6a19f67c2a8f38c426570992ed91fd82aceb4dbb4490fcc13452be3fc0fb - Activation state: tip 0, no active features, protocol 1.0.0
- Store/topology: Badger; loopback API/metrics;
--disable-mdns --no-discovery
Preconditions
An honest server, a client that sends its full frontiers map, and missing blocks remaining when the map first exceeds 1 MiB. No attacker is required.
Invariant
A valid full-frontiers request is accepted up to the protocol's own
maxFrontiers or rejected explicitly. A server parse rejection must not be
recorded as a successful empty round. A fresh node with one honest peer reaches
the server tip in bounded rounds.
Unmodified-target wire proof (r-029 / r-031)
The unmodified target server (xe/9787859) served a 9,001-account / 54,001-block
chain. A rebuilt lab/tools/syncprobe sent one request with synthetic 64-hex
frontiers:
| Frontiers | json.Marshal bytes |
Wire bytes (+1 B newline) | Result |
|---|---|---|---|
| 7,800 | 1,045,230 | 1,045,231 | decoded: 157 pages / 10,000 blocks |
| 7,900 | 1,058,630 | 1,058,631 | 0 pages / 0 blocks; server sync: decode request: unexpected EOF |
| 8,000 | 1,072,030 | 1,072,031 | over the limit |
| 8,335 | 1,116,920 | 1,116,921 | over the limit |
| 10,001 | 1,340,164 | 1,340,165 | over the limit |
Limit: 1,048,576 B. First failing entry count: 7,825 including the newline.
/node before and after: xe/9787859, network_id=t104b-lab,
block_count=54,001, accounts=9,001, pow_difficulty=fffff80000000000.
The server flags were --data <copy of chain>/data --genesis-dir <chain>/genesis --port 23000 --api --api-bind 127.0.0.1 --api-port 23100 --metrics-addr 127.0.0.1:23200 --disable-mdns --no-discovery.
Reproduction: lab/scenarios/t-104b/probe-request-cap.sh <chain> <run-id>; a
copy is r-029/run.sh and r-031/run.sh. Probe source SHA-256:
4ee9b1d72fc484b014944301010ebdf16418d083473f100dd0face81c45938dd; probe
binary SHA-256:
f20c2513c2bf268d744d5f89ac1e0cfe2245ad740ff44908e72c09b4ad8ea933.
The synthetic frontiers match the real 64-hex frontier shape and length; they do
not name real accounts, so the probe measures decode/start behavior, not real
sync data for those keys.
The 9k chain's blocks are low-PoW lab data generated with -difficulty low; the
unmodified server only serves the already-stored chain, and the probe does not
apply or validate the blocks. The request-reader path under test is independent
of PoW; the /node pow_difficulty is the server's configured difficulty, not
the stored blocks' difficulty. The pinned target has the same request reader
and 64-hex frontier shape; the live build (xe/4f19518) was not source-audited,
so live reachability is inferred.
End-to-end stall (instrumented, single observed run)
r-015: 9,001 accounts / 54,001 blocks, XE_DIFFICULTY=low,
XE_SYNC_ORDER=chain_asc. The client applies 50,000 blocks in five rounds,
then applies 0 in two further rounds and stalls at 8,335/9,001 accounts with
4,000 blocks still missing; the server logs decode request: unexpected EOF.
The instrumentation changes ordering, logging, and PoW difficulty only; the
request reader and EOF handling are unchanged. This is one observed run; r-013
is the converging counterexample.
Client-side false success (code reading)
net/sync.go:565-569 treats a clean server EOF as a normal end of response;
net/sync.go:334-337,375-377 records the caller's own frontiers under the
peer ID and returns success. This false-success path was not observed end-to-end
on the unmodified target; the unmodified observation is the wire boundary.
Root cause
net/sync.go:31:maxSyncRequestBytes = 1 << 20.net/sync.go:430:json.NewDecoder(io.LimitReader(s, maxSyncRequestBytes)).net/sync.go:431-436: decode error logs and returns; no error response.net/sync.go:544-554: the client sendsSyncRequest{Frontiers: ledger.Frontiers(), PageSize: ...}as one JSON object.net/sync.go:438-449:maxFrontierstrimming happens after a successful decode, so it cannot protect the reader.net/sync.go:565-569: EOF is treated as a normal end; the caller records the round as successful.
Impact
A node that crosses the cap with missing blocks cannot ask for them through this
path. Fresh onboarding and post-loss recovery are the affected cases. A mature
node that already holds the chain may still log repeated decode errors, but has
nothing missing. Live reachability is inferred from 26,513 live accounts; the
live build (xe/4f19518) was not source-audited. No funds, finality, or supply
effect.
Duplicate cross-references
- #219 / PR #223 cover the 10,000-block response cap's
terminal/continuation signal and a readiness false-green. PR #223 adds
Truncated/HasMorehandling and convergence accounting but does not changemaxSyncRequestBytesor the request reader. This report is the 1 MiB request cap. - #196 is the statechain response byte cap; #8 finding 4 is nil-block/empty-page amplification; #44/#59 are sync-client allocation/resource issues; #60 is the SIGTERM/shutdown hang.
- No existing issue was found for truncating the frontiers request at 1 MiB.
Suggested fix
Paginate or stream the frontiers map (e.g., hash-range cursors), or raise the request cap above one full map. Return an explicit error response on decode failure so the client does not record a false success. Add a regression test that builds a ledger with 10k+ accounts and round-trips a sync request at the 1 MiB boundary.
Payout
XE address: b50f71f5ad1743456550ad7bd7720e18ce3a271f1c73eb90c56a79915404521b
Thread
Nothing public yet.