<!-- XE-13269 · api: GET /blocks/recent accepts ?offset= and silently ignores it — the block list cannot be paged backwards · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13269>. The page is the record; this is the same page for reading.*

XE-13269 · Bounty

# api: GET /blocks/recent accepts ?offset\= and silently ignores it — the block list cannot be paged backwards

Closed · invalid
—claimed Medium
[xe#390](https://github.com/xeprotocol/xe/issues/390)
filed 2026-11-11 14:10 UTC
by targammm

Verdict
:   Invalid

Tier
:   —

Claimed
:   Medium

Area
:   Node / API

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-20 00:25 UTC

Told
:   2026-11-20 00:24 UTC

### Patches

- [xe#409](https://github.com/xeprotocol/xe/pull/409) closed by kleitonbernardino-lab
  fix(api): respect pagination offset and limit in GET /blocks/recent (Fixes #390)
- [xe#414](https://github.com/xeprotocol/xe/pull/414) open by arturbarszcz78
  fix(api): apply pagination offset to /blocks/recent and paginate /pending/{address} (#390, #385)

### History

- [549264](https://bounty.xe.network/log/549264) 2026-11-20 00:24 UTC reply.mirrored
- [548722](https://bounty.xe.network/log/548722) 2026-11-20 00:24 UTC reply.sent
- [544642](https://bounty.xe.network/log/544642) 2026-11-20 00:09 UTC github.state\_pushed
- [544639](https://bounty.xe.network/log/544639) 2026-11-20 00:09 UTC github.labels
- [544510](https://bounty.xe.network/log/544510) 2026-11-20 00:08 UTC proposal.adopted
- [544461](https://bounty.xe.network/log/544461) 2026-11-20 00:08 UTC proposal.adopted
- [544460](https://bounty.xe.network/log/544460) 2026-11-20 00:08 UTC ticket.status new → closed
- [544366](https://bounty.xe.network/log/544366) 2026-11-20 00:08 UTC proposal.adopted
- [544365](https://bounty.xe.network/log/544365) 2026-11-20 00:08 UTC ticket.facts area
- [544364](https://bounty.xe.network/log/544364) 2026-11-20 00:08 UTC proposal.adopted
- [544363](https://bounty.xe.network/log/544363) 2026-11-20 00:08 UTC ticket.facts
- [536122](https://bounty.xe.network/log/536122) 2026-11-19 23:40 UTC note.added

[Full history](https://bounty.xe.network/log?ref=XE-13269) · [JSON](https://bounty.xe.network/v1/tickets/XE-13269) · [markdown](https://bounty.xe.network/XE-13269.md)

### 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` (default `limit=100`, max `1000`).

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 `/accounts` costs 33 pages of full-lattice work before the first block comes back.
- `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.
- 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.
- 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.

## 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 `/frontiers` and `/accounts`.
- #385 — `/pending/{address}` ignores `limit`/`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, `limit` does not reduce cost). No mention of offset or of the unreachable tail.
- XE-0610 (desk) — `/chat/messages` swallows every pagination parameter. Same theme, different handler.

### Thread

**kleitonbernardino-lab**2026-11-11 21:14 UTCgithub

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.

**XE desk**team2026-11-20 00:24 UTCgithub

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.
