<!-- XE-16838 · [Low] GetStateBlockRange gap semantics diverge: BadgerStore returns blocks outside the requested range · testnet -->
*Markdown view of <https://bounty.xe.network/XE-16838>. The page is the record; this is the same page for reading.*

XE-16838 · Bounty

# \[Low\] GetStateBlockRange gap semantics diverge: BadgerStore returns blocks outside the requested range

Closed · duplicate
—
[xe#667](https://github.com/xeprotocol/xe/issues/667)
filed 2026-11-17 06:31 UTC
by kecedanzz77-bit

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   P2P / sync

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-22 23:26 UTC

Told
:   2026-11-22 23:26 UTC

### Patches

None linked.

### History

- [770256](https://bounty.xe.network/log/770256) 2026-11-22 23:26 UTC reply.mirror\_failed
- [769878](https://bounty.xe.network/log/769878) 2026-11-22 23:26 UTC proposal.adopted
- [769877](https://bounty.xe.network/log/769877) 2026-11-22 23:26 UTC reply.sent
- [769876](https://bounty.xe.network/log/769876) 2026-11-22 23:26 UTC proposal.adopted
- [769875](https://bounty.xe.network/log/769875) 2026-11-22 23:26 UTC ticket.status new → closed
- [768849](https://bounty.xe.network/log/768849) 2026-11-22 23:25 UTC proposal.adopted
- [768848](https://bounty.xe.network/log/768848) 2026-11-22 23:25 UTC ticket.facts area
- [768847](https://bounty.xe.network/log/768847) 2026-11-22 23:25 UTC proposal.adopted
- [768846](https://bounty.xe.network/log/768846) 2026-11-22 23:25 UTC ticket.facts
- [768845](https://bounty.xe.network/log/768845) 2026-11-22 23:25 UTC proposal.adopted
- [768844](https://bounty.xe.network/log/768844) 2026-11-22 23:25 UTC ticket.facts
- [766602](https://bounty.xe.network/log/766602) 2026-11-22 23:17 UTC note.added

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

### Report

## Summary

`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.

## Root cause

- MemStore (`store/mem_store.go:~985-996`) iterates indexes `[start, start+count)` and skips missing ones.
- 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.

## Verification

Differential harness, state blocks at indexes 1 and 100, `GetStateBlockRange(1, 2)`:

- MemStore: indexes `[1]`.
- BadgerStore: indexes `[1, 100]` — block 100 is outside the requested range.

## Impact

Statechain 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.

## Note on related reports

#284 (lock starvation) and #363 (keyset case) are different issues.

## Suggested fix

Bound the BadgerStore iteration to indexes `< start+count`.

### Thread

**Joseph Denne**team2026-11-22 23:26 UTCdesk

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the
first verifiable submission, so this one closes as a duplicate. If you believe it is a different
bug, file a new report that links https://bounty.xe.network/XE-16838 and says what differs; it is read like any other.
