Problem Statement. get_aggregates(token) iterates from 0 to KEY_PKG_IDX every call
and reconstructs total_committed, total_claimed, total_expired_cancelled from the
package list. For a deployment with hundreds of packages this is O(N) per read and cannot
be cached.
Why it matters. Dashboard latency and off-chain indexer costs both grow linearly.
Technical Context. lib.rs::get_aggregates reads the pidx index keys, then walks
Package status. A previous fix introduced per-package KEY_PKG_IDX mapping that
preserves enumeration but compounds the iteration cost.
Expected Outcome. Replace per-token i128 totals at status transitions and
get_aggregates returns them in constant time.
Acceptance Criteria.
- A new
KEY_TOTAL_COMMITTED: Map<Address, i128> mirrored after
KEY_TOTAL_LOCKED semantics.
- Mutations encapsulated in a helper
add_to_status_totals(env, token, status, amount).
- Bench:
get_aggregates constant time regardless of package count.
Implementation Notes. This can be coupled with #16 since both refactor storage access.
Files or modules likely to be affected. src/lib.rs, tests/invariants.rs (new).
Dependencies. #15 (invariant test), #16.
Difficulty. Medium
Estimated effort. M
Backlog item #18 from `docs/maintainer-issue-backlog.md.
Problem Statement.
get_aggregates(token)iterates from 0 toKEY_PKG_IDXevery calland reconstructs
total_committed,total_claimed,total_expired_cancelledfrom thepackage list. For a deployment with hundreds of packages this is O(N) per read and cannot
be cached.
Why it matters. Dashboard latency and off-chain indexer costs both grow linearly.
Technical Context.
lib.rs::get_aggregatesreads thepidxindex keys, then walksPackage status. A previous fix introduced per-package
KEY_PKG_IDXmapping thatpreserves enumeration but compounds the iteration cost.
Expected Outcome. Replace per-token
i128totals at status transitions andget_aggregatesreturns them in constant time.Acceptance Criteria.
KEY_TOTAL_COMMITTED: Map<Address, i128>mirrored afterKEY_TOTAL_LOCKEDsemantics.add_to_status_totals(env, token, status, amount).get_aggregatesconstant time regardless of package count.Implementation Notes. This can be coupled with #16 since both refactor storage access.
Files or modules likely to be affected.
src/lib.rs,tests/invariants.rs(new).Dependencies. #15 (invariant test), #16.
Difficulty. Medium
Estimated effort. M
Backlog item #18 from `docs/maintainer-issue-backlog.md.