diff --git a/src/blockencodings.cpp b/src/blockencodings.cpp index 99d7ece5619a..8a9f6fd397a8 100644 --- a/src/blockencodings.cpp +++ b/src/blockencodings.cpp @@ -53,7 +53,7 @@ uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const uint256& txhash) const { -ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector>& extra_txn) { +ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector& extra_txn) { if (cmpctblock.header.IsNull() || (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty())) return READ_STATUS_INVALID; if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > MaxBlockSize() / MIN_TRANSACTION_SIZE) @@ -140,11 +140,14 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c } for (size_t i = 0; i < extra_txn.size(); i++) { - uint64_t shortid = cmpctblock.GetShortID(extra_txn[i].first); + if (extra_txn[i] == nullptr) { + continue; + } + uint64_t shortid = cmpctblock.GetShortID(extra_txn[i]->GetInstanceHash()); std::unordered_map::iterator idit = shorttxids.find(shortid); if (idit != shorttxids.end()) { if (!have_txn[idit->second]) { - txn_available[idit->second] = extra_txn[i].second; + txn_available[idit->second] = extra_txn[i]; have_txn[idit->second] = true; mempool_count++; extra_count++; @@ -156,7 +159,7 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c // Note that we don't want duplication between extra_txn and mempool to // trigger this case, so we compare hashes first if (txn_available[idit->second] && - txn_available[idit->second]->GetHash() != extra_txn[i].second->GetHash()) { + txn_available[idit->second]->GetHash() != extra_txn[i]->GetHash()) { txn_available[idit->second].reset(); mempool_count--; extra_count--; diff --git a/src/blockencodings.h b/src/blockencodings.h index 3290de644e03..c2b5288c73cb 100644 --- a/src/blockencodings.h +++ b/src/blockencodings.h @@ -140,7 +140,7 @@ class PartiallyDownloadedBlock { explicit PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {} // extra_txn is a list of extra transactions to look at, in form - ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector>& extra_txn); + ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector& extra_txn); bool IsTxAvailable(size_t index) const; ReadStatus FillBlock(CBlock& block, const std::vector& vtx_missing); }; diff --git a/src/init/common.cpp b/src/init/common.cpp index 38ace0f66aad..5f54fa936e97 100644 --- a/src/init/common.cpp +++ b/src/init/common.cpp @@ -28,9 +28,9 @@ void AddLoggingArgs(ArgsManager& argsman) { argsman.AddArg("-debuglogfile=", strprintf("Specify location of debug log file (default: %s). Relative paths will be prefixed by a net-specific datadir location. Pass -nodebuglogfile to disable writing the log to a file.", DEFAULT_DEBUGLOGFILE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-debug=", "Output debug and trace logging (default: -nodebug, supplying is optional). " - "If is not supplied or if = 1, output all debug and trace logging. can be: " + LogInstance().LogCategoriesString() + ". This option can be specified multiple times to output multiple categories.", + "If is not supplied or if is 1 or \"all\", output all debug logging. If is 0 or \"none\", any other categories are ignored. Other valid values for are: " + LogInstance().LogCategoriesString() + ". This option can be specified multiple times to output multiple categories.", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); - argsman.AddArg("-debugexclude=", "Exclude debug and trace logging for a category. Can be used in conjunction with -debug=1 to output debug and trace logging for all categories except the specified category. This option can be specified multiple times to exclude multiple categories.", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); + argsman.AddArg("-debugexclude=", "Exclude debug and trace logging for a category. Can be used in conjunction with -debug=1 to output debug and trace logging for all categories except the specified category. This option can be specified multiple times to exclude multiple categories. This takes priority over \"-debug\"", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-logips", strprintf("Include IP addresses in debug output (default: %u)", DEFAULT_LOGIPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-loglevel=|:", strprintf("Set the global or per-category severity level for logging categories enabled with the -debug configuration option or the logging RPC. Possible values are %s (default=%s). The following levels are always logged: error, warning, info. If : is supplied, the setting will override the global one and may be specified multiple times to set multiple category-specific levels. can be: %s.", LogInstance().LogLevelsString(), LogInstance().LogLevelToStr(BCLog::DEFAULT_LOG_LEVEL), LogInstance().LogCategoriesString()), ArgsManager::DISALLOW_NEGATION | ArgsManager::DISALLOW_ELISION | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-logtimestamps", strprintf("Prepend debug output with timestamp (default: %u)", DEFAULT_LOGTIMESTAMPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); diff --git a/src/logging.cpp b/src/logging.cpp index 2f0de91a72d1..e6bdf1f73cd9 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -9,8 +9,8 @@ #include #include -#include #include +#include #include const char * const DEFAULT_DEBUGLOGFILE = "debug.log"; @@ -141,78 +141,82 @@ bool BCLog::Logger::DefaultShrinkDebugFile() const return m_categories == BCLog::NONE; } -struct CLogCategoryDesc { - BCLog::LogFlags flag; - std::string category; -}; - -const CLogCategoryDesc LogCategories[] = -{ - {BCLog::NONE, "0"}, - {BCLog::NONE, ""}, - {BCLog::NET, "net"}, - {BCLog::TOR, "tor"}, - {BCLog::MEMPOOL, "mempool"}, - {BCLog::HTTP, "http"}, - {BCLog::BENCHMARK, "bench"}, - {BCLog::ZMQ, "zmq"}, - {BCLog::WALLETDB, "walletdb"}, - {BCLog::RPC, "rpc"}, - {BCLog::ESTIMATEFEE, "estimatefee"}, - {BCLog::ADDRMAN, "addrman"}, - {BCLog::SELECTCOINS, "selectcoins"}, - {BCLog::REINDEX, "reindex"}, - {BCLog::CMPCTBLOCK, "cmpctblock"}, - {BCLog::RANDOM, "rand"}, - {BCLog::PRUNE, "prune"}, - {BCLog::PROXY, "proxy"}, - {BCLog::MEMPOOLREJ, "mempoolrej"}, - {BCLog::LIBEVENT, "libevent"}, - {BCLog::COINDB, "coindb"}, - {BCLog::QT, "qt"}, - {BCLog::LEVELDB, "leveldb"}, - {BCLog::VALIDATION, "validation"}, - {BCLog::I2P, "i2p"}, - {BCLog::IPC, "ipc"}, +static const std::map LOG_CATEGORIES_BY_STR{ + {"net", BCLog::NET}, + {"tor", BCLog::TOR}, + {"mempool", BCLog::MEMPOOL}, + {"http", BCLog::HTTP}, + {"bench", BCLog::BENCHMARK}, + {"zmq", BCLog::ZMQ}, + {"walletdb", BCLog::WALLETDB}, + {"rpc", BCLog::RPC}, + {"estimatefee", BCLog::ESTIMATEFEE}, + {"addrman", BCLog::ADDRMAN}, + {"selectcoins", BCLog::SELECTCOINS}, + {"reindex", BCLog::REINDEX}, + {"cmpctblock", BCLog::CMPCTBLOCK}, + {"rand", BCLog::RANDOM}, + {"prune", BCLog::PRUNE}, + {"proxy", BCLog::PROXY}, + {"mempoolrej", BCLog::MEMPOOLREJ}, + {"libevent", BCLog::LIBEVENT}, + {"coindb", BCLog::COINDB}, + {"qt", BCLog::QT}, + {"leveldb", BCLog::LEVELDB}, + {"validation", BCLog::VALIDATION}, + {"i2p", BCLog::I2P}, + {"ipc", BCLog::IPC}, #ifdef DEBUG_LOCKCONTENTION - {BCLog::LOCK, "lock"}, + {"lock", BCLog::LOCK}, #endif - {BCLog::BLOCKSTORAGE, "blockstorage"}, - {BCLog::TXRECONCILIATION, "txreconciliation"}, - {BCLog::SCAN, "scan"}, - {BCLog::TXPACKAGES, "txpackages"}, - {BCLog::ALL, "1"}, - {BCLog::ALL, "all"}, + {"blockstorage", BCLog::BLOCKSTORAGE}, + {"txreconciliation", BCLog::TXRECONCILIATION}, + {"scan", BCLog::SCAN}, + {"txpackages", BCLog::TXPACKAGES}, //Start Dash - {BCLog::CHAINLOCKS, "chainlocks"}, - {BCLog::GOBJECT, "gobject"}, - {BCLog::INSTANTSEND, "instantsend"}, - {BCLog::LLMQ, "llmq"}, - {BCLog::LLMQ_DKG, "llmq-dkg"}, - {BCLog::LLMQ_SIGS, "llmq-sigs"}, - {BCLog::MNPAYMENTS, "mnpayments"}, - {BCLog::MNSYNC, "mnsync"}, - {BCLog::COINJOIN, "coinjoin"}, - {BCLog::SPORK, "spork"}, - {BCLog::NETCONN, "netconn"}, - {BCLog::CREDITPOOL, "creditpool"}, - {BCLog::EHF, "ehf"}, - {BCLog::DASH, "dash"}, + {"chainlocks", BCLog::CHAINLOCKS}, + {"gobject", BCLog::GOBJECT}, + {"instantsend", BCLog::INSTANTSEND}, + {"llmq", BCLog::LLMQ}, + {"llmq-dkg", BCLog::LLMQ_DKG}, + {"llmq-sigs", BCLog::LLMQ_SIGS}, + {"mnpayments", BCLog::MNPAYMENTS}, + {"mnsync", BCLog::MNSYNC}, + {"coinjoin", BCLog::COINJOIN}, + {"spork", BCLog::SPORK}, + {"netconn", BCLog::NETCONN}, + {"creditpool", BCLog::CREDITPOOL}, + {"ehf", BCLog::EHF}, + {"dash", BCLog::DASH}, //End Dash }; +static const std::unordered_map LOG_CATEGORIES_BY_FLAG{ + // Swap keys and values from LOG_CATEGORIES_BY_STR. + [](const std::map& in) { + std::unordered_map out; + for (const auto& [k, v] : in) { + const bool inserted{out.emplace(v, k).second}; + assert(inserted); + } + /* Start Dash */ + out.emplace(BCLog::NET_NETCONN, "net|netconn"); + /* End Dash */ + return out; + }(LOG_CATEGORIES_BY_STR) +}; + bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str) { - if (str.empty()) { + if (str.empty() || str == "1" || str == "all") { flag = BCLog::ALL; return true; } - for (const CLogCategoryDesc& category_desc : LogCategories) { - if (category_desc.category == str) { - flag = category_desc.flag; - return true; - } + auto it = LOG_CATEGORIES_BY_STR.find(str); + if (it != LOG_CATEGORIES_BY_STR.end()) { + flag = it->second; + return true; } return false; } @@ -234,108 +238,14 @@ std::string BCLog::Logger::LogLevelToStr(BCLog::Level level) assert(false); } -std::string LogCategoryToStr(BCLog::LogFlags category) +static std::string LogCategoryToStr(BCLog::LogFlags category) { - // Each log category string representation should sync with LogCategories - switch (category) { - case BCLog::LogFlags::NONE: - return ""; - case BCLog::LogFlags::NET: - return "net"; - case BCLog::LogFlags::TOR: - return "tor"; - case BCLog::LogFlags::MEMPOOL: - return "mempool"; - case BCLog::LogFlags::HTTP: - return "http"; - case BCLog::LogFlags::BENCHMARK: - return "bench"; - case BCLog::LogFlags::ZMQ: - return "zmq"; - case BCLog::LogFlags::WALLETDB: - return "walletdb"; - case BCLog::LogFlags::RPC: - return "rpc"; - case BCLog::LogFlags::ESTIMATEFEE: - return "estimatefee"; - case BCLog::LogFlags::ADDRMAN: - return "addrman"; - case BCLog::LogFlags::SELECTCOINS: - return "selectcoins"; - case BCLog::LogFlags::REINDEX: - return "reindex"; - case BCLog::LogFlags::CMPCTBLOCK: - return "cmpctblock"; - case BCLog::LogFlags::RANDOM: - return "rand"; - case BCLog::LogFlags::PRUNE: - return "prune"; - case BCLog::LogFlags::PROXY: - return "proxy"; - case BCLog::LogFlags::MEMPOOLREJ: - return "mempoolrej"; - case BCLog::LogFlags::LIBEVENT: - return "libevent"; - case BCLog::LogFlags::COINDB: - return "coindb"; - case BCLog::LogFlags::QT: - return "qt"; - case BCLog::LogFlags::LEVELDB: - return "leveldb"; - case BCLog::LogFlags::VALIDATION: - return "validation"; - case BCLog::LogFlags::I2P: - return "i2p"; - case BCLog::LogFlags::IPC: - return "ipc"; -#ifdef DEBUG_LOCKCONTENTION - case BCLog::LogFlags::LOCK: - return "lock"; -#endif - case BCLog::LogFlags::BLOCKSTORAGE: - return "blockstorage"; - case BCLog::LogFlags::TXRECONCILIATION: - return "txreconciliation"; - case BCLog::LogFlags::SCAN: - return "scan"; - case BCLog::LogFlags::TXPACKAGES: - return "txpackages"; - /* Start Dash */ - case BCLog::LogFlags::CHAINLOCKS: - return "chainlocks"; - case BCLog::LogFlags::GOBJECT: - return "gobject"; - case BCLog::LogFlags::INSTANTSEND: - return "instantsend"; - case BCLog::LogFlags::LLMQ: - return "llmq"; - case BCLog::LogFlags::LLMQ_DKG: - return "llmq-dkg"; - case BCLog::LogFlags::LLMQ_SIGS: - return "llmq-sigs"; - case BCLog::LogFlags::MNPAYMENTS: - return "mnpayments"; - case BCLog::LogFlags::MNSYNC: - return "mnsync"; - case BCLog::LogFlags::COINJOIN: - return "coinjoin"; - case BCLog::LogFlags::SPORK: - return "spork"; - case BCLog::LogFlags::NETCONN: - return "netconn"; - case BCLog::LogFlags::CREDITPOOL: - return "creditpool"; - case BCLog::LogFlags::EHF: - return "ehf"; - case BCLog::LogFlags::DASH: - return "dash"; - case BCLog::LogFlags::NET_NETCONN: - return "net|netconn"; - /* End Dash */ - case BCLog::LogFlags::ALL: + if (category == BCLog::ALL) { return "all"; } - assert(false); + auto it = LOG_CATEGORIES_BY_FLAG.find(category); + assert(it != LOG_CATEGORIES_BY_FLAG.end()); + return it->second; } static std::optional GetLogLevel(const std::string& level_str) @@ -357,19 +267,14 @@ static std::optional GetLogLevel(const std::string& level_str) std::vector BCLog::Logger::LogCategoriesList(bool enabled_only) const { - // Sort log categories by alphabetical order. - std::array categories; - std::copy(std::begin(LogCategories), std::end(LogCategories), categories.begin()); - std::sort(categories.begin(), categories.end(), [](auto a, auto b) { return a.category < b.category; }); - std::vector ret; - for (const CLogCategoryDesc& category_desc : categories) { - if (category_desc.flag == BCLog::NONE || category_desc.flag == BCLog::ALL || category_desc.flag == BCLog::DASH) continue; - LogCategory catActive; - catActive.category = category_desc.category; - catActive.active = WillLogCategory(category_desc.flag); - if (!enabled_only || catActive.active) { - ret.push_back(catActive); + ret.reserve(LOG_CATEGORIES_BY_STR.size()); + for (const auto& [category, flag] : LOG_CATEGORIES_BY_STR) { + if (flag != BCLog::DASH) { + LogCategory catActive{.category = category, .active = WillLogCategory(flag)}; + if (!enabled_only || catActive.active) { + ret.push_back(catActive); + } } } return ret; diff --git a/src/logging.h b/src/logging.h index 4bb0cd2c766f..7ecb292711b0 100644 --- a/src/logging.h +++ b/src/logging.h @@ -66,10 +66,10 @@ namespace BCLog { #ifdef DEBUG_LOCKCONTENTION LOCK = (1 << 24), #endif - BLOCKSTORAGE = (1 << 26), - TXRECONCILIATION = (1 << 27), - SCAN = (1 << 28), - TXPACKAGES = (1 << 29), + BLOCKSTORAGE = (1 << 25), + TXRECONCILIATION = (1 << 26), + SCAN = (1 << 27), + TXPACKAGES = (1 << 28), //Start Dash CHAINLOCKS = ((uint64_t)1 << 32), @@ -128,7 +128,7 @@ namespace BCLog { std::atomic m_log_level{DEFAULT_LOG_LEVEL}; /** Log categories bitfield. */ - std::atomic m_categories{0}; + std::atomic m_categories{BCLog::NONE}; std::string LogTimestampStr(const std::string& str); std::string LogThreadNameStr(const std::string &str); @@ -136,6 +136,8 @@ namespace BCLog { /** Slots that connect to the print signal */ std::list> m_print_callbacks /* GUARDED_BY(m_cs) */ {}; + std::string GetLogPrefix(LogFlags category, Level level) const; + public: bool m_print_to_console = false; bool m_print_to_file = false; @@ -149,8 +151,6 @@ namespace BCLog { fs::path m_file_path; std::atomic m_reopen_file{false}; - std::string GetLogPrefix(LogFlags category, Level level) const; - /** Send a string to the log output */ void LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, int source_line, BCLog::LogFlags category, BCLog::Level level); diff --git a/src/net.cpp b/src/net.cpp index 68e7ac366c43..1342a93e3f36 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2259,7 +2259,7 @@ void CConnman::CalculateNumConnectionsChangedStats() int torNodes = 0; mapMsgTypeSize mapRecvBytesMsgStats; mapMsgTypeSize mapSentBytesMsgStats; - for (const std::string &msg : getAllNetMessageTypes()) { + for (const auto& msg : ALL_NET_MESSAGE_TYPES) { mapRecvBytesMsgStats[msg] = 0; mapSentBytesMsgStats[msg] = 0; } @@ -2288,7 +2288,7 @@ void CConnman::CalculateNumConnectionsChangedStats() if (last_ping_time > 0) ::g_stats_client->timing("peers.ping_us", last_ping_time, 1.0f); } - for (const std::string &msg : getAllNetMessageTypes()) { + for (const auto& msg : ALL_NET_MESSAGE_TYPES) { ::g_stats_client->gauge("bandwidth.message." + msg + ".totalBytesReceived", mapRecvBytesMsgStats[msg], 1.0f); ::g_stats_client->gauge("bandwidth.message." + msg + ".totalBytesSent", mapSentBytesMsgStats[msg], 1.0f); } @@ -4784,8 +4784,9 @@ CNode::CNode(NodeId idIn, { if (inbound_onion) assert(conn_type_in == ConnectionType::INBOUND); - for (const std::string &msg : getAllNetMessageTypes()) + for (const auto& msg : ALL_NET_MESSAGE_TYPES) { mapRecvBytesPerMsgType[msg] = 0; + } mapRecvBytesPerMsgType[NET_MESSAGE_TYPE_OTHER] = 0; if (fLogIPs) { diff --git a/src/net_processing.cpp b/src/net_processing.cpp index b1cf73382e5f..c46366ad4827 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1149,7 +1149,7 @@ class PeerManagerImpl final : public PeerManager /** Orphan/conflicted/etc transactions that are kept for compact block reconstruction. * The last -blockreconstructionextratxn/DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN of * these are kept in a ring buffer */ - std::vector> vExtraTxnForCompact GUARDED_BY(g_msgproc_mutex); + std::vector vExtraTxnForCompact GUARDED_BY(g_msgproc_mutex); /** Offset into vExtraTxnForCompact to insert the next tx */ size_t vExtraTxnForCompactIt GUARDED_BY(g_msgproc_mutex) = 0; @@ -1975,9 +1975,9 @@ void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx) if (m_opts.max_extra_txs == 0) return; if (vExtraTxnForCompact.size() < m_opts.max_extra_txs) { if (vExtraTxnForCompact.empty()) vExtraTxnForCompact.reserve(m_opts.max_extra_txs); - vExtraTxnForCompact.emplace_back(tx->GetInstanceHash(), tx); + vExtraTxnForCompact.emplace_back(tx); } else { - vExtraTxnForCompact[vExtraTxnForCompactIt] = std::make_pair(tx->GetInstanceHash(), tx); + vExtraTxnForCompact[vExtraTxnForCompactIt] = tx; } vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % m_opts.max_extra_txs; } @@ -5845,7 +5845,7 @@ void PeerManagerImpl::ProcessMessage( } bool found = false; - const std::vector &allMessages = getAllNetMessageTypes(); + const auto& allMessages = ALL_NET_MESSAGE_TYPES; for (const std::string& msg : allMessages) { if(msg == msg_type) { found = true; diff --git a/src/protocol.cpp b/src/protocol.cpp index c672016c3538..1658d419f27c 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -7,177 +7,11 @@ #include -#include - -#define MAKE_MSG(var_name, p2p_name_str) \ - const char* var_name=p2p_name_str; \ - static_assert(std::size(p2p_name_str) <= CMessageHeader::COMMAND_SIZE + 1, "p2p_name_str cannot be greater than COMMAND_SIZE"); // Includes +1 for null termination character. - -namespace NetMsgType { -MAKE_MSG(VERSION, "version"); -MAKE_MSG(VERACK, "verack"); -MAKE_MSG(ADDR, "addr"); -MAKE_MSG(ADDRV2, "addrv2"); -MAKE_MSG(SENDADDRV2, "sendaddrv2"); -MAKE_MSG(INV, "inv"); -MAKE_MSG(GETDATA, "getdata"); -MAKE_MSG(MERKLEBLOCK, "merkleblock"); -MAKE_MSG(GETBLOCKS, "getblocks"); -MAKE_MSG(GETHEADERS, "getheaders"); -MAKE_MSG(TX, "tx"); -MAKE_MSG(HEADERS, "headers"); -MAKE_MSG(BLOCK, "block"); -MAKE_MSG(GETADDR, "getaddr"); -MAKE_MSG(MEMPOOL, "mempool"); -MAKE_MSG(PING, "ping"); -MAKE_MSG(PONG, "pong"); -MAKE_MSG(NOTFOUND, "notfound"); -MAKE_MSG(FILTERLOAD, "filterload"); -MAKE_MSG(FILTERADD, "filteradd"); -MAKE_MSG(FILTERCLEAR, "filterclear"); -MAKE_MSG(SENDHEADERS, "sendheaders"); -MAKE_MSG(SENDCMPCT, "sendcmpct"); -MAKE_MSG(CMPCTBLOCK, "cmpctblock"); -MAKE_MSG(GETBLOCKTXN, "getblocktxn"); -MAKE_MSG(BLOCKTXN, "blocktxn"); -MAKE_MSG(GETCFILTERS, "getcfilters"); -MAKE_MSG(CFILTER, "cfilter"); -MAKE_MSG(GETCFHEADERS, "getcfheaders"); -MAKE_MSG(CFHEADERS, "cfheaders"); -MAKE_MSG(GETCFCHECKPT, "getcfcheckpt"); -MAKE_MSG(CFCHECKPT, "cfcheckpt"); -MAKE_MSG(SENDTXRCNCL, "sendtxrcncl"); -// Dash message types -MAKE_MSG(SPORK, "spork"); -MAKE_MSG(GETSPORKS, "getsporks"); -MAKE_MSG(DSACCEPT, "dsa"); -MAKE_MSG(DSVIN, "dsi"); -MAKE_MSG(DSFINALTX, "dsf"); -MAKE_MSG(DSSIGNFINALTX, "dss"); -MAKE_MSG(DSCOMPLETE, "dsc"); -MAKE_MSG(DSSTATUSUPDATE, "dssu"); -MAKE_MSG(DSTX, "dstx"); -MAKE_MSG(DSQUEUE, "dsq"); -MAKE_MSG(SENDDSQUEUE, "senddsq"); -MAKE_MSG(SYNCSTATUSCOUNT, "ssc"); -MAKE_MSG(MNGOVERNANCESYNC, "govsync"); -MAKE_MSG(MNGOVERNANCEOBJECT, "govobj"); -MAKE_MSG(MNGOVERNANCEOBJECTVOTE, "govobjvote"); -MAKE_MSG(GETMNLISTDIFF, "getmnlistd"); -MAKE_MSG(MNLISTDIFF, "mnlistdiff"); -MAKE_MSG(QSENDRECSIGS, "qsendrecsigs"); -MAKE_MSG(QFCOMMITMENT, "qfcommit"); -MAKE_MSG(QCONTRIB, "qcontrib"); -MAKE_MSG(QCOMPLAINT, "qcomplaint"); -MAKE_MSG(QJUSTIFICATION, "qjustify"); -MAKE_MSG(QPCOMMITMENT, "qpcommit"); -MAKE_MSG(QWATCH, "qwatch"); -MAKE_MSG(QSIGSESANN, "qsigsesann"); -MAKE_MSG(QSIGSHARESINV, "qsigsinv"); -MAKE_MSG(QGETSIGSHARES, "qgetsigs"); -MAKE_MSG(QBSIGSHARES, "qbsigs"); -MAKE_MSG(QSIGREC, "qsigrec"); -MAKE_MSG(QSIGSHARE, "qsigshare"); -MAKE_MSG(QGETDATA, "qgetdata"); -MAKE_MSG(QDATA, "qdata"); -MAKE_MSG(CLSIG, "clsig"); -MAKE_MSG(ISDLOCK, "isdlock"); -MAKE_MSG(MNAUTH, "mnauth"); -MAKE_MSG(GETHEADERS2, "getheaders2"); -MAKE_MSG(SENDHEADERS2, "sendheaders2"); -MAKE_MSG(HEADERS2, "headers2"); -MAKE_MSG(GETQUORUMROTATIONINFO, "getqrinfo"); -MAKE_MSG(QUORUMROTATIONINFO, "qrinfo"); -MAKE_MSG(PLATFORMBAN, "platformban"); -}; // namespace NetMsgType - -/** All known message types. Keep this in the same order as the list of - * messages above and in protocol.h. - */ -const static std::vector g_all_net_message_types{ - NetMsgType::VERSION, - NetMsgType::VERACK, - NetMsgType::ADDR, - NetMsgType::ADDRV2, - NetMsgType::SENDADDRV2, - NetMsgType::INV, - NetMsgType::GETDATA, - NetMsgType::MERKLEBLOCK, - NetMsgType::GETBLOCKS, - NetMsgType::GETHEADERS, - NetMsgType::TX, - NetMsgType::HEADERS, - NetMsgType::BLOCK, - NetMsgType::GETADDR, - NetMsgType::MEMPOOL, - NetMsgType::PING, - NetMsgType::PONG, - NetMsgType::NOTFOUND, - NetMsgType::FILTERLOAD, - NetMsgType::FILTERADD, - NetMsgType::FILTERCLEAR, - NetMsgType::SENDHEADERS, - NetMsgType::SENDCMPCT, - NetMsgType::CMPCTBLOCK, - NetMsgType::GETBLOCKTXN, - NetMsgType::BLOCKTXN, - NetMsgType::GETCFILTERS, - NetMsgType::CFILTER, - NetMsgType::GETCFHEADERS, - NetMsgType::CFHEADERS, - NetMsgType::GETCFCHECKPT, - NetMsgType::CFCHECKPT, - NetMsgType::SENDTXRCNCL, - // Dash message types - // NOTE: do NOT include non-implmented here, we want them to be "Unknown command" in ProcessMessage() - NetMsgType::SPORK, - NetMsgType::GETSPORKS, - NetMsgType::SENDDSQUEUE, - NetMsgType::DSACCEPT, - NetMsgType::DSVIN, - NetMsgType::DSFINALTX, - NetMsgType::DSSIGNFINALTX, - NetMsgType::DSCOMPLETE, - NetMsgType::DSSTATUSUPDATE, - NetMsgType::DSTX, - NetMsgType::DSQUEUE, - NetMsgType::SYNCSTATUSCOUNT, - NetMsgType::MNGOVERNANCESYNC, - NetMsgType::MNGOVERNANCEOBJECT, - NetMsgType::MNGOVERNANCEOBJECTVOTE, - NetMsgType::GETMNLISTDIFF, - NetMsgType::MNLISTDIFF, - NetMsgType::QSENDRECSIGS, - NetMsgType::QFCOMMITMENT, - NetMsgType::QCONTRIB, - NetMsgType::QCOMPLAINT, - NetMsgType::QJUSTIFICATION, - NetMsgType::QPCOMMITMENT, - NetMsgType::QWATCH, - NetMsgType::QSIGSESANN, - NetMsgType::QSIGSHARESINV, - NetMsgType::QGETSIGSHARES, - NetMsgType::QBSIGSHARES, - NetMsgType::QSIGREC, - NetMsgType::QSIGSHARE, - NetMsgType::QGETDATA, - NetMsgType::QDATA, - NetMsgType::CLSIG, - NetMsgType::ISDLOCK, - NetMsgType::MNAUTH, - NetMsgType::GETHEADERS2, - NetMsgType::SENDHEADERS2, - NetMsgType::HEADERS2, - NetMsgType::GETQUORUMROTATIONINFO, - NetMsgType::QUORUMROTATIONINFO, - NetMsgType::PLATFORMBAN, -}; - /** Message types that are not allowed by blocks-relay-only policy. * We do not want most of CoinJoin, DKG or LLMQ signing messages to be relayed * to/from nodes via connections that were established in this mode. * Make sure to keep this list up to date whenever a new message type is added. - * NOTE: Unlike the list above, this list is sorted alphabetically. + * NOTE: Unlike ALL_NET_MESSAGE_TYPES in protocol.h, this list is sorted alphabetically. */ const static std::string netMessageTypesViolateBlocksOnly[] = { NetMsgType::DSACCEPT, @@ -312,11 +146,6 @@ std::string CInv::ToString() const } } -const std::vector &getAllNetMessageTypes() -{ - return g_all_net_message_types; -} - bool NetMessageViolatesBlocksOnly(const std::string& msg_type) { return netMessageTypesViolateBlocksOnlySet.find(msg_type) != netMessageTypesViolateBlocksOnlySet.end(); diff --git a/src/protocol.h b/src/protocol.h index c9c8337d9965..e607ac9f0751 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -55,106 +56,105 @@ class CMessageHeader /** * Bitcoin protocol message types. When adding new message types, don't forget - * to update allNetMessageTypes in protocol.cpp. + * to update ALL_NET_MESSAGE_TYPES below. */ namespace NetMsgType { - /** * The version message provides information about the transmitting node to the * receiving node at the beginning of a connection. */ -extern const char* VERSION; +inline constexpr const char* VERSION{"version"}; /** * The verack message acknowledges a previously-received version message, * informing the connecting node that it can begin to send other messages. */ -extern const char* VERACK; +inline constexpr const char* VERACK{"verack"}; /** * The addr (IP address) message relays connection information for peers on the * network. */ -extern const char* ADDR; +inline constexpr const char* ADDR{"addr"}; /** * The addrv2 message relays connection information for peers on the network just * like the addr message, but is extended to allow gossiping of longer node * addresses (see BIP155). */ -extern const char *ADDRV2; +inline constexpr const char* ADDRV2{"addrv2"}; /** * The sendaddrv2 message signals support for receiving ADDRV2 messages (BIP155). * It also implies that its sender can encode as ADDRV2 and would send ADDRV2 * instead of ADDR to a peer that has signaled ADDRV2 support by sending SENDADDRV2. */ -extern const char *SENDADDRV2; +inline constexpr const char* SENDADDRV2{"sendaddrv2"}; /** * The inv message (inventory message) transmits one or more inventories of * objects known to the transmitting peer. */ -extern const char* INV; +inline constexpr const char* INV{"inv"}; /** * The getdata message requests one or more data objects from another node. */ -extern const char* GETDATA; +inline constexpr const char* GETDATA{"getdata"}; /** * The merkleblock message is a reply to a getdata message which requested a * block using the inventory type MSG_MERKLEBLOCK. * @since protocol version 70001 as described by BIP37. */ -extern const char* MERKLEBLOCK; +inline constexpr const char* MERKLEBLOCK{"merkleblock"}; /** * The getblocks message requests an inv message that provides block header * hashes starting from a particular point in the block chain. */ -extern const char* GETBLOCKS; +inline constexpr const char* GETBLOCKS{"getblocks"}; /** * The getheaders message requests a headers message that provides block * headers starting from a particular point in the block chain. * @since protocol version 31800. */ -extern const char* GETHEADERS; +inline constexpr const char* GETHEADERS{"getheaders"}; /** * The tx message transmits a single transaction. */ -extern const char* TX; +inline constexpr const char* TX{"tx"}; /** * The headers message sends one or more block headers to a node which * previously requested certain headers with a getheaders message. * @since protocol version 31800. */ -extern const char* HEADERS; +inline constexpr const char* HEADERS{"headers"}; /** * The block message transmits a single serialized block. */ -extern const char* BLOCK; +inline constexpr const char* BLOCK{"block"}; /** * The getaddr message requests an addr message from the receiving node, * preferably one with lots of IP addresses of other receiving nodes. */ -extern const char* GETADDR; +inline constexpr const char* GETADDR{"getaddr"}; /** * The mempool message requests the TXIDs of transactions that the receiving * node has verified as valid but which have not yet appeared in a block. * @since protocol version 60002 as described by BIP35. * Only available with service bit NODE_BLOOM, see also BIP111. */ -extern const char* MEMPOOL; +inline constexpr const char* MEMPOOL{"mempool"}; /** * The ping message is sent periodically to help confirm that the receiving * peer is still connected. */ -extern const char* PING; +inline constexpr const char* PING{"ping"}; /** * The pong message replies to a ping message, proving to the pinging node that * the ponging node is still alive. * @since protocol version 60001 as described by BIP31. */ -extern const char* PONG; +inline constexpr const char* PONG{"pong"}; /** * The notfound message is a reply to a getdata message which requested an * object the receiving node does not have available for relay. * @since protocol version 70001. */ -extern const char* NOTFOUND; +inline constexpr const char* NOTFOUND{"notfound"}; /** * The filterload message tells the receiving peer to filter all relayed * transactions and requested merkle blocks through the provided filter. @@ -162,7 +162,7 @@ extern const char* NOTFOUND; * Only available with service bit NODE_BLOOM since protocol version * 70011 as described by BIP111. */ -extern const char* FILTERLOAD; +inline constexpr const char* FILTERLOAD{"filterload"}; /** * The filteradd message tells the receiving peer to add a single element to a * previously-set bloom filter, such as a new public key. @@ -170,7 +170,7 @@ extern const char* FILTERLOAD; * Only available with service bit NODE_BLOOM since protocol version * 70011 as described by BIP111. */ -extern const char* FILTERADD; +inline constexpr const char* FILTERADD{"filteradd"}; /** * The filterclear message tells the receiving peer to remove a previously-set * bloom filter. @@ -178,13 +178,13 @@ extern const char* FILTERADD; * Only available with service bit NODE_BLOOM since protocol version * 70011 as described by BIP111. */ -extern const char* FILTERCLEAR; +inline constexpr const char* FILTERCLEAR{"filterclear"}; /** * Indicates that a node prefers to receive new block announcements via a * "headers" message rather than an "inv". * @since protocol version 70012 as described by BIP130. */ -extern const char* SENDHEADERS; +inline constexpr const char* SENDHEADERS{"sendheaders"}; /** * Contains a 1-byte bool and 8-byte LE version number. @@ -193,36 +193,36 @@ extern const char* SENDHEADERS; * "cmpctblock" message rather than an "inv", depending on message contents. * @since protocol version 70209 as described by BIP 152 */ -extern const char* SENDCMPCT; +inline constexpr const char* SENDCMPCT{"sendcmpct"}; /** * Contains a CBlockHeaderAndShortTxIDs object - providing a header and * list of "short txids". * @since protocol version 70209 as described by BIP 152 */ -extern const char* CMPCTBLOCK; +inline constexpr const char* CMPCTBLOCK{"cmpctblock"}; /** * Contains a BlockTransactionsRequest * Peer should respond with "blocktxn" message. * @since protocol version 70209 as described by BIP 152 */ -extern const char* GETBLOCKTXN; +inline constexpr const char* GETBLOCKTXN{"getblocktxn"}; /** * Contains a BlockTransactions. * Sent in response to a "getblocktxn" message. * @since protocol version 70209 as described by BIP 152 */ -extern const char* BLOCKTXN; +inline constexpr const char* BLOCKTXN{"blocktxn"}; /** * getcfilters requests compact filters for a range of blocks. * Only available with service bit NODE_COMPACT_FILTERS as described by * BIP 157 & 158. */ -extern const char* GETCFILTERS; +inline constexpr const char* GETCFILTERS{"getcfilters"}; /** * cfilter is a response to a getcfilters request containing a single compact * filter. */ -extern const char* CFILTER; +inline constexpr const char* CFILTER{"cfilter"}; /** * getcfheaders requests a compact filter header and the filter hashes for a * range of blocks, which can then be used to reconstruct the filter headers @@ -230,79 +230,156 @@ extern const char* CFILTER; * Only available with service bit NODE_COMPACT_FILTERS as described by * BIP 157 & 158. */ -extern const char* GETCFHEADERS; +inline constexpr const char* GETCFHEADERS{"getcfheaders"}; /** * cfheaders is a response to a getcfheaders request containing a filter header * and a vector of filter hashes for each subsequent block in the requested range. */ -extern const char* CFHEADERS; +inline constexpr const char* CFHEADERS{"cfheaders"}; /** * getcfcheckpt requests evenly spaced compact filter headers, enabling * parallelized download and validation of the headers between them. * Only available with service bit NODE_COMPACT_FILTERS as described by * BIP 157 & 158. */ -extern const char* GETCFCHECKPT; +inline constexpr const char* GETCFCHECKPT{"getcfcheckpt"}; /** * cfcheckpt is a response to a getcfcheckpt request containing a vector of * evenly spaced filter headers for blocks on the requested chain. */ -extern const char* CFCHECKPT; +inline constexpr const char* CFCHECKPT{"cfcheckpt"}; /** * Contains a 4-byte version number and an 8-byte salt. * The salt is used to compute short txids needed for efficient * txreconciliation, as described by BIP 330. */ -extern const char* SENDTXRCNCL; +inline constexpr const char* SENDTXRCNCL{"sendtxrcncl"}; // Dash message types // NOTE: do NOT declare non-implmented here, we don't want them to be exposed to the outside // TODO: add description -extern const char* SPORK; -extern const char* GETSPORKS; -extern const char* DSACCEPT; -extern const char* DSVIN; -extern const char* DSFINALTX; -extern const char* DSSIGNFINALTX; -extern const char* DSCOMPLETE; -extern const char* DSSTATUSUPDATE; -extern const char* DSTX; -extern const char* DSQUEUE; -extern const char* SENDDSQUEUE; -extern const char* SYNCSTATUSCOUNT; -extern const char* MNGOVERNANCESYNC; -extern const char* MNGOVERNANCEOBJECT; -extern const char* MNGOVERNANCEOBJECTVOTE; -extern const char* GETMNLISTDIFF; -extern const char* MNLISTDIFF; -extern const char* QSENDRECSIGS; -extern const char* QFCOMMITMENT; -extern const char* QCONTRIB; -extern const char* QCOMPLAINT; -extern const char* QJUSTIFICATION; -extern const char* QPCOMMITMENT; -extern const char* QWATCH; -extern const char* QSIGSESANN; -extern const char* QSIGSHARESINV; -extern const char* QGETSIGSHARES; -extern const char* QBSIGSHARES; -extern const char* QSIGREC; -extern const char* QSIGSHARE; -extern const char* QGETDATA; -extern const char* QDATA; -extern const char* CLSIG; -extern const char* ISDLOCK; -extern const char* MNAUTH; -extern const char* GETHEADERS2; -extern const char* SENDHEADERS2; -extern const char* HEADERS2; -extern const char* GETQUORUMROTATIONINFO; -extern const char* QUORUMROTATIONINFO; -extern const char* PLATFORMBAN; -}; - -/* Get a vector of all valid message types (see above) */ -const std::vector& getAllNetMessageTypes(); +inline constexpr const char* SPORK{"spork"}; +inline constexpr const char* GETSPORKS{"getsporks"}; +inline constexpr const char* DSACCEPT{"dsa"}; +inline constexpr const char* DSVIN{"dsi"}; +inline constexpr const char* DSFINALTX{"dsf"}; +inline constexpr const char* DSSIGNFINALTX{"dss"}; +inline constexpr const char* DSCOMPLETE{"dsc"}; +inline constexpr const char* DSSTATUSUPDATE{"dssu"}; +inline constexpr const char* DSTX{"dstx"}; +inline constexpr const char* DSQUEUE{"dsq"}; +inline constexpr const char* SENDDSQUEUE{"senddsq"}; +inline constexpr const char* SYNCSTATUSCOUNT{"ssc"}; +inline constexpr const char* MNGOVERNANCESYNC{"govsync"}; +inline constexpr const char* MNGOVERNANCEOBJECT{"govobj"}; +inline constexpr const char* MNGOVERNANCEOBJECTVOTE{"govobjvote"}; +inline constexpr const char* GETMNLISTDIFF{"getmnlistd"}; +inline constexpr const char* MNLISTDIFF{"mnlistdiff"}; +inline constexpr const char* QSENDRECSIGS{"qsendrecsigs"}; +inline constexpr const char* QFCOMMITMENT{"qfcommit"}; +inline constexpr const char* QCONTRIB{"qcontrib"}; +inline constexpr const char* QCOMPLAINT{"qcomplaint"}; +inline constexpr const char* QJUSTIFICATION{"qjustify"}; +inline constexpr const char* QPCOMMITMENT{"qpcommit"}; +inline constexpr const char* QWATCH{"qwatch"}; +inline constexpr const char* QSIGSESANN{"qsigsesann"}; +inline constexpr const char* QSIGSHARESINV{"qsigsinv"}; +inline constexpr const char* QGETSIGSHARES{"qgetsigs"}; +inline constexpr const char* QBSIGSHARES{"qbsigs"}; +inline constexpr const char* QSIGREC{"qsigrec"}; +inline constexpr const char* QSIGSHARE{"qsigshare"}; +inline constexpr const char* QGETDATA{"qgetdata"}; +inline constexpr const char* QDATA{"qdata"}; +inline constexpr const char* CLSIG{"clsig"}; +inline constexpr const char* ISDLOCK{"isdlock"}; +inline constexpr const char* MNAUTH{"mnauth"}; +inline constexpr const char* GETHEADERS2{"getheaders2"}; +inline constexpr const char* SENDHEADERS2{"sendheaders2"}; +inline constexpr const char* HEADERS2{"headers2"}; +inline constexpr const char* GETQUORUMROTATIONINFO{"getqrinfo"}; +inline constexpr const char* QUORUMROTATIONINFO{"qrinfo"}; +inline constexpr const char* PLATFORMBAN{"platformban"}; +}; // namespace NetMsgType + +/** All known message types (see above). Keep this in the same order as the list of messages above. */ +inline const std::array ALL_NET_MESSAGE_TYPES{std::to_array({ + NetMsgType::VERSION, + NetMsgType::VERACK, + NetMsgType::ADDR, + NetMsgType::ADDRV2, + NetMsgType::SENDADDRV2, + NetMsgType::INV, + NetMsgType::GETDATA, + NetMsgType::MERKLEBLOCK, + NetMsgType::GETBLOCKS, + NetMsgType::GETHEADERS, + NetMsgType::TX, + NetMsgType::HEADERS, + NetMsgType::BLOCK, + NetMsgType::GETADDR, + NetMsgType::MEMPOOL, + NetMsgType::PING, + NetMsgType::PONG, + NetMsgType::NOTFOUND, + NetMsgType::FILTERLOAD, + NetMsgType::FILTERADD, + NetMsgType::FILTERCLEAR, + NetMsgType::SENDHEADERS, + NetMsgType::SENDCMPCT, + NetMsgType::CMPCTBLOCK, + NetMsgType::GETBLOCKTXN, + NetMsgType::BLOCKTXN, + NetMsgType::GETCFILTERS, + NetMsgType::CFILTER, + NetMsgType::GETCFHEADERS, + NetMsgType::CFHEADERS, + NetMsgType::GETCFCHECKPT, + NetMsgType::CFCHECKPT, + NetMsgType::SENDTXRCNCL, + // Dash message types + // NOTE: do NOT include non-implmented here, we want them to be "Unknown command" in ProcessMessage() + NetMsgType::SPORK, + NetMsgType::GETSPORKS, + NetMsgType::SENDDSQUEUE, + NetMsgType::DSACCEPT, + NetMsgType::DSVIN, + NetMsgType::DSFINALTX, + NetMsgType::DSSIGNFINALTX, + NetMsgType::DSCOMPLETE, + NetMsgType::DSSTATUSUPDATE, + NetMsgType::DSTX, + NetMsgType::DSQUEUE, + NetMsgType::SYNCSTATUSCOUNT, + NetMsgType::MNGOVERNANCESYNC, + NetMsgType::MNGOVERNANCEOBJECT, + NetMsgType::MNGOVERNANCEOBJECTVOTE, + NetMsgType::GETMNLISTDIFF, + NetMsgType::MNLISTDIFF, + NetMsgType::QSENDRECSIGS, + NetMsgType::QFCOMMITMENT, + NetMsgType::QCONTRIB, + NetMsgType::QCOMPLAINT, + NetMsgType::QJUSTIFICATION, + NetMsgType::QPCOMMITMENT, + NetMsgType::QWATCH, + NetMsgType::QSIGSESANN, + NetMsgType::QSIGSHARESINV, + NetMsgType::QGETSIGSHARES, + NetMsgType::QBSIGSHARES, + NetMsgType::QSIGREC, + NetMsgType::QSIGSHARE, + NetMsgType::QGETDATA, + NetMsgType::QDATA, + NetMsgType::CLSIG, + NetMsgType::ISDLOCK, + NetMsgType::MNAUTH, + NetMsgType::GETHEADERS2, + NetMsgType::SENDHEADERS2, + NetMsgType::HEADERS2, + NetMsgType::GETQUORUMROTATIONINFO, + NetMsgType::QUORUMROTATIONINFO, + NetMsgType::PLATFORMBAN, +})}; /* Whether the message type violates blocks-relay-only policy */ bool NetMessageViolatesBlocksOnly(const std::string& msg_type); diff --git a/src/rpc/node.cpp b/src/rpc/node.cpp index 8d757a7cc60e..5cff27703c50 100644 --- a/src/rpc/node.cpp +++ b/src/rpc/node.cpp @@ -1047,7 +1047,6 @@ static RPCHelpMan logging() " - \"all\", \"1\" : represent all logging categories.\n" " - \"dash\" activates all Dash-specific categories at once.\n" "To deactivate all categories at once you can specify \"all\" in .\n" - " - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n" , { {"include", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "The of categories to add to debug logging", diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp index 83017f716ece..fa5268129ecf 100644 --- a/src/test/blockencodings_tests.cpp +++ b/src/test/blockencodings_tests.cpp @@ -14,7 +14,7 @@ #include -std::vector> extra_txn; +std::vector extra_txn; BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegTestingSetup) @@ -155,8 +155,8 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest) shortIDs.prefilledtxn.resize(1); shortIDs.prefilledtxn[0] = {1, block.vtx[1]}; shortIDs.shorttxids.resize(2); - shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[0]->GetHash()); - shortIDs.shorttxids[1] = shortIDs.GetShortID(block.vtx[2]->GetHash()); + shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[0]->GetInstanceHash()); + shortIDs.shorttxids[1] = shortIDs.GetShortID(block.vtx[2]->GetInstanceHash()); CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); stream << shortIDs; @@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest) shortIDs.prefilledtxn[0] = {0, block.vtx[0]}; shortIDs.prefilledtxn[1] = {1, block.vtx[2]}; // id == 1 as it is 1 after index 1 shortIDs.shorttxids.resize(1); - shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[1]->GetHash()); + shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[1]->GetInstanceHash()); CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); stream << shortIDs; diff --git a/src/test/fuzz/p2p_transport_serialization.cpp b/src/test/fuzz/p2p_transport_serialization.cpp index cf168942c6a0..46d1ba9c0ff8 100644 --- a/src/test/fuzz/p2p_transport_serialization.cpp +++ b/src/test/fuzz/p2p_transport_serialization.cpp @@ -19,13 +19,12 @@ #include #include -std::vector g_all_messages; +auto g_all_messages = ALL_NET_MESSAGE_TYPES; void initialize_p2p_transport_serialization() { ECC_Start(); SelectParams(ChainType::REGTEST); - g_all_messages = getAllNetMessageTypes(); std::sort(g_all_messages.begin(), g_all_messages.end()); } diff --git a/src/test/fuzz/partially_downloaded_block.cpp b/src/test/fuzz/partially_downloaded_block.cpp index 75caea1fd835..f2af861a15b5 100644 --- a/src/test/fuzz/partially_downloaded_block.cpp +++ b/src/test/fuzz/partially_downloaded_block.cpp @@ -56,7 +56,7 @@ FUZZ_TARGET(partially_downloaded_block, .init = initialize_pdb) // The coinbase is always available available.insert(0); - std::vector> extra_txn; + std::vector extra_txn; for (size_t i = 1; i < block->vtx.size(); ++i) { auto tx{block->vtx[i]}; @@ -64,7 +64,7 @@ FUZZ_TARGET(partially_downloaded_block, .init = initialize_pdb) bool add_to_mempool{fuzzed_data_provider.ConsumeBool()}; if (add_to_extra_txn) { - extra_txn.emplace_back(tx->GetHash(), tx); + extra_txn.emplace_back(tx); available.insert(i); } diff --git a/src/test/fuzz/process_message.cpp b/src/test/fuzz/process_message.cpp index c1c0a0820c0a..bace953e7a61 100644 --- a/src/test/fuzz/process_message.cpp +++ b/src/test/fuzz/process_message.cpp @@ -35,7 +35,7 @@ void initialize_process_message() { if (const auto val{std::getenv("LIMIT_TO_MESSAGE_TYPE")}) { LIMIT_TO_MESSAGE_TYPE = val; - Assert(std::count(getAllNetMessageTypes().begin(), getAllNetMessageTypes().end(), LIMIT_TO_MESSAGE_TYPE)); // Unknown message type passed + Assert(std::count(ALL_NET_MESSAGE_TYPES.begin(), ALL_NET_MESSAGE_TYPES.end(), LIMIT_TO_MESSAGE_TYPE)); // Unknown message type passed } static const auto testing_setup = MakeNoLogFileContext( diff --git a/test/fuzz/test_runner.py b/test/fuzz/test_runner.py index 623ddfacf8c2..414fc96e3aba 100755 --- a/test/fuzz/test_runner.py +++ b/test/fuzz/test_runner.py @@ -206,15 +206,15 @@ def transform_process_message_target(targets, src_dir): p2p_msg_target = "process_message" if (p2p_msg_target, {}) in targets: lines = subprocess.run( - ["git", "grep", "--function-context", "g_all_net_message_types{", src_dir / "src" / "protocol.cpp"], + ["git", "grep", "--function-context", "ALL_NET_MESSAGE_TYPES{", src_dir / "src" / "protocol.h"], check=True, stdout=subprocess.PIPE, text=True, ).stdout.splitlines() # Dash: NetMsgType identifiers do not always match the message type string (e.g. DSACCEPT is "dsa"), - # so map each identifier to the string given in its MAKE_MSG() definition - msg_types = {l.split("(", 1)[1].split(",")[0]: l.split("\"")[1] for l in (src_dir / "src" / "protocol.cpp").read_text().splitlines() if l.startswith("MAKE_MSG(")} - lines = [msg_types[l.split("::", 1)[1].split(",")[0]] for l in lines if l.startswith("src/protocol.cpp- NetMsgType::")] + # so map each identifier to the string given in its NetMsgType definition + msg_types = {l.split("char* ", 1)[1].split("{")[0]: l.split("\"")[1] for l in (src_dir / "src" / "protocol.h").read_text().splitlines() if l.startswith("inline constexpr const char* ")} + lines = [msg_types[l.split("::", 1)[1].split(",")[0]] for l in lines if l.startswith("src/protocol.h- NetMsgType::")] assert len(lines) targets += [(p2p_msg_target, {"LIMIT_TO_MESSAGE_TYPE": m}) for m in lines] return targets