api: GET /blocks/recent accepts ?offset= and silently ignores it — the block list cannot be paged backwards
Report
Area: Node / API — GET /blocks/recent (api/handler.go:665-686)
Claimed tier: Medium (documented API contract does not hold; API returns the wrong page). Minor is fair if the missing parameter is treated as docs-only.
Node: xe/3019b76, testnet-0005, https://ldn.core.test.network
Method: read-only, unauthenticated GETs. No writes, no sustained campaign.
Summary
GET /blocks/recent accepts ?offset= and discards it. Every offset returns the identical page, so the block list cannot be paged backwards — and the returned page is the wrong one.
docs/api.md:23 (mirrored at https://test.network/llms-full.txt:649) states the contract for every list endpoint:
Pagination. List endpoints take
?offset=N&limit=M(defaultlimit=100, max1000).
Nine sibling call sites honour it. This handler is the only one that does not.
Root cause
func (h *Handler) handleGetRecentBlocks(w http.ResponseWriter, r *http.Request) {
_, limit := parsePagination(r) // offset parsed, then thrown away
blocks := h.cachedRecentBlocks()
...
if len(blocks) > limit {
blocks = blocks[:limit]
}
writeJSON(w, http.StatusOK, blocks)
}
parsePagination returns both values; only limit is bound. The producer has no offset to pass either — core/ledger.go:2415 is GetRecentBlocks(limit int) and starts each chain at len(chain) - limit, so the snapshot is always "newest N".
grep -rn "parsePagination(r)" api/ → 10 call sites; api/handler.go:666 is the only _, limit :=.
Evidence
Six offsets fired concurrently, so all land in the same 1 s cache window (drift excluded), three trials:
trial 0: distinct first-hashes across 6 offsets = 1
{0: '864e7012c36f3ee5', 1: '864e7012c36f3ee5', 5: '864e7012c36f3ee5',
50: '864e7012c36f3ee5', 500: '864e7012c36f3ee5', 999: '864e7012c36f3ee5'}
trial 1: identical trial 2: identical
Controls — same parameter, same concurrency, on endpoints that implement it:
/pending offset0=000031aa7f58 offset3=0000d7c4ebba -> differs (works)
/frontiers offset0=0000fd1d0783 offset3=000b0c1356e9 -> differs (works)
/accounts offset0=76ffbdce7d7a offset3=5f352e83fc8d -> differs (works)
/reputation offset0=26740934b576 offset3=81f5e4e1f959 -> differs (works)
/statechain/kv offset0=epoch.0 offset3=epoch.100 -> differs (works)
limit works on the target endpoint, so this is specifically offset and not a broken parser:
GET /blocks/recent?limit=1 -> 1 row
GET /blocks/recent?limit=1000 -> 1000 rows
GET /blocks/recent?limit=1&offset=999 -> still the row at position 0
since= is not a way around it: a real block taken from its own account chain, with since set one second before its timestamp, never appears.
block 2000-deep (outside the window) + since=ts-1 -> present = False, rows = 1000
block 60000-deep (outside the window) + since=ts-1 -> present = False, rows = 1000
control: in-window block + since=ts-1 -> present = True
Impact
Reachable history is the newest 1000 blocks — 0.114 % of the 874 812-block lattice, ~50 min of chain (both move with the chain; measured 2026-11-11). ?limit= caps at 1000, so the cap cannot be dodged with a bigger page.
- No list route reaches block N−1000 or older.
GET /blocks/{hash}works only once you already have a hash. Paging a single account's chain misses every account with no block in the last 50 min; iterating/accountscosts 33 pages of full-lattice work before the first block comes back. sincereads as the fix and is not: a window that starts before the snapshot returns the snapshot, so "everything since T" gets 1000 rows with no truncation signal and missing boundary blocks.- The shipped explorer has the same blind spot —
web/assets/block.js:64callsapi('/blocks/recent')with no paging args and never follows on. - The caller gets the wrong page: under the documented convention
offset=999&limit=1is block 1000, and it is block 1. A client that trusts the parameter builds a page sequence with 100 % overlap and believes it has the whole chain.
Suggested fix
offset, limit := parsePagination(r)
...
if offset >= len(blocks) {
blocks = nil
} else {
blocks = blocks[offset:]
if len(blocks) > limit {
blocks = blocks[:limit]
}
}
That honours the contract, but only within the 1000-block snapshot — offset=1000 still returns nothing. Real history needs the snapshot widened, or GetRecentBlocks given an offset that walks the frontier index backwards instead of starting at len(chain)-limit. If only the cheap half is wanted, documenting the endpoint as "newest 1000, no paging" and dropping the parameter would at least stop the contract lying.
Reproduction
B=https://ldn.core.test.network
for o in 0 1 5 50 500 999; do
curl -s "$B/blocks/recent?limit=1&offset=$o" \
| python3 -c 'import sys,json;print(json.load(sys.stdin)[0]["hash"])'
done
Full script with all four sections and the controls: will attach on the desk filing (poc_final.sh).
Dedup
Desk full-text (1058 tickets) and GitHub search both checked; nothing reports offset on this endpoint.
- #217 / #215 / #70 — full-lattice work regardless of
limit, on/frontiersand/accounts. - #385 —
/pending/{address}ignoreslimit/offset(unbounded response). - #277 — docs errors incl. silent normalisation of invalid
limit/offset. Here the offset is valid and still dropped. - XE-0220 (desk) — same endpoint, different defect (synchronous 12 s rebuild,
limitdoes not reduce cost). No mention of offset or of the unreachable tail. - XE-0610 (desk) —
/chat/messagesswallows every pagination parameter. Same theme, different handler.
Thread
Opened PR #409 to resolve this issue by binding offset from parsePagination and applying paginateSlice in handleGetRecentBlocks, together with unit test coverage for pagination parameters and ?since= timestamp filtering.
Thanks for the report. We read it against the code and could not confirm a bug in what it describes.
This report is closed as invalid. If we have missed something, file a new report that links https://bounty.xe.network/XE-13269 and says what; it is read like any other.