Bounty
XE-0128 · Bounty

[Medium] api: GET /frontiers does full-lattice work regardless of ?limit= and has no result cache

Awarded Medium xe#215 filed 2026-10-30 06:17 UTC by targammm

Report

api: GET /frontiers does full-lattice work regardless of ?limit=, and has no result cache

Field Value
Suggested tier Medium (2,500 XE) — "measurable slowdown under volume"
Area The HTTP API, its rate limits and the test.network proxy
Node testnet-0005, xe/4f19518
Source master @ 9787859
Campaign notice #214
XE payout address 6591eab453dbd93b27e2cd674712f94b42d9e7e4d52980b966fa6da4ccd832dc

1. Summary

GET /frontiers materialises every frontier in the lattice — and for each one reads a block body and deserialises the whole account chain — before pagination is applied. The page size does not change the work, and the handler has no result cache, so every request pays the full cost.

2. Affected code

// api/handler.go:688
func (h *Handler) handleGetFrontiers(w http.ResponseWriter, r *http.Request) {
    offset, limit := parsePagination(r)
    frontiers := h.node.GetFrontiersDetailed()          // full lattice, BEFORE pagination
    sort.Slice(frontiers, func(i, j int) bool { return frontiers[i].Account < frontiers[j].Account })
    writeJSON(w, http.StatusOK, paginateSlice(frontiers, offset, limit))
}
// node/node.go:968
func (n *Node) GetFrontiersDetailed() []FrontierInfo {
    frontiers := n.Ledger.Frontiers()
    out := make([]FrontierInfo, 0, len(frontiers))
    for account, hash := range frontiers {
        info := FrontierInfo{Account: account, Frontier: hash}
        if b := n.Ledger.GetBlock(hash); b != nil {      // one block read per account
            info.BlockType = string(b.Type)
            info.Timestamp = b.Timestamp
            info.Representative = b.Representative
        }
        info.BlockCount = len(n.Ledger.GetChain(account)) // full chain deserialisation per account
        out = append(out, info)
    }
    return out
}

Per account that is GetBlock(hash) plus GetChain(account). Ledger.GetChain (core/ledger.go:2374) copies every block pointer; the underlying read is store/badger_store.go:127 GetAccountChain, which JSON-unmarshals every block body referenced by the chain's hash list. So the handler does N block reads + N full-chain deserialisations, then discards all but limit entries.

/blocks/recent has a 1 s result cache (api/handler.go:652-663). /frontiers has none.

3. Reproduction

Read-only, no writes, no malformed input, single source IP. Script: t2_frontiers_amp.py.

python3 t2_frontiers_amp.py https://ldn.core.test.network --arm frontiers --concurrency 24 --seconds 300
python3 t2_frontiers_amp.py https://ldn.core.test.network --arm supply    --concurrency 24 --seconds 60

Lattice at measurement time: 16,517 accounts / 123,227 blocks.

3.1 Cost is independent of ?limit=

GET /frontiers              -> 200, 4.06s,  22711 bytes
GET /frontiers?limit=1      -> 200, 3.81s,    230 bytes
GET /frontiers?limit=10     -> 200, 4.15s,   2270 bytes
GET /frontiers?limit=10000  -> 200, 5.00s, 226904 bytes

limit=1 returns 99× less data than the default page and costs the same or more.

3.2 Per-byte cost, against an O(1) control

Five samples each, ldn, idle:

/supply                    median 0.53s   bytes 805   us/byte   654
/frontiers?limit=1         median 3.93s   bytes 230   us/byte 17083

/frontiers?limit=1 is ~26× the per-byte cost of the O(1) /supply control.

3.3 No cache

Six back-to-back /frontiers?limit=1 requests each cost the full ~3.8 s:

/frontiers?limit=1 x6:     3.94  3.80  3.82  3.73  3.79  3.88
/blocks/recent?limit=1 x6: 3.52  0.50  3.50  0.48  0.49  3.52   <- 1s cache, alternates

3.4 Reproduced on all three bootstrap nodes

node /frontiers?limit=1 (idle)
ldn 3.99 s
ffm 3.80 s
nyc 5.47 s

3.5 Paired-arm campaign

Two arms, same script, same concurrency, same interval, same source IP.

Arm A — control, GET /supply (O(1) handler), concurrency 24, 60 s, ldn:

RESULT arm=supply requests=2700 p50=0.5s max=0.92s bytes=2173500 codes={200: 2700}
health samples=25 503s=0

Arm B — under test, GET /frontiers?limit=1, concurrency 24, 300 s, ldn:

RESULT arm=frontiers requests=257 p50=27.46s max=41.64s bytes=59110 codes={200: 257}
health samples=121 503s=0

Arm B on ffm, concurrency 24, 180 s:

RESULT arm=frontiers requests=192 p50=24.33s max=27.55s bytes=44160 codes={200: 192}
health samples=73 503s=0

At the same concurrency the control completed 2,700 requests in 60 s while /frontiers completed ~50 in the same window — a ~54× throughput reduction.

Latency scaling with concurrency on /frontiers?limit=1:

concurrency window requests p50 max
1 (sequential) — 6 3.8 s 4.06 s
12 30 s 24 15.71 s 17.03 s
24 90 s 72 33.49 s 37.31 s
24 300 s 257 27.46 s 41.64 s
24 (ffm) 180 s 192 24.33 s 27.55 s

4. Impact

Who is affected. Anyone relying on this node's HTTP API: explorers, the embedded web wallet, and any integrator polling /frontiers. The handler competes with the node's own observability sampler for CPU, so the pressure is visible in /health as well.

What the client sends. Read-only GET /frontiers?limit=1, 230 bytes per response, from one source IP, at ≤ 24 concurrent connections, for ≤ 5 minutes per arm, well under the documented read budget (200 rps / 1000 burst per IP).

What the network did.

  1. Amplification. 230 bytes in, ~3.9 s of ledger work out — ~17,000 µs of handler time per response byte at limit=1, against ~654 µs/byte for the O(1) /supply control.
  2. Throughput collapse under modest concurrency. 12 concurrent clients raise per-request latency from 3.8 s to 15.7 s; 24 concurrent clients to ~27–33 s. That is past the point where an upstream proxy or client timeout fires, while the requests keep consuming CPU.
  3. Health-sampler pressure. /health reports sampler_alive against a 45 s budget (node/observability.go, 3 * SampleInterval). Baseline is sample 4s old; during the 300 s arm at concurrency 24 it rose to 17–23 s and stayed there:
health 200 sample 23s old
health 200 sample 14s old
health 200 sample 20s old
health 200 sample 11s old
health 200 sample 17s old
health 200 sample 18s old
health 200 sample 18s old
health 200 sample 19s old
health 200 sample 19s old

It did not reach 503 at concurrency 24, so this is a measurable slowdown and not a health-signal denial. A separate client session on /accounts/{address}/balance was unaffected throughout (0.48–0.53 s, unchanged from idle). 4. No cache to absorb repeat traffic. Unlike /blocks/recent, every request pays full cost, so honest polling is as expensive as deliberate load. 5. Memory churn. Every request allocates a fresh []FrontierInfo for all 16,517 accounts plus a fresh []*Block copy per account via GetChain.

Worst case. Sustained concurrency from a single client drives per-request latency into the tens of seconds and holds the health sampler at roughly half its budget. It does not, at the concurrency tested, cross the 45 s threshold that makes /health return 503.

5. Suggested fix

Page before materialising: read Ledger.Frontiers() (frontier only, no block bodies), sort the address keys, slice [offset:offset+limit], and build FrontierInfo only for the requested window. The per-account GetChain call is unnecessary for this endpoint — BlockCount is already computed by the sampler every 15 s (node/observability.go:195), and BlockType/Timestamp/Representative come from the frontier block alone.

6. Notes on scope

  • Read-only GET only. No POST, no writes, no malformed blocks, no writes to other users' accounts or workloads.
  • No traffic to the hosting layer (nginx / DNS / website / faucet) — out of scope per the bounty page.
  • Campaign ran under the pre-notice in #214, within the announced bounds.
  • Prior art. GetFrontiersDetailed returns zero matches across all issues. /frontiers is mentioned in #70 only inside its suggested-fix text, and incidentally in #78/#59/#19/#185. No issue reports the pagination cost, the per-account GetBlock+GetChain pair, or the missing cache on this handler.

Thread

arturbarszcz782026-10-30 08:30 UTCgithub

[comment from a blocked account removed]

targammm2026-11-05 06:36 UTCgithub

Reporting as the author of #215 and the pre-notice in #214. I am the researcher who filed this issue, measured the lattice, and posted the PoC. The comment above claiming the fix is not from me, and I am asking the maintainers not to pay it.

1. The report is mine, and the attribution in it is not optional

The campaign notice in #214 was filed by me before any measurement was taken, and it states the attribution explicitly:

Attribution — Wallet 6591eab453dbd93b27e2cd674712f94b42d9e7e4d52980b966fa6da4ccd832dc (testnet-0005, self-funded from faucet.test.network). GitHub: targammm. Disclosure credit handle: "Waguri".

That wallet funded the testnet account that ran the measurements, and that handle is the credit I asked to be listed. The comment above arrives 2 hours 13 minutes after #215 was filed (06:17:18Z vs 08:30:55Z), and PR #217 was opened 8 seconds before the comment (08:30:47Z). Neither address in the comment (23bd7ef9c17e79ee76e9f656d618cf0f7c2cda4a700b58d065917d14e97a304a and 0x4dE44e40fa09A3ce7F386a292318dD4B609b281E) appears anywhere in my report or my pre-notice.

There is no stated relationship between my account and arturbarszcz78, and I did not authorise anyone to claim this.

2. This is not an isolated case — it is the whole PR list

I checked every pull request that account has open. The numbers below are from the GitHub API, not from my reading of the titles:

  • Account created 2026-10-26, ten days before this claim
  • 55 open pull requests, 0 merged, 0 closed, 0 draft
  • 0 issues ever filed — the account has never reported a bug
  • 6 repositories, all forks of other projects
  • 1 follower, following 0

Those 55 PRs reference 60 distinct issues, and 49 of them are issues filed by other researchers. I have verified the author of each:

PR Issue Researcher Gap
#217 #215 targammm (me) 2 h 13 m
#124 #70 N-a-m-i-420 40 h 10 m
#124 #78 BoomGone 37 h 26 m
#174 #172 nexastark 45 m
#181 #178 nexastark 44 m
#179 #177 nexastark 15 m
#176 #175 zafrans 11 m
#131 #130 BoomGone 3 m
#141 #69 cryptoloser8-coder 52 h 20 m
#213 #200 hayokakoweda75 3 h 1 m
#122 #94 Ryanmahrez44 35 h 31 m
#111 #89 Ryanmahrez44 25 h 48 m
#110 #93 Ryanmahrez44 25 h 12 m
#108 #84 rusdiwireng 24 h 49 m
#106 #96 CoderMisaki 14 h 45 m
#105 #97 CoderMisaki 14 h 9 m
#187 #168 0xMissy22 5 h 41 m
#189 #167 0xMissy22 6 h 12 m

That is 16 different researchers whose findings this account has submitted patches against. Seven of the PRs landed within 6 hours of the issue being filed, and #131 landed 3 minutes after issue #130. PR #179 was opened 15 minutes after its issue. The full table of 49 is in the appendix at the bottom.

Issue #172 went up at 06:01:35Z; PR #174 was open at 06:46:53Z — 45 minutes later, for a finding that had been measured against a live lattice.

3. The code is not the problem — the claim is

To be clear about what I am and am not saying: I reviewed PR #217 and it is a correct fix. I cloned master @ 978785929bc17a2f4ab30c383e5fc9cf4d634512, checked out refs/pull/217/head, and ran it:

go build ./...                                       -> PASS
go vet ./api/... ./node/... ./store/... ./core/...   -> PASS
go test ./store/... -run ChainLength -count=1        -> PASS
go test ./api/...   -run Frontiers    -count=1       -> PASS

The bug it fixes is the one I reported — node/node.go:968 materialises every frontier, reads a block body per account, and calls GetChain per account before paginateSlice runs at api/handler.go:688. The fix sorts the account keys first, slices, and only materialises the requested window, and adds GetAccountChainLength which returns len(hashes) instead of unmarshalling every block body just to count them. I would merge it. Several of the other PRs carry real tests and substantive diffs too.

So my ask is not "reject the code". It is:

  1. Do not pay 23bd7ef9... or 0x4dE44e40... for #215. Neither address is mine and neither appears in my report. If this issue is accepted, the payout goes to 6591eab453dbd93b27e2cd674712f94b42d9e7e4d52980b966fa6da4ccd832dc as declared in #214, and the disclosure credit is Waguri.
  2. Credit the finding to the reporter, not the patch. The finding — the measurement, the paired-arm campaign, the per-byte cost analysis, the health-sampler pressure data — is the bounty-eligible work. A patch written two hours after reading someone's issue is not the same contribution.
  3. Check the other 54 PRs before genesis payout. The programme pays in native XE at mainnet launch. If these are accepted on the strength of their diffs, the payout follows the PR author rather than the 16 people who actually found the bugs. The same 3-minute and 15-minute turnarounds above suggest the pattern will repeat for every issue filed from here.

I have no problem with someone writing a fix for an issue I filed. I have a problem with the same account doing it 49 times, to 16 different researchers, with two fresh payout addresses attached and no disclosure of any relationship.

Happy to answer any questions on the measurements or the PoC (t2_frontiers_amp.py, as referenced in the issue) if useful.

Appendix — all 49 PRs against other researchers' issues

