Skip to content

Make wallet network immutable after creation, or document and validate it explicitly #359

Done

Description

@emma31-dev

Describe the enhancement

The --network flag is a top-level option on every command, which makes it look like a per-invocation choice. In reality the network is fixed at wallet create and stored in the wallet config. Passing a different value later fails with Error: Generic error: Network mismatch: loaded testnet, expected testnet4, which does not explain why. Either the flag should be ignored on non-creation commands (network read from config), or the mismatch should be caught early with a clear message naming the wallet's stored network and suggesting the fix.

Use case

Descriptors only distinguish mainnet from non-mainnet (xpub vs tpub). Testnet, testnet4, signet, and regtest all share tpub, so the network genuinely cannot be inferred from the descriptor and has to be stored and validated separately so the current check is correct, only the UX is wrong. A user who created a wallet on one network and later types a different --network out of habit, or omits the flag entirely if it has a default, gets an opaque error that reads like a descriptor problem. A specific message for example: This wallet was created for network 'testnet'; remove --network or pass --network testnet turns a confusing failure into a one-line fix. Ignoring the flag on non-creation commands would be cleaner still, since the value is not actually a choice at that point.

Additional context

The flag is defined on CliOpts and flows into every subcommand, so nothing at the definition site signals that it is creation-time-only. At minimum, the --network help text should note that on non-creation commands it must match the wallet's stored network. The generic wrapping in Error::Generic is what hides the cause: the underlying check knows both the stored network and the requested one, but that information never reaches the user.

Activity

  1. added
    enhancement
    on Oct 18, 2026
  2. emma31-dev commented on Oct 22, 2026

    @emma31-dev
    ContributorAuthor

    Here is my Proposed approach:

    • Remove the top-level --network option. Add it to the commands that use it: wallet config, key, and descriptor, plus the feature-gated silent_payment_code and resolve_dns_recipient commands. Normal wallet commands and the REPL will continue using the network stored in the wallet config.

    • Add a shared mainnet-warning helper. Call it when configuring a wallet and when loading one for wallet operations, using the wallet’s actual configured network. Commands that don’t use a wallet won’t emit this warning.

    • Keep --force for overwriting other wallet configuration, but reject attempts to change an existing wallet’s network. The error will identify the wallet and suggest using a new wallet name for a different network. Keep the persisted-wallet network check and make its error actionable for existing mismatches.

  3. muawiya1 commented on Nov 2, 2026

    @muawiya1
    Contributor

    Hi @emma31-dev I have a different proposal for this issue.

    1. Keep the top-level --network option for now, but explain in the help text that normal wallet commands use the network saved in the wallet configuration.
    2. Prevent wallet config --force from changing an existing wallet's network while still allowing updates to other settings.
    3. Improve the network mismatch error to show the wallet name, the network in its database, and the network in config.toml with guidance on what to correct.

    I think this would address the mismatch without changing how users currently run the commands. Moving--network could then be handled separately.

  4. emma31-dev commented on Nov 2, 2026

    @emma31-dev
    ContributorAuthor

    @muawiya1 I agree that the change will create more friction for users so I think it should rather be documented and a clear error is emitted during the mismatch.

  5. muawiya1 commented on Nov 3, 2026

    @muawiya1
    Contributor

    Can I take on this issue using my proposed approach, keeping --network where it is, documenting its behaviour and improving the error message when the networks do not match?

  6. emma31-dev commented on Nov 3, 2026

    @emma31-dev
    ContributorAuthor

    @muawiya1 sure you can work on it then tag me to it so I review later.

  7. moved this from Todo to In Progress in BDK-CLIon Nov 8, 2026
  8. vadim-anfv commented on Nov 8, 2026

    @vadim-anfv
    Collaborator

    Thanks @emma31-dev, good catch.

    @muawiya1 I see #377, it is in my review queue.

  9. added 3 commits that reference this issue on Nov 16, 2026
    e6707ca
    346de54
    4f0f845
  10. added this to the CLI 4.1.0 milestone on Nov 18, 2026
  11. moved this from In Progress to Done in BDK-CLIon Nov 24, 2026
  12. added a commit that references this issue on Nov 24, 2026
    6106144
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions