scripted-diff: Use inline constexpr over (static) const

Both are fine and this refactor shouldn't change any behavior.

However, inline constexpr will ensure each symbol has a single address
across all TU, making the release binary smaller.

Note, a follow-up commit will deal with string literals (const char*)
and other static const, which can not be constexpr (e.g. std::vector).

-BEGIN VERIFY SCRIPT-
 # Limit to types that can be constexpr
 type='bool|CAmount|size_t|((signed|unsigned) )?int|u?int[0-9]+_t|std::array|DatabaseFormat|CFeeRate|std::streamsize'
 sed -i --regexp-extended "s/^(static )?const (${type})\>/inline constexpr \2/" $( \
   git grep -l --extended-regexp "^(static )?const " -- \
     '*.h' \
     ':(exclude)src/leveldb' \
     ':(exclude)src/secp256k1' \
 )
-END VERIFY SCRIPT-
This commit is contained in:
MarcoFalke
2026-07-31 07:29:00 +02:00
parent faedb52583
commit fad753611b
36 changed files with 121 additions and 121 deletions

View File

@@ -119,11 +119,11 @@ using kernel::CBlockFileInfo;
using kernel::BlockTreeDB;
/** The pre-allocation chunk size for blk?????.dat files (since 0.8) */
static const unsigned int BLOCKFILE_CHUNK_SIZE{16_MiB};
inline constexpr unsigned int BLOCKFILE_CHUNK_SIZE{16_MiB};
/** The pre-allocation chunk size for rev?????.dat files (since 0.8) */
static const unsigned int UNDOFILE_CHUNK_SIZE{1_MiB};
inline constexpr unsigned int UNDOFILE_CHUNK_SIZE{1_MiB};
/** The maximum size of a blk?????.dat file (since 0.8) */
static const unsigned int MAX_BLOCKFILE_SIZE{128_MiB};
inline constexpr unsigned int MAX_BLOCKFILE_SIZE{128_MiB};
/** Size of header written by WriteBlock before a serialized CBlock (8 bytes) */
inline constexpr uint32_t STORAGE_HEADER_BYTES{std::tuple_size_v<MessageStartChars> + sizeof(unsigned int)};

View File

@@ -12,7 +12,7 @@ class ArgsManager;
namespace node {
static const bool DEFAULT_PRINT_MODIFIED_FEE = false;
inline constexpr bool DEFAULT_PRINT_MODIFIED_FEE = false;
/**
* Read the mining options set in \p args. Returns an error if one was

View File

@@ -9,33 +9,33 @@
* network protocol versioning
*/
static const int PROTOCOL_VERSION = 70017;
inline constexpr int PROTOCOL_VERSION = 70017;
//! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;
inline constexpr int INIT_PROTO_VERSION = 209;
//! disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION = 31800;
inline constexpr int MIN_PEER_PROTO_VERSION = 31800;
//! BIP 0031, pong message, is enabled for all versions AFTER this one
static const int BIP0031_VERSION = 60000;
inline constexpr int BIP0031_VERSION = 60000;
//! "sendheaders" message type and announcing blocks with headers starts with this version
static const int SENDHEADERS_VERSION = 70012;
inline constexpr int SENDHEADERS_VERSION = 70012;
//! "feefilter" tells peers to filter invs to you by fee starts with this version
static const int FEEFILTER_VERSION = 70013;
inline constexpr int FEEFILTER_VERSION = 70013;
//! short-id-based block download starts with this version
static const int SHORT_IDS_BLOCKS_VERSION = 70014;
inline constexpr int SHORT_IDS_BLOCKS_VERSION = 70014;
//! not banning for invalid compact blocks starts with this version
static const int INVALID_CB_NO_BAN_VERSION = 70015;
inline constexpr int INVALID_CB_NO_BAN_VERSION = 70015;
//! "wtxidrelay" message type for wtxid-based relay starts with this version
static const int WTXID_RELAY_VERSION = 70016;
inline constexpr int WTXID_RELAY_VERSION = 70016;
//! "feature" message type for feature negotiation starts with this version
static const int FEATURE_VERSION = 70017;
inline constexpr int FEATURE_VERSION = 70017;
#endif // BITCOIN_NODE_PROTOCOL_VERSION_H

View File

@@ -25,13 +25,13 @@ struct NodeContext;
* By default, a transaction with a fee rate higher than this will be rejected
* by these RPCs and the GUI. This can be overridden with the maxfeerate argument.
*/
static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
inline constexpr CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
/** Maximum burn value for sendrawtransaction, submitpackage, and testmempoolaccept RPC calls.
* By default, a transaction with a burn value higher than this will be rejected
* by these RPCs and the GUI. This can be overridden with the maxburnamount argument.
*/
static const CAmount DEFAULT_MAX_BURN_AMOUNT{0};
inline constexpr CAmount DEFAULT_MAX_BURN_AMOUNT{0};
/**
* Submit a transaction to the mempool and (optionally) relay it to all P2P peers.