rpc: inform if privatebroadcast is enabled in getnetworkinfo #35267

pull polespinasa wants to merge 3 commits into bitcoin:master from polespinasa:2026-05-11-getprivatetransactioninfoonlyifenabled changing 5 files +16 −1
  1. polespinasa commented at 10:10 PM on May 11, 2026: member

    Adds a new return key to getnetworkinfo that informs if privatebroadcast is being used.

    This is motivated by: https://github.com/sparrowwallet/sparrow/issues/1989

    Knowing if privatebroadcast is set can be useful for some external software like Sparrow to avoid call getprivatebroadcastinfo each time to see if broadcast was done through that.

    sliv3r@sliv3r-tuxedo:~/Documentos/Projectes/BitcoinCore/bitcoin$ ./build/bin/bitcoin-cli --testnet4 getnetworkinfo
    {
      "version": 319900,
      "subversion": "/Satoshi:31.99.0/",
      ...
      "localrelay": true,
      "privatebroadcast": "disabled",
      "timeoffset": 0,
    ...
    }
    sliv3r@sliv3r-tuxedo:~/Documentos/Projectes/BitcoinCore/bitcoin$ ./build/bin/bitcoin-cli --testnet4 getnetworkinfo
    {
      "version": 319900,
      "subversion": "/Satoshi:31.99.0/",
      ...
      "localrelay": true,
      "privatebroadcast": "enabled",
      "timeoffset": 0,
      ...
    }
    
  2. DrahtBot added the label RPC/REST/ZMQ on May 11, 2026
  3. DrahtBot commented at 10:10 PM on May 11, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35267.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK andrewtoth, w0xlt
    Approach ACK stickies-v

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34628 (p2p: Replace per-peer transaction rate-limiting with global rate limits by ajtowns)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. polespinasa force-pushed on May 11, 2026
  5. DrahtBot added the label CI failed on May 11, 2026
  6. DrahtBot commented at 10:25 PM on May 11, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task lint: https://github.com/bitcoin/bitcoin/actions/runs/25700308615/job/75458691350</sub> <sub>LLM reason (✨ experimental): CI failed due to a lint error: missing required trailing newline in doc/release-notes-35267.md (lint check trailing_newline).</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  7. in test/functional/p2p_private_broadcast.py:349 in d68687e981


    andrewtoth commented at 10:27 PM on May 11, 2026:

    We already call getprivatebroadcastinfo() here for the tx_originator, so we can assert it's True here instead of duplicating the call for it below.


    polespinasa commented at 10:37 PM on May 11, 2026:

    done


    polespinasa commented at 2:24 PM on May 12, 2026:

    I've reverted this change and moved back where it was inspired by your other comment. That's a function called multiple times, there is no need to perform that check each time it is called.


    stickies-v commented at 7:23 AM on May 14, 2026:

    It doesn't seem straightforward to verify that this change to NetTest doesn't potentially cause issues to other tests that use this class. I think it'd be better to keep this self contained?


    polespinasa commented at 9:05 AM on May 14, 2026:

    The only approach that I can imagine while containing the test inside test_getnetworkinfo() is this, but I don't really like it:

    $ git diff
    diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py
    index 1a4d1b44ff..9acfe8ef83 100755
    --- a/test/functional/rpc_net.py
    +++ b/test/functional/rpc_net.py
    @@ -24,6 +24,7 @@ from test_framework.util import (
         assert_greater_than,
         assert_raises_rpc_error,
         p2p_port,
    +    write_config,
     )
     from test_framework.wallet import MiniWallet
     
    @@ -64,16 +65,12 @@ class NetTest(BitcoinTestFramework):
             self.num_nodes = 2
             self.extra_args = [
                 ["-minrelaytxfee=0.00001000"],
    -            [
    -                "-minrelaytxfee=0.00000500",
    -                "-privatebroadcast",
    -            ],
    +            ["-minrelaytxfee=0.00000500"],
             ]
             # Specify a non-working proxy to make sure no actual connections to public IPs are attempted
             for args in self.extra_args:
                 args.append("-proxy=127.0.0.1:1")
             self.supports_cli = False
    -        self.disable_autoconnect = False
     
         def run_test(self):
             # We need miniwallet to make a transaction
    @@ -218,7 +215,17 @@ class NetTest(BitcoinTestFramework):
             assert_equal(info['connections_in'], 1)
             assert_equal(info['connections_out'], 1)
             assert_equal(info['privatebroadcast'], "disabled")
    +
    +        # Temporarily rewrite node 1's config without connect=0 so that
    +        # -privatebroadcast (which is incompatible with -connect) can be tested.
    +        write_config(self.nodes[1].datadir_path / "bitcoin.conf", n=1, chain=self.chain, disable_autoconnect=False)
    +        self.restart_node(1, extra_args=["-minrelaytxfee=0.00000500", "-proxy=127.0.0.1:1", "-privatebroadcast"])
             assert_equal(self.nodes[1].getnetworkinfo()['privatebroadcast'], "enabled")
    +        write_config(self.nodes[1].datadir_path / "bitcoin.conf", n=1, chain=self.chain, extra_config="bind=127.0.0.1\n")
    +        self.restart_node(1, extra_args=self.extra_args[1])
    +        self.connect_nodes(0, 1)
    +        self.sync_all()
     
             with self.nodes[0].assert_debug_log(expected_msgs=['SetNetworkActive: false\n']):
                 self.nodes[0].setnetworkactive(state=False)
    
    
  8. in src/rpc/mempool.cpp:151 in d68687e981
     147 | @@ -148,6 +148,7 @@ static RPCMethod getprivatebroadcastinfo()
     148 |          RPCResult{
     149 |              RPCResult::Type::OBJ, "", "",
     150 |              {
     151 | +                {RPCResult::Type::BOOL, "private_broadcast_enabled", "If -privatebroadcast is set"},
    


    andrewtoth commented at 10:28 PM on May 11, 2026:

    Why not just enabled? The RPC is already getprivatebroadcast?

                    {RPCResult::Type::BOOL, "enabled", "If -privatebroadcast is set"},
    

    polespinasa commented at 10:37 PM on May 11, 2026:

    done

  9. andrewtoth approved
  10. andrewtoth commented at 10:29 PM on May 11, 2026: contributor

    Concept ACK

  11. polespinasa force-pushed on May 11, 2026
  12. polespinasa force-pushed on May 11, 2026
  13. in doc/release-notes-35267.md:4 in a714a5d484 outdated
       0 | @@ -0,0 +1,4 @@
       1 | +RPC
       2 | +---
       3 | +
       4 | +The `getprivatebroadcastinfo` RPC now exposes if `-privatebroadcast` startup option was set with a new response key `enabled`.
    


    andrewtoth commented at 12:32 AM on May 12, 2026:

    Needs a trailing newline to get CI to pass.

    The `getprivatebroadcastinfo` RPC now exposes whether the `-privatebroadcast` startup option is enabled with a new response key `enabled`.
    

    polespinasa commented at 11:07 AM on May 12, 2026:

    woops, fixed thanks

  14. in src/rpc/mempool.cpp:151 in a714a5d484 outdated
     147 | @@ -148,6 +148,7 @@ static RPCMethod getprivatebroadcastinfo()
     148 |          RPCResult{
     149 |              RPCResult::Type::OBJ, "", "",
     150 |              {
     151 | +                {RPCResult::Type::BOOL, "enabled", "If -privatebroadcast is set"},
    


    andrewtoth commented at 12:33 AM on May 12, 2026:
                    {RPCResult::Type::BOOL, "enabled", "If -privatebroadcast is enabled"},
    

    polespinasa commented at 11:09 AM on May 12, 2026:

    done

  15. in src/rpc/mempool.cpp:181 in a714a5d484 outdated
     177 | @@ -177,6 +178,10 @@ static RPCMethod getprivatebroadcastinfo()
     178 |              const NodeContext& node{EnsureAnyNodeContext(request.context)};
     179 |              const PeerManager& peerman{EnsurePeerman(node)};
     180 |              const auto txs{peerman.GetPrivateBroadcastInfo()};
     181 | +            UniValue ret(UniValue::VOBJ);
    


    andrewtoth commented at 12:35 AM on May 12, 2026:

    nit: we don't need to move this line. We could just push the enabled value below where we push transactions.


    polespinasa commented at 11:10 AM on May 12, 2026:

    done

  16. in test/functional/p2p_private_broadcast.py:350 in a714a5d484 outdated
     346 | @@ -347,6 +347,9 @@ def get_destinations_len():
     347 |  
     348 |          # Verify the tx we just observed is tracked in getprivatebroadcastinfo.
     349 |          pbinfo = self.nodes[0].getprivatebroadcastinfo()
     350 | +        # originator should report that privatebroadcast was set while the should not
    


    andrewtoth commented at 12:35 AM on May 12, 2026:
            # originator should report that privatebroadcast was set while the receiver should not
    

    polespinasa commented at 11:11 AM on May 12, 2026:

    done

  17. in test/functional/p2p_private_broadcast.py:352 in a714a5d484 outdated
     346 | @@ -347,6 +347,9 @@ def get_destinations_len():
     347 |  
     348 |          # Verify the tx we just observed is tracked in getprivatebroadcastinfo.
     349 |          pbinfo = self.nodes[0].getprivatebroadcastinfo()
     350 | +        # originator should report that privatebroadcast was set while the should not
     351 | +        assert_equal(pbinfo["enabled"], True)
     352 | +        assert_equal(self.nodes[1].getprivatebroadcastinfo()["enabled"], False)
    


    andrewtoth commented at 12:36 AM on May 12, 2026:

    I think this line can still be moved to the beginning of the test. We don't need to check it for each broadcast.


    polespinasa commented at 11:12 AM on May 12, 2026:

    done

  18. andrewtoth commented at 12:38 AM on May 12, 2026: contributor

    PR description is stale, showing the old private_broadcast_enabled field name.

  19. polespinasa force-pushed on May 12, 2026
  20. polespinasa force-pushed on May 12, 2026
  21. polespinasa force-pushed on May 12, 2026
  22. DrahtBot removed the label CI failed on May 12, 2026
  23. in src/rpc/mempool.cpp:151 in 9c2479687b
     147 | @@ -148,6 +148,7 @@ static RPCMethod getprivatebroadcastinfo()
     148 |          RPCResult{
     149 |              RPCResult::Type::OBJ, "", "",
     150 |              {
     151 | +                {RPCResult::Type::BOOL, "enabled", "If -privatebroadcast is enabled"},
    


    stickies-v commented at 12:56 PM on May 12, 2026:

    Perhaps a "status" of Type::STR would be more expressive and extensible?


    polespinasa commented at 2:25 PM on May 12, 2026:

    What other expressions could we need?


    stickies-v commented at 3:40 PM on May 12, 2026:

    It's hard to predict how APIs get extended in the future. Booleans make backwards-compatible upgrades harder. See https://ariya.io/2011/08/hall-of-api-shame-boolean-trap/ . For boolean traps, I don't think the onus should be on the reviewer to think of what other situations might arise, but one that came to mind is: "status": "err-no-tor". I believe we currently don't allow starting up when no private network is found, but that may change in the future.


    polespinasa commented at 7:46 PM on May 12, 2026:

    Fair enough, makes sense.

  24. in src/rpc/mempool.cpp:204 in 9c2479687b
     200 | @@ -200,6 +201,8 @@ static RPCMethod getprivatebroadcastinfo()
     201 |              }
     202 |  
     203 |              UniValue ret(UniValue::VOBJ);
     204 | +            const bool private_broadcast_enabled{gArgs.GetBoolArg("-privatebroadcast", DEFAULT_PRIVATE_BROADCAST)};
    


    stickies-v commented at 1:06 PM on May 12, 2026:

    Using startup args seems brittle. Perhaps a better approach is to expose this in PeerManager::GetInfo(), and then surface it in getnetworkinfo() alongside the other peerman details?


    polespinasa commented at 2:30 PM on May 12, 2026:

    Using startup args seems brittle

    Did it this way to keep the format from sendrawtransaction

    surface it in getnetworkinfo()

    Concept~0 here, I am fine with both approaches. @andrewtoth what do you think?


    rkrux commented at 2:35 PM on May 12, 2026:

    In 30ba2d3eabfe31559604c641ff4c89b424583298

    There's already a similar boolean present in PeerManager, would prefer for it to be used.

    https://github.com/bitcoin/bitcoin/blob/10ca73c02cbff59f2134c0c7da3b8d0a7e727475/src/net_processing.h#L95-L96


    rkrux commented at 2:47 PM on May 12, 2026:

    then surface it in getnetworkinfo()

    I'm leaning towards this based on the descriptions of both these RPCs.

    getnetworkinfo - Returns an object containing various state info regarding P2P networking getprivatebroadcastinfo - Returns information about transactions that are currently being privately broadcast

    getnetworkinfo's description is already sufficient if this new key is added there, but if added in getprivatebroadcastinfo then its description would need to be updated as well.

  25. stickies-v commented at 1:06 PM on May 12, 2026: contributor

    Concept ACK, seems useful to expose.

  26. rkrux commented at 2:48 PM on May 12, 2026: contributor

    Code review at 9c2479687b541ff4c3567d5d297bdcccc5b05636

  27. w0xlt commented at 4:50 PM on May 12, 2026: contributor

    Concept ACK

  28. polespinasa force-pushed on May 13, 2026
  29. in src/rpc/net.cpp:655 in a6116dd3c5
     651 | @@ -652,6 +652,7 @@ static RPCMethod getnetworkinfo()
     652 |                              {RPCResult::Type::STR, "SERVICE_NAME", "the service name"},
     653 |                          }},
     654 |                          {RPCResult::Type::BOOL, "localrelay", "true if transaction relay is requested from peers"},
     655 | +                        {RPCResult::Type::STR, "privatebroadcast", "if private broadcast is enabled"},
    


    polespinasa commented at 7:49 PM on May 13, 2026:

    Question for reviewers, do you prefer status of private broadcast ? Following #35267 (review) idea of extension?


    stickies-v commented at 10:19 PM on May 13, 2026:

    "private broadcast status (one of \"enabled\", \"disabled\")" has my preference

  30. polespinasa renamed this:
    rpc: inform if privatebroadcast is enabled in getprivatebroadcastinfo
    rpc: inform if privatebroadcast is enabled in getnetworkinfo
    on May 13, 2026
  31. polespinasa commented at 7:52 PM on May 13, 2026: member

    Force pushed to address comments, moved it to getnetworkinfo and changed it from bool to string to make it more flexible to being updated in the future.

    Diff: https://github.com/bitcoin/bitcoin/compare/9c2479687b541ff4c3567d5d297bdcccc5b05636..a6116dd3c5da3fedbb1b44218600e2b7f7219a76

  32. stickies-v commented at 8:36 AM on May 14, 2026: contributor

    Approach ACK. I think it makes more sense to squash the top 3 commits, they all really belong together and are trivial enough?

  33. rpc: Expose if privatebroadcast is enabled in getnetworkinfo RPC c8d2ebdccc
  34. test: getnetworkinfo rpc informs if privatebroadcast is set 5c0be9cff1
  35. add release notes 740dafcd3a
  36. polespinasa force-pushed on May 14, 2026
  37. polespinasa commented at 9:06 AM on May 14, 2026: member

    I think it makes more sense to squash the top 3 commits

    Squashed the fist two. I like keeping tests in a separate commit.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-18 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me