{"id":"XE-13269","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"390","source_url":"https://github.com/xeprotocol/xe/issues/390","reporter_id":2482,"title":"api: GET /blocks/recent accepts ?offset= and silently ignores it — the block list cannot be paged backwards","area":"node-api","claimed_tier":"medium","assessed_tier":null,"verdict":"invalid","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"invalid","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:06.005478+00:00","updated_at":"2026-11-20T00:25:45.043364+00:00","source_created_at":"2026-11-11T14:10:14+00:00","told_at":"2026-11-20T00:24:46+00:00","status_changed_at":"2026-11-20T00:08:44.132951+00:00","url":"https://bounty.xe.network/XE-13269","body":"**Area:** Node / API — `GET /blocks/recent` (`api/handler.go:665-686`)\n**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.\n**Node:** `xe/3019b76`, `testnet-0005`, `https://ldn.core.test.network`\n**Method:** read-only, unauthenticated GETs. No writes, no sustained campaign.\n\n## Summary\n\n`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.\n\n`docs/api.md:23` (mirrored at `https://test.network/llms-full.txt:649`) states the contract for every list endpoint:\n\n> **Pagination.** List endpoints take `?offset=N&limit=M` (default `limit=100`, max `1000`).\n\nNine sibling call sites honour it. This handler is the only one that does not.\n\n## Root cause\n\n```go\nfunc (h *Handler) handleGetRecentBlocks(w http.ResponseWriter, r *http.Request) {\n\t_, limit := parsePagination(r)      // offset parsed, then thrown away\n\tblocks := h.cachedRecentBlocks()\n\t...\n\tif len(blocks) > limit {\n\t\tblocks = blocks[:limit]\n\t}\n\twriteJSON(w, http.StatusOK, blocks)\n}\n```\n\n`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\".\n\n`grep -rn \"parsePagination(r)\" api/` → 10 call sites; `api/handler.go:666` is the only `_, limit :=`.\n\n## Evidence\n\nSix offsets fired concurrently, so all land in the same 1 s cache window (drift excluded), three trials:\n\n```\ntrial 0: distinct first-hashes across 6 offsets = 1\n  {0: '864e7012c36f3ee5', 1: '864e7012c36f3ee5', 5: '864e7012c36f3ee5',\n   50: '864e7012c36f3ee5', 500: '864e7012c36f3ee5', 999: '864e7012c36f3ee5'}\ntrial 1: identical        trial 2: identical\n```\n\nControls — same parameter, same concurrency, on endpoints that implement it:\n\n```\n/pending        offset0=000031aa7f58  offset3=0000d7c4ebba  -> differs (works)\n/frontiers      offset0=0000fd1d0783  offset3=000b0c1356e9  -> differs (works)\n/accounts       offset0=76ffbdce7d7a  offset3=5f352e83fc8d  -> differs (works)\n/reputation     offset0=26740934b576  offset3=81f5e4e1f959  -> differs (works)\n/statechain/kv  offset0=epoch.0       offset3=epoch.100     -> differs (works)\n```\n\n`limit` works on the target endpoint, so this is specifically offset and not a broken parser:\n\n```\nGET /blocks/recent?limit=1            -> 1 row\nGET /blocks/recent?limit=1000         -> 1000 rows\nGET /blocks/recent?limit=1&offset=999 -> still the row at position 0\n```\n\n`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.\n\n```\nblock 2000-deep  (outside the window) + since=ts-1 -> present = False, rows = 1000\nblock 60000-deep (outside the window) + since=ts-1 -> present = False, rows = 1000\ncontrol: in-window block + since=ts-1             -> present = True\n```\n\n## Impact\n\nReachable 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.\n\n- 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 `/accounts` costs 33 pages of full-lattice work before the first block comes back.\n- `since` reads 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.\n- The shipped explorer has the same blind spot — `web/assets/block.js:64` calls `api('/blocks/recent')` with no paging args and never follows on.\n- The caller gets the wrong page: under the documented convention `offset=999&limit=1` is 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.\n\n## Suggested fix\n\n```go\noffset, limit := parsePagination(r)\n...\nif offset >= len(blocks) {\n\tblocks = nil\n} else {\n\tblocks = blocks[offset:]\n\tif len(blocks) > limit {\n\t\tblocks = blocks[:limit]\n\t}\n}\n```\n\nThat 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.\n\n## Reproduction\n\n```bash\nB=https://ldn.core.test.network\nfor o in 0 1 5 50 500 999; do\n  curl -s \"$B/blocks/recent?limit=1&offset=$o\" \\\n    | python3 -c 'import sys,json;print(json.load(sys.stdin)[0][\"hash\"])'\ndone\n```\n\nFull script with all four sections and the controls: will attach on the desk filing (`poc_final.sh`).\n\n## Dedup\n\nDesk full-text (1058 tickets) and GitHub search both checked; nothing reports offset on this endpoint.\n\n- #217 / #215 / #70 — full-lattice work regardless of `limit`, on `/frontiers` and `/accounts`.\n- #385 — `/pending/{address}` ignores `limit`/`offset` (unbounded response).\n- #277 — docs errors incl. silent normalisation of *invalid* `limit`/`offset`. Here the offset is valid and still dropped.\n- XE-0220 (desk) — same endpoint, different defect (synchronous 12 s rebuild, `limit` does not reduce cost). No mention of offset or of the unreachable tail.\n- XE-0610 (desk) — `/chat/messages` swallows every pagination parameter. Same theme, different handler.\n","patch_refs":[{"id":548,"repo":"xeprotocol/xe","kind":"pr","ref":"409","title":"fix(api): respect pagination offset and limit in GET /blocks/recent (Fixes #390)","url":"https://github.com/xeprotocol/xe/pull/409","note":"","state":"closed","author":"kleitonbernardino-lab","added_by":"desk","created_at":"2026-11-14T20:42:19.991182+00:00"},{"id":553,"repo":"xeprotocol/xe","kind":"pr","ref":"414","title":"fix(api): apply pagination offset to /blocks/recent and paginate /pending/{address} (#390, #385)","url":"https://github.com/xeprotocol/xe/pull/414","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-11-14T20:42:20.063853+00:00"}],"thread":[{"id":3131,"source":"github","source_ref":"6807180894","author":"kleitonbernardino-lab","team":false,"body":"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.","created_at":"2026-11-11T21:14:16+00:00"},{"id":13038,"source":"github","source_ref":"7026261610","author":"XE desk","team":true,"body":"Thanks for the report. We read it against the code and could not confirm a bug in what it describes.\n\nThis report is closed as invalid. If we have missed something, file a new report that links\nhttps://bounty.xe.network/XE-13269 and says what; it is read like any other.","created_at":"2026-11-20T00:24:46+00:00"}]}