Skip to content

fix(store): avl to bptree#1270

Open
notJoon wants to merge 19 commits intomainfrom
refactor/avl-to-bptree
Open

fix(store): avl to bptree#1270
notJoon wants to merge 19 commits intomainfrom
refactor/avl-to-bptree

Conversation

@notJoon
Copy link
Copy Markdown
Member

@notJoon notJoon commented Apr 23, 2026

Summary by CodeRabbit

  • Infrastructure Improvements
    • Replaced many internal tree-backed storages with a new B+ tree-based implementation for improved performance and scalability.
  • Behavior
    • Consolidated snapshot/compaction and lookup helpers for more reliable historical queries and stricter cleanup checks; no public API changes expected.
  • Tests
    • Updated test suites and mocks to align with the new storage implementation.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

Warning

Rate limit exceeded

@dongwon8247 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 55 minutes and 37 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 55 minutes and 37 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c9bf83fb-37fb-4f72-9c26-de0998e2492b

📥 Commits

Reviewing files that changed from the base of the PR and between 33bb2a7 and abb490b.

📒 Files selected for processing (65)
  • contract/r/gnoswap/gov/governance/v1/governance_propose.gno
  • contract/r/gnoswap/gov/governance/v1/init.gno
  • contract/r/gnoswap/gov/governance/v1/instance.gno
  • contract/r/gnoswap/gov/governance/v1/parameter_registry.gno
  • contract/r/gnoswap/gov/staker/delegation_manager.gno
  • contract/r/gnoswap/gov/staker/store.gno
  • contract/r/gnoswap/gov/staker/store_test.gno
  • contract/r/gnoswap/gov/staker/types.gno
  • contract/r/gnoswap/gov/staker/v1/_mock_test.gno
  • contract/r/gnoswap/gov/staker/v1/getter.gno
  • contract/r/gnoswap/gov/staker/v1/init.gno
  • contract/r/gnoswap/launchpad/v1/init.gno
  • contract/r/gnoswap/pool/pool.gno
  • contract/r/gnoswap/position/v1/init.gno
  • contract/r/gnoswap/protocol_fee/store.gno
  • contract/r/gnoswap/referral/keeper.gno
  • contract/r/gnoswap/staker/pool.gno
  • contract/r/gnoswap/staker/v1/external_incentive.gno
  • contract/r/gnoswap/staker/v1/init.gno
  • contract/r/gnoswap/staker/v1/staker.gno
  • tests/integration/testdata/base/data_structure_gas_measurement.txtar
  • tests/integration/testdata/base/persistent_data_structure_benchmark.txtar
  • tests/integration/testdata/deploy.txtar
  • tests/integration/testdata/gov/governance/cancel_active_proposal_should_fail.txtar
  • tests/integration/testdata/gov/governance/collect_deposit_to_inactivated_project.txtar
  • tests/integration/testdata/gov/governance/create_community_pool_spend_proposal.txtar
  • tests/integration/testdata/gov/governance/create_invalid_parameter_change_proposal.txtar
  • tests/integration/testdata/gov/governance/create_parameter_change_proposal.txtar
  • tests/integration/testdata/gov/governance/create_proposal_with_invalid_params.txtar
  • tests/integration/testdata/gov/governance/create_text_proposal.txtar
  • tests/integration/testdata/gov/governance/execute_text_proposal_should_fail.txtar
  • tests/integration/testdata/gov/governance/execute_unfinished_proposal_should_fail.txtar
  • tests/integration/testdata/gov/staker/collect_reward_from_launchpad_invalid_caller.txtar
  • tests/integration/testdata/gov/staker/delegate_and_redelegate.txtar
  • tests/integration/testdata/gov/staker/delegate_and_undelegate.txtar
  • tests/integration/testdata/launchpad/collect_left_before_project_ended_should_fail.txtar
  • tests/integration/testdata/launchpad/collect_protocol_fee_failure.txtar
  • tests/integration/testdata/launchpad/create_new_launchpad_project.txtar
  • tests/integration/testdata/launchpad/deposit_gns_to_inactivated_project_should_fail.txtar
  • tests/integration/testdata/pool/create_pool_and_mint.txtar
  • tests/integration/testdata/pool/gnoswap_swap_wrapper_template.txtar
  • tests/integration/testdata/pool/swap_wugnot_gns_tokens.txtar
  • tests/integration/testdata/position/position_mint_with_gnot.txtar
  • tests/integration/testdata/position/reposition.txtar
  • tests/integration/testdata/position/stake_position.txtar
  • tests/integration/testdata/router/exact_in_single_swap_route.txtar
  • tests/integration/testdata/router/exact_in_swap_route.txtar
  • tests/integration/testdata/router/exact_out_swap_route.txtar
  • tests/integration/testdata/router/exact_out_swap_route_with_gnot.txtar
  • tests/integration/testdata/staker/collect_reward_immediately_after_stake_token.txtar
  • tests/integration/testdata/staker/end_non_existent_external_incentive_fail.txtar
  • tests/integration/testdata/staker/staker_create_external_incentive.txtar
  • tests/integration/testdata/upgradable/broken_version_recovery.txtar
  • tests/integration/testdata/upgradable/data_consistency_after_ugrade.txtar
  • tests/integration/testdata/upgradable/gov_staker_upgrade.txtar
  • tests/integration/testdata/upgradable/governance_upgrade.txtar
  • tests/integration/testdata/upgradable/initializer_security.txtar
  • tests/integration/testdata/upgradable/launchpad_upgrade.txtar
  • tests/integration/testdata/upgradable/pool_upgrade.txtar
  • tests/integration/testdata/upgradable/position_upgrade.txtar
  • tests/integration/testdata/upgradable/protocol_fee_upgrade.txtar
  • tests/integration/testdata/upgradable/rich_state_preservation.txtar
  • tests/integration/testdata/upgradable/router_upgrade.txtar
  • tests/integration/testdata/upgradable/staker_upgrade.txtar
  • tests/integration/testdata/upgradable/store_permission_enforcement.txtar

Walkthrough

Migrates persistent in-memory tree implementations from AVL (avl.Tree) to B+Tree (bptree.BPTree) across contracts, stores, mocks, tests and docs; updates imports, types, constructors, getters/setters, cast helpers, and introduces snapshot helpers (e.g., latestBefore, compactHistoryAtCutoff) used by staker/reward cleanup logic.

Changes

Cohort / File(s) Summary
Store core & cast helpers
contract/p/gnoswap/store/doc.gno, contract/p/gnoswap/store/kv_store.gno, contract/p/gnoswap/store/types.gno, contract/p/gnoswap/store/utils.gno, contract/p/gnoswap/store/*_test.gno
GetTree/castToTree docs, imports, casts and tests changed to target *bptree.BPTree (error messages and signatures updated).
Version manager
contract/p/gnoswap/version_manager/...
initializers/rotree imports and types switched to B+Tree (bptree.NewBPTree32() / rotree wrappers).
Governance (runtime & v1)
contract/r/gnoswap/gov/governance/..., contract/r/gnoswap/gov/governance/v1/...
All persisted governance trees migrated avl→bptree; public signatures, runtime casts, initializers and tests adjusted.
Gov-staker core, delegation & snapshots
contract/r/gnoswap/gov/staker/..., contract/r/gnoswap/gov/staker/v1/...
Broad avl→bptree migration for delegation stores, history and mocks; added/refactored helpers latestBefore and compactHistoryAtCutoff and updated snapshot/cleanup flows.
Staker reward & helper modules
contract/r/gnoswap/gov/staker/v1/reward_calculation_*.gno, contract/r/gnoswap/staker/...
Reward-calculation and related helpers now use B+Tree; duplicated reverse-iteration logic folded into latestBefore; some signatures simplified.
Launchpad
contract/r/gnoswap/launchpad/...
Projects, tier reward managers and deposits storage migrated to B+Tree; constructors, getters/setters and tests updated.
Pool & Position
contract/r/gnoswap/pool/..., contract/r/gnoswap/position/...
Pool ticks/positions and position stores use *bptree.BPTree; public types, cloning, init and tests updated.
Protocol fee & Referral
contract/r/gnoswap/protocol_fee/..., contract/r/gnoswap/referral/keeper.gno
Accumulator/history and referral last-op maps switched to bptree; getters/setters and tests updated.
Staker core types & wrappers
contract/r/gnoswap/staker/..., contract/r/gnoswap/staker/v1/...
UintTree and many staker wrappers now backed by bptree.BPTree; constructors and helper functions updated.
Mocks, tests & scenarios
contract/r/gnoswap/mock/..., contract/r/gnoswap/test/fuzz/_mock_test.gno, contract/r/scenario/..., tests/integration/testdata/deploy.txtar
All test mocks, helpers and scenario inits now construct/use bptree.NewBPTree32(); txtar startup package references updated.
Misc docs & minor comments
assorted README.md, doc.gno and inline comments across modules
Text/docs/comments updated to reflect B+Tree terminology where applicable.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(store): avl to bptree' directly summarizes the main change: migrating store implementation from AVL tree to B+Tree across the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/avl-to-bptree

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 and usage tips.

@notJoon notJoon marked this pull request as ready for review April 23, 2026 02:50
@notJoon notJoon changed the title test(store): avl to bptree fix(store): avl to bptree Apr 23, 2026
@dongwon8247
Copy link
Copy Markdown
Member

@notJoon

B+ Tree Strengths to Leverage

After migration, these patterns become cheaper — simplify any prior workarounds:

  1. Repeated GetByIndex → use IterateByOffset (O(1) per step via leaf linked list).
  2. Large-range Iterate / ReverseIterate → cache-friendly leaf walk; remove any bespoke descending-iteration code.

Check-1: Is NewBPTree32() the Right Default?

Fanout 32 is a starting point, not an answer. Rules of thumb:

  1. Keep 32 if size < ~32, workload is point-query dominant, or write churn is high.
  2. Bump to 64 / 128 for large trees (thousands+) or read-heavy range-scan workloads.
  3. Never go below 32 without a benchmark justifying it.

Check-2: Benchmark Validation

NewBPTree32() must be validated — not assumed — on hot-path / large trees:

  1. Target trees: governance (proposals, proposalUserVotingInfos, userProposals, configs), staker (userDelegations, rewardStates), plus any per-tx hot-path tree (pool ticks, position registries).
  2. Compare: vs. prior AVL implementation, realistic size and op mix, with gas measured.
  3. Sweep: at minimum fanout 32 vs. 64 (and 128 for the largest). Pick empirical winner.
  4. Default is provisional until benchmarks confirm — otherwise switch to NewBPTreeN(n) with the best observed value.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 11

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (6)
contract/r/gnoswap/gov/staker/v1/util_test.gno (1)

142-142: ⚠️ Potential issue | 🟡 Minor

Update stale AVL wording in the test comments.

These comments still describe AVL trees even though the fixtures now use B+Tree.

Proposed comment cleanup
-// TestUtil_getUint64FromTree tests retrieving uint64 from AVL tree
+// TestUtil_getUint64FromTree tests retrieving uint64 from B+Tree
@@
-// TestUtil_updateUint64InTree tests updating uint64 in AVL tree
+// TestUtil_updateUint64InTree tests updating uint64 in B+Tree
@@
-// TestUtil_getOrCreateInnerTree tests getting or creating inner AVL tree
+// TestUtil_getOrCreateInnerTree tests getting or creating inner B+Tree

Also applies to: 207-207, 301-301

contract/r/gnoswap/staker/v1/calculate_pool_position_reward.gno (1)

175-181: ⚠️ Potential issue | 🟡 Minor

Stale inline comment.

The comment at Line 176 still describes the value as a slice of incentive IDs, but the 2-level structure (per the PR-wide migration and the test setup in external_incentive_test.gno) stores a *bptree.BPTree keyed by poolPath[]string at each timestamp.

📝 Proposed fix
 	incentivesByTime.Iterate(startTime, endTime, func(_ int64, value any) bool {
-		// Value is a slice of incentive IDs (handles timestamp collisions)
+		// Value is a B+Tree keyed by poolPath → []string (handles same-timestamp, multi-pool incentives)
 		poolIncentiveIds, ok := value.(*bptree.BPTree)
contract/r/gnoswap/staker/v1/external_incentive_test.gno (1)

1006-1006: ⚠️ Potential issue | 🟡 Minor

Stale "AVL Tree" reference in comment.

After the migration this no longer refers to an AVL tree. Consider generalizing the comment (or just saying "set semantics").

📝 Proposed fix
-	// Verify it's only added once (AVL Tree property)
+	// Verify it's only added once (set semantics on underlying tree)
contract/p/gnoswap/version_manager/version_manager.gno (2)

168-173: ⚠️ Potential issue | 🟡 Minor

Stale "AVL tree" reference in doc comment.

The backing store is now a B+Tree; update the doc for accuracy.

📝 Proposed fix
-// GetInitializers returns the AVL tree containing all registered initializer functions.
+// GetInitializers returns the B+Tree containing all registered initializer functions.
 // Keys are package paths, values are initializer functions.
 // Useful for inspecting which versions are available.

243-245: ⚠️ Potential issue | 🟡 Minor

Stale "AVL tree" reference in doc comment.

Same as above — please update to reflect the B+Tree backing.

📝 Proposed fix
 // makeInitializerSafe creates a safe copy of an initializer function for read-only tree access.
-// This is used by GetInitializers to wrap the internal AVL tree in a read-only view,
+// This is used by GetInitializers to wrap the internal B+Tree in a read-only view,
 // preventing external modification of registered initializers.
contract/r/gnoswap/staker/v1/reward_calculation_types.gno (1)

68-85: ⚠️ Potential issue | 🟡 Minor

Update the UintTree doc comment to B+Tree.

Line 68 still says this wrapper is around an AVL tree, but the field and constructor now use *bptree.BPTree.

Proposed fix
-// UintTree is a wrapper around an AVL tree for storing block timestamps as strings.
+// UintTree is a wrapper around a B+Tree for storing block timestamps as strings.
🧹 Nitpick comments (6)
contract/r/gnoswap/staker/tree.gno (1)

11-28: Update the stale AVL wording in UintTree docs.

The implementation now wraps *bptree.BPTree, but the exported type comment still says “AVL tree.”

Documentation cleanup
-// UintTree is a wrapper around an AVL tree for storing block timestamps as strings.
+// UintTree is a wrapper around a B+Tree for storing block timestamps as strings.
contract/r/gnoswap/gov/staker/tree.gno (1)

11-28: Update the stale AVL wording in UintTree docs.

The implementation now wraps *bptree.BPTree, but the exported type comment still says “AVL tree.”

Documentation cleanup
-// UintTree is a wrapper around an AVL tree for storing block timestamps as strings.
+// UintTree is a wrapper around a B+Tree for storing block timestamps as strings.
contract/r/gnoswap/staker/pool.gno (1)

213-228: Refresh the Incentives field documentation.

Line 217 still documents the backing store as AVL, but Line 228 now uses *bptree.BPTree.

Documentation cleanup
-//   - incentives: AVL tree storing ExternalIncentive objects indexed by incentiveId
+//   - incentives: B+Tree storing ExternalIncentive objects indexed by incentiveId
contract/r/gnoswap/gov/staker/v1/util_test.gno (1)

345-345: Use the table’s expected panic message.

Line 345 hardcodes the B+Tree cast message, so future cases could set expectedPanicMessage and still assert the wrong value.

Proposed test cleanup
-				uassert.PanicsWithMessage(t, "failed to cast value to *bptree.BPTree: uint64", func() {
+				uassert.PanicsWithMessage(t, tc.expectedPanicMessage, func() {
contract/r/gnoswap/referral/keeper.gno (1)

14-19: Update stale doc comment referring to AVL.

The struct doc comment still says "using AVL tree storage" but the backing store is now *bptree.BPTree. Update to avoid misleading future readers.

📝 Proposed fix
-// keeper implements ReferralKeeper using AVL tree storage.
-// It includes rate limiting to prevent abuse.
+// keeper implements ReferralKeeper using B+Tree storage.
+// It includes rate limiting to prevent abuse.
 type keeper struct {
 	store   *bptree.BPTree // address(string) -> referral address(string)
 	lastOps *bptree.BPTree // address(string) -> last operation timestamp(int64)
 }
contract/r/gnoswap/protocol_fee/store.gno (1)

7-7: LGTM — KV-backed B+Tree migration is consistent across all four accumulators.

Note: the redundant s.kvStore.Set(StoreKey..., tree) at the end of each Set*Item method (e.g., lines 109, 157, 205, 253) is harmless since kvStore.GetTree returns a pointer and mutations already persist, but it’s preserved from the pre-migration shape and probably worth a follow-up cleanup in a separate PR rather than mixing in here.

Also applies to: 70-70, 73-73, 118-118, 121-121, 166-166, 169-169, 214-214, 217-217


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d8f54f57-5ba7-40d4-bebd-367275ca926d

📥 Commits

Reviewing files that changed from the base of the PR and between 7931e1a and 70b6b67.

📒 Files selected for processing (101)
  • contract/p/gnoswap/store/doc.gno
  • contract/p/gnoswap/store/kv_store.gno
  • contract/p/gnoswap/store/kv_store_test.gno
  • contract/p/gnoswap/store/types.gno
  • contract/p/gnoswap/store/utils.gno
  • contract/p/gnoswap/store/utils_test.gno
  • contract/p/gnoswap/version_manager/doc.gno
  • contract/p/gnoswap/version_manager/types.gno
  • contract/p/gnoswap/version_manager/version_manager.gno
  • contract/p/gnoswap/version_manager/version_manager_test.gno
  • contract/r/gnoswap/gov/governance/store.gno
  • contract/r/gnoswap/gov/governance/store_test.gno
  • contract/r/gnoswap/gov/governance/types.gno
  • contract/r/gnoswap/gov/governance/v1/_helper_test.gno
  • contract/r/gnoswap/gov/governance/v1/_mock_test.gno
  • contract/r/gnoswap/gov/governance/v1/governance_propose.gno
  • contract/r/gnoswap/gov/governance/v1/governance_snapshot_test.gno
  • contract/r/gnoswap/gov/governance/v1/governance_vote_test.gno
  • contract/r/gnoswap/gov/governance/v1/init.gno
  • contract/r/gnoswap/gov/governance/v1/instance.gno
  • contract/r/gnoswap/gov/governance/v1/parameter_registry.gno
  • contract/r/gnoswap/gov/staker/delegation_manager.gno
  • contract/r/gnoswap/gov/staker/delegation_manager_test.gno
  • contract/r/gnoswap/gov/staker/emission_reward_manager.gno
  • contract/r/gnoswap/gov/staker/launchpad_project_deposits.gno
  • contract/r/gnoswap/gov/staker/launchpad_project_deposits_test.gno
  • contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno
  • contract/r/gnoswap/gov/staker/protocol_fee_reward_manager_test.gno
  • contract/r/gnoswap/gov/staker/store.gno
  • contract/r/gnoswap/gov/staker/store_test.gno
  • contract/r/gnoswap/gov/staker/tree.gno
  • contract/r/gnoswap/gov/staker/types.gno
  • contract/r/gnoswap/gov/staker/v1/_mock_test.gno
  • contract/r/gnoswap/gov/staker/v1/getter.gno
  • contract/r/gnoswap/gov/staker/v1/init.gno
  • contract/r/gnoswap/gov/staker/v1/staker_delegate_test.gno
  • contract/r/gnoswap/gov/staker/v1/staker_delegation_snapshot.gno
  • contract/r/gnoswap/gov/staker/v1/staker_delegation_snapshot_cleanup_test.gno
  • contract/r/gnoswap/gov/staker/v1/staker_delegation_snapshot_test.gno
  • contract/r/gnoswap/gov/staker/v1/state.gno
  • contract/r/gnoswap/gov/staker/v1/state_delegation_history_test.gno
  • contract/r/gnoswap/gov/staker/v1/state_test.gno
  • contract/r/gnoswap/gov/staker/v1/util.gno
  • contract/r/gnoswap/gov/staker/v1/util_test.gno
  • contract/r/gnoswap/launchpad/getter_test.gno
  • contract/r/gnoswap/launchpad/reward_manager.gno
  • contract/r/gnoswap/launchpad/store.gno
  • contract/r/gnoswap/launchpad/store_test.gno
  • contract/r/gnoswap/launchpad/types.gno
  • contract/r/gnoswap/launchpad/v1/_helper_test.gno
  • contract/r/gnoswap/launchpad/v1/init.gno
  • contract/r/gnoswap/launchpad/v1/launchpad_project_test.gno
  • contract/r/gnoswap/launchpad/v1/launchpad_reward_test.gno
  • contract/r/gnoswap/launchpad/v1/reward_manager_test.gno
  • contract/r/gnoswap/mock/pool_store.gno
  • contract/r/gnoswap/mock/position_store.gno
  • contract/r/gnoswap/pool/getter_utils.gno
  • contract/r/gnoswap/pool/pool.gno
  • contract/r/gnoswap/pool/pool_test.gno
  • contract/r/gnoswap/pool/store.gno
  • contract/r/gnoswap/pool/store_test.gno
  • contract/r/gnoswap/pool/types.gno
  • contract/r/gnoswap/pool/v1/_helper_test.gno
  • contract/r/gnoswap/pool/v1/getter_test.gno
  • contract/r/gnoswap/pool/v1/init.gno
  • contract/r/gnoswap/pool/v1/swap_test.gno
  • contract/r/gnoswap/pool/v1/tick_test.gno
  • contract/r/gnoswap/position/store.gno
  • contract/r/gnoswap/position/store_test.gno
  • contract/r/gnoswap/position/types.gno
  • contract/r/gnoswap/position/v1/_mock_test.gno
  • contract/r/gnoswap/position/v1/init.gno
  • contract/r/gnoswap/protocol_fee/store.gno
  • contract/r/gnoswap/protocol_fee/types.gno
  • contract/r/gnoswap/protocol_fee/v1/_mock_test.gno
  • contract/r/gnoswap/protocol_fee/v1/protocol_fee_state.gno
  • contract/r/gnoswap/protocol_fee/v1/protocol_fee_state_test.gno
  • contract/r/gnoswap/referral/keeper.gno
  • contract/r/gnoswap/router/v1/_mock_test.gno
  • contract/r/gnoswap/staker/pool.gno
  • contract/r/gnoswap/staker/store.gno
  • contract/r/gnoswap/staker/store_test.gno
  • contract/r/gnoswap/staker/tree.gno
  • contract/r/gnoswap/staker/types.gno
  • contract/r/gnoswap/staker/v1/_mock_test.gno
  • contract/r/gnoswap/staker/v1/calculate_pool_position_reward.gno
  • contract/r/gnoswap/staker/v1/external_incentive.gno
  • contract/r/gnoswap/staker/v1/external_incentive_test.gno
  • contract/r/gnoswap/staker/v1/getter_test.gno
  • contract/r/gnoswap/staker/v1/init.gno
  • contract/r/gnoswap/staker/v1/reward_calculation_incentives.gno
  • contract/r/gnoswap/staker/v1/reward_calculation_pool.gno
  • contract/r/gnoswap/staker/v1/reward_calculation_pool_tier.gno
  • contract/r/gnoswap/staker/v1/reward_calculation_pool_tier_test.gno
  • contract/r/gnoswap/staker/v1/reward_calculation_tick.gno
  • contract/r/gnoswap/staker/v1/reward_calculation_types.gno
  • contract/r/gnoswap/staker/v1/staker.gno
  • contract/r/gnoswap/staker/v1/staker_test.gno
  • contract/r/gnoswap/test/fuzz/_mock_test.gno
  • contract/r/scenario/upgrade/implements/mock/gov/governance/test_impl.gno
  • contract/r/scenario/upgrade/implements/v3_valid/launchpad/init.gno

Comment thread contract/p/gnoswap/store/utils.gno
Comment thread contract/r/gnoswap/gov/governance/store.gno
Comment thread contract/r/gnoswap/gov/staker/delegation_manager_test.gno Outdated
Comment thread contract/r/gnoswap/gov/staker/delegation_manager.gno
Comment thread contract/r/gnoswap/gov/staker/store.gno Outdated
Comment thread contract/r/gnoswap/gov/staker/v1/staker_delegation_snapshot.gno
Comment thread contract/r/gnoswap/gov/staker/v1/staker_delegation_snapshot.gno
Comment thread contract/r/gnoswap/launchpad/store.gno
Comment thread contract/r/gnoswap/launchpad/v1/launchpad_project_test.gno Outdated
Comment thread contract/r/gnoswap/position/store.gno
notJoon and others added 11 commits April 23, 2026 12:03
Updates stale AVL references in comments, READMEs, and test annotations
that the earlier docs pass did not cover. Also corrects
setDistributionBpsPct comment, which described a map as an AVL tree.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
42 txtar files declared loadpkg gno.land/p/nt/avl/v0 but never reference
the package; the dependency became dead after the AVL→B+Tree migration.
The data_structure_gas_measurement fixture still uses avl and is left
alone since reworking it requires re-measuring gas values.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces avl.NewTree with bptree.NewBPTree32 and renames AVLxxx helpers
to BPTreexxx so the fixture reflects the current tree implementation.
B+Tree assertions use a 'GAS USED:' prefix placeholder; concrete values
must be re-measured (run the txtar and paste the new gas numbers back).
Map, slice, and struct assertions are unchanged since none of them touch
the tree package.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Fills in B+Tree gas placeholders and refreshes every other entry with
values captured by running the txtar through gno.land/pkg/integration.
Map, slice, and struct measurements also shifted (unrelated to the tree
swap — they track gno VM gas accounting as it stands today), so every
expectation is re-blessed in the same pass.

Observations worth keeping in mind:
- B+Tree Insert/Get at 1000 items cost ~148M gas, roughly 5x the Map
  equivalent (~31M). Confirms Map stays preferable for pure point-query
  workloads where stable key-ordering is not needed.
- B+Tree Iterate 100 cost ~14.4M vs Map Iterate 100 at ~2.8M, so the
  linked-list leaf walk still carries real overhead at this size; the
  ordered-iteration benefit only pays off where ordering is required.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extends the data_structure benchmark to measure B+Tree at fanout 32/64/128
side by side so the Phase 2-4 tuning work has a concrete reference for
"does raising fanout actually help this workload". All 49 GAS USED values
are deterministic (re-verified with a second run).

Key findings recorded in the fixture header:
- N=10:   fanout has no effect (tree fits in a single leaf)
- N=100:  64 ≈ -8% vs 32, 128 ≈ -16% vs 32  (largest win range)
- N=1000: 64 ≈ -8% vs 32, 128 ≈ -9% vs 32   (128 gain diminishes)

Guidance: 32→64 is a near-free ~8% for any tree past a single leaf;
64→128 mostly pays off at the 100-ish item range. Small trees (N<32)
stay on 32.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@dongwon8247 dongwon8247 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add more commits to open discussions on optimizing data types. please wait.

dongwon and others added 2 commits April 25, 2026 12:06
…timization targets

Add persistent_data_structure_benchmark.txtar measuring per-operation
gas on realm-persisted state with realistic struct values (8 fields,
~200 bytes).  This is the authoritative evidence for BPTree vs Map
decisions — the previous ephemeral benchmarks overstated Map's
advantage by not accounting for serialization/deserialization cost.

Key findings from persistent benchmark:
- N<200: Map wins for Get (2.8x), Set (1.6x), and Add (1.7x)
- N>=500: BPTree wins for Get (2.0x), Set (3.2x), and Add (3.0x)
- Incremental add (the actual init pattern) follows the same crossover
- Fanout 64 saves ~4% over 32 at N>=1000

Annotate 16 BPTree instances across 12 modules with TODO comments
citing benchmark evidence:
- 6 trees (N<200, no Iterate): recommend map conversion
- 10 trees (N>=1000): recommend fanout 32→64 upgrade

Also clarify the purpose header of data_structure_gas_measurement.txtar
to distinguish it from the persistent benchmark (ephemeral fanout sweep
vs authoritative decision reference).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Dongwon <74406335+dongwon8247@users.noreply.github.com>
@dongwon8247
Copy link
Copy Markdown
Member

Can you check 3b08f75 to see if it's worth changing the data type? @notJoon @junghoon-vans @jinoosss

The RBAC validator functions (updatableRoleNameValidator,
removableRoleNameValidator) reference prbac.ROLE_ADMIN and
prbac.IsSystemRole but the import was missing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

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.

3 participants