From 1dd62c5295ca319c94f7233bcb2e11f9d37a33f1 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 11 May 2023 18:35:54 -0700 Subject: [PATCH 1/2] refactor: move GetServicesNames from rpc/util.{h,cpp} to rpc/net.cpp as it is only called from that compilation unit. This avoids needlessly compiling GetServicesNames() in the 35 other files that include rpc/util.h. --- src/rpc/net.cpp | 13 +++++++++++++ src/rpc/util.cpp | 11 ----------- src/rpc/util.h | 3 --- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index f7b6c683446..50fee4a1f9a 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -91,6 +92,18 @@ static RPCHelpMan ping() }; } +/** Returns, given services flags, a list of humanly readable (known) network services */ +static UniValue GetServicesNames(ServiceFlags services) +{ + UniValue servicesNames(UniValue::VARR); + + for (const auto& flag : serviceFlagsToStr(services)) { + servicesNames.push_back(flag); + } + + return servicesNames; +} + static RPCHelpMan getpeerinfo() { return RPCHelpMan{ diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 9a941be1816..3a8b01e01ce 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -1302,17 +1302,6 @@ std::vector EvalDescriptorStringOrObject(const UniValue& scanobject, Fl return ret; } -UniValue GetServicesNames(ServiceFlags services) -{ - UniValue servicesNames(UniValue::VARR); - - for (const auto& flag : serviceFlagsToStr(services)) { - servicesNames.push_back(flag); - } - - return servicesNames; -} - /** Convert a vector of bilingual strings to a UniValue::VARR containing their original untranslated values. */ [[nodiscard]] static UniValue BilingualStringsToUniValue(const std::vector& bilingual_strings) { diff --git a/src/rpc/util.h b/src/rpc/util.h index 392540ffad5..663ae34d8bf 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -132,9 +132,6 @@ std::pair ParseDescriptorRange(const UniValue& value); /** Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range of 1000. */ std::vector EvalDescriptorStringOrObject(const UniValue& scanobject, FlatSigningProvider& provider, const bool expand_priv = false); -/** Returns, given services flags, a list of humanly readable (known) network services */ -UniValue GetServicesNames(ServiceFlags services); - /** * Serializing JSON objects depends on the outer type. Only arrays and * dictionaries can be nested in json. The top-level outer type is "NONE". From bbb68ffdbdafb6717dcadac074f6098750b8aa77 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sun, 23 Jul 2023 20:45:10 -0600 Subject: [PATCH 2/2] refactor: drop protocol.h include header in rpc/util.h as it was only needed for GetServicesNames(). This potentially avoids needlessly compiling the 500 lines of protocol.h in the 35 files other than rpc/net.cpp that include rpc/util.h. Drop an unneeded CPubKey forward declaration. The other IWYU suggestions would require more extensive changes in other files. Add 3 already-missing include headers in other translation units that are needed to compile without protocol.h in rpc/util.h, as it includes netaddress.h, which in turn includes util/strencodings.h. --- src/httprpc.cpp | 1 + src/rest.cpp | 1 + src/rpc/mempool.cpp | 1 + src/rpc/util.h | 2 -- 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 661406e122c..c72dbf10bc9 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include diff --git a/src/rest.cpp b/src/rest.cpp index ba149c1a9ec..69a8d5effd8 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp index 377e9de0e84..bcc58fe1a6d 100644 --- a/src/rpc/mempool.cpp +++ b/src/rpc/mempool.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/src/rpc/util.h b/src/rpc/util.h index 663ae34d8bf..609ec32818d 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -59,7 +58,6 @@ extern const std::string UNIX_EPOCH_TIME; extern const std::string EXAMPLE_ADDRESS[2]; class FillableSigningProvider; -class CPubKey; class CScript; struct Sections;