Skip to content

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Oct 7, 2025

Previously the bool relay argument to BroadcastTransaction() designated:

relay=true: add to the mempool and broadcast to all peers
relay=false: add to the mempool

Change this to an enum, so it is more readable and easier to extend with a 3rd option. Consider these example call sites:

Paint(true);
// Or
Paint(/*is_red=*/true);

vs

Paint(RED);

The idea for putting TxBroadcastMethod into node/types.h by Ryan.


This is part of #29415 Broadcast own transactions only via short-lived Tor or I2P connections. Putting it in its own PR to reduce the size of #29415 and because it does not logically depend on the other commits from there.

Previously the `bool relay` argument to `BroadcastTransaction()`
designated:

```
relay=true: add to the mempool and broadcast to all peers
relay=false: add to the mempool
```

Change this to an `enum`, so it is more readable and easier to extend
with a 3rd option. Consider these example call sites:

```cpp
Paint(true);
// Or
Paint(/*is_red=*/true);
```

vs

```cpp
Paint(RED);
```

The idea for putting `TxBroadcastMethod` into `node/types.h` by Ryan.

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 7, 2025

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

Code Coverage & Benchmarks

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

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK kevkevinpal

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #33565 (net_processing: rename RelayTransaction to better describe what it does by vasild)
  • #29415 (Broadcast own transactions only via short-lived Tor or I2P connections by vasild)
  • #29278 (Wallet: Add maxfeerate wallet startup option by ismaelsadeeq)
  • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)

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.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • and/if -> if/how [clarifies intent: "and/if" is not valid phrasing; "if/how" or "and, if so, how" conveys whether to add to mempool and, if so, how to broadcast]

drahtbot_id_5_m

//! Transaction is added to memory pool, if the transaction fee is below the
//! amount specified by max_tx_fee, and broadcast to all peers if relay is set to true.
//! Return false if the transaction could not be added due to the fee or for another reason.
//! Consume a local transaction, optionally adding it to the mempool and
Copy link
Contributor

Choose a reason for hiding this comment

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

The transaction is passed by const ref, so it's not really "consuming" it. Perhaps "Process a local transaction"?

* Methods to broadcast a local transaction.
* Used to influence `BroadcastTransaction()` and its callers.
*/
enum TxBroadcastMethod : uint8_t {
Copy link
Member

Choose a reason for hiding this comment

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

Probably should use class enums for new things?

@bitcoin bitcoin deleted a comment from GrayHatGuy Oct 10, 2025
Copy link
Contributor

@kevkevinpal kevkevinpal left a comment

Choose a reason for hiding this comment

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

Concept ACK

I think it makes sense to change to an enum instead of just a bool. I added a few comments but I have still yet to pull and build on my local machine

};

/**
* Methods to broadcast a local transaction.
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a method

Suggested change
* Methods to broadcast a local transaction.
* Enum to signal to broadcast a local transaction.

Comment on lines +88 to +90
switch (broadcast_method) {
case ADD_TO_MEMPOOL_NO_BROADCAST:
case ADD_TO_MEMPOOL_AND_BROADCAST_TO_ALL:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm confused but why include this switch statement if previously we didnt need to? I don't see any if statement for relay here

Comment on lines +1978 to +1987
const char* what{""};
switch (broadcast_method) {
case node::ADD_TO_MEMPOOL_AND_BROADCAST_TO_ALL:
what = "to mempool and for broadcast to peers";
break;
case node::ADD_TO_MEMPOOL_NO_BROADCAST:
what = "to mempool without broadcast";
break;
}
WalletLogPrintf("Submitting wtx %s %s\n", wtx.GetHash().ToString(), what);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need the what variable if it's just used as a string to print directly after the if block

Suggested change
const char* what{""};
switch (broadcast_method) {
case node::ADD_TO_MEMPOOL_AND_BROADCAST_TO_ALL:
what = "to mempool and for broadcast to peers";
break;
case node::ADD_TO_MEMPOOL_NO_BROADCAST:
what = "to mempool without broadcast";
break;
}
WalletLogPrintf("Submitting wtx %s %s\n", wtx.GetHash().ToString(), what);
switch (broadcast_method) {
case node::ADD_TO_MEMPOOL_AND_BROADCAST_TO_ALL:
WalletLogPrintf("Submitting wtx %s to mempool and for broadcast to peers\n", wtx.GetHash().ToString());
break;
case node::ADD_TO_MEMPOOL_NO_BROADCAST:
WalletLogPrintf("Submitting wtx %s to mempool without broadcast\n", wtx.GetHash().ToString());
break;
}

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants