<!-- XE-16839 · [Low] MemStore list methods return Go-map-randomized order; BadgerStore returns key-sorted order · testnet -->
*Markdown view of <https://bounty.xe.network/XE-16839>. The page is the record; this is the same page for reading.*

XE-16839 · Bounty

# \[Low\] MemStore list methods return Go-map-randomized order; BadgerStore returns key-sorted order

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

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   Node / API

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-22 23:26 UTC

Told
:   2026-11-22 23:26 UTC

### Patches

None linked.

### History

- [770254](https://bounty.xe.network/log/770254) 2026-11-22 23:26 UTC reply.mirror\_failed
- [769870](https://bounty.xe.network/log/769870) 2026-11-22 23:26 UTC proposal.adopted
- [769869](https://bounty.xe.network/log/769869) 2026-11-22 23:26 UTC reply.sent
- [769868](https://bounty.xe.network/log/769868) 2026-11-22 23:26 UTC proposal.adopted
- [769867](https://bounty.xe.network/log/769867) 2026-11-22 23:26 UTC ticket.status new → closed
- [768837](https://bounty.xe.network/log/768837) 2026-11-22 23:25 UTC proposal.adopted
- [768836](https://bounty.xe.network/log/768836) 2026-11-22 23:25 UTC ticket.facts area
- [768835](https://bounty.xe.network/log/768835) 2026-11-22 23:25 UTC proposal.adopted
- [768834](https://bounty.xe.network/log/768834) 2026-11-22 23:25 UTC ticket.facts
- [768833](https://bounty.xe.network/log/768833) 2026-11-22 23:25 UTC proposal.adopted
- [768832](https://bounty.xe.network/log/768832) 2026-11-22 23:25 UTC ticket.facts
- [766611](https://bounty.xe.network/log/766611) 2026-11-22 23:17 UTC note.added

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

### Report

## Summary

MemStore's list methods iterate Go maps directly, so their result order is randomized per call; BadgerStore iterates keys lexicographically, so its order is deterministic. The same list query returns different orderings depending on the backend.

## Root cause

MemStore's `GetAllPending` (`store/mem_store.go:192-201`), `GetPendingByDest`, `GetAllLeases`, `GetLeasesByProvider`, `GetLeasesByState`, `GetAllConflicts`, `GetConflictsForAccount`, `GetVotesByConflict`, and `IterateDelegations` all iterate Go maps (`for _, x := range m.pending` / `m.leases` / `m.conflicts` ...). BadgerStore iterates keys in lexicographic order. Note the authors knew map order was a problem for pagination — `GetPendingPage` is explicitly sorted in MemStore — but the other list methods were not.

## Verification

Differential harness, 3 pendings, repeated reads across process runs:

- MemStore order varied read-to-read (`[hhh aaa mmm]`, then `[mmm hhh aaa]`, then `[aaa mmm hhh]`).
- BadgerStore always `[aaa hhh mmm]`.

## Impact

API list pagination unstable on MemStore (the same page request returns different items across calls); any order-dependent consumer diverges between backends; test nondeterminism.

## Note on related reports

Searched the MemStore-vs-BadgerStore reports (#652, #226, #8, #70, #498, #622, #572, #571, #591) — none of them cover list ordering.

## Suggested fix

Sort results in the MemStore list methods, as `GetPendingPage` already does.

### 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-16839 and says what differs; it is read like any other.
