Skip to content

feat: [INFRA] Optimize Storage Architecture for State Archival Limits - #34

Merged
Queenode merged 4 commits into
Kolo-Org:mainfrom
Skinny001:storage-rent-optimization
Aug 22, 2026
Merged

feat: [INFRA] Optimize Storage Architecture for State Archival Limits#34
Queenode merged 4 commits into
Kolo-Org:mainfrom
Skinny001:storage-rent-optimization

Conversation

@Skinny001

Copy link
Copy Markdown
Contributor

This pull request refactors how member-related state is tracked and managed in the contract, consolidating multiple storage keys into a single MemberState struct per member. It also introduces a new cycle tracking mechanism for contributions and payouts, and allows for a configurable cycle length during initialization. Several test cases are updated to reflect the new initialization parameter.
Close #26
State Management Improvements

  • Introduced a MemberState struct to hold each member's total_contributions, last_contribution_cycle_id, and has_received_payout, replacing multiple scattered storage keys with a single entry per member (DataKey::Member). [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

  • All member-specific contribution and participation state is now accessed and updated through this struct, simplifying logic for contributions, withdrawals, and member removal. [1] [2] [3] [4] [5] [6] [7] [8]

Cycle and TTL Handling

  • Added CurrentCycleId and CycleLengthLedgers to the instance storage, enabling explicit cycle tracking and dynamic TTL calculation for both the contract and individual members. TTLs are now based on the number of members and the cycle length. [1] [2] [3] [4]

  • The contract increments CurrentCycleId at the end of each cycle, and contribution checks use this ID to determine if a member has already contributed in the current cycle. [1] [2]

Initialization and Configuration

Code Cleanup and Simplification

  • Removed obsolete storage keys such as Contributions, HasContributedThisCycle, and User, consolidating all relevant state into MemberState. [1] [2] [3] [4] [5] [6]

  • Updated TTL extension logic to use the new member and cycle-based TTL calculations for both the contract instance and individual members. [1] [2]

Test Updates

  • All contract tests are updated to pass the new expected_cycle_days parameter to the initialize method. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]…d O(1) cycle reset

  • Replace 3 persistent entries per member (Contributions, HasContributedThisCycle, HasReceivedPayout) with single MemberState struct under DataKey::Member(Address)

  • Add dynamic TTL: extend_instance_ttl() uses CycleLengthLedgers from init param (expected_cycle_days, default 30 days); extend_member_ttl() covers full rotation

  • O(1) reset_cycle() via CurrentCycleId increment instead of per-member iteration

  • All 19 tests pass, clippy clean, fmt clean, release build succeeds

…d O(1) cycle reset

- Replace 3 persistent entries per member (Contributions, HasContributedThisCycle, HasReceivedPayout)
  with single MemberState struct under DataKey::Member(Address)
- Add dynamic TTL: extend_instance_ttl() uses CycleLengthLedgers from init param
  (expected_cycle_days, default 30 days); extend_member_ttl() covers full rotation
- O(1) reset_cycle() via CurrentCycleId increment instead of per-member iteration
- All 19 tests pass, clippy clean, fmt clean, release build succeeds
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a8e61b70-7321-4acf-ab29-84c37c8fa492


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Queenode

Copy link
Copy Markdown
Contributor

Thank you for your contribution @Skinny001 , please fix conflict, it was as a result of the previously merged PR.

@Skinny001
Skinny001 force-pushed the storage-rent-optimization branch from ff81f87 to e15ffd0 Compare August 22, 2026 16:58
@Skinny001

Copy link
Copy Markdown
Contributor Author

Thank you for your contribution @Skinny001 , please fix conflict, it was as a result of the previously merged PR.

@Queenode all fixed

@Queenode

Copy link
Copy Markdown
Contributor

Thank you for your contribution @Skinny001

@Queenode
Queenode merged commit 4112eaf into Kolo-Org:main Aug 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[INFRA] Optimize Storage Architecture for State Archival Limits

2 participants