{"id":"XE-16838","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"667","source_url":"https://github.com/xeprotocol/xe/issues/667","reporter_id":2920,"title":"[Low] GetStateBlockRange gap semantics diverge: BadgerStore returns blocks outside the requested range","area":"p2p-sync","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-17T06:33:15.120478+00:00","updated_at":"2026-11-22T23:26:12.748847+00:00","source_created_at":"2026-11-17T06:31:46+00:00","told_at":"2026-11-22T23:26:12.788525+00:00","status_changed_at":"2026-11-22T23:26:12.758805+00:00","url":"https://bounty.xe.network/XE-16838","body":"## Summary\n\n`GetStateBlockRange(start, count)` disagrees between backends when the chain has gaps: MemStore returns only blocks whose index is inside `[start, start+count)`, while BadgerStore returns the next `count` existing blocks regardless of index — serving blocks outside the requested window.\n\n## Root cause\n\n- MemStore (`store/mem_store.go:~985-996`) iterates indexes `[start, start+count)` and skips missing ones.\n- BadgerStore (`store/badger_store.go:~2013-2041`) seeks to the start key and returns the next `count` existing blocks, with no upper-bound check on the index.\n\n## Verification\n\nDifferential harness, state blocks at indexes 1 and 100, `GetStateBlockRange(1, 2)`:\n- MemStore: indexes `[1]`.\n- BadgerStore: indexes `[1, 100]` — block 100 is outside the requested range.\n\n## Impact\n\nStatechain sync paging (`statechain/sync.go:174`, `idx += len(blocks)`) and API range reads return different data per backend; Badger can serve blocks outside the requested window and mis-advance the sync cursor. Requires gaps (healthy chains have none; `replay()` rejects gaps at startup), so latent.\n\n## Note on related reports\n\n#284 (lock starvation) and #363 (keyset case) are different issues.\n\n## Suggested fix\n\nBound the BadgerStore iteration to indexes `< start+count`.","patch_refs":[],"thread":[{"id":18812,"source":"desk","source_ref":"reply:16489","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-16838 and says what differs; it is read like any other.","created_at":"2026-11-22T23:26:12.748847+00:00"}]}