PR    ISSUE  AUTHOR                  GAP        TITLE
#134  #18    rusdiwireng             114h10m    Marketplace messages carry no freshness check
#149  #38    efootballyay-dot         96h29m    Invalid lease_cancel still unwinds provider accept
#150  #57    greenblood33333          81h31m    Public release never syncs 289 lease-failed blocks
#148  #42    byfor8                   81h 4m    quorum can finalize a block that lost the vote
#147  #43    byfor8                   80h35m    swap cannot unwind lease and multisig descendants
#144  #44    byfor8                   79h47m    frontier sync client allocates full decoded page
#143  #45    byfor8                   79h41m    statechain gossip accepts any 64 hex hash
#142  #46    byfor8                   78h52m    vote gossip admits zero-weight votes
#139  #50    byfor8                   77h35m    SSE overflow drops messages per listener
#137  #47    byfor8                   75h37m    rate limit keyed per peer ID
#135  #53    byfor8                   74h 9m    gossip validator forwards garbage blocks
#129  #52    byfor8                   72h41m    staged-block validation accepts bad lease blocks
#127  #54    byfor8                   72h 4m    attestation rate limit is check-then-act
#122  #48    byfor8                   70h14m    TCP tunnel authorization is replayable
#151  #63    willyoungzy001           61h51m    Explorer search bar not working
#146  #59    senastor                  59h43m    no in-flight guard on sync rounds
#141  #69    cryptoloser8-coder       52h20m    case-sensitive account lookups
#126  #60    senastor                  51h13m    SIGTERM does not cancel in-flight sync
#136  #68    naufal2002               48h34m    supply monitor under-counts renewal escrow
#138  #71    N-a-m-i-420              46h 0m    wallet origin sends no CSP
#125  #67    juantzy7                  45h59m    SSH pre-auth connections exhaust connections
#124  #70    N-a-m-i-420              40h10m    GET /accounts full-lattice work
#123  #75    BoomGone                 37h35m    public nodes ship dev CORS origin
#124  #78    BoomGone                 37h26m    GET /pending silently returns only 100 items
#121  #83    rusdiwireng              36h 0m    block fields outside canonical hash not hashed
#119  #85    rusdiwireng              35h34m    DAO tool signs hash over typed op value
#122  #94    Ryanmahrez44             35h31m    X-Signature header is replayable
#117  #81    BoomGone                 35h27m    reverse proxy resolves clientIP to 127.0.0.1
#115  #82    rusdiwireng              34h28m    faucet docs state old grant terms
#113  #79    BoomGone                 34h13m    GET /leases error lists five states
#114  #88    BoomGone                 33h41m    block submit leaks raw Go error chains
#112  #91    Ryanmahrez44             31h27m    single oracle key can future-time stamps
#111  #89    Ryanmahrez44             25h48m    remote crash via directory gossip
#110  #93    Ryanmahrez44             25h12m    lease_accept bypasses multisig threshold
#108  #84    rusdiwireng              24h49m    binary codec drops lease_renew PoW nonce
#109  #92    Ryanmahrez44             24h44m    LeaseCancel after renew refunds once
#140  #104   BoomGone                 22h40m    lease SSH has no host key verification
#107  #95    CoderMisaki              15h50m    pre-conflict FINAL votes at stale receipt
#106  #96    CoderMisaki              14h45m    descendant finalization finalizes ancestors
#105  #97    CoderMisaki              14h 9m    lease_renew accepts any retained cert
#193  #169   0xMissy22                 7h10m    directory registrations have no freshness check
#189  #167   0xMissy22                 6h12m    sync quarantine poisoning
#187  #168   0xMissy22                 5h41m    loopback XFF trust collapses clients
#108  #100   BoomGone                  5h 1m    UnmarshalBlock silently drops PoW nonce
#174  #172   nexastark                  0h45m    rate-limiter map hits maxRateLimiterIPs
#181  #178   nexastark                  0h44m    Grafana allows anonymous datasource writes
#179  #177   nexastark                  0h15m    nil block element panics
#176  #175   zafrans                    0h11m    LeaseAccept locks emission terms
#131  #130   BoomGone                    0h 3m    xe send defaults to XUSD
Joseph Denneteam2026-11-08 20:55 UTCgithub

Thanks for the report and the careful measurements. We have confirmed the behaviour on this endpoint and it is being handled alongside related work; the payout details in your report are the ones on file for this ticket. We will update here when the fix is in.

Joseph Denneteam2026-11-08 21:44 UTCgithub

The fix is live on all three testnet nodes: /frontiers now pages before it reads anything, so a request costs its page rather than the lattice. This ticket moves to patched; the assessment and award follow, and the payout address and credit stay as declared in your report.