Skip to content

Commit 46d78d4

Browse files
committed
Add p2p message "wtxidrelay"
When sent to and received from a given peer, enables using wtxid's for announcing and fetching transactions with that peer.
1 parent 2d282e0 commit 46d78d4

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

src/net_processing.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,10 @@ void ProcessMessage(
23422342
if (pfrom.fInbound)
23432343
PushNodeVersion(pfrom, connman, GetAdjustedTime());
23442344

2345+
if (nVersion >= WTXID_RELAY_VERSION) {
2346+
connman.PushMessage(&pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::WTXIDRELAY));
2347+
}
2348+
23452349
connman.PushMessage(&pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERACK));
23462350

23472351
pfrom.nServices = nServices;
@@ -2478,6 +2482,18 @@ void ProcessMessage(
24782482
return;
24792483
}
24802484

2485+
// Feature negotiation of wtxidrelay should happen between VERSION and
2486+
// VERACK, to avoid relay problems from switching after a connection is up
2487+
if (msg_type == NetMsgType::WTXIDRELAY) {
2488+
if (pfrom.nVersion >= WTXID_RELAY_VERSION) {
2489+
LOCK(cs_main);
2490+
if (!State(pfrom.GetId())->m_wtxid_relay) {
2491+
State(pfrom.GetId())->m_wtxid_relay = true;
2492+
}
2493+
}
2494+
return;
2495+
}
2496+
24812497
if (!pfrom.fSuccessfullyConnected) {
24822498
// Must have a verack message before anything else
24832499
LOCK(cs_main);

src/protocol.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const char *GETCFHEADERS="getcfheaders";
4646
const char *CFHEADERS="cfheaders";
4747
const char *GETCFCHECKPT="getcfcheckpt";
4848
const char *CFCHECKPT="cfcheckpt";
49+
const char *WTXIDRELAY="wtxidrelay";
4950
} // namespace NetMsgType
5051

5152
/** All known message types. Keep this in the same order as the list of
@@ -83,6 +84,7 @@ const static std::string allNetMessageTypes[] = {
8384
NetMsgType::CFHEADERS,
8485
NetMsgType::GETCFCHECKPT,
8586
NetMsgType::CFCHECKPT,
87+
NetMsgType::WTXIDRELAY,
8688
};
8789
const static std::vector<std::string> allNetMessageTypesVec(allNetMessageTypes, allNetMessageTypes+ARRAYLEN(allNetMessageTypes));
8890

src/protocol.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ extern const char* GETCFCHECKPT;
261261
* evenly spaced filter headers for blocks on the requested chain.
262262
*/
263263
extern const char* CFCHECKPT;
264+
/**
265+
* Indicates that a node prefers to relay transactions via wtxid, rather than
266+
* txid.
267+
* @since protocol version 70016 as described by BIP 339.
268+
*/
269+
extern const char *WTXIDRELAY;
264270
}; // namespace NetMsgType
265271

266272
/* Get a vector of all valid message types (see above) */
@@ -402,7 +408,7 @@ enum GetDataMsg : uint32_t {
402408
MSG_TX = 1,
403409
MSG_BLOCK = 2,
404410
MSG_WTX = 5, //!< Defined in BIP 339
405-
// The following can only occur in getdata. Invs always use TX or BLOCK.
411+
// The following can only occur in getdata. Invs always use TX/WTX or BLOCK.
406412
MSG_FILTERED_BLOCK = 3, //!< Defined in BIP37
407413
MSG_CMPCT_BLOCK = 4, //!< Defined in BIP152
408414
MSG_WITNESS_BLOCK = MSG_BLOCK | MSG_WITNESS_FLAG, //!< Defined in BIP144

src/version.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* network protocol versioning
1010
*/
1111

12-
static const int PROTOCOL_VERSION = 70015;
12+
static const int PROTOCOL_VERSION = 70016;
1313

1414
//! initial proto version, to be increased after version/verack negotiation
1515
static const int INIT_PROTO_VERSION = 209;
@@ -35,4 +35,7 @@ static const int SHORT_IDS_BLOCKS_VERSION = 70014;
3535
//! not banning for invalid compact blocks starts with this version
3636
static const int INVALID_CB_NO_BAN_VERSION = 70015;
3737

38+
//! "wtxidrelay" command for wtxid-based relay starts with this version
39+
static const int WTXID_RELAY_VERSION = 70016;
40+
3841
#endif // BITCOIN_VERSION_H

0 commit comments

Comments
 (0)