Skip to content

Maintain incremental running totals for aggregates #226

Closed

Description

@kilodesodiq-arch

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.

Activity

  1. Clement-coder commented on Jul 20, 2026

    @Clement-coder

    Hi,

    I’m a full-stack software and blockchain engineer with hands-on experience delivering production-ready solutions across frontend, backend, and blockchain systems.

    I’d like to take ownership of this issue. I’ve reviewed the requirements and can implement a scalable, maintainable, and well-tested solution that fully satisfies the acceptance criteria.

    Ready to start immediately and keep the team updated throughout the process.

  2. Moonwalker-rgb commented on Jul 23, 2026

    @Moonwalker-rgb
    Contributor

    Hi maintainer,

    I would like to request assignment for this smart contract performance ticket to optimize get_aggregates.I will introduce KEY_TOTAL_COMMITTED (along with mirrored totals) and encapsulate state mutations in an add_to_status_totals helper to track totals at status transitions. This will replace the linear $O(N)$ package iteration with $O(1)$ constant-time reads for dashboards and indexers, and add invariant tests in tests/invariants.rs.Please assign this to me so I can improve the contract's scalability and read performance.

  3. grantfox-oss commented on Jul 23, 2026

    @grantfox-oss

    🦊 GrantFox — @Moonwalker-rgb has been assigned to this issue as part of the Official Campaign | FWC26 campaign!

    Next steps:

    1. Open a Pull Request referencing this issue (e.g., Closes #226)
    2. Your PR will be reviewed by the ChainForgee maintainers

    Good luck! Track your progress on GrantFox.

  4. grantfox-oss commented on Jul 28, 2026

    @grantfox-oss

    🎉 This issue has been marked as completed on GrantFox as part of the Official Campaign | FWC26 campaign!

    @Moonwalker-rgb's PR #416 was approved and merged by @kilodesodiq-arch.

    🏆 @Moonwalker-rgb: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (557 total points). Track your full progress on GrantFox.

    👏 Great work, @Moonwalker-rgb! Keep contributing to ChainForgee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions