Skip to content

Keep a refill's address reveals out of unrelated wallet persists - #1269

Open
shubhamkmr04 wants to merge 1 commit into
lightningdevkit:mainfrom
shubhamkmr04:address-pool-staged-reveals
Open

shubhamkmr04 wants to merge 1 commit into
lightningdevkit:mainfrom
shubhamkmr04:address-pool-staged-reveals

Conversation

@shubhamkmr04

Copy link
Copy Markdown
Contributor

Fixes #1213.

When the address pool's refill fails to write the pool record, it keeps the addresses it just revealed with the persister and skips flushing them, so no index becomes durable without record coverage. But it kept them in the pending change set that every other persist call flushes. A sync or transaction persist that succeeded next made them durable anyway, and after a restart those indices were never pooled or handed out again. Repeated with no deposit in between, the gap could grow past the full-scan stop gap, and a restore from seed would miss later funds.

Changes

  • KVStoreWalletPersister gets a separate staged_change_set. stage() now merges into it, and only persist_staged() moves it into the pending set, which the refill calls only after its record write succeeded. persist_changeset() flushes the pending set alone. This is the approach proposed in Unrelated wallet persists can flush address reveals the pool record does not cover #1213, with its names, adapted to current main.
  • The refill's comment no longer says an unrelated persist can still flush the reveals.

An aborted refill still loses nothing: its reveals stay staged for the next refill, or die with the process and are re-derived to the same indices.

Tests

Both fail without the fix. The existing pool tests, including aborting_a_refill_mid_persist_loses_no_reveals and pool_survives_a_crash_at_any_point_during_refill, still pass.

No CHANGELOG entry, as the address pool hasn't been released yet.

This change was developed with the assistance of Claude Code.

A failed pool-record write left the refill's address reveals in the persister's pending change set, which every other persist call flushes. An unrelated persist that succeeded next made them durable while no pool record covered them, so after a restart their indices were never pooled or handed out again, widening the gap a restore from seed must scan across.

Stage the refill's reveals in a change set of their own, which only `persist_staged` merges into the pending one, after the refill's record write succeeded. The fix and the persister-level test are the ones proposed in lightningdevkit#1213, adapted to current main.

Fixes lightningdevkit#1213.

Developed with assistance from Claude Code.
@ldk-reviews-bot

ldk-reviews-bot commented Dec 1, 2026 •

Copy link
Copy Markdown

I've assigned @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-reviews-bot
ldk-reviews-bot requested a review from tnull December 1, 2026 07:24
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.

Unrelated wallet persists can flush address reveals the pool record does not cover

2 participants