test: add tests for private broadcast #33843

pull vasild wants to merge 14 commits into bitcoin:master from vasild:private_broadcast_tests changing 27 files +1584 −96
  1. vasild commented at 3:15 pm on November 10, 2025: contributor

    This PR contains #29415 + two more commits that add functional and fuzz tests.

    Putting those in a separate PR not to burden the main one, since the tests are extensive: code: 1036 insertions(+), 91 deletions(-) tests: 548 insertions(+), 5 deletions(-)

  2. log: introduce a new category for private broadcast 0cf71d16f6
  3. init: introduce a new option to enable/disable private broadcast
    Co-authored-by: brunoerg <brunoely.gc@gmail.com>
    c0a5a9547c
  4. net: introduce a new connection type for private broadcast
    We will open a short-lived connection to a random Tor or I2P peer,
    send our transaction to that peer and close the connection.
    07de378ed2
  5. net: implement opening PRIVATE_BROADCAST connections
    Implement opening `ConnectionType::PRIVATE_BROADCAST` connections with
    the following properties:
    * Only to Tor or I2P (or IPv4/IPv6 through the Tor proxy, if provided)
    * Open such connections only when requested and don't maintain N opened
      connections of this type.
    * Since this is substantially different than what
      `OpenNetworkConnection()` does, open the private broadcast connections
      from a different thread instead of modifying `OpenNetworkConnection()`
      to also open those types of connections.
    7ce142dbe2
  6. net_processing: rename RelayTransaction() to better describe what it does
    Rename `PeerManager::RelayTransaction()` to
    `PeerManager::InitiateTxBroadcastToAll()`. The transaction is not
    relayed when the method returns. It is only enqueued for a possible
    broadcasting at a later time. Also, there will be another method which
    only does so to Tor or I2P peers.
    92e0e6d04c
  7. node: extend node::TxBroadcast with a 3rd option
    Extend `node::TxBroadcast` with a 3rd option to not add the
    transaction to the mempool and broadcast privately.
    
    This is a non-functional change - `BroadcastTransaction()` will not
    do anything if the 3rd options is passed and is not used by any of
    its callers.
    faa9dd527d
  8. net_processing: store transactions for private broadcast in PeerManager
    Extend `PeerManager` with a transaction storage and a new method
    `ScheduleTxForPrivateBroadcast()` which:
    * adds a transaction to that storage and
    * calls `CConnman::PrivateBroadcastAdd()` to open dedicated privacy
      connections that will pick an entry from the transaction storage and
      broadcast it.
    78ec55b031
  9. net_processing: reorder the code that handles the VERSION message
    Change the order in which code snippets are executed as a result of
    receiving the `VERSION` message. Move the snippets that do
    `MakeAndPushMessage()` near the end. This will help with handling of
    private broadcast connections - they do not require any of that.
    
    This is a non-functional change.
    c5785d5243
  10. net_processing: handle ConnectionType::PRIVATE_BROADCAST connections
    For connections of type `ConnectionType::PRIVATE_BROADCAST`:
    * After receiving VERACK, relay a transaction from the list of
      transactions for private broadcast and disconnect
    * Don't process any messages after VERACK
    * Don't send any messages other than the minimum required for the
      transaction relay
    82d5948683
  11. net_processing: stop private broadcast of a transaction after round-trip
    Remove the transaction from the list of transactions to broadcast after
    we receive it from the network.
    
    Only remove the transaction if it is the same as the one we sent: both
    txid and wtxid match. Don't remove transactions that have the same txid
    and different wxtid. Such transactions show that some of the private
    broadcast recipients malleated the witness and the transaction made it
    back to us. The witness could be either:
    * invalid, in which case the transaction will not be accepted in
      anybody's pool; or
    * valid, in which case either the original or the malleated transaction
      will make it to nodes' mempools and eventually be mined. Our response
      is to keep broadcasting the original. If the malleated transaction
      wins then we will eventually stop broadcasting the original when it
      gets stale and gets removed from the "to broadcast" storage cause it
      is not acceptable in our mempool.
    f478097e81
  12. net_processing: retry private broadcast
    Periodically check for stale transactions in peerman and if found,
    reschedule new connections to be opened by connman for broadcasting
    them.
    faeff579b5
  13. rpc: use private broadcast from sendrawtransaction RPC if -privatebroadcast is ON d419fbc42b
  14. test: add functional test for private broadcast 29ef3c62de
  15. test: add fuzz test for private broadcast
    Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
    8e4084f7b6
  16. dergoegge commented at 3:20 pm on November 10, 2025: member
    Can you elaborate on the rational here? Why would the tests burden the main change? In my opinion, the purpose of tests should be to make it easier to review a code change and gain confidence in it’s correctness etc. Splitting them from the code change seems counter productive.
  17. fanquake commented at 3:23 pm on November 10, 2025: member
    Concept NACK to deferring adding tests until after adding a new feature.
  18. vasild commented at 3:46 pm on November 10, 2025: contributor
  19. vasild closed this on Nov 10, 2025


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: 2025-11-21 00:13 UTC

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