Skip to content

Commit

Permalink
Add p2p message "wtxidrelay"
Browse files Browse the repository at this point in the history
When sent to and received from a given peer, enables using wtxid's for
announcing and fetching transactions with that peer.
  • Loading branch information
sdaftuar committed Jul 19, 2020
1 parent 2d282e0 commit 46d78d4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,10 @@ void ProcessMessage(
if (pfrom.fInbound)
PushNodeVersion(pfrom, connman, GetAdjustedTime());

if (nVersion >= WTXID_RELAY_VERSION) {
connman.PushMessage(&pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::WTXIDRELAY));
}

connman.PushMessage(&pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERACK));

pfrom.nServices = nServices;
Expand Down Expand Up @@ -2478,6 +2482,18 @@ void ProcessMessage(
return;
}

// Feature negotiation of wtxidrelay should happen between VERSION and
// VERACK, to avoid relay problems from switching after a connection is up
if (msg_type == NetMsgType::WTXIDRELAY) {
if (pfrom.nVersion >= WTXID_RELAY_VERSION) {
LOCK(cs_main);
if (!State(pfrom.GetId())->m_wtxid_relay) {
State(pfrom.GetId())->m_wtxid_relay = true;
}
}
return;
}

if (!pfrom.fSuccessfullyConnected) {
// Must have a verack message before anything else
LOCK(cs_main);
Expand Down
2 changes: 2 additions & 0 deletions src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const char *GETCFHEADERS="getcfheaders";
const char *CFHEADERS="cfheaders";
const char *GETCFCHECKPT="getcfcheckpt";
const char *CFCHECKPT="cfcheckpt";
const char *WTXIDRELAY="wtxidrelay";
} // namespace NetMsgType

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

Expand Down
8 changes: 7 additions & 1 deletion src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ extern const char* GETCFCHECKPT;
* evenly spaced filter headers for blocks on the requested chain.
*/
extern const char* CFCHECKPT;
/**
* Indicates that a node prefers to relay transactions via wtxid, rather than
* txid.
* @since protocol version 70016 as described by BIP 339.
*/
extern const char *WTXIDRELAY;
}; // namespace NetMsgType

/* Get a vector of all valid message types (see above) */
Expand Down Expand Up @@ -402,7 +408,7 @@ enum GetDataMsg : uint32_t {
MSG_TX = 1,
MSG_BLOCK = 2,
MSG_WTX = 5, //!< Defined in BIP 339
// The following can only occur in getdata. Invs always use TX or BLOCK.
// The following can only occur in getdata. Invs always use TX/WTX or BLOCK.
MSG_FILTERED_BLOCK = 3, //!< Defined in BIP37
MSG_CMPCT_BLOCK = 4, //!< Defined in BIP152
MSG_WITNESS_BLOCK = MSG_BLOCK | MSG_WITNESS_FLAG, //!< Defined in BIP144
Expand Down
5 changes: 4 additions & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* network protocol versioning
*/

static const int PROTOCOL_VERSION = 70015;
static const int PROTOCOL_VERSION = 70016;

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

//! "wtxidrelay" command for wtxid-based relay starts with this version
static const int WTXID_RELAY_VERSION = 70016;

#endif // BITCOIN_VERSION_H

0 comments on commit 46d78d4

Please sign in to comment.