Skip to content

clightning, mempool: connect to bitcoind as their own RPC users - #277

Merged
prusnak merged 2 commits into
bitcoinix:masterfrom
ostermayer:bitcoind-rpc-user-per-service
Nov 18, 2026
Merged

prusnak merged 2 commits into
bitcoinix:masterfrom
ostermayer:bitcoind-rpc-user-per-service

Conversation

@ostermayer

@ostermayer ostermayer commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #127.

clightning added getblockfrompeer and mempool added gettxoutsetinfo to the whitelist of
the shared public RPC user. rpcwhitelist is a list option, so the module system merged
both into one list for public, and every service that connects as public got them. With
mempool enabled, electrs, fulcrum and lnd could call gettxoutsetinfo, which walks the whole
UTXO set and can keep bitcoind busy for minutes. BTCPay's user builds on the public list, so
it got gettxoutsetinfo too. The comment in bitcoind-rpc-public-whitelist.nix said each
module grants these methods to itself, which only btcpayserver did.

This PR gives clightning and mempool their own RPC users, as btcpayserver has:

  • clightning: the public whitelist plus getblockfrompeer when bcli is the backend. With
    trustedcoin, it's the public whitelist alone.
  • mempool: the public whitelist plus gettxoutsetinfo.
  • An empty rpcwhitelist disables whitelisting for its user. So when the public
    whitelist is empty, both new whitelists stay empty too, and the services keep the
    unrestricted access they had through public.
  • Each user gets its own generated password and HMAC (bitcoin-rpcpassword-<user>,
    bitcoin-HMAC-<user>), owned like the btcpayserver ones.
  • clightning and mempool connect as their new users and leave the bitcoinrpc-public
    group, since they no longer read its password.
  • The public user keeps only the base whitelist. BTCPay's whitelist is now the base list
    plus getblockfrompeer, which is what nbxplorer probes for. It never needed
    gettxoutsetinfo.

