Skip to content

Commit 181ffad

Browse files
sdaftuarjnewbery
authored andcommitted
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 9382672 commit 181ffad

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
@@ -2055,6 +2055,10 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
20552055
if (pfrom->fInbound)
20562056
PushNodeVersion(pfrom, connman, GetAdjustedTime());
20572057

2058+
if (nVersion >= WTXID_RELAY_VERSION) {
2059+
connman->PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::WTXIDRELAY));
2060+
}
2061+
20582062
connman->PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERACK));
20592063

20602064
pfrom->nServices = nServices;
@@ -2194,6 +2198,18 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
21942198
return true;
21952199
}
21962200

2201+
// Feature negotiation of wtxidrelay should happen between VERSION and
2202+
// VERACK, to avoid relay problems from switching after a connection is up
2203+
if (msg_type == NetMsgType::WTXIDRELAY) {
2204+
if (pfrom->nVersion >= WTXID_RELAY_VERSION) {
2205+
LOCK(cs_main);
2206+
if (!State(pfrom->GetId())->m_wtxid_relay) {
2207+
State(pfrom->GetId())->m_wtxid_relay = true;
2208+
}
2209+
}
2210+
return false;
2211+
}
2212+
21972213
if (!pfrom->fSuccessfullyConnected) {
21982214
// Must have a verack message before anything else
21992215
LOCK(cs_main);

src/protocol.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const char *SENDCMPCT="sendcmpct";
4040
const char *CMPCTBLOCK="cmpctblock";
4141
const char *GETBLOCKTXN="getblocktxn";
4242
const char *BLOCKTXN="blocktxn";
43+
const char *WTXIDRELAY="wtxidrelay";
4344
} // namespace NetMsgType
4445

4546
/** All known message types. Keep this in the same order as the list of
@@ -71,6 +72,7 @@ const static std::string allNetMessageTypes[] = {
7172
NetMsgType::CMPCTBLOCK,
7273
NetMsgType::GETBLOCKTXN,
7374
NetMsgType::BLOCKTXN,
75+
NetMsgType::WTXIDRELAY,
7476
};
7577
const static std::vector<std::string> allNetMessageTypesVec(allNetMessageTypes, allNetMessageTypes+ARRAYLEN(allNetMessageTypes));
7678

src/protocol.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ extern const char *GETBLOCKTXN;
234234
* @since protocol version 70014 as described by BIP 152
235235
*/
236236
extern const char *BLOCKTXN;
237+
/**
238+
* Indicates that a node prefers to relay transactions via wtxid, rather than
239+
* txid.
240+
* @since protocol version 70016 as described by BIP 339.
241+
*/
242+
extern const char *WTXIDRELAY;
237243
};
238244

239245
/* Get a vector of all valid message types (see above) */
@@ -367,7 +373,7 @@ enum GetDataMsg : uint32_t {
367373
MSG_TX = 1,
368374
MSG_BLOCK = 2,
369375
MSG_WTX = 5, //!< Defined in BIP 339
370-
// The following can only occur in getdata. Invs always use TX or BLOCK.
376+
// The following can only occur in getdata. Invs always use TX/WTX or BLOCK.
371377
MSG_FILTERED_BLOCK = 3, //!< Defined in BIP37
372378
MSG_CMPCT_BLOCK = 4, //!< Defined in BIP152
373379
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;
@@ -42,4 +42,7 @@ static const int SHORT_IDS_BLOCKS_VERSION = 70014;
4242
//! not banning for invalid compact blocks starts with this version
4343
static const int INVALID_CB_NO_BAN_VERSION = 70015;
4444

45+
//! "wtxidrelay" command for wtxid-based relay starts with this version
46+
static const int WTXID_RELAY_VERSION = 70016;
47+
4548
#endif // BITCOIN_VERSION_H

0 commit comments

Comments
 (0)