[Low] GetStateBlockRange gap semantics diverge: BadgerStore returns blocks outside the requested range
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 nextcountexisting 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
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.