Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #377 +/- ##
==========================================
+ Coverage 59.63% 59.87% +0.23%
==========================================
Files 25 25
Lines 4544 4558 +14
==========================================
+ Hits 2710 2729 +19
+ Misses 1834 1829 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
emma31-dev
left a comment
There was a problem hiding this comment.
Thanks for this!
The config-level fix is solid. Blocking wallet config --force from changing an existing wallet's network and surfacing a mismatch error that names the wallet and both networks is a real improvement, and the tests cover it well.
One thing though: my issue extends beyond the config/database layer. For wallet-scoped commands, the network should come from the loaded wallet (ctx.state.wallet.network()), but in some handlers it is still read from the top-level --network via ctx.network. For example create_dns_tx in src/handlers/dns/mod.rs, unspent in src/handlers/offline.rs, and wallet-scoped HWI in src/handlers/hwi.rs. If the top-level value is configured differently from the wallet's network, those commands can fail or use the wrong network even when config and the database agree. It currently works only because main.rs/repl.rs happen to build AppContext with runtime.network; that invariant is implicit and easy to break again.
So this PR fixes the config-side reproduction, but the ctx.network vs wallet.network() issue is still open. A good follow-up would be to use the wallet's network in those handlers (or remove the duplicated network from wallet contexts) and add a regression test that runs a wallet command with a different top-level --network. But personally i think that will need a separate PR.
Thanks for working on this part of it.
|
Thank you @emma31-dev for taking your time to take a look at my work, I hadn’t looked at that part because this PR was focused on the mismatch between config.toml and the wallet database, this was really a good catch. After checking the code, I believe you're right, because the wallet scope handlers read And I agree that this should be handled in a separate PR, I would be happy to work on it. |
1ec6700 to
340a74d
Compare
|
Thanks @emma31-dev, I’ve changed “Fixes #359” to “Related to #359” in both the PR description and the commit message, so merging won’t close the issue. I also rebased on master to resolve the |
emma31-dev
left a comment
There was a problem hiding this comment.
Thanks for the update. The config-level fix itself looks good: wallet config --force can no longer change an existing wallet’s network, and the mismatch error now names the wallet, both networks, and how to fix config.toml.
I ran the config tests on the current head (340a74d):
cargo test --features default --test cli test_configtest result: ok. 8 passed; 0 failed
A few things to tidy up before this merges.
Could you rebase this down to one commit? The four commits (help text, force guard, mismatch error, changelog) are one logical change and read better squashed.
Thank you.
340a74d to
4f0f845
Compare
|
Thank you @emma31-dev for the review, I have made the requested changes. |
@muawiya1 please include this fix as a commit. It is not large enough to be a separate PR. |
4f0f845 to
b823d0c
Compare
tvpeter
left a comment
There was a problem hiding this comment.
hi @muawiya1 ,
Thank you so much for continuing to work on this.
So for the comments on the error variant, since this is a binary app, we don't want to reinvent the wheel by defining new error types. We import them from the library and wrap it in the error enum and reuse it. So changing the error from Error: Generic error: Network mismatch: loaded regtest, expected signet to Wallet 'network_wallet' is configured for network 'regtest', and --force cannot change it to 'signet' improves users experience but the cost of doing that is not worth it (importing errors, matching the returned error and all).
Apologies for the multiple reviews.
Thank you.
Running `wallet config --force` without the original `--network` saved the default network (testnet) over the existing one. The config then no longer matched the wallet database, and the wallet failed to load with a generic error. - Reject a `--force` that would change an existing wallet's network - Clarify the wallet load error for a network mismatch Fixes bitcoindevkit#359
Wallet handlers read the network from a separate argument instead of the wallet. Take the network from `wallet.network()` and remove the argument. Fixes bitcoindevkit#359
b823d0c to
5010229
Compare
|
Thank you @tvpeter for taking the time to review this and for the detailed feedback. I have made the changes. |
Co-authored-by: Peter Tyonum <28492640+tvpeter@users.noreply.github.com>
|
Please squash into two commits. |
Description
Wallet commands other than
wallet configalready use the network saved inconfig.toml. The mismatch happens when that network differs from the one in the wallet database.One way to reproduce this is to run
wallet config --forcewithout the original--networkoption. When the defaulttestnetnetwork is used, it overwrites the saved network while the database keeps the original one.This PR:
wallet config --forcefrom changing an existing wallet's network, while still allowing updates to other settings.config.tomldoesn't match the wallet database.create_dns_tx,unspentand wallet HWI always use the wallet's network.Fixes #359
Notes to the reviewers
--networkremains a top-level option. Moving it is left for separate work.wallet config --forceuses the defaulttestnetnetwork for a wallet configured on another network, the command now fails instead of overwriting the saved network.--forcecannot repair an existing network mismatch.LoadWalletand itsFromimpl are gated behind either thesqliteorredbfeature because only persisted wallets load from a database.wallet.network()in their constructors, so the handlers didn't need to change.CHANGELOG.mdentry for thewallet config --forcefix.Checklists
All Submissions:
cargo fmtandcargo clippybefore committingBugfixes: