Repository navigation
Description
Describe the bug
In REPL mode, wallet changes are never written to the database. The non-REPL path calls wallet.persist() after every wallet command, but the REPL loop never does, and there is no Drop fallback.
The REPL does load a persisted wallet via runtime.build_wallet(true), so this is a missing write, not a no-database case. Affects both sqlite and redb, since both go through the same RuntimeWallet::persist() , which is only called from the two non-REPL sites. src/handlers/repl.rs also executes commands without persisting.
Consequence: everything done in a session is lost on exit , most visibly the address index, but also created/bumped txs, broadcast txs, UTXO lock state, and scan/sync results.
To Reproduce
On regtest with default features (repl, sqlite):
- Create a wallet with any datatype.
- Start
bdk-cli repl --wallet w, runwallet new_addresstwice → indicesn. - Exit and start the REPL again, run
wallet new_address→ indexnagain. - Control: run
bdk-cli --network regtest --datadir <dir> wallet --wallet w new_addresstwice in separate processes → indicesn,n+1(correctly persisted). - Running the REPL again after step 4 resumes at index
n+2, proving reads work and only REPL writes are missing.
Observed:
REPL run 1: new_address -> index 0, new_address -> index 1
REPL run 2 (fresh process): new_address -> index 0 <– rolled back
REPL run 3 (fresh process): new_address -> index 0 <– still rolled back
non-REPL: 0 then 1 (persisted); REPL then resumes at 2
Expected behavior
REPL commands should persist the wallet (at least after each successful command), so a new session resumes from the last state and new_address never reuses an address.
Build environment
- BDK-CLI tag/commit: 6579837 (
master, v4.0.0) - OS+version: macOS 12.7.6
- Rust/Cargo version: rustc 1.97.1, cargo 1.97.1
- Rust/Cargo target: x86_64-apple-darwin
Additional context
Suggested fix: persist after each successful REPL command rather than only on exit, so a crash or Ctrl-C doesn't lose the session either:
let should_exit = crate::handlers::repl::respond(
runtime.network,
&mut wallet,
/* ... */
&line,
runtime.home_dir.clone(),
/* ... */
&wallet_name,
)
.await
.map_err(Error::Generic)?;
wallet.persist()?;
if should_exit {
break;
}
Activity