Skip to content

feat(key-wallet): address pools gap limit can be externally modified runtime - #822

Merged
xdustinface merged 1 commit into
devfrom
feat/set-gap-limit
Jun 25, 2026
Merged

xdustinface merged 1 commit into
devfrom
feat/set-gap-limit

Conversation

@ZocoLini

@ZocoLini ZocoLini commented Jun 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added support to increase an account’s address gap limit, automatically regenerating and returning newly generated addresses across all pools.
    • Gap limit inputs are capped to a safe maximum and applied consistently.
  • Bug Fixes
    • Address pools now expand reliably when the gap limit changes, with generated-range tracking kept current.
    • Monitoring revision is bumped when new addresses are generated, even if a later pool update fails.

@ZocoLini
ZocoLini requested a review from xdustinface June 24, 2026 11:18
@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b7fb0ecb-cf9f-45ed-95e3-1e830f3a8b57

📥 Commits

Reviewing files that changed from the base of the PR and between e5e170e and bbfa00b.

📒 Files selected for processing (2)
  • key-wallet/src/managed_account/address_pool.rs
  • key-wallet/src/managed_account/managed_account_trait.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • key-wallet/src/managed_account/address_pool.rs
  • key-wallet/src/managed_account/managed_account_trait.rs

📝 Walkthrough

Walkthrough

Adds a set_gap_limit method to AddressPool that clamps the new limit to MAX_GAP_LIMIT, updates the internal field, and returns addresses generated via maintain_gap_limit. A corresponding default method on ManagedAccountTrait applies this across all pools and bumps the monitor revision when new addresses are produced.

Changes

Gap Limit Widening Feature

Layer / File(s) Summary
AddressPool::set_gap_limit implementation and tests
key-wallet/src/managed_account/address_pool.rs
Adds set_gap_limit that caps input at MAX_GAP_LIMIT, updates self.gap_limit, and delegates to maintain_gap_limit. Unit test test_set_gap_limit_widens_and_generates verifies pool growth, highest_generated updates, and the cap enforcement.
ManagedAccountTrait::set_gap_limit orchestration
key-wallet/src/managed_account/managed_account_trait.rs
Adds a default trait method that iterates all address pools, calls the pool-level set_gap_limit, aggregates resulting AddressInfo, and calls bump_monitor_revision when the collection is non-empty.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hippity-hop, the gap grows wide,
New addresses spring up with pride!
A cap keeps the limit in check,
The monitor bumps — what the heck!
More addresses found, none gone to waste,
All generated at bunny pace! 🌟

🚥 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 matches the main change: adding runtime gap-limit updates for key-wallet address pools.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/set-gap-limit

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@key-wallet/src/managed_account/address_pool.rs`:
- Around line 889-896: The set_gap_limit path in address_pool::set_gap_limit
currently allows a zero gap_limit, which later causes underflow in
maintain_gap_limit when it computes self.gap_limit - 1. Clamp the input to a
minimum of 1 before storing it, while still respecting
crate::gap_limit::MAX_GAP_LIMIT, and keep the existing maintain_gap_limit call
so staged address generation remains bounded.

In `@key-wallet/src/managed_account/managed_account_trait.rs`:
- Around line 557-570: The set_gap_limit method in managed_account_trait can
leave monitor_revision stale if an earlier address pool is updated and a later
pool returns an error before bump_monitor_revision() runs. Change the flow in
set_gap_limit so revision tracking is updated atomically with the address-pool
mutations: either avoid partial updates by collecting results/errors before
returning, or ensure any successful state changes still trigger
bump_monitor_revision() even on failure. Use set_gap_limit and
bump_monitor_revision as the key points to adjust.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0bf6bc99-a210-4dd7-a21e-5ca11eb8c692

📥 Commits

Reviewing files that changed from the base of the PR and between d9fe0a3 and e5e170e.

📒 Files selected for processing (2)
  • key-wallet/src/managed_account/address_pool.rs
  • key-wallet/src/managed_account/managed_account_trait.rs

@codecov

codecov Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.14286% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.82%. Comparing base (d9fe0a3) to head (bbfa00b).

Files with missing lines Patch % Lines
...allet/src/managed_account/managed_account_trait.rs 0.00% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #822      +/-   ##
==========================================
- Coverage   73.04%   72.82%   -0.22%     
==========================================
  Files         323      323              
  Lines       72046    72095      +49     
==========================================
- Hits        52623    52505     -118     
- Misses      19423    19590     +167     
Flag Coverage Δ
core 76.74% <ø> (ø)
ffi 45.87% <ø> (-1.48%) ⬇️
rpc 20.00% <ø> (ø)
spv 90.27% <ø> (-0.04%) ⬇️
wallet 71.79% <57.14%> (-0.04%) ⬇️
Files with missing lines Coverage Δ
key-wallet/src/managed_account/address_pool.rs 67.10% <100.00%> (+1.25%) ⬆️
...allet/src/managed_account/managed_account_trait.rs 33.94% <0.00%> (-2.86%) ⬇️

... and 23 files with indirect coverage changes

@ZocoLini
ZocoLini force-pushed the feat/set-gap-limit branch from e5e170e to bbfa00b Compare June 25, 2026 11:54
@github-actions github-actions Bot added the ready-for-review CodeRabbit has approved this PR label Jun 25, 2026
@xdustinface
xdustinface merged commit 7262125 into dev Jun 25, 2026
38 checks passed
@xdustinface
xdustinface deleted the feat/set-gap-limit branch June 25, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review CodeRabbit has approved this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants