Skip to content

Commit 6c13b13

Browse files
committed
Merge bitcoin/bitcoin#29421: net: make the list of known message types a compile time constant
b3efb48 protocol: make message types constexpr (Vasil Dimov) 2fa9de0 net: make the list of known message types a compile time constant (Vasil Dimov) Pull request description: Turn the `std::vector` to `std::array` because it is cheaper and allows us to have the number of the messages as a compile time constant: `ALL_NET_MESSAGE_TYPES.size()` which can be used in future code to build other `std::array`s with that size. --- This change is part of bitcoin/bitcoin#29418 but it makes sense on its own and would be good to have it, regardless of the fate of bitcoin/bitcoin#29418. Also, if this is merged, that would reduce the size of bitcoin/bitcoin#29418, thus the current standalone PR. ACKs for top commit: achow101: ACK b3efb48 jonatack: ACK b3efb48 maflcko: utACK b3efb48 🎊 willcl-ark: ACK b3efb48 Tree-SHA512: 6d3860c138c64514ebab13d97ea67893e2d346dfac30a48c3d9bc769a1970407375ea4170afdb522411ced306a14a9af4eede99e964d1fb1ea3efff5d5eb57af
2 parents a786fd2 + b3efb48 commit 6c13b13

File tree

6 files changed

+80
-131
lines changed

6 files changed

+80
-131
lines changed

src/net.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3736,8 +3736,9 @@ CNode::CNode(NodeId idIn,
37363736
{
37373737
if (inbound_onion) assert(conn_type_in == ConnectionType::INBOUND);
37383738

3739-
for (const std::string &msg : getAllNetMessageTypes())
3739+
for (const auto& msg : ALL_NET_MESSAGE_TYPES) {
37403740
mapRecvBytesPerMsgType[msg] = 0;
3741+
}
37413742
mapRecvBytesPerMsgType[NET_MESSAGE_TYPE_OTHER] = 0;
37423743

37433744
if (fLogIPs) {

src/protocol.cpp

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -7,87 +7,6 @@
77

88
#include <common/system.h>
99

10-
#include <atomic>
11-
12-
namespace NetMsgType {
13-
const char* VERSION = "version";
14-
const char* VERACK = "verack";
15-
const char* ADDR = "addr";
16-
const char* ADDRV2 = "addrv2";
17-
const char* SENDADDRV2 = "sendaddrv2";
18-
const char* INV = "inv";
19-
const char* GETDATA = "getdata";
20-
const char* MERKLEBLOCK = "merkleblock";
21-
const char* GETBLOCKS = "getblocks";
22-
const char* GETHEADERS = "getheaders";
23-
const char* TX = "tx";
24-
const char* HEADERS = "headers";
25-
const char* BLOCK = "block";
26-
const char* GETADDR = "getaddr";
27-
const char* MEMPOOL = "mempool";
28-
const char* PING = "ping";
29-
const char* PONG = "pong";
30-
const char* NOTFOUND = "notfound";
31-
const char* FILTERLOAD = "filterload";
32-
const char* FILTERADD = "filteradd";
33-
const char* FILTERCLEAR = "filterclear";
34-
const char* SENDHEADERS = "sendheaders";
35-
const char* FEEFILTER = "feefilter";
36-
const char* SENDCMPCT = "sendcmpct";
37-
const char* CMPCTBLOCK = "cmpctblock";
38-
const char* GETBLOCKTXN = "getblocktxn";
39-
const char* BLOCKTXN = "blocktxn";
40-
const char* GETCFILTERS = "getcfilters";
41-
const char* CFILTER = "cfilter";
42-
const char* GETCFHEADERS = "getcfheaders";
43-
const char* CFHEADERS = "cfheaders";
44-
const char* GETCFCHECKPT = "getcfcheckpt";
45-
const char* CFCHECKPT = "cfcheckpt";
46-
const char* WTXIDRELAY = "wtxidrelay";
47-
const char* SENDTXRCNCL = "sendtxrcncl";
48-
} // namespace NetMsgType
49-
50-
/** All known message types. Keep this in the same order as the list of
51-
* messages above and in protocol.h.
52-
*/
53-
const static std::vector<std::string> g_all_net_message_types{
54-
NetMsgType::VERSION,
55-
NetMsgType::VERACK,
56-
NetMsgType::ADDR,
57-
NetMsgType::ADDRV2,
58-
NetMsgType::SENDADDRV2,
59-
NetMsgType::INV,
60-
NetMsgType::GETDATA,
61-
NetMsgType::MERKLEBLOCK,
62-
NetMsgType::GETBLOCKS,
63-
NetMsgType::GETHEADERS,
64-
NetMsgType::TX,
65-
NetMsgType::HEADERS,
66-
NetMsgType::BLOCK,
67-
NetMsgType::GETADDR,
68-
NetMsgType::MEMPOOL,
69-
NetMsgType::PING,
70-
NetMsgType::PONG,
71-
NetMsgType::NOTFOUND,
72-
NetMsgType::FILTERLOAD,
73-
NetMsgType::FILTERADD,
74-
NetMsgType::FILTERCLEAR,
75-
NetMsgType::SENDHEADERS,
76-
NetMsgType::FEEFILTER,
77-
NetMsgType::SENDCMPCT,
78-
NetMsgType::CMPCTBLOCK,
79-
NetMsgType::GETBLOCKTXN,
80-
NetMsgType::BLOCKTXN,
81-
NetMsgType::GETCFILTERS,
82-
NetMsgType::CFILTER,
83-
NetMsgType::GETCFHEADERS,
84-
NetMsgType::CFHEADERS,
85-
NetMsgType::GETCFCHECKPT,
86-
NetMsgType::CFCHECKPT,
87-
NetMsgType::WTXIDRELAY,
88-
NetMsgType::SENDTXRCNCL,
89-
};
90-
9110
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
9211
: pchMessageStart{pchMessageStartIn}
9312
{
@@ -164,11 +83,6 @@ std::string CInv::ToString() const
16483
}
16584
}
16685

167-
const std::vector<std::string> &getAllNetMessageTypes()
168-
{
169-
return g_all_net_message_types;
170-
}
171-
17286
/**
17387
* Convert a service flag (NODE_*) to a human readable string.
17488
* It supports unknown service flags which will be returned as "UNKNOWN[...]".

0 commit comments

Comments
 (0)