0diff --git a/src/net.cpp b/src/net.cpp
1index a2f80cbcf7..133abae117 100644
2--- a/src/net.cpp
3+++ b/src/net.cpp
4@@ -3670,13 +3670,13 @@ CNode::CNode(NodeId idIn,
5 nLocalHostNonce{nLocalHostNonceIn},
6 m_recv_flood_size{node_opts.recv_flood_size},
7 m_i2p_sam_session{std::move(node_opts.i2p_sam_session)}
8 {
9 if (inbound_onion) assert(conn_type_in == ConnectionType::INBOUND);
10
11- for (const std::string &msg : getAllNetMessageTypes())
12+ for (const auto& msg : g_all_net_message_types)
13 mapRecvBytesPerMsgType[msg] = 0;
14 mapRecvBytesPerMsgType[NET_MESSAGE_TYPE_OTHER] = 0;
15
16 if (fLogIPs) {
17 LogPrint(BCLog::NET, "Added connection to %s peer=%d\n", m_addr_name, id);
18 } else {
19diff --git a/src/protocol.cpp b/src/protocol.cpp
20index 27a0a2ffc1..0b22cc47aa 100644
21--- a/src/protocol.cpp
22+++ b/src/protocol.cpp
23@@ -46,53 +46,12 @@ const char* CFHEADERS = "cfheaders";
24 const char* GETCFCHECKPT = "getcfcheckpt";
25 const char* CFCHECKPT = "cfcheckpt";
26 const char* WTXIDRELAY = "wtxidrelay";
27 const char* SENDTXRCNCL = "sendtxrcncl";
28 } // namespace NetMsgType
29
30-/** All known message types. Keep this in the same order as the list of
31- * messages above and in protocol.h.
32- */
33-const static std::vector<std::string> g_all_net_message_types{
34- NetMsgType::VERSION,
35- NetMsgType::VERACK,
36- NetMsgType::ADDR,
37- NetMsgType::ADDRV2,
38- NetMsgType::SENDADDRV2,
39- NetMsgType::INV,
40- NetMsgType::GETDATA,
41- NetMsgType::MERKLEBLOCK,
42- NetMsgType::GETBLOCKS,
43- NetMsgType::GETHEADERS,
44- NetMsgType::TX,
45- NetMsgType::HEADERS,
46- NetMsgType::BLOCK,
47- NetMsgType::GETADDR,
48- NetMsgType::MEMPOOL,
49- NetMsgType::PING,
50- NetMsgType::PONG,
51- NetMsgType::NOTFOUND,
52- NetMsgType::FILTERLOAD,
53- NetMsgType::FILTERADD,
54- NetMsgType::FILTERCLEAR,
55- NetMsgType::SENDHEADERS,
56- NetMsgType::FEEFILTER,
57- NetMsgType::SENDCMPCT,
58- NetMsgType::CMPCTBLOCK,
59- NetMsgType::GETBLOCKTXN,
60- NetMsgType::BLOCKTXN,
61- NetMsgType::GETCFILTERS,
62- NetMsgType::CFILTER,
63- NetMsgType::GETCFHEADERS,
64- NetMsgType::CFHEADERS,
65- NetMsgType::GETCFCHECKPT,
66- NetMsgType::CFCHECKPT,
67- NetMsgType::WTXIDRELAY,
68- NetMsgType::SENDTXRCNCL,
69-};
70-
71 CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
72 : pchMessageStart{pchMessageStartIn}
73 {
74 // Copy the command name
75 size_t i = 0;
76 for (; i < COMMAND_SIZE && pszCommand[i] != 0; ++i) pchCommand[i] = pszCommand[i];
77@@ -175,17 +134,12 @@ std::string CInv::ToString() const
78 return strprintf("%s %s", GetCommand(), hash.ToString());
79 } catch(const std::out_of_range &) {
80 return strprintf("0x%08x %s", type, hash.ToString());
81 }
82 }
83
84-const std::vector<std::string> &getAllNetMessageTypes()
85-{
86- return g_all_net_message_types;
87-}
88-
89 /**
90 * Convert a service flag (NODE_*) to a human readable string.
91 * It supports unknown service flags which will be returned as "UNKNOWN[...]".
92 * [@param](/bitcoin-bitcoin/contributor/param/)[in] bit the service flag is calculated as (1 << bit)
93 */
94 static std::string serviceFlagToStr(size_t bit)
95diff --git a/src/protocol.h b/src/protocol.h
96index e405253632..2a6b85dea5 100644
97--- a/src/protocol.h
98+++ b/src/protocol.h
99@@ -264,14 +264,50 @@ extern const char* WTXIDRELAY;
100 * The salt is used to compute short txids needed for efficient
101 * txreconciliation, as described by BIP 330.
102 */
103 extern const char* SENDTXRCNCL;
104 }; // namespace NetMsgType
105
106-/* Get a vector of all valid message types (see above) */
107-const std::vector<std::string>& getAllNetMessageTypes();
108+/** All known message types (see above). Keep this in the same order as the list of messages above. */
109+static const std::array g_all_net_message_types{
110+ NetMsgType::VERSION,
111+ NetMsgType::VERACK,
112+ NetMsgType::ADDR,
113+ NetMsgType::ADDRV2,
114+ NetMsgType::SENDADDRV2,
115+ NetMsgType::INV,
116+ NetMsgType::GETDATA,
117+ NetMsgType::MERKLEBLOCK,
118+ NetMsgType::GETBLOCKS,
119+ NetMsgType::GETHEADERS,
120+ NetMsgType::TX,
121+ NetMsgType::HEADERS,
122+ NetMsgType::BLOCK,
123+ NetMsgType::GETADDR,
124+ NetMsgType::MEMPOOL,
125+ NetMsgType::PING,
126+ NetMsgType::PONG,
127+ NetMsgType::NOTFOUND,
128+ NetMsgType::FILTERLOAD,
129+ NetMsgType::FILTERADD,
130+ NetMsgType::FILTERCLEAR,
131+ NetMsgType::SENDHEADERS,
132+ NetMsgType::FEEFILTER,
133+ NetMsgType::SENDCMPCT,
134+ NetMsgType::CMPCTBLOCK,
135+ NetMsgType::GETBLOCKTXN,
136+ NetMsgType::BLOCKTXN,
137+ NetMsgType::GETCFILTERS,
138+ NetMsgType::CFILTER,
139+ NetMsgType::GETCFHEADERS,
140+ NetMsgType::CFHEADERS,
141+ NetMsgType::GETCFCHECKPT,
142+ NetMsgType::CFCHECKPT,
143+ NetMsgType::WTXIDRELAY,
144+ NetMsgType::SENDTXRCNCL,
145+};
146
147 /** nServices flags */
148 enum ServiceFlags : uint64_t {
149 // NOTE: When adding here, be sure to update serviceFlagToStr too
150 // Nothing
151 NODE_NONE = 0,
152diff --git a/src/test/fuzz/p2p_transport_serialization.cpp b/src/test/fuzz/p2p_transport_serialization.cpp
153index 21d8dab536..853661b4d4 100644
154--- a/src/test/fuzz/p2p_transport_serialization.cpp
155+++ b/src/test/fuzz/p2p_transport_serialization.cpp
156@@ -18,19 +18,18 @@
157 #include <limits>
158 #include <optional>
159 #include <vector>
160
161 namespace {
162
163-std::vector<std::string> g_all_messages;
164+auto g_all_messages = g_all_net_message_types;
165
166 void initialize_p2p_transport_serialization()
167 {
168 ECC_Start();
169 SelectParams(ChainType::REGTEST);
170- g_all_messages = getAllNetMessageTypes();
171 std::sort(g_all_messages.begin(), g_all_messages.end());
172 }
173
174 } // namespace
175
176 FUZZ_TARGET(p2p_transport_serialization, .init = initialize_p2p_transport_serialization)
177@@ -147,13 +146,13 @@ void SimulationTest(Transport& initiator, Transport& responder, R& rng, FuzzedDa
178 if (c < ' ' || c > 0x7E) break;
179 ret += c;
180 }
181 return ret;
182 } else {
183 // Otherwise, use it as index into the list of known messages.
184- return g_all_messages[v % g_all_messages.size()];
185+ return std::string{g_all_messages[v % g_all_messages.size()]};
186 }
187 };
188
189 // Function to construct a CSerializedNetMsg to send.
190 auto make_msg_fn = [&](bool first) {
191 CSerializedNetMsg msg;
192diff --git a/src/test/fuzz/process_message.cpp b/src/test/fuzz/process_message.cpp
193index d38d1bb40e..24c711f421 100644
194--- a/src/test/fuzz/process_message.cpp
195+++ b/src/test/fuzz/process_message.cpp
196@@ -42,13 +42,13 @@ std::string_view LIMIT_TO_MESSAGE_TYPE{};
197 } // namespace
198
199 void initialize_process_message()
200 {
201 if (const auto val{std::getenv("LIMIT_TO_MESSAGE_TYPE")}) {
202 LIMIT_TO_MESSAGE_TYPE = val;
203- Assert(std::count(getAllNetMessageTypes().begin(), getAllNetMessageTypes().end(), LIMIT_TO_MESSAGE_TYPE)); // Unknown message type passed
204+ Assert(std::count(g_all_net_message_types.begin(), g_all_net_message_types.end(), LIMIT_TO_MESSAGE_TYPE)); // Unknown message type passed
205 }
206
207 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
208 /*chain_type=*/ChainType::REGTEST,
209 /*extra_args=*/{"-txreconciliation"});
210 g_setup = testing_setup.get();