Skip to content

Optimize commitment_core::get_commitments_created_between to avoid scanning AllCommitmentIds #497

Description

@1nonlypiece

📌 Description

commitment_core::get_commitments_created_between (line ~735) answers time-range
analytics queries by scanning the DataKey::AllCommitmentIds vector, which grows
unbounded with every create_commitment. As the protocol scales, this linear scan
plus per-id storage reads becomes a costly, potentially limit-exceeding operation.

This issue introduces a time-bucketed index so range queries are bounded.

🎯 Requirements and Context

  • Maintain a time-bucketed index (e.g. per-day buckets of commitment IDs) updated on create_commitment.
  • get_commitments_created_between must read only the relevant buckets, not the global list.
  • Results must be identical to the current full-scan implementation (add an equivalence test).
  • Index writes must not regress create_commitment correctness or its reentrancy/fee paths.

🛠️ Suggested Execution

1. Fork the repo and create a branch

git checkout -b perf/core-time-bucket-index

2. Implement changes

  • Add the bucketed index key and update create_commitment + get_commitments_created_between in contracts/commitment_core/src/lib.rs with /// docs.
  • Record before/after costs in benchmarks/.

3. Test and commit

  • Extend contracts/commitment_core/src/tests.rs and benchmarks.rs.
  • Run: cargo test --target wasm32v1-none --release
  • Edge cases: empty range, single-bucket range, multi-bucket range, boundary timestamps, equivalence vs full scan.

Example commit message

perf: time-bucketed index for commitment range queries

✅ Guidelines

  • Minimum 95% test coverage on the indexed paths.
  • Document the equivalence guarantee and measured savings.
  • Timeframe: 96 hours.

🏷️ Labels

type-performance · area-contracts · MAYBE REWARDED · GRANTFOX OSS · OFFICIAL CAMPAIGN

💬 Community & Support

  • Join the CommitLabs contributor Discord to coordinate and get unblocked fast: https://discord.gg/WV7tdYkJk
  • Introduce yourself before starting to avoid duplicate work.
  • Maintainers triage actively and review fast.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions