From fae759be793043565f93957d150e482226c8ebb7 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 4 Aug 2026 10:11:10 +0200 Subject: [PATCH] scripted-diff: Use inline constexpr over plain constexpr Both are identical since C++17 and this refactor shouldn't change any behavior. The benefits are consistency and to be explicit, to avoid confusion with the C++11/14 constexpr. Co-Authored-By: l0rinc -BEGIN VERIFY SCRIPT- sed -i --regexp-extended 's/^constexpr \S+ \w+(\[\])? ?[={]/inline &/' $( \ git grep -l '^constexpr ' -- \ '*.h' \ ':(exclude)src/minisketch' \ ) -END VERIFY SCRIPT- --- src/blockfilter.h | 4 ++-- src/common/pcp.h | 2 +- src/httpserver.h | 6 +++--- src/ipc/util.h | 2 +- src/musig.h | 2 +- src/net_permissions.h | 4 ++-- src/node/utxo_snapshot.h | 2 +- src/script/miniscript.h | 10 +++++----- src/serialize.h | 2 +- src/test/fuzz/util/descriptor.h | 10 +++++----- src/test/util/net.h | 8 ++++---- src/torcontrol.h | 10 +++++----- src/util/check.h | 4 ++-- src/wallet/wallet.h | 10 +++++----- 14 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/blockfilter.h b/src/blockfilter.h index 225d3b16bed..26ddfb616d8 100644 --- a/src/blockfilter.h +++ b/src/blockfilter.h @@ -87,8 +87,8 @@ public: bool MatchAny(const ElementSet& elements) const; }; -constexpr uint8_t BASIC_FILTER_P = 19; -constexpr uint32_t BASIC_FILTER_M = 784931; +inline constexpr uint8_t BASIC_FILTER_P = 19; +inline constexpr uint32_t BASIC_FILTER_M = 784931; enum class BlockFilterType : uint8_t { diff --git a/src/common/pcp.h b/src/common/pcp.h index c48317f7301..2c6b776fe2c 100644 --- a/src/common/pcp.h +++ b/src/common/pcp.h @@ -20,7 +20,7 @@ class CThreadInterrupt; // NAT-PMP and PCP use network byte order (big-endian). //! Mapping nonce size in bytes (see RFC6887 section 11.1). -constexpr size_t PCP_MAP_NONCE_SIZE = 12; +inline constexpr size_t PCP_MAP_NONCE_SIZE = 12; //! PCP mapping nonce. Arbitrary data chosen by the client to identify a mapping. typedef std::array PCPMappingNonce; diff --git a/src/httpserver.h b/src/httpserver.h index 2f58d787e5c..1ed6ff1ed51 100644 --- a/src/httpserver.h +++ b/src/httpserver.h @@ -68,16 +68,16 @@ namespace http_bitcoin { using util::LineReader; //! Shortest valid request line, used by libevent in evhttp_parse_request_line() -constexpr size_t MIN_REQUEST_LINE_LENGTH = std::string_view("GET / HTTP/1.0").size(); +inline constexpr size_t MIN_REQUEST_LINE_LENGTH = std::string_view("GET / HTTP/1.0").size(); //! Maximum size of each headers line in an HTTP request, //! also the maximum size of all headers total. //! See https://github.com/bitcoin/bitcoin/pull/6859 //! And libevent http.c evhttp_parse_headers_() -constexpr size_t MAX_HEADERS_SIZE{8192}; +inline constexpr size_t MAX_HEADERS_SIZE{8192}; //! Maximum size of an HTTP request body -constexpr uint64_t MAX_BODY_SIZE{32_MiB}; +inline constexpr uint64_t MAX_BODY_SIZE{32_MiB}; //! Thrown when a request body exceeds MAX_BODY_SIZE (or *will* exceed, in chunked transfer) //! so the server can reply with more specific code 413 (content too large) vs general 400 (bad request) diff --git a/src/ipc/util.h b/src/ipc/util.h index 6352f981746..03ce1534172 100644 --- a/src/ipc/util.h +++ b/src/ipc/util.h @@ -25,7 +25,7 @@ namespace mp { class EventLoop; using ProcessId = int; using SocketId = int; -constexpr SocketId SocketError{-1}; +inline constexpr SocketId SocketError{-1}; using Stream = SocketId; inline Stream MakeStream(EventLoop&, SocketId socket) diff --git a/src/musig.h b/src/musig.h index b17d299c6d2..4fb69b29231 100644 --- a/src/musig.h +++ b/src/musig.h @@ -15,7 +15,7 @@ struct secp256k1_musig_keyagg_cache; class MuSig2SecNonceImpl; struct secp256k1_musig_secnonce; -constexpr size_t MUSIG2_PUBNONCE_SIZE{66}; +inline constexpr size_t MUSIG2_PUBNONCE_SIZE{66}; //! Compute the full aggregate pubkey from the given participant pubkeys in their current order. //! Outputs the secp256k1_musig_keyagg_cache and validates that the computed aggregate pubkey matches an expected aggregate pubkey. diff --git a/src/net_permissions.h b/src/net_permissions.h index dd4d29513e9..8a713919f25 100644 --- a/src/net_permissions.h +++ b/src/net_permissions.h @@ -17,9 +17,9 @@ struct bilingual_str; extern const std::vector NET_PERMISSIONS_DOC; /** Default for -whitelistrelay. */ -constexpr bool DEFAULT_WHITELISTRELAY = true; +inline constexpr bool DEFAULT_WHITELISTRELAY = true; /** Default for -whitelistforcerelay. */ -constexpr bool DEFAULT_WHITELISTFORCERELAY = false; +inline constexpr bool DEFAULT_WHITELISTFORCERELAY = false; enum class NetPermissionFlags : uint32_t { None = 0, diff --git a/src/node/utxo_snapshot.h b/src/node/utxo_snapshot.h index 12a451808b3..f3a3b8d946a 100644 --- a/src/node/utxo_snapshot.h +++ b/src/node/utxo_snapshot.h @@ -125,7 +125,7 @@ std::optional ReadSnapshotBaseBlockhash(fs::path chaindir) //! Suffix appended to the chainstate (leveldb) dir when created based upon //! a snapshot. -constexpr std::string_view SNAPSHOT_CHAINSTATE_SUFFIX = "_snapshot"; +inline constexpr std::string_view SNAPSHOT_CHAINSTATE_SUFFIX = "_snapshot"; //! Return a path to the snapshot-based chainstate dir, if one exists. diff --git a/src/script/miniscript.h b/src/script/miniscript.h index b088619fb47..eba2fe2e754 100644 --- a/src/script/miniscript.h +++ b/src/script/miniscript.h @@ -271,15 +271,15 @@ namespace internal { inline constexpr uint32_t MAX_TAPMINISCRIPT_STACK_ELEM_SIZE{65}; //! version + nLockTime -constexpr uint32_t TX_OVERHEAD{4 + 4}; +inline constexpr uint32_t TX_OVERHEAD{4 + 4}; //! prevout + nSequence + scriptSig -constexpr uint32_t TXIN_BYTES_NO_WITNESS{36 + 4 + 1}; +inline constexpr uint32_t TXIN_BYTES_NO_WITNESS{36 + 4 + 1}; //! nValue + script len + OP_0 + pushdata 32. -constexpr uint32_t P2WSH_TXOUT_BYTES{8 + 1 + 1 + 33}; +inline constexpr uint32_t P2WSH_TXOUT_BYTES{8 + 1 + 1 + 33}; //! Data other than the witness in a transaction. Overhead + vin count + one vin + vout count + one vout + segwit marker -constexpr uint32_t TX_BODY_LEEWAY_WEIGHT{(TX_OVERHEAD + GetSizeOfCompactSize(1) + TXIN_BYTES_NO_WITNESS + GetSizeOfCompactSize(1) + P2WSH_TXOUT_BYTES) * WITNESS_SCALE_FACTOR + 2}; +inline constexpr uint32_t TX_BODY_LEEWAY_WEIGHT{(TX_OVERHEAD + GetSizeOfCompactSize(1) + TXIN_BYTES_NO_WITNESS + GetSizeOfCompactSize(1) + P2WSH_TXOUT_BYTES) * WITNESS_SCALE_FACTOR + 2}; //! Maximum possible stack size to spend a Taproot output (excluding the script itself). -constexpr uint32_t MAX_TAPSCRIPT_SAT_SIZE{GetSizeOfCompactSize(MAX_STACK_SIZE) + (GetSizeOfCompactSize(MAX_TAPMINISCRIPT_STACK_ELEM_SIZE) + MAX_TAPMINISCRIPT_STACK_ELEM_SIZE) * MAX_STACK_SIZE + GetSizeOfCompactSize(TAPROOT_CONTROL_MAX_SIZE) + TAPROOT_CONTROL_MAX_SIZE}; +inline constexpr uint32_t MAX_TAPSCRIPT_SAT_SIZE{GetSizeOfCompactSize(MAX_STACK_SIZE) + (GetSizeOfCompactSize(MAX_TAPMINISCRIPT_STACK_ELEM_SIZE) + MAX_TAPMINISCRIPT_STACK_ELEM_SIZE) * MAX_STACK_SIZE + GetSizeOfCompactSize(TAPROOT_CONTROL_MAX_SIZE) + TAPROOT_CONTROL_MAX_SIZE}; /** The maximum size of a script depending on the context. */ constexpr uint32_t MaxScriptSize(MiniscriptContext ms_ctx) { diff --git a/src/serialize.h b/src/serialize.h index 4dbfe819b32..e6926b3579e 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -49,7 +49,7 @@ inline constexpr unsigned int MAX_VECTOR_ALLOCATE = 5000000; * is likely the only way to do so. */ struct deserialize_type {}; -constexpr deserialize_type deserialize {}; +inline constexpr deserialize_type deserialize {}; /* * Lowest-level serialization and conversion. diff --git a/src/test/fuzz/util/descriptor.h b/src/test/fuzz/util/descriptor.h index 974e9ae83a7..86773162513 100644 --- a/src/test/fuzz/util/descriptor.h +++ b/src/test/fuzz/util/descriptor.h @@ -49,7 +49,7 @@ public: }; //! Default maximum number of derivation indexes in a single derivation path when limiting its depth. -constexpr int MAX_DEPTH{2}; +inline constexpr int MAX_DEPTH{2}; /** * Whether the buffer, if it represents a valid descriptor, contains a derivation path deeper than @@ -58,9 +58,9 @@ constexpr int MAX_DEPTH{2}; bool HasDeepDerivPath(std::span buff, int max_depth = MAX_DEPTH); //! Default maximum number of sub-fragments. -constexpr int MAX_SUBS{1'000}; +inline constexpr int MAX_SUBS{1'000}; //! Maximum number of nested sub-fragments we'll allow in a descriptor. -constexpr size_t MAX_NESTED_SUBS{10'000}; +inline constexpr size_t MAX_NESTED_SUBS{10'000}; /** * Whether the buffer, if it represents a valid descriptor, contains a fragment with more @@ -70,7 +70,7 @@ bool HasTooManySubFrag(std::span buff, int max_subs = MAX_SUBS, size_t max_nested_subs = MAX_NESTED_SUBS); //! Default maximum number of wrappers per fragment. -constexpr int MAX_WRAPPERS{100}; +inline constexpr int MAX_WRAPPERS{100}; /** * Whether the buffer, if it represents a valid descriptor, contains a fragment with more @@ -80,7 +80,7 @@ bool HasTooManyWrappers(std::span buff, int max_wrappers = MAX_WR /// Default maximum leaf size. This should be large enough to cover an extended /// key, including paths "/", inside and outside of "[]". -constexpr uint32_t MAX_LEAF_SIZE{200}; +inline constexpr uint32_t MAX_LEAF_SIZE{200}; /// Whether the expanded buffer (after calling GetDescriptor() in /// MockedDescriptorConverter) has a leaf size too large. diff --git a/src/test/util/net.h b/src/test/util/net.h index 8954e631d3d..8014bbcc366 100644 --- a/src/test/util/net.h +++ b/src/test/util/net.h @@ -118,7 +118,7 @@ struct ConnmanTestMsg : public CConnman { EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex); }; -constexpr ServiceFlags ALL_SERVICE_FLAGS[]{ +inline constexpr ServiceFlags ALL_SERVICE_FLAGS[]{ NODE_NONE, NODE_NETWORK, NODE_BLOOM, @@ -128,7 +128,7 @@ constexpr ServiceFlags ALL_SERVICE_FLAGS[]{ NODE_P2P_V2, }; -constexpr NetPermissionFlags ALL_NET_PERMISSION_FLAGS[]{ +inline constexpr NetPermissionFlags ALL_NET_PERMISSION_FLAGS[]{ NetPermissionFlags::None, NetPermissionFlags::BloomFilter, NetPermissionFlags::Relay, @@ -141,7 +141,7 @@ constexpr NetPermissionFlags ALL_NET_PERMISSION_FLAGS[]{ NetPermissionFlags::All, }; -constexpr ConnectionType ALL_CONNECTION_TYPES[]{ +inline constexpr ConnectionType ALL_CONNECTION_TYPES[]{ ConnectionType::INBOUND, ConnectionType::OUTBOUND_FULL_RELAY, ConnectionType::MANUAL, @@ -151,7 +151,7 @@ constexpr ConnectionType ALL_CONNECTION_TYPES[]{ ConnectionType::PRIVATE_BROADCAST, }; -constexpr auto ALL_NETWORKS = std::array{ +inline constexpr auto ALL_NETWORKS = std::array{ Network::NET_UNROUTABLE, Network::NET_IPV4, Network::NET_IPV6, diff --git a/src/torcontrol.h b/src/torcontrol.h index 8079c356447..8a1a5b6e52a 100644 --- a/src/torcontrol.h +++ b/src/torcontrol.h @@ -21,15 +21,15 @@ #include #include -constexpr uint16_t DEFAULT_TOR_SOCKS_PORT{9050}; -constexpr int DEFAULT_TOR_CONTROL_PORT = 9051; +inline constexpr uint16_t DEFAULT_TOR_SOCKS_PORT{9050}; +inline constexpr int DEFAULT_TOR_CONTROL_PORT = 9051; extern const std::string DEFAULT_TOR_CONTROL; inline constexpr bool DEFAULT_LISTEN_ONION = true; /** Tor control reply code. Ref: https://spec.torproject.org/control-spec/replies.html */ -constexpr int TOR_REPLY_OK{250}; -constexpr int TOR_REPLY_UNRECOGNIZED{510}; -constexpr int TOR_REPLY_SYNTAX_ERROR{512}; //!< Syntax error in command argument +inline constexpr int TOR_REPLY_OK{250}; +inline constexpr int TOR_REPLY_UNRECOGNIZED{510}; +inline constexpr int TOR_REPLY_SYNTAX_ERROR{512}; //!< Syntax error in command argument CService DefaultOnionServiceTarget(uint16_t port); diff --git a/src/util/check.h b/src/util/check.h index 4f5b0010161..249027a51d3 100644 --- a/src/util/check.h +++ b/src/util/check.h @@ -18,14 +18,14 @@ #include #include -constexpr bool G_FUZZING_BUILD{ +inline constexpr bool G_FUZZING_BUILD{ #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION true #else false #endif }; -constexpr bool G_ABORT_ON_FAILED_ASSUME{G_FUZZING_BUILD || +inline constexpr bool G_ABORT_ON_FAILED_ASSUME{G_FUZZING_BUILD || #ifdef ABORT_ON_FAILED_ASSUME true #else diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 08ad18d33ed..6e66a479f22 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -119,7 +119,7 @@ inline constexpr CAmount DEFAULT_CONSOLIDATE_FEERATE{10000}; // 10 sat/vbyte */ inline constexpr CAmount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE = 0; //! discourage APS fee higher than this amount -constexpr CAmount HIGH_APS_FEE{COIN / 10000}; +inline constexpr CAmount HIGH_APS_FEE{COIN / 10000}; //! minimum recommended increment for replacement txs inline constexpr CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000; //! Default for -spendzeroconfchange @@ -134,18 +134,18 @@ inline constexpr bool DEFAULT_WALLETBROADCAST = true; inline constexpr bool DEFAULT_DISABLE_WALLET = false; inline constexpr bool DEFAULT_WALLETCROSSCHAIN = false; //! -maxtxfee default -constexpr CAmount DEFAULT_TRANSACTION_MAXFEE{COIN / 10}; +inline constexpr CAmount DEFAULT_TRANSACTION_MAXFEE{COIN / 10}; //! Discourage users to set fees higher than this amount (in satoshis) per kB -constexpr CAmount HIGH_TX_FEE_PER_KB{COIN / 100}; +inline constexpr CAmount HIGH_TX_FEE_PER_KB{COIN / 100}; //! -maxtxfee will warn if called with a higher fee than this amount (in satoshis) -constexpr CAmount HIGH_MAX_TX_FEE{100 * HIGH_TX_FEE_PER_KB}; +inline constexpr CAmount HIGH_MAX_TX_FEE{100 * HIGH_TX_FEE_PER_KB}; //! Pre-calculated constants for input size estimation in *virtual size* inline constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE = 91; class CCoinControl; //! Default for -addresstype -constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::BECH32}; +inline constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::BECH32}; inline constexpr uint64_t KNOWN_WALLET_FLAGS = WALLET_FLAG_AVOID_REUSE