The pinned trustedcoin 0.8.7 reads bitcoin-rpcuser and bitcoin-rpcpassword from
lightningd and calls getblockchaininfo, getblockhash, getblock, getrawtransaction,
estimatesmartfee and sendrawtransaction. All of them are in the base list, so it keeps
working with the clightning user. It still logs that password at startup (#191), but now
it's the password of the clightning user, not the one that electrs, fulcrum and lnd share.
The other clightning plugins don't talk to bitcoind.

Migration

A 0.2.0 notice fires for every config that enables clightning or mempool. No option
marks a bitcoind on another node, since the bitcoind-remote.nix preset only changes the
bitcoind unit. And configs that supply their own secrets have to act either way. So the
text depends on the config instead. With nix-bitcoin.generateSecrets, it says there's
nothing else to do when bitcoind runs on the node. Otherwise it says to create the new secrets first.
For a bitcoind on another node, it lists the whitelists to set there. It also says to
remove getblockfrompeer and gettxoutsetinfo from the remote public user if it has
them, whatever the new config enables, since the old config may have added them. With
BTCPay Server, it says to set the remote BTCPay user's whitelist again, since that list
builds on the public one and had gettxoutsetinfo with mempool.

The released 0.1.5 notice for mempool's RPC password told users to save the password
to bitcoin-rpcpassword-public. Notices are evaluated against the current code, which
reads bitcoin-rpcpassword-mempool, so it now names that file. So does the 0.1.5 section
of docs/upgrading.md, which also says that releases before 0.2.0 read
bitcoin-rpcpassword-public.

docs/upgrading.md says what each setup has to do. The guide for a bitcoind on another
node in docs/configuration.md now lists the new users, their whitelists, their
password files, and the local HMAC files that setup checks.

The migration tests for the currencyrate and rebalance plugins and for mempool's RPC
password stay as master has them. Once 0.2.0 is released, later notices block every
older config there, so a new test checks the 0.1.5 notices by their message.

Testing

  • test/configuration.nix: new checks that public has neither method, clightning and
    btcpayserver have only getblockfrompeer, mempool has only gettxoutsetinfo, and
    clightning with trustedcoin has neither. With an empty public whitelist, both new
    whitelists are empty. Also that both services read their own
    password and aren't in bitcoinrpc-public, and what the notice says for which config,
    including the remote public and BTCPay whitelists.
  • test/suite/security.py, test rpc-whitelist: public can't call either method, and
    each service user can call only its own. Before this change, public could call
    gettxoutsetinfo in the regtest scenario.
  • module-config and test-runner checks pass, and the mdBook build succeeds.
  • regtest scenario passes. The bitcoind log shows public refused
    gettxoutsetinfo and getblockfrompeer, mempool refused getblockfrompeer, and
    clightning and btcpayserver refused gettxoutsetinfo.
  • trustedcoin scenario fails, as it does on master 772846d. trustedcoin logs
    bitcoind RPC working as user clightning, and rpc-whitelist passes: clightning
    is refused getblockfrompeer and gettxoutsetinfo. The failure is a startup race in
    trustedcoin, unrelated to this change. When clightning restarts right after bitcoind,
    lightningd asks for the chain tip before trustedcoin's OnInit has set up its
    bitcoind client. trustedcoin then falls back to block explorers, which the VM can't
    reach, returns tip: 0, and lightningd exits with bitcoind has gone backwards.
    The start then hangs in clightning's postStart until it times out.
  • After the rebase onto master c3d955c (Keep unreleased migration notices visible on master #283), module-config, test-runner, ci-workflows, regtest and trustedcoin pass on the KVM host. acknowledged replaces current, because master now rejects config version 0.2.0 before the release. It checks that a config at 0.2.0 doesn't get the notice once 0.2.0 is released. On master, the notice is a warning until 0.2.0 is released, and the tests pass with version.nix at 0.1.6 and at 0.2.0. Deleting a 0.1.5 notice fails testMigrationNotices015 with version.nix at 0.1.6 and at 0.2.0.

Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra (two passes plus rechecks), Kimi K3.1 Pro (two passes), DeepSeek V4.1 Flash 1017 and GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224 and #283. Kimi K3.1 Pro (two passes) and Claude Fable 5.2 reviewed both rebases.

@github-actions github-actions Bot added area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix type: feature New capability or service labels Nov 16, 2026

@viberaven viberaven left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1c0796fe84c4.

No actionable findings. Traced both new RPC users through generated usernames, passwords/HMACs, secret permissions, service group removal, and bitcoind whitelist construction. The shared public whitelist loses the service-specific methods, and the empty-whitelist override retains its documented meaning. The migration guidance covers generated, supplied, and remote-node credentials and removal of the old remote grants. Local module-config and mdBook builds pass. I inspected the per-user RPC assertions and successful CI results; I did not rerun the service VMs locally.

Review performed with Codex (GPT-6 Astra).

@github-actions github-actions Bot added the status: rebase needed Merge conflicts need to be resolved label Nov 16, 2026
@ostermayer
ostermayer force-pushed the bitcoind-rpc-user-per-service branch from 1c0796f to 28301ae Compare November 18, 2026 00:19
clightning added getblockfrompeer and mempool added gettxoutsetinfo to the
whitelist of the `public` RPC user. `rpcwhitelist` is a list option, so the
module system merged both into one list, and every service that connects as
`public` got them. With mempool enabled, electrs, fulcrum and lnd could call
gettxoutsetinfo, which walks the whole UTXO set and can keep bitcoind busy for
minutes. BTCPay's user builds on the public list, so it got gettxoutsetinfo too.

Give clightning and mempool their own RPC users, as btcpayserver has, with the
public whitelist plus the method that each of them calls. An empty public
whitelist disables whitelisting, so their whitelists stay empty then too. Each
user gets its own generated password and HMAC. The public user keeps only the
base whitelist.
The two services leave the bitcoinrpc-public group, since they no longer read
its password.

Setups that supply secrets themselves have to create the secrets of the new
users, and setups with bitcoind on another node also the users there. So add
a 0.2.0 notice for every config with clightning or mempool. Document the new
users in the guide for a bitcoind on another node. The 0.1.5 notice for
mempool's RPC password is evaluated against the current code, so point it and
its upgrade notes at `bitcoin-rpcpassword-mempool`. A new test checks the
0.1.5 notices by their message, since later notices block every older config
once 0.2.0 is released.

Fixes bitcoinix#127.

Assisted-by: Claude Code (Claude Opus 5.5)
@ostermayer
ostermayer force-pushed the bitcoind-rpc-user-per-service branch from 28301ae to d422ca9 Compare November 18, 2026 01:01
@github-actions github-actions Bot added status: rebase needed Merge conflicts need to be resolved and removed status: rebase needed Merge conflicts need to be resolved labels Nov 18, 2026
@prusnak prusnak added this to the v0.2.0 milestone Nov 18, 2026
prusnak
prusnak previously approved these changes Nov 18, 2026
@github-actions github-actions Bot removed the status: rebase needed Merge conflicts need to be resolved label Nov 18, 2026
@prusnak
prusnak merged commit ede362d into bitcoinix:master Nov 18, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix type: feature New capability or service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clightning, mempool: per-service RPC grants widen the shared public bitcoind user for every consumer

3 participants