Skip to content

fix(repl): persist wallet after each command - #376

Open
emma31-dev wants to merge 1 commit into
bitcoindevkit:masterfrom
emma31-dev:fix/repl-wallet-persist
Open

emma31-dev wants to merge 1 commit into
bitcoindevkit:masterfrom
emma31-dev:fix/repl-wallet-persist

Conversation

@emma31-dev

Copy link
Copy Markdown
Contributor

Fixes #375

Description

REPL mode loaded a persisted wallet, but the REPL loop never called wallet.persist(). The non-REPL path persists after every wallet command, so changes made inside the REPL were lost on exit.

This adds wallet.persist()? after every successful REPL command. Consequences of the bug this fixes:

  • wallet new_address rewound the address index each session, handing out already-used addresses
  • create_tx / bump_fee results disappeared from the tx graph
  • broadcast transactions were not recorded
  • lock_utxo / unlock_utxo state was lost
  • full_scan / sync results were discarded, so funds appeared missing until re-syncing

Notes to the reviewers

  • I persist after each command, not only on exit, so a crash or Ctrl-C doesn't discard the session either. Persisting an empty changeset is a no-op in BDK, so the extra calls are cheap.
  • Failed commands do not persist, matching the non-REPL path (cmd.execute(...)? skips the persist on error). Happy to change this if reviewers prefer persisting regardless.
  • The new test is gated on repl + sqlite (not repl + electrum like the existing repl_tests) so it runs under the default feature set. It spawns two separate REPL processes against the same datadir and asserts the address index advances 0 -> 1.
  • I confirmed the test fails on current master (0 vs 1) and passes with the fix.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

Bugfixes:

  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

The REPL loaded a persisted wallet but never called `wallet.persist()`, so
every change made in a session was lost on exit: the address index rewound
(reusing already handed-out addresses), and created or broadcast transactions,
UTXO locks and scan results disappeared.

Persist after each successful command, matching the non-REPL path, so the
state also survives a crash or Ctrl-C instead of only being flushed on exit.

Add a regression test that runs `wallet new_address` in two consecutive REPL
processes and asserts the address index advances.
@emma31-dev
emma31-dev force-pushed the fix/repl-wallet-persist branch from 11a6cb8 to 977a703 Compare November 14, 2026 19:55
@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.34%. Comparing base (eb9536d) to head (977a703).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #376   +/-   ##
=======================================
  Coverage   59.33%   59.34%           
=======================================
  Files          25       25           
  Lines        4562     4563    +1     
=======================================
+ Hits         2707     2708    +1     
  Misses       1855     1855           
Flag Coverage Δ
rust 59.34% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tvpeter tvpeter added this to the CLI 4.1.0 milestone Nov 18, 2026
@tvpeter tvpeter moved this from Todo to Ready to Review in BDK-CLI Nov 18, 2026
@muawiya1

Copy link
Copy Markdown

tACK 977a703

The new test fails on master’s src/main.rs and passes on this PR branch.

I also tested it manually. On master, I ran wallet new_address twice in the REPL, exited, and did it again. The second session started back from index 0 and gave me the same addresses. On this PR branch, the second session continued from index 2 with new addresses, so the index is now saved between sessions.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready to Review

Development

Successfully merging this pull request may close these issues.

REPL mode never persists wallet changes in the REPL loop

3 participants