From fad753611b5c074f38120fd9c1a87e37cc44bf6a Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Fri, 31 Jul 2026 07:29:00 +0200 Subject: [PATCH] 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- --- src/chainparamsseeds.h | 8 ++++---- src/clientversion.h | 2 +- src/consensus/consensus.h | 14 ++++++------- src/crypto/aes.h | 4 ++-- src/dbwrapper.h | 6 +++--- src/httpserver.h | 6 +++--- src/kernel/disconnected_transactions.h | 2 +- src/logging.h | 10 ++++----- src/net.h | 28 +++++++++++++------------- src/net_processing.h | 10 ++++----- src/netaddress.h | 6 +++--- src/netbase.h | 4 ++-- src/node/blockstorage.h | 6 +++--- src/node/mining_args.h | 2 +- src/node/protocol_version.h | 20 +++++++++--------- src/node/transaction.h | 4 ++-- src/policy/policy.h | 4 ++-- src/protocol.h | 4 ++-- src/psbt.h | 2 +- src/pubkey.h | 4 ++-- src/qt/guiconstants.h | 8 ++++---- src/qt/intro.h | 2 +- src/qt/qrimagewidget.h | 2 +- src/rpc/mining.h | 2 +- src/script/script.h | 16 +++++++-------- src/serialize.h | 2 +- src/torcontrol.h | 2 +- src/txmempool.h | 2 +- src/util/subprocess.h | 4 ++-- src/validation.h | 6 +++--- src/versionbits.h | 8 ++++---- src/wallet/coincontrol.h | 6 +++--- src/wallet/crypter.h | 6 +++--- src/wallet/scriptpubkeyman.h | 2 +- src/wallet/test/util.h | 2 +- src/wallet/wallet.h | 26 ++++++++++++------------ 36 files changed, 121 insertions(+), 121 deletions(-) diff --git a/src/chainparamsseeds.h b/src/chainparamsseeds.h index 5cf8d6ba407..729d7050826 100644 --- a/src/chainparamsseeds.h +++ b/src/chainparamsseeds.h @@ -10,7 +10,7 @@ * * Each line contains a BIP155 serialized (networkID, addr, port) tuple. */ -static const uint8_t chainparams_seed_main[] = { +inline constexpr uint8_t chainparams_seed_main[] = { 0x06,0x10,0xfc,0x11,0xf7,0x69,0x16,0xe6,0x36,0x11,0x58,0xae,0x1d,0x4a,0xfc,0xf7,0x57,0xa4,0x20,0x8d, 0x06,0x10,0xfc,0x17,0x43,0x69,0x54,0x14,0x4b,0x1f,0x56,0x89,0xd3,0xed,0x40,0x39,0x33,0x5c,0x20,0x8d, 0x06,0x10,0xfc,0x1f,0x22,0xc3,0x95,0xdc,0xa3,0xaf,0x4a,0x93,0x82,0x51,0xbe,0xb9,0x18,0x58,0x20,0x8d, @@ -2072,7 +2072,7 @@ static const uint8_t chainparams_seed_main[] = { 0x04,0x20,0xce,0x07,0x95,0xf3,0xa5,0xc1,0x90,0xc4,0x50,0xd5,0x22,0x86,0xa7,0x26,0x37,0x08,0xa2,0x31,0x1e,0x0d,0x77,0x48,0x0d,0x46,0xe0,0xfb,0x3d,0x71,0x60,0xe7,0x1d,0xce,0x20,0x8d, }; -static const uint8_t chainparams_seed_signet[] = { +inline constexpr uint8_t chainparams_seed_signet[] = { 0x06,0x10,0xfc,0x1f,0x22,0xc3,0x95,0xdc,0xa3,0xaf,0x4a,0x93,0x82,0x51,0xbe,0xb9,0x18,0x58,0x95,0xbd, 0x05,0x20,0xd7,0x4d,0xd9,0xc4,0x7c,0x80,0x24,0x1d,0x48,0x2f,0x52,0xba,0x2a,0xaf,0x5d,0xf2,0xfc,0x04,0x58,0x56,0x4a,0x61,0x0f,0xde,0x4e,0xd8,0x13,0x55,0x98,0x55,0x53,0xc1,0x00,0x00, 0x05,0x20,0xd8,0xaf,0x32,0x40,0x0d,0x25,0x72,0x91,0xf5,0x14,0x2a,0xa7,0x7b,0x9f,0x6b,0xe8,0x02,0x9f,0x16,0x5e,0xa0,0xe0,0x6d,0x85,0xcc,0x79,0xf2,0xe2,0xc1,0x2b,0xe0,0x20,0x00,0x00, @@ -2245,7 +2245,7 @@ static const uint8_t chainparams_seed_signet[] = { 0x04,0x20,0xc9,0x95,0x5a,0xf7,0x9a,0x27,0x09,0x6a,0xa2,0x24,0x65,0xb7,0x07,0xf0,0x28,0xee,0x8b,0xa9,0x5e,0x7c,0x37,0x19,0x14,0xc4,0x36,0x73,0x42,0xd2,0x87,0xae,0xa2,0x47,0x95,0xbd, }; -static const uint8_t chainparams_seed_test[] = { +inline constexpr uint8_t chainparams_seed_test[] = { 0x06,0x10,0xfc,0x1f,0x22,0xc3,0x95,0xdc,0xa3,0xaf,0x4a,0x93,0x82,0x51,0xbe,0xb9,0x18,0x58,0x47,0x9d, 0x05,0x20,0x39,0x06,0xc0,0x95,0x12,0xe1,0xf8,0x86,0xc2,0x36,0x76,0xa9,0x96,0x2a,0x9d,0xbd,0x3d,0x70,0x43,0xfc,0x99,0xbf,0x27,0x15,0xa4,0x9c,0x10,0xa1,0xd5,0xa3,0x9d,0x52,0x00,0x00, 0x05,0x20,0x40,0x81,0xae,0x55,0xb2,0x9d,0xd0,0xff,0x99,0x51,0xd8,0xbc,0x35,0xb2,0x06,0xb7,0x1c,0xf6,0x16,0x35,0xae,0xc6,0xf7,0xa4,0x72,0xf8,0x37,0x41,0x8e,0x91,0x7b,0x2e,0x00,0x00, @@ -2429,7 +2429,7 @@ static const uint8_t chainparams_seed_test[] = { 0x04,0x20,0xcc,0x99,0x76,0x52,0x43,0xcc,0x45,0x0a,0x49,0x5d,0x3f,0xa5,0x82,0xc3,0xc0,0xdb,0xcf,0xe5,0xda,0xfb,0xb3,0xd0,0xb9,0xd1,0xbc,0x1b,0x15,0x19,0xed,0xe0,0xd1,0x5f,0x47,0x9d, }; -static const uint8_t chainparams_seed_testnet4[] = { +inline constexpr uint8_t chainparams_seed_testnet4[] = { 0x06,0x10,0xfc,0x1f,0x22,0xc3,0x95,0xdc,0xa3,0xaf,0x4a,0x93,0x82,0x51,0xbe,0xb9,0x18,0x58,0xbc,0xcd, 0x05,0x20,0xd3,0xbc,0x25,0x95,0x63,0x7f,0x34,0x02,0x18,0x69,0x91,0x9a,0x79,0x57,0x10,0xc0,0xe0,0xf5,0xcd,0x84,0x56,0x95,0xec,0x43,0xa4,0x9d,0xba,0x1b,0xb3,0xea,0x34,0x60,0x00,0x00, 0x05,0x20,0xd8,0xee,0x64,0x35,0x6c,0x53,0xe7,0x40,0xb8,0xc3,0x15,0x60,0x5b,0x9c,0x66,0x3d,0xbb,0xd9,0x7c,0x99,0xcc,0x3a,0x3a,0xf6,0xcb,0xd5,0xd4,0x51,0x98,0x04,0x68,0xad,0x00,0x00, diff --git a/src/clientversion.h b/src/clientversion.h index f4822a12b69..cbdb62b24f0 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -23,7 +23,7 @@ #include #include -static const int CLIENT_VERSION = +inline constexpr int CLIENT_VERSION = 10000 * CLIENT_VERSION_MAJOR + 100 * CLIENT_VERSION_MINOR + 1 * CLIENT_VERSION_BUILD; diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h index 5d22d58284d..3666525388f 100644 --- a/src/consensus/consensus.h +++ b/src/consensus/consensus.h @@ -10,18 +10,18 @@ #include /** The maximum allowed size for a serialized block, in bytes (only for buffer size limits) */ -static const unsigned int MAX_BLOCK_SERIALIZED_SIZE = 4000000; +inline constexpr unsigned int MAX_BLOCK_SERIALIZED_SIZE = 4000000; /** The maximum allowed weight for a block, see BIP 141 (network rule) */ -static const unsigned int MAX_BLOCK_WEIGHT = 4000000; +inline constexpr unsigned int MAX_BLOCK_WEIGHT = 4000000; /** The maximum allowed number of signature check operations in a block (network rule) */ -static const int64_t MAX_BLOCK_SIGOPS_COST = 80000; +inline constexpr int64_t MAX_BLOCK_SIGOPS_COST = 80000; /** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */ -static const int COINBASE_MATURITY = 100; +inline constexpr int COINBASE_MATURITY = 100; -static const int WITNESS_SCALE_FACTOR = 4; +inline constexpr int WITNESS_SCALE_FACTOR = 4; -static const size_t MIN_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 60; // 60 is the lower bound for the size of a valid serialized CTransaction -static const size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 10; // 10 is the lower bound for the size of a serialized CTransaction +inline constexpr size_t MIN_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 60; // 60 is the lower bound for the size of a valid serialized CTransaction +inline constexpr size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 10; // 10 is the lower bound for the size of a serialized CTransaction /** Flags for nSequence and nLockTime locks */ /** Interpret sequence numbers as relative lock-time constraints. */ diff --git a/src/crypto/aes.h b/src/crypto/aes.h index 617bb62de91..4892c09766c 100644 --- a/src/crypto/aes.h +++ b/src/crypto/aes.h @@ -12,8 +12,8 @@ extern "C" { #include } -static const int AES_BLOCKSIZE = 16; -static const int AES256_KEYSIZE = 32; +inline constexpr int AES_BLOCKSIZE = 16; +inline constexpr int AES256_KEYSIZE = 32; /** An encryption class for AES-256. */ class AES256Encrypt diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 1eb68a3bb1f..654919378c9 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -27,9 +27,9 @@ namespace leveldb { class Env; } // namespace leveldb -static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64; -static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024; -static const size_t DBWRAPPER_MAX_FILE_SIZE{32_MiB}; +inline constexpr size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64; +inline constexpr size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024; +inline constexpr size_t DBWRAPPER_MAX_FILE_SIZE{32_MiB}; //! User-controlled performance and debug options. struct DBOptions { diff --git a/src/httpserver.h b/src/httpserver.h index 943dc12def4..2f58d787e5c 100644 --- a/src/httpserver.h +++ b/src/httpserver.h @@ -32,15 +32,15 @@ class SignalInterrupt; /** * The default value for `-rpcthreads`. This number of threads will be created at startup. */ -static const int DEFAULT_HTTP_THREADS=16; +inline constexpr int DEFAULT_HTTP_THREADS=16; /** * The default value for `-rpcworkqueue`. This is the maximum depth of the work queue, * we don't allocate this number of work queue items upfront. */ -static const int DEFAULT_HTTP_WORKQUEUE=64; +inline constexpr int DEFAULT_HTTP_WORKQUEUE=64; -static const int DEFAULT_HTTP_SERVER_TIMEOUT=30; +inline constexpr int DEFAULT_HTTP_SERVER_TIMEOUT=30; enum class HTTPRequestMethod { UNKNOWN, diff --git a/src/kernel/disconnected_transactions.h b/src/kernel/disconnected_transactions.h index 50eac519332..c9f4d6f7c6c 100644 --- a/src/kernel/disconnected_transactions.h +++ b/src/kernel/disconnected_transactions.h @@ -15,7 +15,7 @@ #include /** Maximum bytes for transactions to store for processing during reorg */ -static const unsigned int MAX_DISCONNECTED_TX_POOL_BYTES{20'000'000}; +inline constexpr unsigned int MAX_DISCONNECTED_TX_POOL_BYTES{20'000'000}; /** * DisconnectedBlockTransactions diff --git a/src/logging.h b/src/logging.h index 688f2b607f0..2bb8232bcba 100644 --- a/src/logging.h +++ b/src/logging.h @@ -27,11 +27,11 @@ #include #include -static const bool DEFAULT_LOGTIMEMICROS = false; -static const bool DEFAULT_LOGIPS = false; -static const bool DEFAULT_LOGTIMESTAMPS = true; -static const bool DEFAULT_LOGTHREADNAMES = false; -static const bool DEFAULT_LOGSOURCELOCATIONS = false; +inline constexpr bool DEFAULT_LOGTIMEMICROS = false; +inline constexpr bool DEFAULT_LOGIPS = false; +inline constexpr bool DEFAULT_LOGTIMESTAMPS = true; +inline constexpr bool DEFAULT_LOGTHREADNAMES = false; +inline constexpr bool DEFAULT_LOGSOURCELOCATIONS = false; inline constexpr bool DEFAULT_LOGLEVELALWAYS = false; extern const char * const DEFAULT_DEBUGLOGFILE; diff --git a/src/net.h b/src/net.h index 9911d91fb92..16ae5a6522a 100644 --- a/src/net.h +++ b/src/net.h @@ -62,43 +62,43 @@ inline constexpr auto FEELER_INTERVAL = 2min; /** Run the extra block-relay-only connection loop once every 5 minutes. **/ inline constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min; /** Maximum length of incoming protocol messages (no message over 4 MB is currently acceptable). */ -static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000; +inline constexpr unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000; /** Maximum length of the user agent string in `version` message */ -static const unsigned int MAX_SUBVERSION_LENGTH = 256; +inline constexpr unsigned int MAX_SUBVERSION_LENGTH = 256; /** Maximum number of automatic outgoing nodes over which we'll relay everything (blocks, tx, addrs, etc) */ -static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS = 8; +inline constexpr int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS = 8; /** Maximum number of addnode outgoing nodes */ -static const int MAX_ADDNODE_CONNECTIONS = 8; +inline constexpr int MAX_ADDNODE_CONNECTIONS = 8; /** Maximum number of block-relay-only outgoing connections */ -static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2; +inline constexpr int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2; /** Maximum number of feeler connections */ -static const int MAX_FEELER_CONNECTIONS = 1; +inline constexpr int MAX_FEELER_CONNECTIONS = 1; /** Maximum number of private broadcast connections */ inline constexpr size_t MAX_PRIVATE_BROADCAST_CONNECTIONS{64}; /** -listen default */ -static const bool DEFAULT_LISTEN = true; +inline constexpr bool DEFAULT_LISTEN = true; /** The maximum number of peer connections to maintain. */ -static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS{200}; +inline constexpr unsigned int DEFAULT_MAX_PEER_CONNECTIONS{200}; /** Default percentage of inbound connection slots that tx-relaying peers can use */ -static const int DEFAULT_FULL_RELAY_INBOUND_PCT{50}; +inline constexpr int DEFAULT_FULL_RELAY_INBOUND_PCT{50}; /** The default for -maxuploadtarget. 0 = Unlimited */ static const std::string DEFAULT_MAX_UPLOAD_TARGET{"0M"}; /** Default for blocks only*/ -static const bool DEFAULT_BLOCKSONLY = false; +inline constexpr bool DEFAULT_BLOCKSONLY = false; /** -peertimeout default */ -static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60; +inline constexpr int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60; /** Default for -privatebroadcast. */ inline constexpr bool DEFAULT_PRIVATE_BROADCAST{false}; /** Number of file descriptors required for message capture **/ -static const int NUM_FDS_MESSAGE_CAPTURE = 1; +inline constexpr int NUM_FDS_MESSAGE_CAPTURE = 1; /** Interval for ASMap Health Check **/ inline constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL{24}; inline constexpr bool DEFAULT_FORCEDNSSEED{false}; inline constexpr bool DEFAULT_DNSSEED{true}; inline constexpr bool DEFAULT_FIXEDSEEDS{true}; -static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000; -static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000; +inline constexpr size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000; +inline constexpr size_t DEFAULT_MAXSENDBUFFER = 1 * 1000; inline constexpr bool DEFAULT_V2_TRANSPORT{true}; diff --git a/src/net_processing.h b/src/net_processing.h index 50c329e2891..f26b95c5787 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -41,16 +41,16 @@ class Warnings; inline constexpr bool DEFAULT_TXRECONCILIATION_ENABLE{false}; /** Default number of non-mempool transactions to keep around for block reconstruction. Includes orphan, replaced, and rejected transactions. */ -static const uint32_t DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN{100}; +inline constexpr uint32_t DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN{100}; /** Default maximum per-second rate for sending transaction inventory to peers. */ inline constexpr unsigned int DEFAULT_TX_SEND_RATE{14}; -static const bool DEFAULT_PEERBLOOMFILTERS = false; -static const bool DEFAULT_PEERBLOCKFILTERS = false; +inline constexpr bool DEFAULT_PEERBLOOMFILTERS = false; +inline constexpr bool DEFAULT_PEERBLOCKFILTERS = false; /** Maximum number of outstanding CMPCTBLOCK requests for the same block. */ -static const unsigned int MAX_CMPCTBLOCKS_INFLIGHT_PER_BLOCK = 3; +inline constexpr unsigned int MAX_CMPCTBLOCKS_INFLIGHT_PER_BLOCK = 3; /** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends * less than this number, we reached its tip. Changing this value is a protocol upgrade. */ -static const unsigned int MAX_HEADERS_RESULTS = 2000; +inline constexpr unsigned int MAX_HEADERS_RESULTS = 2000; /** The compactblocks version we support. See BIP 152. */ inline constexpr uint64_t CMPCTBLOCKS_VERSION{2}; diff --git a/src/netaddress.h b/src/netaddress.h index 60028fd7aca..bb452a11275 100644 --- a/src/netaddress.h +++ b/src/netaddress.h @@ -59,14 +59,14 @@ enum Network { /// Prefix of an IPv6 address when it contains an embedded IPv4 address. /// Used when (un)serializing addresses in ADDRv1 format (pre-BIP155). -static const std::array IPV4_IN_IPV6_PREFIX{ +inline constexpr std::array IPV4_IN_IPV6_PREFIX{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}; /// Prefix of an IPv6 address when it contains an embedded TORv2 address. /// Used when (un)serializing addresses in ADDRv1 format (pre-BIP155). /// Such dummy IPv6 addresses are guaranteed to not be publicly routable as they /// fall under RFC4193's fc00::/7 subnet allocated to unique-local addresses. -static const std::array TORV2_IN_IPV6_PREFIX{ +inline constexpr std::array TORV2_IN_IPV6_PREFIX{ 0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43}; /// Prefix of an IPv6 address when it contains an embedded "internal" address. @@ -74,7 +74,7 @@ static const std::array TORV2_IN_IPV6_PREFIX{ /// The prefix comes from 0xFD + SHA256("bitcoin")[0:5]. /// Such dummy IPv6 addresses are guaranteed to not be publicly routable as they /// fall under RFC4193's fc00::/7 subnet allocated to unique-local addresses. -static const std::array INTERNAL_IN_IPV6_PREFIX{ +inline constexpr std::array INTERNAL_IN_IPV6_PREFIX{ 0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24 // 0xFD + sha256("bitcoin")[0:5]. }; diff --git a/src/netbase.h b/src/netbase.h index af51853a51a..ae85eebda41 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -25,9 +25,9 @@ extern int nConnectTimeout; extern bool fNameLookup; //! -timeout default -static const int DEFAULT_CONNECT_TIMEOUT = 5000; +inline constexpr int DEFAULT_CONNECT_TIMEOUT = 5000; //! -dns default -static const int DEFAULT_NAME_LOOKUP = true; +inline constexpr int DEFAULT_NAME_LOOKUP = true; /** Prefix for unix domain socket addresses (which are local filesystem paths) */ const std::string ADDR_PREFIX_UNIX = "unix:"; diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h index 9178fb21824..c871bf3f924 100644 --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -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 + sizeof(unsigned int)}; diff --git a/src/node/mining_args.h b/src/node/mining_args.h index 8baa7395285..053913168d7 100644 --- a/src/node/mining_args.h +++ b/src/node/mining_args.h @@ -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 diff --git a/src/node/protocol_version.h b/src/node/protocol_version.h index a72ac777465..db58f3a74a3 100644 --- a/src/node/protocol_version.h +++ b/src/node/protocol_version.h @@ -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 diff --git a/src/node/transaction.h b/src/node/transaction.h index d27057a4a93..c83a28ed1bd 100644 --- a/src/node/transaction.h +++ b/src/node/transaction.h @@ -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. diff --git a/src/policy/policy.h b/src/policy/policy.h index 87d20486bbf..54434b9b60e 100644 --- a/src/policy/policy.h +++ b/src/policy/policy.h @@ -77,11 +77,11 @@ inline constexpr unsigned int DEFAULT_ANCESTOR_LIMIT{25}; /** Default for -limitdescendantcount, max number of in-mempool descendants */ inline constexpr unsigned int DEFAULT_DESCENDANT_LIMIT{25}; /** Default for -datacarrier */ -static const bool DEFAULT_ACCEPT_DATACARRIER = true; +inline constexpr bool DEFAULT_ACCEPT_DATACARRIER = true; /** * Default setting for -datacarriersize in vbytes. */ -static const unsigned int MAX_OP_RETURN_RELAY = MAX_STANDARD_TX_WEIGHT / WITNESS_SCALE_FACTOR; +inline constexpr unsigned int MAX_OP_RETURN_RELAY = MAX_STANDARD_TX_WEIGHT / WITNESS_SCALE_FACTOR; /** * An extra transaction can be added to a package, as long as it only has one * ancestor and is no larger than this. Not really any reason to make this diff --git a/src/protocol.h b/src/protocol.h index a53f15e455a..0fd3c59261e 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -487,8 +487,8 @@ public: }; /** getdata message type flags */ -const uint32_t MSG_WITNESS_FLAG = 1 << 30; -const uint32_t MSG_TYPE_MASK = 0xffffffff >> 2; +inline constexpr uint32_t MSG_WITNESS_FLAG = 1 << 30; +inline constexpr uint32_t MSG_TYPE_MASK = 0xffffffff >> 2; /** getdata / inv message types. * These numbers are defined by the protocol. When adding a new value, be sure diff --git a/src/psbt.h b/src/psbt.h index 233a4fb673d..30e0036f85c 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -90,7 +90,7 @@ inline constexpr uint8_t PSBT_SEPARATOR = 0x00; // BIP 174 does not specify a maximum file size, but we set a limit anyway // to prevent reading a stream indefinitely and running out of memory. -const std::streamsize MAX_FILE_SIZE_PSBT = 100000000; // 100 MB +inline constexpr std::streamsize MAX_FILE_SIZE_PSBT = 100000000; // 100 MB // PSBT version number inline constexpr uint32_t PSBT_HIGHEST_VERSION = 2; diff --git a/src/pubkey.h b/src/pubkey.h index 28dc4a80b56..8acfd7241c7 100644 --- a/src/pubkey.h +++ b/src/pubkey.h @@ -16,8 +16,8 @@ #include #include -const unsigned int BIP32_EXTKEY_SIZE = 74; -const unsigned int BIP32_EXTKEY_WITH_VERSION_SIZE = 78; +inline constexpr unsigned int BIP32_EXTKEY_SIZE = 74; +inline constexpr unsigned int BIP32_EXTKEY_WITH_VERSION_SIZE = 78; using KeyFingerprint = std::array; diff --git a/src/qt/guiconstants.h b/src/qt/guiconstants.h index 79d5b577e3b..462b7413ea1 100644 --- a/src/qt/guiconstants.h +++ b/src/qt/guiconstants.h @@ -17,12 +17,12 @@ inline constexpr auto MODEL_UPDATE_DELAY{250ms}; inline constexpr auto SHUTDOWN_POLLING_DELAY{200ms}; /* AskPassphraseDialog -- Maximum passphrase length */ -static const int MAX_PASSPHRASE_SIZE = 1024; +inline constexpr int MAX_PASSPHRASE_SIZE = 1024; /* BitcoinGUI -- Size of icons in status bar */ -static const int STATUSBAR_ICONSIZE = 16; +inline constexpr int STATUSBAR_ICONSIZE = 16; -static const bool DEFAULT_SPLASHSCREEN = true; +inline constexpr bool DEFAULT_SPLASHSCREEN = true; /* Invalid field background style */ #define STYLE_INVALID "border: 3px solid #FF8080" @@ -41,7 +41,7 @@ static const bool DEFAULT_SPLASHSCREEN = true; /* Tooltips longer than this (in characters) are converted into rich text, so that they can be word-wrapped. */ -static const int TOOLTIP_WRAP_THRESHOLD = 80; +inline constexpr int TOOLTIP_WRAP_THRESHOLD = 80; /* Number of frames in spinner animation */ #define SPINNER_FRAMES 36 diff --git a/src/qt/intro.h b/src/qt/intro.h index db6c1d50b23..c8e015baeff 100644 --- a/src/qt/intro.h +++ b/src/qt/intro.h @@ -11,7 +11,7 @@ #include #include -static const bool DEFAULT_CHOOSE_DATADIR = false; +inline constexpr bool DEFAULT_CHOOSE_DATADIR = false; namespace interfaces { class Node; diff --git a/src/qt/qrimagewidget.h b/src/qt/qrimagewidget.h index b65b2b7a0dc..6eb9bed2a75 100644 --- a/src/qt/qrimagewidget.h +++ b/src/qt/qrimagewidget.h @@ -9,7 +9,7 @@ #include /* Maximum allowed URI length */ -static const int MAX_URI_LENGTH = 255; +inline constexpr int MAX_URI_LENGTH = 255; /* Size of exported QR Code image */ inline constexpr int QR_IMAGE_SIZE = 300; diff --git a/src/rpc/mining.h b/src/rpc/mining.h index a6c243c22c5..e99a9e74d38 100644 --- a/src/rpc/mining.h +++ b/src/rpc/mining.h @@ -8,6 +8,6 @@ #include /** Default max iterations to try in RPC generatetodescriptor, generatetoaddress, and generateblock. */ -static const uint64_t DEFAULT_MAX_TRIES{1000000}; +inline constexpr uint64_t DEFAULT_MAX_TRIES{1000000}; #endif // BITCOIN_RPC_MINING_H diff --git a/src/script/script.h b/src/script/script.h index 5590ecce215..6997df99eea 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -26,32 +26,32 @@ #include // Maximum number of bytes pushable to the stack -static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; +inline constexpr unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // Maximum number of non-push operations per script -static const int MAX_OPS_PER_SCRIPT = 201; +inline constexpr int MAX_OPS_PER_SCRIPT = 201; // Maximum number of public keys per multisig -static const int MAX_PUBKEYS_PER_MULTISIG = 20; +inline constexpr int MAX_PUBKEYS_PER_MULTISIG = 20; /** The limit of keys in OP_CHECKSIGADD-based scripts. It is due to the stack limit in BIP342. */ inline constexpr unsigned int MAX_PUBKEYS_PER_MULTI_A = 999; // Maximum script length in bytes -static const int MAX_SCRIPT_SIZE = 10000; +inline constexpr int MAX_SCRIPT_SIZE = 10000; // Maximum number of values on script interpreter stack -static const int MAX_STACK_SIZE = 1000; +inline constexpr int MAX_STACK_SIZE = 1000; // Threshold for nLockTime: below this value it is interpreted as block number, // otherwise as UNIX timestamp. -static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC +inline constexpr unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC // Maximum nLockTime. Since a lock time indicates the last invalid timestamp, a // transaction with this lock time will never be valid unless lock time // checking is disabled (by setting all input sequence numbers to // SEQUENCE_FINAL). -static const uint32_t LOCKTIME_MAX = 0xFFFFFFFFU; +inline constexpr uint32_t LOCKTIME_MAX = 0xFFFFFFFFU; // Tag for input annex. If there are at least two witness elements for a transaction input, // and the first byte of the last element is 0x50, this last element is called annex, and @@ -214,7 +214,7 @@ enum opcodetype }; // Maximum value that an opcode can be -static const unsigned int MAX_OPCODE = OP_NOP10; +inline constexpr unsigned int MAX_OPCODE = OP_NOP10; std::string GetOpName(opcodetype opcode); diff --git a/src/serialize.h b/src/serialize.h index 5d8b4109b11..4dbfe819b32 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -35,7 +35,7 @@ inline constexpr uint64_t MAX_SIZE = 0x02000000; /** Maximum amount of memory (in bytes) to allocate at once when deserializing vectors. */ -static const unsigned int MAX_VECTOR_ALLOCATE = 5000000; +inline constexpr unsigned int MAX_VECTOR_ALLOCATE = 5000000; /** * Dummy data type to identify deserializing constructors. diff --git a/src/torcontrol.h b/src/torcontrol.h index 06a9d3e8bd3..8079c356447 100644 --- a/src/torcontrol.h +++ b/src/torcontrol.h @@ -24,7 +24,7 @@ constexpr uint16_t DEFAULT_TOR_SOCKS_PORT{9050}; constexpr int DEFAULT_TOR_CONTROL_PORT = 9051; extern const std::string DEFAULT_TOR_CONTROL; -static const bool DEFAULT_LISTEN_ONION = true; +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}; diff --git a/src/txmempool.h b/src/txmempool.h index bf033474b02..35339d3f252 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -47,7 +47,7 @@ class ValidationSignals; struct bilingual_str; /** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */ -static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF; +inline constexpr uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF; /** How much linearization cost required for TxGraph clusters to have * "acceptable" quality, if they cannot be optimally linearized with less cost. */ diff --git a/src/util/subprocess.h b/src/util/subprocess.h index 3d01f4b7f9c..022fe43a00a 100644 --- a/src/util/subprocess.h +++ b/src/util/subprocess.h @@ -116,12 +116,12 @@ namespace subprocess { // Max buffer size allocated on stack for read error // from pipe -static const size_t SP_MAX_ERR_BUF_SIZ = 1024; +inline constexpr size_t SP_MAX_ERR_BUF_SIZ = 1024; // Default buffer capacity for OutBuffer and ErrBuffer. // If the data exceeds this capacity, the buffer size is grown // by 1.5 times its previous capacity -static const size_t DEFAULT_BUF_CAP_BYTES = 8192; +inline constexpr size_t DEFAULT_BUF_CAP_BYTES = 8192; /*----------------------------------------------- diff --git a/src/validation.h b/src/validation.h index 52480e14018..d1141afe5a3 100644 --- a/src/validation.h +++ b/src/validation.h @@ -73,8 +73,8 @@ class SignalInterrupt; } // namespace util /** Block files containing a block-height within MIN_BLOCKS_TO_KEEP of ActiveChain().Tip() will not be pruned. */ -static const unsigned int MIN_BLOCKS_TO_KEEP = 288; -static const signed int DEFAULT_CHECKBLOCKS = 6; +inline constexpr unsigned int MIN_BLOCKS_TO_KEEP = 288; +inline constexpr signed int DEFAULT_CHECKBLOCKS = 6; inline constexpr int DEFAULT_CHECKLEVEL{3}; // Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev???.dat) // At 1MB per block, 288 blocks = 288MB. @@ -84,7 +84,7 @@ inline constexpr int DEFAULT_CHECKLEVEL{3}; // full block file chunks, we need the high water mark which triggers the prune to be // one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB // Setting the target to >= 550 MiB will make it likely we can respect the target. -static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES{550_MiB}; +inline constexpr uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES{550_MiB}; /** Maximum number of dedicated script-checking threads allowed */ inline constexpr int MAX_SCRIPTCHECK_THREADS{15}; diff --git a/src/versionbits.h b/src/versionbits.h index f88ead0dce6..6e3743c29e7 100644 --- a/src/versionbits.h +++ b/src/versionbits.h @@ -16,13 +16,13 @@ class CChainParams; /** What block version to use for new blocks (pre versionbits) */ -static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION = 4; +inline constexpr int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION = 4; /** What bits to set in version for versionbits blocks */ -static const int32_t VERSIONBITS_TOP_BITS = 0x20000000UL; +inline constexpr int32_t VERSIONBITS_TOP_BITS = 0x20000000UL; /** What bitmask determines whether versionbits is in use */ -static const int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL; +inline constexpr int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL; /** Total bits available for versionbits (BIP 323) */ -static const int32_t VERSIONBITS_NUM_BITS = 5; +inline constexpr int32_t VERSIONBITS_NUM_BITS = 5; /** Opaque type for BIP9 state. See versionbits_impl.h for details. */ enum class ThresholdState : uint8_t; diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h index f67649f7e44..9bc04fc0d87 100644 --- a/src/wallet/coincontrol.h +++ b/src/wallet/coincontrol.h @@ -19,10 +19,10 @@ #include namespace wallet { -const int DEFAULT_MIN_DEPTH = 0; -const int DEFAULT_MAX_DEPTH = 9999999; +inline constexpr int DEFAULT_MIN_DEPTH = 0; +inline constexpr int DEFAULT_MAX_DEPTH = 9999999; -const int DEFAULT_WALLET_TX_VERSION = CTransaction::CURRENT_VERSION; +inline constexpr int DEFAULT_WALLET_TX_VERSION = CTransaction::CURRENT_VERSION; //! Default for -avoidpartialspends inline constexpr bool DEFAULT_AVOIDPARTIALSPENDS = false; diff --git a/src/wallet/crypter.h b/src/wallet/crypter.h index 90871245e57..03fd83258e8 100644 --- a/src/wallet/crypter.h +++ b/src/wallet/crypter.h @@ -11,9 +11,9 @@ namespace wallet { -const unsigned int WALLET_CRYPTO_KEY_SIZE = 32; -const unsigned int WALLET_CRYPTO_SALT_SIZE = 8; -const unsigned int WALLET_CRYPTO_IV_SIZE = 16; +inline constexpr unsigned int WALLET_CRYPTO_KEY_SIZE = 32; +inline constexpr unsigned int WALLET_CRYPTO_SALT_SIZE = 8; +inline constexpr unsigned int WALLET_CRYPTO_IV_SIZE = 16; /** * Private key encryption is done based on a CMasterKey, diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h index ccf8ae10d34..94a4f3318f4 100644 --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -61,7 +61,7 @@ public: inline constexpr int64_t UNKNOWN_TIME = std::numeric_limits::max(); //! Default for -keypool -static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000; +inline constexpr unsigned int DEFAULT_KEYPOOL_SIZE = 1000; std::vector GetAffectedKeys(const CScript& spk, const SigningProvider& provider); diff --git a/src/wallet/test/util.h b/src/wallet/test/util.h index 0af46e5577a..050a80b064a 100644 --- a/src/wallet/test/util.h +++ b/src/wallet/test/util.h @@ -25,7 +25,7 @@ class CWallet; class WalletDatabase; struct WalletContext; -static const DatabaseFormat DATABASE_FORMATS[] = { +inline constexpr DatabaseFormat DATABASE_FORMATS[] = { DatabaseFormat::SQLITE, }; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 6d26b386bea..ce9d3d2e188 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -103,13 +103,13 @@ void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr& std::unique_ptr MakeWalletDatabase(const std::string& name, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error); //! -fallbackfee default -static const CAmount DEFAULT_FALLBACK_FEE = 0; +inline constexpr CAmount DEFAULT_FALLBACK_FEE = 0; //! -discardfee default -static const CAmount DEFAULT_DISCARD_FEE = 10000; +inline constexpr CAmount DEFAULT_DISCARD_FEE = 10000; //! -mintxfee default -static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000; +inline constexpr CAmount DEFAULT_TRANSACTION_MINFEE = 1000; //! -consolidatefeerate default -static const CAmount DEFAULT_CONSOLIDATE_FEERATE{10000}; // 10 sat/vbyte +inline constexpr CAmount DEFAULT_CONSOLIDATE_FEERATE{10000}; // 10 sat/vbyte /** * maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled by default * @@ -117,22 +117,22 @@ static const CAmount DEFAULT_CONSOLIDATE_FEERATE{10000}; // 10 sat/vbyte * A value of 0 (current default) means to attempt to do partial spend avoidance, and use its results if the fees remain *unchanged* * A value > 0 means to do partial spend avoidance if the fee difference against a regular coin selection instance is in the range [0..value]. */ -static const CAmount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE = 0; +inline constexpr CAmount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE = 0; //! discourage APS fee higher than this amount constexpr CAmount HIGH_APS_FEE{COIN / 10000}; //! minimum recommended increment for replacement txs -static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000; +inline constexpr CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000; //! Default for -spendzeroconfchange -static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true; +inline constexpr bool DEFAULT_SPEND_ZEROCONF_CHANGE = true; //! Default for -walletrejectlongchains -static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS{true}; +inline constexpr bool DEFAULT_WALLET_REJECT_LONG_CHAINS{true}; //! -txconfirmtarget default -static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6; +inline constexpr unsigned int DEFAULT_TX_CONFIRM_TARGET = 6; //! -walletrbf default -static const bool DEFAULT_WALLET_RBF = true; -static const bool DEFAULT_WALLETBROADCAST = true; -static const bool DEFAULT_DISABLE_WALLET = false; -static const bool DEFAULT_WALLETCROSSCHAIN = false; +inline constexpr bool DEFAULT_WALLET_RBF = true; +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}; //! Discourage users to set fees higher than this amount (in satoshis) per kB