Skip to content

wallet: avoid global access in external signer SPKM - #35429

Open
w0xlt wants to merge 2 commits into
bitcoin:masterfrom
w0xlt:wallet-external-signer-no-globals
Open

w0xlt wants to merge 2 commits into
bitcoin:masterfrom
w0xlt:wallet-external-signer-no-globals

Conversation

@w0xlt

@w0xlt w0xlt commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

This PR removes direct access to process-wide state from ExternalSignerScriptPubKeyMan.

Instead of reading gArgs/Params() from the SPKM, the wallet load/setup path now reads the external signer command and chain once, stores them on CWallet, and passes the narrow values into the external signer SPKM.

This keeps argument and chain selection at the wallet boundary and makes the SPKM less coupled to global state.

@DrahtBot DrahtBot added the Wallet label Jun 1, 2026
@DrahtBot

DrahtBot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36990 (test: replace hard-coded RPC error codes by l0rinc)
  • #35444 (wallet: make descriptor SPKM mutex non-recursive by w0xlt)
  • #33112 (wallet: relax external_signer flag constraints by Sjors)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@sedited

sedited commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Ping for rebase @w0xlt

@sedited

sedited commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Are you still working on this?

w0xlt added 2 commits November 2, 2026 12:37
ExternalSignerScriptPubKeyMan::GetExternalSigner() reached into global state
(gArgs for -signer, Params() for the chain type) from deep inside the signing
and descriptor-setup paths.

Capture both in LoadWalletArgs -- where the wallet already reads its other
settings from the injected WalletContext -- store them on CWallet, and pass
them to ExternalSignerScriptPubKeyMan through its LoadFromStorage() and
CreateNew() factories. GetExternalSigner() now takes the command and chain as
parameters.

When -signer is unset the command is empty and the same "restart bitcoind
with -signer" error is returned. The chain string comes from the same
ArgsManager that Params() is selected from at startup.

-signer is now read when the wallet is loaded rather than each time a signer
is used, so a value changed at runtime (e.g. via the GUI options dialog,
which already requires a restart) only applies to wallets loaded afterwards.
This matches the other wallet options read in LoadWalletArgs.
Add unit tests asserting that:
- GetExternalSigner() with an empty command returns the "needs -signer"
  error before any external process is launched.
- LoadWalletArgs captures -signer and the chain from the wallet's
  injected ArgsManager. The chain is set to differ from the global
  Params(), so reading it from globals would fail the test.

In wallet_signer.py, check the debug log when spending from a wallet
loaded with a disconnected signer. A missing signer and an empty -signer
command both surface as the same "External signer not found" RPC error,
so the log message is what shows that the configured command reached
the loaded wallet's ScriptPubKeyMan.
@w0xlt
w0xlt force-pushed the wallet-external-signer-no-globals branch from c0dc4d5 to d28c185 Compare November 2, 2026 21:29
@w0xlt

w0xlt commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@sedited Still on it, thanks for the ping!
Rebased, conflicts resolved, and tests strengthened. Ready for review.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants