diff --git a/contrib/seeds/generate-seeds.py b/contrib/seeds/generate-seeds.py index 2dfad0c70e5..ff2b4028f00 100755 --- a/contrib/seeds/generate-seeds.py +++ b/contrib/seeds/generate-seeds.py @@ -22,9 +22,9 @@ These files must consist of lines in the format The output will be several data structures with the peers in binary format: - static const uint8_t chainparams_seed_{main,signet,test,testnet4}[]={ - ... - } + inline constexpr uint8_t chainparams_seed_{main,signet,test,testnet4}[]{ + ... + }; These should be pasted into `src/chainparamsseeds.h`. ''' @@ -137,7 +137,7 @@ def bip155_serialize(spec): return r def process_nodes(g, f, structname): - g.write('static const uint8_t %s[] = {\n' % structname) + g.write("inline constexpr uint8_t %s[]{\n" % structname) for line in f: comment = line.find('#') if comment != -1: diff --git a/src/addresstype.h b/src/addresstype.h index 862049dec73..79fcf3d1db5 100644 --- a/src/addresstype.h +++ b/src/addresstype.h @@ -118,7 +118,7 @@ public: }; /** Witness program for Pay-to-Anchor output script type */ -static const std::vector ANCHOR_BYTES{0x4e, 0x73}; +inline const std::vector ANCHOR_BYTES{0x4e, 0x73}; struct PayToAnchor : public WitnessUnknown { diff --git a/src/addrman.h b/src/addrman.h index 9449c938ca1..70697f76e64 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -23,25 +23,25 @@ class NetGroupManager; /** Over how many buckets entries with tried addresses from a single group (/16 for IPv4) are spread */ -static constexpr uint32_t ADDRMAN_TRIED_BUCKETS_PER_GROUP{8}; +inline constexpr uint32_t ADDRMAN_TRIED_BUCKETS_PER_GROUP{8}; /** Over how many buckets entries with new addresses originating from a single group are spread */ -static constexpr uint32_t ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP{64}; +inline constexpr uint32_t ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP{64}; /** Maximum number of times an address can occur in the new table */ -static constexpr int32_t ADDRMAN_NEW_BUCKETS_PER_ADDRESS{8}; +inline constexpr int32_t ADDRMAN_NEW_BUCKETS_PER_ADDRESS{8}; /** How old addresses can maximally be */ -static constexpr auto ADDRMAN_HORIZON{30 * 24h}; +inline constexpr auto ADDRMAN_HORIZON{30 * 24h}; /** After how many failed attempts we give up on a new node */ -static constexpr int32_t ADDRMAN_RETRIES{3}; +inline constexpr int32_t ADDRMAN_RETRIES{3}; /** How many successive failures are allowed ... */ -static constexpr int32_t ADDRMAN_MAX_FAILURES{10}; +inline constexpr int32_t ADDRMAN_MAX_FAILURES{10}; /** ... in at least this duration */ -static constexpr auto ADDRMAN_MIN_FAIL{7 * 24h}; +inline constexpr auto ADDRMAN_MIN_FAIL{7 * 24h}; /** How recent a successful connection should be before we allow an address to be evicted from tried */ -static constexpr auto ADDRMAN_REPLACEMENT{4h}; +inline constexpr auto ADDRMAN_REPLACEMENT{4h}; /** The maximum number of tried addr collisions to store */ -static constexpr size_t ADDRMAN_SET_TRIED_COLLISION_SIZE{10}; +inline constexpr size_t ADDRMAN_SET_TRIED_COLLISION_SIZE{10}; /** The maximum time we'll spend trying to resolve a tried table collision */ -static constexpr auto ADDRMAN_TEST_WINDOW{40min}; +inline constexpr auto ADDRMAN_TEST_WINDOW{40min}; class InvalidAddrManVersionError : public std::ios_base::failure { @@ -53,7 +53,7 @@ class AddrManImpl; class AddrInfo; /** Default for -checkaddrman */ -static constexpr int32_t DEFAULT_ADDRMAN_CONSISTENCY_CHECKS{0}; +inline constexpr int32_t DEFAULT_ADDRMAN_CONSISTENCY_CHECKS{0}; /** Location information for an address in AddrMan */ struct AddressPosition { diff --git a/src/addrman_impl.h b/src/addrman_impl.h index 88ee92e1b04..e6e2cab8dce 100644 --- a/src/addrman_impl.h +++ b/src/addrman_impl.h @@ -23,14 +23,14 @@ #include /** Total number of buckets for tried addresses */ -static constexpr int32_t ADDRMAN_TRIED_BUCKET_COUNT_LOG2{8}; -static constexpr int ADDRMAN_TRIED_BUCKET_COUNT{1 << ADDRMAN_TRIED_BUCKET_COUNT_LOG2}; +inline constexpr int32_t ADDRMAN_TRIED_BUCKET_COUNT_LOG2{8}; +inline constexpr int ADDRMAN_TRIED_BUCKET_COUNT{1 << ADDRMAN_TRIED_BUCKET_COUNT_LOG2}; /** Total number of buckets for new addresses */ -static constexpr int32_t ADDRMAN_NEW_BUCKET_COUNT_LOG2{10}; -static constexpr int ADDRMAN_NEW_BUCKET_COUNT{1 << ADDRMAN_NEW_BUCKET_COUNT_LOG2}; +inline constexpr int32_t ADDRMAN_NEW_BUCKET_COUNT_LOG2{10}; +inline constexpr int ADDRMAN_NEW_BUCKET_COUNT{1 << ADDRMAN_NEW_BUCKET_COUNT_LOG2}; /** Maximum allowed number of entries in buckets for new and tried addresses */ -static constexpr int32_t ADDRMAN_BUCKET_SIZE_LOG2{6}; -static constexpr int ADDRMAN_BUCKET_SIZE{1 << ADDRMAN_BUCKET_SIZE_LOG2}; +inline constexpr int32_t ADDRMAN_BUCKET_SIZE_LOG2{6}; +inline constexpr int ADDRMAN_BUCKET_SIZE{1 << ADDRMAN_BUCKET_SIZE_LOG2}; /** * User-defined type for the internally used nIds diff --git a/src/banman.h b/src/banman.h index 93149e63c5a..815e2438ae2 100644 --- a/src/banman.h +++ b/src/banman.h @@ -16,10 +16,10 @@ #include // NOTE: When adjusting this, update rpcnet:setban's help ("24h") -static constexpr unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24; // Default 24-hour ban +inline constexpr unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24; // Default 24-hour ban /// How often to dump banned addresses/subnets to disk. -static constexpr std::chrono::minutes DUMP_BANS_INTERVAL{15}; +inline constexpr std::chrono::minutes DUMP_BANS_INTERVAL{15}; class CClientUIInterface; class CNetAddr; diff --git a/src/bech32.h b/src/bech32.h index 9a43a58f396..f16aa8559b5 100644 --- a/src/bech32.h +++ b/src/bech32.h @@ -23,8 +23,8 @@ namespace bech32 { -static constexpr size_t CHECKSUM_SIZE = 6; -static constexpr char SEPARATOR = '1'; +inline constexpr size_t CHECKSUM_SIZE = 6; +inline constexpr char SEPARATOR = '1'; enum class Encoding { INVALID, //!< Failed decoding diff --git a/src/bip324.h b/src/bip324.h index 821cc3f759f..276f71e4a89 100644 --- a/src/bip324.h +++ b/src/bip324.h @@ -15,7 +15,7 @@ #include #include -static constexpr unsigned BIP324_SHORTIDS_IMPLEMENTED{38}; +inline constexpr unsigned BIP324_SHORTIDS_IMPLEMENTED{38}; /** The BIP324 packet cipher, encapsulating its key derivation, stream cipher, and AEAD. */ class BIP324Cipher 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/chain.h b/src/chain.h index 7701e9262a4..1ca218458b9 100644 --- a/src/chain.h +++ b/src/chain.h @@ -26,7 +26,7 @@ * Maximum amount of time that a block timestamp is allowed to exceed the * current time before the block will be accepted. */ -static constexpr int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60; +inline constexpr int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60; /** * Timestamp window used as a grace period by code that compares external @@ -34,10 +34,10 @@ static constexpr int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60; * to block timestamps. This should be set at least as high as * MAX_FUTURE_BLOCK_TIME. */ -static constexpr int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME; +inline constexpr int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME; //! Init values for CBlockIndex nSequenceId when loaded from disk -static constexpr int32_t SEQ_ID_BEST_CHAIN_FROM_DISK = 0; -static constexpr int32_t SEQ_ID_INIT_FROM_DISK = 1; +inline constexpr int32_t SEQ_ID_BEST_CHAIN_FROM_DISK = 0; +inline constexpr int32_t SEQ_ID_INIT_FROM_DISK = 1; enum BlockStatus : uint32_t { //! Unused. 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/common/bloom.h b/src/common/bloom.h index c9ed89f85e3..18399bd8d83 100644 --- a/src/common/bloom.h +++ b/src/common/bloom.h @@ -15,8 +15,8 @@ class COutPoint; class CTransaction; //! 20,000 items with fp rate < 0.1% or 10,000 items and <0.0001% -static constexpr unsigned int MAX_BLOOM_FILTER_SIZE = 36000; // bytes -static constexpr unsigned int MAX_HASH_FUNCS = 50; +inline constexpr unsigned int MAX_BLOOM_FILTER_SIZE{36'000}; // bytes +inline constexpr unsigned int MAX_HASH_FUNCS = 50; /** * First two bits of nFlags control how much IsRelevantAndUpdate actually updates 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/consensus/amount.h b/src/consensus/amount.h index 2a65a83123e..a2a383cc898 100644 --- a/src/consensus/amount.h +++ b/src/consensus/amount.h @@ -12,7 +12,7 @@ typedef int64_t CAmount; /** The amount of satoshis in one BTC. */ -static constexpr CAmount COIN = 100000000; +inline constexpr CAmount COIN{100'000'000}; /** No amount larger than this (in satoshi) is valid. * @@ -23,7 +23,7 @@ static constexpr CAmount COIN = 100000000; * critical; in unusual circumstances like a(nother) overflow bug that allowed * for the creation of coins out of thin air modification could lead to a fork. * */ -static constexpr CAmount MAX_MONEY = 21000000 * COIN; +inline constexpr CAmount MAX_MONEY{21'000'000 * COIN}; inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } #endif // BITCOIN_CONSENSUS_AMOUNT_H diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h index f1595f31d3f..96195e28193 100644 --- a/src/consensus/consensus.h +++ b/src/consensus/consensus.h @@ -10,28 +10,28 @@ #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{4'000'000}; /** 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{4'000'000}; /** 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{80'000}; /** 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. */ -static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE = (1 << 0); +inline constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE = (1 << 0); /** * Maximum number of seconds that the timestamp of the first * block of a difficulty adjustment period is allowed to * be earlier than the last block of the previous period (BIP94). */ -static constexpr int64_t MAX_TIMEWARP = 600; +inline constexpr int64_t MAX_TIMEWARP = 600; #endif // BITCOIN_CONSENSUS_CONSENSUS_H diff --git a/src/consensus/validation.h b/src/consensus/validation.h index 9e8a4ce59dd..1525a036231 100644 --- a/src/consensus/validation.h +++ b/src/consensus/validation.h @@ -20,10 +20,10 @@ /** Index marker for when no witness commitment is present in a coinbase transaction. */ -static constexpr int NO_WITNESS_COMMITMENT{-1}; +inline constexpr int NO_WITNESS_COMMITMENT{-1}; /** Minimum size of a witness commitment structure. Defined in BIP 141. **/ -static constexpr size_t MINIMUM_WITNESS_COMMITMENT{38}; +inline constexpr size_t MINIMUM_WITNESS_COMMITMENT{38}; /** A "reason" why a transaction was invalid, suitable for determining whether the * provider of the transaction should be banned/ignored/disconnected/etc. 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..1ed6ff1ed51 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, @@ -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/i2p.h b/src/i2p.h index 38556d8744a..3da2c105034 100644 --- a/src/i2p.h +++ b/src/i2p.h @@ -48,7 +48,7 @@ namespace sam { * The longest known message is ~1400 bytes, so this is high enough not to be triggered during * normal operation, yet low enough to avoid a malicious proxy from filling our memory. */ -static constexpr size_t MAX_MSG_SIZE{65536}; +inline constexpr size_t MAX_MSG_SIZE{65'536}; /** * I2P SAM session. diff --git a/src/index/blockfilterindex.h b/src/index/blockfilterindex.h index 0bb4a74e125..12b5741138d 100644 --- a/src/index/blockfilterindex.h +++ b/src/index/blockfilterindex.h @@ -25,10 +25,10 @@ class BlockFilter; class CBlockIndex; enum class BlockFilterType : uint8_t; -static const char* const DEFAULT_BLOCKFILTERINDEX = "0"; +inline constexpr const char* DEFAULT_BLOCKFILTERINDEX{"0"}; /** Interval between compact filter checkpoints. See BIP 157. */ -static constexpr int CFCHECKPT_INTERVAL = 1000; +inline constexpr int CFCHECKPT_INTERVAL = 1000; /** * BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of diff --git a/src/index/coinstatsindex.h b/src/index/coinstatsindex.h index 0e26fba56d9..fe61cbc7a68 100644 --- a/src/index/coinstatsindex.h +++ b/src/index/coinstatsindex.h @@ -22,7 +22,7 @@ namespace kernel { struct CCoinsStats; } -static constexpr bool DEFAULT_COINSTATSINDEX{false}; +inline constexpr bool DEFAULT_COINSTATSINDEX{false}; /** * CoinStatsIndex maintains statistics on the UTXO set. diff --git a/src/index/db_key.h b/src/index/db_key.h index 7c31f8afb8a..ffea70db2da 100644 --- a/src/index/db_key.h +++ b/src/index/db_key.h @@ -26,8 +26,8 @@ namespace index_util { * Keys for the hash index have the type [DB_BLOCK_HASH, uint256]. */ -static constexpr uint8_t DB_BLOCK_HASH{'s'}; -static constexpr uint8_t DB_BLOCK_HEIGHT{'t'}; +inline constexpr uint8_t DB_BLOCK_HASH{'s'}; +inline constexpr uint8_t DB_BLOCK_HEIGHT{'t'}; struct DBHeightKey { int height; diff --git a/src/index/txindex.h b/src/index/txindex.h index 0358e0ae49f..f35b9495767 100644 --- a/src/index/txindex.h +++ b/src/index/txindex.h @@ -16,7 +16,7 @@ namespace interfaces { class Chain; } -static constexpr bool DEFAULT_TXINDEX{false}; +inline constexpr bool DEFAULT_TXINDEX{false}; /** * TxIndex is used to look up transactions included in the blockchain by hash. diff --git a/src/index/txospenderindex.h b/src/index/txospenderindex.h index 35ca30d8b31..9a2103ca718 100644 --- a/src/index/txospenderindex.h +++ b/src/index/txospenderindex.h @@ -21,7 +21,7 @@ struct CDiskTxPos; -static constexpr bool DEFAULT_TXOSPENDERINDEX{false}; +inline constexpr bool DEFAULT_TXOSPENDERINDEX{false}; struct TxoSpender { CTransactionRef tx; diff --git a/src/init.h b/src/init.h index f3a55da35ee..ef0588a9c89 100644 --- a/src/init.h +++ b/src/init.h @@ -9,9 +9,9 @@ #include //! Default value for -daemon option -static constexpr bool DEFAULT_DAEMON = false; +inline constexpr bool DEFAULT_DAEMON = false; //! Default value for -daemonwait option -static constexpr bool DEFAULT_DAEMONWAIT = false; +inline constexpr bool DEFAULT_DAEMONWAIT = false; class ArgsManager; namespace interfaces { 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/kernel/blockmanager_opts.h b/src/kernel/blockmanager_opts.h index 3d8af68b808..396a3ff1d93 100644 --- a/src/kernel/blockmanager_opts.h +++ b/src/kernel/blockmanager_opts.h @@ -15,7 +15,7 @@ class CChainParams; namespace kernel { -static constexpr bool DEFAULT_XOR_BLOCKSDIR{true}; +inline constexpr bool DEFAULT_XOR_BLOCKSDIR{true}; /** * An options struct for `BlockManager`, more ergonomically referred to as diff --git a/src/kernel/caches.h b/src/kernel/caches.h index 6bc10c92355..c355ed0a4bd 100644 --- a/src/kernel/caches.h +++ b/src/kernel/caches.h @@ -12,18 +12,18 @@ #include //! Minimum total database cache (bytes) -static constexpr uint64_t MIN_DBCACHE_BYTES{4_MiB}; +inline constexpr uint64_t MIN_DBCACHE_BYTES{4_MiB}; //! Maximum total database cache on current architecture (bytes) -static constexpr uint64_t MAX_DBCACHE_BYTES{sizeof(void*) == 4 ? 1_GiB : std::numeric_limits::max()}; +inline constexpr uint64_t MAX_DBCACHE_BYTES{sizeof(void*) == 4 ? 1_GiB : std::numeric_limits::max()}; //! Suggested default amount of cache reserved for the kernel (bytes) -static constexpr uint64_t DEFAULT_KERNEL_CACHE{450_MiB}; +inline constexpr uint64_t DEFAULT_KERNEL_CACHE{450_MiB}; //! Default LevelDB write batch size -static constexpr uint64_t DEFAULT_DB_CACHE_BATCH{32_MiB}; +inline constexpr uint64_t DEFAULT_DB_CACHE_BATCH{32_MiB}; //! Max memory allocated to block tree DB specific cache (bytes) -static constexpr uint64_t MAX_BLOCK_DB_CACHE{2_MiB}; +inline constexpr uint64_t MAX_BLOCK_DB_CACHE{2_MiB}; //! Max memory allocated to coin DB specific cache (bytes) -static constexpr uint64_t MAX_COINS_DB_CACHE{8_MiB}; +inline constexpr uint64_t MAX_COINS_DB_CACHE{8_MiB}; namespace kernel { struct CacheSizes { diff --git a/src/kernel/chainstatemanager_opts.h b/src/kernel/chainstatemanager_opts.h index 554d032eddc..806331caed9 100644 --- a/src/kernel/chainstatemanager_opts.h +++ b/src/kernel/chainstatemanager_opts.h @@ -21,8 +21,8 @@ class CChainParams; class ValidationSignals; -static constexpr auto DEFAULT_MAX_TIP_AGE{24h}; -static constexpr int32_t DEFAULT_PREVOUTFETCH_THREADS{8}; +inline constexpr auto DEFAULT_MAX_TIP_AGE{24h}; +inline constexpr int32_t DEFAULT_PREVOUTFETCH_THREADS{8}; namespace kernel { 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/kernel/mempool_options.h b/src/kernel/mempool_options.h index 392c837fbbf..80b5316eee6 100644 --- a/src/kernel/mempool_options.h +++ b/src/kernel/mempool_options.h @@ -16,15 +16,15 @@ class ValidationSignals; /** Default for -maxmempool, maximum megabytes of mempool memory usage */ -static constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300}; +inline constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300}; /** Default for -maxmempool when blocksonly is set */ -static constexpr unsigned int DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB{5}; +inline constexpr unsigned int DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB{5}; /** Default for -mempoolexpiry, expiration time for mempool transactions in hours */ -static constexpr unsigned int DEFAULT_MEMPOOL_EXPIRY_HOURS{336}; +inline constexpr unsigned int DEFAULT_MEMPOOL_EXPIRY_HOURS{336}; /** Whether to fall back to legacy V1 serialization when writing mempool.dat */ -static constexpr bool DEFAULT_PERSIST_V1_DAT{false}; +inline constexpr bool DEFAULT_PERSIST_V1_DAT{false}; /** Default for -acceptnonstdtxn */ -static constexpr bool DEFAULT_ACCEPT_NON_STD_TXN{false}; +inline constexpr bool DEFAULT_ACCEPT_NON_STD_TXN{false}; namespace kernel { /** diff --git a/src/key.h b/src/key.h index 56f416ea8d0..87b130a8732 100644 --- a/src/key.h +++ b/src/key.h @@ -25,7 +25,7 @@ typedef struct secp256k1_context_struct secp256k1_context; typedef std::vector > CPrivKey; /** Size of ECDH shared secrets. */ -constexpr static size_t ECDH_SECRET_SIZE = CSHA256::OUTPUT_SIZE; +inline constexpr size_t ECDH_SECRET_SIZE = CSHA256::OUTPUT_SIZE; // Used to represent ECDH shared secret (ECDH_SECRET_SIZE bytes) using ECDHSecret = std::array; diff --git a/src/logging.h b/src/logging.h index 4bdcd0f241d..2bb8232bcba 100644 --- a/src/logging.h +++ b/src/logging.h @@ -27,12 +27,12 @@ #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; -static constexpr bool DEFAULT_LOGLEVELALWAYS = 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; extern bool fLogIPs; diff --git a/src/mapport.h b/src/mapport.h index 2133907badb..a33f9c609df 100644 --- a/src/mapport.h +++ b/src/mapport.h @@ -5,7 +5,7 @@ #ifndef BITCOIN_MAPPORT_H #define BITCOIN_MAPPORT_H -static constexpr bool DEFAULT_NATPMP = true; +inline constexpr bool DEFAULT_NATPMP = true; void StartMapPort(bool enable); void InterruptMapPort(); 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.h b/src/net.h index 04c26a11e5e..ea0c651d11e 100644 --- a/src/net.h +++ b/src/net.h @@ -56,51 +56,51 @@ class CScheduler; struct bilingual_str; /** Time after which to disconnect, after waiting for a ping response (or inactivity). */ -static constexpr std::chrono::minutes TIMEOUT_INTERVAL{20}; +inline constexpr std::chrono::minutes TIMEOUT_INTERVAL{20}; /** Run the feeler connection loop once every 2 minutes. **/ -static constexpr auto FEELER_INTERVAL = 2min; +inline constexpr auto FEELER_INTERVAL = 2min; /** Run the extra block-relay-only connection loop once every 5 minutes. **/ -static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min; +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 */ -static constexpr size_t MAX_PRIVATE_BROADCAST_CONNECTIONS{64}; +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"}; +inline 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. */ -static constexpr bool DEFAULT_PRIVATE_BROADCAST{false}; +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 **/ -static constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL{24}; +inline constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL{24}; -static constexpr bool DEFAULT_FORCEDNSSEED{false}; -static constexpr bool DEFAULT_DNSSEED{true}; -static constexpr bool DEFAULT_FIXEDSEEDS{true}; -static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000; -static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000; +inline constexpr bool DEFAULT_FORCEDNSSEED{false}; +inline constexpr bool DEFAULT_DNSSEED{true}; +inline constexpr bool DEFAULT_FIXEDSEEDS{true}; +inline constexpr size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000; +inline constexpr size_t DEFAULT_MAXSENDBUFFER = 1 * 1000; -static constexpr bool DEFAULT_V2_TRANSPORT{true}; +inline constexpr bool DEFAULT_V2_TRANSPORT{true}; typedef int64_t NodeId; diff --git a/src/net_permissions.h b/src/net_permissions.h index fbaa8f1d4ca..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, @@ -46,7 +46,7 @@ enum class NetPermissionFlags : uint32_t { Implicit = (1U << 31), All = BloomFilter | ForceRelay | Relay | NoBan | Mempool | Download | Addr, }; -static inline constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPermissionFlags b) +constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPermissionFlags b) { using t = std::underlying_type_t; return static_cast(static_cast(a) | static_cast(b)); diff --git a/src/net_processing.h b/src/net_processing.h index a381a6d80bc..f26b95c5787 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -38,21 +38,21 @@ class Warnings; } // namespace node /** Whether transaction reconciliation protocol should be enabled by default. */ -static constexpr bool DEFAULT_TXRECONCILIATION_ENABLE{false}; +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. */ -static constexpr unsigned int DEFAULT_TX_SEND_RATE{14}; -static const bool DEFAULT_PEERBLOOMFILTERS = false; -static const bool DEFAULT_PEERBLOCKFILTERS = false; +inline constexpr unsigned int DEFAULT_TX_SEND_RATE{14}; +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. */ -static constexpr uint64_t CMPCTBLOCKS_VERSION{2}; +inline constexpr uint64_t CMPCTBLOCKS_VERSION{2}; struct CNodeStateStats { int nSyncHeight = -1; diff --git a/src/netaddress.h b/src/netaddress.h index 2191da54b76..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,35 +74,35 @@ 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]. }; /// All CJDNS addresses start with 0xFC. See /// https://github.com/cjdelisle/cjdns/blob/master/doc/Whitepaper.md#pulling-it-all-together -static constexpr uint8_t CJDNS_PREFIX{0xFC}; +inline constexpr uint8_t CJDNS_PREFIX{0xFC}; /// Size of IPv4 address (in bytes). -static constexpr size_t ADDR_IPV4_SIZE = 4; +inline constexpr size_t ADDR_IPV4_SIZE = 4; /// Size of IPv6 address (in bytes). -static constexpr size_t ADDR_IPV6_SIZE = 16; +inline constexpr size_t ADDR_IPV6_SIZE = 16; /// Size of TORv3 address (in bytes). This is the length of just the address /// as used in BIP155, without the checksum and the version byte. -static constexpr size_t ADDR_TORV3_SIZE = 32; +inline constexpr size_t ADDR_TORV3_SIZE = 32; /// Size of I2P address (in bytes). -static constexpr size_t ADDR_I2P_SIZE = 32; +inline constexpr size_t ADDR_I2P_SIZE = 32; /// Size of CJDNS address (in bytes). -static constexpr size_t ADDR_CJDNS_SIZE = 16; +inline constexpr size_t ADDR_CJDNS_SIZE = 16; /// Size of "internal" (NET_INTERNAL) address (in bytes). -static constexpr size_t ADDR_INTERNAL_SIZE = 10; +inline constexpr size_t ADDR_INTERNAL_SIZE = 10; /// SAM 3.1 and earlier do not support specifying ports and force the port to 0. -static constexpr uint16_t I2P_SAM31_PORT{0}; +inline constexpr uint16_t I2P_SAM31_PORT{0}; std::string OnionToString(std::span addr); diff --git a/src/netbase.h b/src/netbase.h index af51853a51a..3bde9ad4471 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -25,12 +25,12 @@ 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:"; +inline const std::string ADDR_PREFIX_UNIX = "unix:"; enum class ConnectionDirection { None = 0, diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h index 0ab595ac851..c871bf3f924 100644 --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -119,17 +119,17 @@ 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) */ -static constexpr uint32_t STORAGE_HEADER_BYTES{std::tuple_size_v + sizeof(unsigned int)}; +inline constexpr uint32_t STORAGE_HEADER_BYTES{std::tuple_size_v + sizeof(unsigned int)}; /** Total overhead when writing undo data: header (8 bytes) plus checksum (32 bytes) */ -static constexpr uint32_t UNDO_DATA_DISK_OVERHEAD{STORAGE_HEADER_BYTES + uint256::size()}; +inline constexpr uint32_t UNDO_DATA_DISK_OVERHEAD{STORAGE_HEADER_BYTES + uint256::size()}; // Because validation code takes pointers to the map's CBlockIndex objects, if // we ever switch to another associative container, we need to either use a diff --git a/src/node/caches.h b/src/node/caches.h index 14056a2516f..4e8b49b37dc 100644 --- a/src/node/caches.h +++ b/src/node/caches.h @@ -15,7 +15,7 @@ class ArgsManager; //! Reserved non-dbcache memory usage. -static constexpr uint64_t DBCACHE_WARNING_RESERVED_RAM{2_GiB}; +inline constexpr uint64_t DBCACHE_WARNING_RESERVED_RAM{2_GiB}; namespace node { uint64_t GetDefaultDBCache(); diff --git a/src/node/chainstatemanager_args.h b/src/node/chainstatemanager_args.h index cbcbb6b47ca..9f62244ffd6 100644 --- a/src/node/chainstatemanager_args.h +++ b/src/node/chainstatemanager_args.h @@ -11,7 +11,7 @@ class ArgsManager; /** -par default (number of script-checking threads, 0 = auto) */ -static constexpr int DEFAULT_SCRIPTCHECK_THREADS{0}; +inline constexpr int DEFAULT_SCRIPTCHECK_THREADS{0}; namespace node { [[nodiscard]] util::Result ApplyArgsManOptions(const ArgsManager& args, ChainstateManager::Options& opts); diff --git a/src/node/kernel_notifications.h b/src/node/kernel_notifications.h index b152e7a476a..2f1089405dc 100644 --- a/src/node/kernel_notifications.h +++ b/src/node/kernel_notifications.h @@ -26,7 +26,7 @@ enum class Warning; namespace node { class Warnings; -static constexpr int DEFAULT_STOPATHEIGHT{0}; +inline constexpr int DEFAULT_STOPATHEIGHT{0}; //! State tracked by the KernelNotifications interface meant to be used by //! mining code, index code, RPCs, and other code sitting above the validation diff --git a/src/node/mempool_persist_args.h b/src/node/mempool_persist_args.h index 7973ec5821a..28ff297986d 100644 --- a/src/node/mempool_persist_args.h +++ b/src/node/mempool_persist_args.h @@ -15,7 +15,7 @@ namespace node { * Default for -persistmempool, indicating whether the node should attempt to * automatically load the mempool on start and save to disk on shutdown */ -static constexpr bool DEFAULT_PERSIST_MEMPOOL{true}; +inline constexpr bool DEFAULT_PERSIST_MEMPOOL{true}; bool ShouldPersistMempool(const ArgsManager& argsman); fs::path MempoolPath(const ArgsManager& argsman); 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/node/txdownloadman.h b/src/node/txdownloadman.h index bef1d162d22..e362110212e 100644 --- a/src/node/txdownloadman.h +++ b/src/node/txdownloadman.h @@ -22,20 +22,20 @@ class TxDownloadManagerImpl; /** Maximum number of in-flight transaction requests from a peer. It is not a hard limit, but the threshold at which * point the OVERLOADED_PEER_TX_DELAY kicks in. */ -static constexpr int32_t MAX_PEER_TX_REQUEST_IN_FLIGHT = 100; +inline constexpr int32_t MAX_PEER_TX_REQUEST_IN_FLIGHT = 100; /** Maximum number of transactions to consider for requesting, per peer. It provides a reasonable DoS limit to * per-peer memory usage spent on announcements, while covering peers continuously sending INVs at the maximum * rate (by our own policy, see DEFAULT_TX_SEND_RATE) for several minutes, while not receiving * the actual transaction (from any peer) in response to requests for them. */ -static constexpr int32_t MAX_PEER_TX_ANNOUNCEMENTS = 5000; +inline constexpr int32_t MAX_PEER_TX_ANNOUNCEMENTS = 5000; /** How long to delay requesting transactions via txids, if we have wtxid-relaying peers */ -static constexpr auto TXID_RELAY_DELAY{2s}; +inline constexpr auto TXID_RELAY_DELAY{2s}; /** How long to delay requesting transactions from non-preferred peers */ -static constexpr auto NONPREF_PEER_TX_DELAY{2s}; +inline constexpr auto NONPREF_PEER_TX_DELAY{2s}; /** How long to delay requesting transactions from overloaded peers (see MAX_PEER_TX_REQUEST_IN_FLIGHT). */ -static constexpr auto OVERLOADED_PEER_TX_DELAY{2s}; +inline constexpr auto OVERLOADED_PEER_TX_DELAY{2s}; /** How long to wait before downloading a transaction from an additional peer */ -static constexpr auto GETDATA_TX_INTERVAL{60s}; +inline constexpr auto GETDATA_TX_INTERVAL{60s}; struct TxDownloadOptions { /** Read-only reference to mempool. */ const CTxMemPool& m_mempool; diff --git a/src/node/txorphanage.h b/src/node/txorphanage.h index 81c57da33e8..4411f15d0a4 100644 --- a/src/node/txorphanage.h +++ b/src/node/txorphanage.h @@ -17,10 +17,10 @@ namespace node { /** Default value for TxOrphanage::m_reserved_usage_per_peer. Helps limit the total amount of memory used by the orphanage. */ -static constexpr int64_t DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER{404'000}; +inline constexpr int64_t DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER{404'000}; /** Default value for TxOrphanage::m_max_global_latency_score. Helps limit the maximum latency for operations like * EraseForBlock and LimitOrphans. */ -static constexpr unsigned int DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE{3000}; +inline constexpr unsigned int DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE{3000}; /** A class to track orphan transactions (failed on TX_MISSING_INPUTS) * Since we cannot distinguish orphans from bad transactions with non-existent inputs, we heavily limit the amount of diff --git a/src/node/txreconciliation.h b/src/node/txreconciliation.h index 68deeabaf64..c9db24802ff 100644 --- a/src/node/txreconciliation.h +++ b/src/node/txreconciliation.h @@ -12,7 +12,7 @@ #include /** Supported transaction reconciliation protocol version */ -static constexpr uint32_t TXRECONCILIATION_VERSION{1}; +inline constexpr uint32_t TXRECONCILIATION_VERSION{1}; enum class ReconciliationRegisterResult { NOT_FOUND, diff --git a/src/node/utxo_snapshot.h b/src/node/utxo_snapshot.h index 482edd3e6fc..f3a3b8d946a 100644 --- a/src/node/utxo_snapshot.h +++ b/src/node/utxo_snapshot.h @@ -25,7 +25,7 @@ #include // UTXO set snapshot magic bytes -static constexpr std::array SNAPSHOT_MAGIC_BYTES = {'u', 't', 'x', 'o', 0xff}; +inline constexpr std::array SNAPSHOT_MAGIC_BYTES = {'u', 't', 'x', 'o', 0xff}; class Chainstate; @@ -110,7 +110,7 @@ public: //! //! Because we only allow loading a single snapshot at a time, there will only be one //! chainstate directory with this filename present within it. -const fs::path SNAPSHOT_BLOCKHASH_FILENAME{"base_blockhash"}; +inline const fs::path SNAPSHOT_BLOCKHASH_FILENAME{"base_blockhash"}; //! Write out the blockhash of the snapshot base block that was used to construct //! this chainstate. This value is read in during subsequent initializations and @@ -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/outputtype.h b/src/outputtype.h index 4dde381b356..2b4c4d9baea 100644 --- a/src/outputtype.h +++ b/src/outputtype.h @@ -23,7 +23,7 @@ enum class OutputType { UNKNOWN, }; -static constexpr auto OUTPUT_TYPES = std::array{ +inline constexpr auto OUTPUT_TYPES = std::array{ OutputType::LEGACY, OutputType::P2SH_SEGWIT, OutputType::BECH32, diff --git a/src/policy/feerate.h b/src/policy/feerate.h index 8f13f8d0dca..965edf25f22 100644 --- a/src/policy/feerate.h +++ b/src/policy/feerate.h @@ -16,8 +16,8 @@ #include #include -const std::string CURRENCY_UNIT = "BTC"; // One formatted unit -const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit +inline const std::string CURRENCY_UNIT = "BTC"; // One formatted unit +inline const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit enum class FeeRateFormat { BTC_KVB, //!< Use BTC/kvB fee rate unit @@ -38,7 +38,7 @@ public: /** Fee rate of 0 satoshis per 0 vB */ CFeeRate() = default; template // Disallow silent float -> int conversion - explicit CFeeRate(const I m_feerate_kvb) : m_feerate(FeePerVSize(m_feerate_kvb, 1000)) {} + explicit constexpr CFeeRate(const I m_feerate_kvb) : m_feerate(FeePerVSize(m_feerate_kvb, 1000)) {} /** * Construct a fee rate from a fee in satoshis and a vsize in vB. diff --git a/src/policy/fees/block_policy_estimator.h b/src/policy/fees/block_policy_estimator.h index d513f15a858..a87970cd4dc 100644 --- a/src/policy/fees/block_policy_estimator.h +++ b/src/policy/fees/block_policy_estimator.h @@ -23,16 +23,16 @@ // How often to flush fee estimates to fee_estimates.dat. -static constexpr std::chrono::hours FEE_FLUSH_INTERVAL{1}; +inline constexpr std::chrono::hours FEE_FLUSH_INTERVAL{1}; /** fee_estimates.dat that are more than 60 hours (2.5 days) old will not be read, * as fee estimates are based on historical data and may be inaccurate if * network activity has changed. */ -static constexpr std::chrono::hours MAX_FILE_AGE{60}; +inline constexpr std::chrono::hours MAX_FILE_AGE{60}; // Whether we allow importing a fee_estimates file older than MAX_FILE_AGE. -static constexpr bool DEFAULT_ACCEPT_STALE_FEE_ESTIMATES{false}; +inline constexpr bool DEFAULT_ACCEPT_STALE_FEE_ESTIMATES{false}; class AutoFile; class TxConfirmStats; @@ -47,7 +47,7 @@ enum class FeeEstimateHorizon { LONG_HALFLIFE, }; -static constexpr auto ALL_FEE_ESTIMATE_HORIZONS = std::array{ +inline constexpr auto ALL_FEE_ESTIMATE_HORIZONS = std::array{ FeeEstimateHorizon::SHORT_HALFLIFE, FeeEstimateHorizon::MED_HALFLIFE, FeeEstimateHorizon::LONG_HALFLIFE, diff --git a/src/policy/packages.h b/src/policy/packages.h index 1a7e101ef46..e5704fb3796 100644 --- a/src/policy/packages.h +++ b/src/policy/packages.h @@ -16,12 +16,12 @@ #include /** Default maximum number of transactions in a package. */ -static constexpr uint32_t MAX_PACKAGE_COUNT{25}; +inline constexpr uint32_t MAX_PACKAGE_COUNT{25}; /** Default maximum total weight of transactions in a package in weight to allow for context-less checks. This must allow a superset of sigops weighted vsize limited transactions to not disallow transactions we would have otherwise accepted individually. */ -static constexpr uint32_t MAX_PACKAGE_WEIGHT = 404'000; +inline constexpr uint32_t MAX_PACKAGE_WEIGHT = 404'000; static_assert(MAX_PACKAGE_WEIGHT >= MAX_STANDARD_TX_WEIGHT); // Packages are part of a single cluster, so ensure that the package limits are diff --git a/src/policy/policy.h b/src/policy/policy.h index 13bcf4cef75..ea66fa4b84e 100644 --- a/src/policy/policy.h +++ b/src/policy/policy.h @@ -22,77 +22,77 @@ class CFeeRate; class CScript; /** Default for -blockmaxweight, which controls the range of block weights the mining code will create **/ -static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{MAX_BLOCK_WEIGHT}; +inline constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{MAX_BLOCK_WEIGHT}; /** Default for -blockreservedweight **/ -static constexpr unsigned int DEFAULT_BLOCK_RESERVED_WEIGHT{8000}; +inline constexpr unsigned int DEFAULT_BLOCK_RESERVED_WEIGHT{8000}; /** Default sigops cost to reserve for coinbase transaction outputs when creating block templates. */ -static constexpr unsigned int DEFAULT_COINBASE_OUTPUT_MAX_ADDITIONAL_SIGOPS{400}; +inline constexpr unsigned int DEFAULT_COINBASE_OUTPUT_MAX_ADDITIONAL_SIGOPS{400}; /** This accounts for the block header, var_int encoding of the transaction count and a minimally viable * coinbase transaction. It adds an additional safety margin, because even with a thorough understanding * of block serialization, it's easy to make a costly mistake when trying to squeeze every last byte. * Setting a lower value is prevented at startup. */ -static constexpr unsigned int MINIMUM_BLOCK_RESERVED_WEIGHT{2000}; +inline constexpr unsigned int MINIMUM_BLOCK_RESERVED_WEIGHT{2000}; /** Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code **/ -static constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE{1}; +inline constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE{1}; /** The maximum weight for transactions we're willing to relay/mine */ -static constexpr int32_t MAX_STANDARD_TX_WEIGHT{400000}; +inline constexpr int32_t MAX_STANDARD_TX_WEIGHT{400'000}; /** The minimum non-witness size for transactions we're willing to relay/mine: one larger than 64 */ -static constexpr unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE{65}; +inline constexpr unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE{65}; /** Maximum number of signature check operations in an IsStandard() P2SH script */ -static constexpr unsigned int MAX_P2SH_SIGOPS{15}; +inline constexpr unsigned int MAX_P2SH_SIGOPS{15}; /** The maximum number of sigops we're willing to relay/mine in a single tx */ -static constexpr unsigned int MAX_STANDARD_TX_SIGOPS_COST{MAX_BLOCK_SIGOPS_COST/5}; +inline constexpr unsigned int MAX_STANDARD_TX_SIGOPS_COST{MAX_BLOCK_SIGOPS_COST/5}; /** The maximum number of potentially executed legacy signature operations in a single standard tx */ -static constexpr unsigned int MAX_TX_LEGACY_SIGOPS{2'500}; +inline constexpr unsigned int MAX_TX_LEGACY_SIGOPS{2'500}; /** Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or replacement **/ -static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE{100}; +inline constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE{100}; /** Default for -bytespersigop */ -static constexpr unsigned int DEFAULT_BYTES_PER_SIGOP{20}; +inline constexpr unsigned int DEFAULT_BYTES_PER_SIGOP{20}; /** Default for -permitbaremultisig */ -static constexpr bool DEFAULT_PERMIT_BAREMULTISIG{true}; +inline constexpr bool DEFAULT_PERMIT_BAREMULTISIG{true}; /** The maximum number of witness stack items in a standard P2WSH script */ -static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS{100}; +inline constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS{100}; /** The maximum size in bytes of each witness stack item in a standard P2WSH script */ -static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE{80}; +inline constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE{80}; /** The maximum size in bytes of each witness stack item in a standard BIP 342 script (Taproot, leaf version 0xc0) */ -static constexpr unsigned int MAX_STANDARD_TAPSCRIPT_STACK_ITEM_SIZE{80}; +inline constexpr unsigned int MAX_STANDARD_TAPSCRIPT_STACK_ITEM_SIZE{80}; /** The maximum size in bytes of a standard witnessScript */ -static constexpr unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE{3600}; +inline constexpr unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE{3600}; /** The maximum size of a standard ScriptSig */ -static constexpr unsigned int MAX_STANDARD_SCRIPTSIG_SIZE{1650}; +inline constexpr unsigned int MAX_STANDARD_SCRIPTSIG_SIZE{1650}; /** Min feerate for defining dust. * Changing the dust limit changes which transactions are * standard and should be done with care and ideally rarely. It makes sense to * only increase the dust limit after prior releases were already not creating * outputs below the new threshold */ -static constexpr unsigned int DUST_RELAY_TX_FEE{3000}; +inline constexpr unsigned int DUST_RELAY_TX_FEE{3000}; /** Default for -minrelaytxfee, minimum relay fee for transactions */ -static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{100}; +inline constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{100}; /** Maximum number of transactions per cluster (default) */ -static constexpr unsigned int DEFAULT_CLUSTER_LIMIT{64}; +inline constexpr unsigned int DEFAULT_CLUSTER_LIMIT{64}; /** Maximum size of cluster in virtual kilobytes */ -static constexpr unsigned int DEFAULT_CLUSTER_SIZE_LIMIT_KVB{101}; +inline constexpr unsigned int DEFAULT_CLUSTER_SIZE_LIMIT_KVB{101}; /** Default for -limitancestorcount, max number of in-mempool ancestors */ -static constexpr unsigned int DEFAULT_ANCESTOR_LIMIT{25}; +inline constexpr unsigned int DEFAULT_ANCESTOR_LIMIT{25}; /** Default for -limitdescendantcount, max number of in-mempool descendants */ -static constexpr unsigned int DEFAULT_DESCENDANT_LIMIT{25}; +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 * configurable as it doesn't materially change DoS parameters. */ -static constexpr unsigned int EXTRA_DESCENDANT_TX_SIZE_LIMIT{10000}; +inline constexpr unsigned int EXTRA_DESCENDANT_TX_SIZE_LIMIT{10'000}; /** * Maximum number of ephemeral dust outputs allowed. */ -static constexpr unsigned int MAX_DUST_OUTPUTS_PER_TX{1}; +inline constexpr unsigned int MAX_DUST_OUTPUTS_PER_TX{1}; /** * Mandatory script verification flags that all new transactions must comply with for @@ -101,7 +101,7 @@ static constexpr unsigned int MAX_DUST_OUTPUTS_PER_TX{1}; * Note that this does not affect consensus validity; see GetBlockScriptFlags() * for that. */ -static constexpr script_verify_flags MANDATORY_SCRIPT_VERIFY_FLAGS{SCRIPT_VERIFY_P2SH | +inline constexpr script_verify_flags MANDATORY_SCRIPT_VERIFY_FLAGS{SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_NULLDUMMY | SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY | @@ -115,7 +115,7 @@ static constexpr script_verify_flags MANDATORY_SCRIPT_VERIFY_FLAGS{SCRIPT_VERIFY * the additional (non-mandatory) rules here, to improve forwards and * backwards compatibility. */ -static constexpr script_verify_flags STANDARD_SCRIPT_VERIFY_FLAGS{MANDATORY_SCRIPT_VERIFY_FLAGS | +inline constexpr script_verify_flags STANDARD_SCRIPT_VERIFY_FLAGS{MANDATORY_SCRIPT_VERIFY_FLAGS | SCRIPT_VERIFY_STRICTENC | SCRIPT_VERIFY_MINIMALDATA | SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS | @@ -131,10 +131,10 @@ static constexpr script_verify_flags STANDARD_SCRIPT_VERIFY_FLAGS{MANDATORY_SCRI SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE}; /** For convenience, standard but not mandatory verify flags. */ -static constexpr script_verify_flags STANDARD_NOT_MANDATORY_VERIFY_FLAGS{STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS}; +inline constexpr script_verify_flags STANDARD_NOT_MANDATORY_VERIFY_FLAGS{STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS}; /** Used as the flags parameter to sequence and nLocktime checks in non-consensus code. */ -static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS{LOCKTIME_VERIFY_SEQUENCE}; +inline constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS{LOCKTIME_VERIFY_SEQUENCE}; CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee); @@ -148,8 +148,8 @@ std::vector GetDust(const CTransaction& tx, CFeeRate dust_relay_rate); // Changing the default transaction version requires a two step process: first // adapting relay policy by bumping TX_MAX_STANDARD_VERSION, and then later // allowing the new transaction version in the wallet/RPC. -static constexpr decltype(CTransaction::version) TX_MIN_STANDARD_VERSION{1}; -static constexpr decltype(CTransaction::version) TX_MAX_STANDARD_VERSION{3}; +inline constexpr decltype(CTransaction::version) TX_MIN_STANDARD_VERSION{1}; +inline constexpr decltype(CTransaction::version) TX_MAX_STANDARD_VERSION{3}; /** * Check for standard transaction types diff --git a/src/policy/rbf.h b/src/policy/rbf.h index 0ba646ca8d1..81769602bc0 100644 --- a/src/policy/rbf.h +++ b/src/policy/rbf.h @@ -23,7 +23,7 @@ class uint256; /** Maximum number of unique clusters that can be affected by an RBF (Rule #5); * see GetEntriesForConflicts() */ -static constexpr uint32_t MAX_REPLACEMENT_CANDIDATES{100}; +inline constexpr uint32_t MAX_REPLACEMENT_CANDIDATES{100}; /** The rbf state of unconfirmed transactions */ enum class RBFTransactionState { diff --git a/src/policy/truc_policy.h b/src/policy/truc_policy.h index b6fe6e1242b..fb1d718bfeb 100644 --- a/src/policy/truc_policy.h +++ b/src/policy/truc_policy.h @@ -17,21 +17,21 @@ // This module enforces rules for BIP 431 TRUC transactions which help make // RBF abilities more robust. A transaction with version=3 is treated as TRUC. -static constexpr decltype(CTransaction::version) TRUC_VERSION{3}; +inline constexpr decltype(CTransaction::version) TRUC_VERSION{3}; // TRUC only allows 1 parent and 1 child when unconfirmed. This translates to a descendant set size // of 2 and ancestor set size of 2. /** Maximum number of transactions including an unconfirmed tx and its descendants. */ -static constexpr unsigned int TRUC_DESCENDANT_LIMIT{2}; +inline constexpr unsigned int TRUC_DESCENDANT_LIMIT{2}; /** Maximum number of transactions including a TRUC tx and all its mempool ancestors. */ -static constexpr unsigned int TRUC_ANCESTOR_LIMIT{2}; +inline constexpr unsigned int TRUC_ANCESTOR_LIMIT{2}; /** Maximum sigop-adjusted virtual size of all v3 transactions. */ -static constexpr int64_t TRUC_MAX_VSIZE{10000}; -static constexpr int64_t TRUC_MAX_WEIGHT{TRUC_MAX_VSIZE * WITNESS_SCALE_FACTOR}; +inline constexpr int64_t TRUC_MAX_VSIZE{10'000}; +inline constexpr int64_t TRUC_MAX_WEIGHT{TRUC_MAX_VSIZE * WITNESS_SCALE_FACTOR}; /** Maximum sigop-adjusted virtual size of a tx which spends from an unconfirmed TRUC transaction. */ -static constexpr int64_t TRUC_CHILD_MAX_VSIZE{1000}; -static constexpr int64_t TRUC_CHILD_MAX_WEIGHT{TRUC_CHILD_MAX_VSIZE * WITNESS_SCALE_FACTOR}; +inline constexpr int64_t TRUC_CHILD_MAX_VSIZE{1000}; +inline constexpr int64_t TRUC_CHILD_MAX_WEIGHT{TRUC_CHILD_MAX_VSIZE * WITNESS_SCALE_FACTOR}; // These limits are within the default cluster limits. static_assert(TRUC_MAX_VSIZE + TRUC_CHILD_MAX_VSIZE <= DEFAULT_CLUSTER_SIZE_LIMIT_KVB * 1000); diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 17fea5b46b5..9fc8923fba7 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -177,8 +177,8 @@ struct TransactionSerParams { const bool allow_witness; SER_PARAMS_OPFUNC }; -static constexpr TransactionSerParams TX_WITH_WITNESS{.allow_witness = true}; -static constexpr TransactionSerParams TX_NO_WITNESS{.allow_witness = false}; +inline constexpr TransactionSerParams TX_WITH_WITNESS{.allow_witness = true}; +inline constexpr TransactionSerParams TX_NO_WITNESS{.allow_witness = false}; /** * Basic transaction serialization format: diff --git a/src/protocol.h b/src/protocol.h index a15a3aa60af..0fd3c59261e 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -310,8 +310,8 @@ inline const std::array ALL_NET_MESSAGE_TYPES{std::to_array({ NetMsgType::FEATURE, })}; -static constexpr size_t MAX_FEATUREID_LENGTH{80}; -static constexpr size_t MAX_FEATUREDATA_LENGTH{512}; +inline constexpr size_t MAX_FEATUREID_LENGTH{80}; +inline constexpr size_t MAX_FEATUREDATA_LENGTH{512}; namespace NetMsgFeature { //inline constexpr std::string_view FOO{"BIP-FOO"}; @@ -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 b0177a3e555..bd9678a1d18 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -29,71 +29,71 @@ enum class TransactionError; using common::PSBTError; // Magic bytes -static constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff}; +inline constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff}; // Global types -static constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX = 0x00; -static constexpr uint8_t PSBT_GLOBAL_XPUB = 0x01; -static constexpr uint8_t PSBT_GLOBAL_TX_VERSION = 0x02; -static constexpr uint8_t PSBT_GLOBAL_FALLBACK_LOCKTIME = 0x03; -static constexpr uint8_t PSBT_GLOBAL_INPUT_COUNT = 0x04; -static constexpr uint8_t PSBT_GLOBAL_OUTPUT_COUNT = 0x05; -static constexpr uint8_t PSBT_GLOBAL_TX_MODIFIABLE = 0x06; -static constexpr uint8_t PSBT_GLOBAL_VERSION = 0xFB; -static constexpr uint8_t PSBT_GLOBAL_PROPRIETARY = 0xFC; +inline constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX = 0x00; +inline constexpr uint8_t PSBT_GLOBAL_XPUB = 0x01; +inline constexpr uint8_t PSBT_GLOBAL_TX_VERSION = 0x02; +inline constexpr uint8_t PSBT_GLOBAL_FALLBACK_LOCKTIME = 0x03; +inline constexpr uint8_t PSBT_GLOBAL_INPUT_COUNT = 0x04; +inline constexpr uint8_t PSBT_GLOBAL_OUTPUT_COUNT = 0x05; +inline constexpr uint8_t PSBT_GLOBAL_TX_MODIFIABLE = 0x06; +inline constexpr uint8_t PSBT_GLOBAL_VERSION = 0xFB; +inline constexpr uint8_t PSBT_GLOBAL_PROPRIETARY = 0xFC; // Input types -static constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO = 0x00; -static constexpr uint8_t PSBT_IN_WITNESS_UTXO = 0x01; -static constexpr uint8_t PSBT_IN_PARTIAL_SIG = 0x02; -static constexpr uint8_t PSBT_IN_SIGHASH = 0x03; -static constexpr uint8_t PSBT_IN_REDEEMSCRIPT = 0x04; -static constexpr uint8_t PSBT_IN_WITNESSSCRIPT = 0x05; -static constexpr uint8_t PSBT_IN_BIP32_DERIVATION = 0x06; -static constexpr uint8_t PSBT_IN_SCRIPTSIG = 0x07; -static constexpr uint8_t PSBT_IN_SCRIPTWITNESS = 0x08; -static constexpr uint8_t PSBT_IN_RIPEMD160 = 0x0A; -static constexpr uint8_t PSBT_IN_SHA256 = 0x0B; -static constexpr uint8_t PSBT_IN_HASH160 = 0x0C; -static constexpr uint8_t PSBT_IN_HASH256 = 0x0D; -static constexpr uint8_t PSBT_IN_PREVIOUS_TXID = 0x0e; -static constexpr uint8_t PSBT_IN_OUTPUT_INDEX = 0x0f; -static constexpr uint8_t PSBT_IN_SEQUENCE = 0x10; -static constexpr uint8_t PSBT_IN_REQUIRED_TIME_LOCKTIME = 0x11; -static constexpr uint8_t PSBT_IN_REQUIRED_HEIGHT_LOCKTIME = 0x12; -static constexpr uint8_t PSBT_IN_TAP_KEY_SIG = 0x13; -static constexpr uint8_t PSBT_IN_TAP_SCRIPT_SIG = 0x14; -static constexpr uint8_t PSBT_IN_TAP_LEAF_SCRIPT = 0x15; -static constexpr uint8_t PSBT_IN_TAP_BIP32_DERIVATION = 0x16; -static constexpr uint8_t PSBT_IN_TAP_INTERNAL_KEY = 0x17; -static constexpr uint8_t PSBT_IN_TAP_MERKLE_ROOT = 0x18; -static constexpr uint8_t PSBT_IN_MUSIG2_PARTICIPANT_PUBKEYS = 0x1a; -static constexpr uint8_t PSBT_IN_MUSIG2_PUB_NONCE = 0x1b; -static constexpr uint8_t PSBT_IN_MUSIG2_PARTIAL_SIG = 0x1c; -static constexpr uint8_t PSBT_IN_PROPRIETARY = 0xFC; +inline constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO = 0x00; +inline constexpr uint8_t PSBT_IN_WITNESS_UTXO = 0x01; +inline constexpr uint8_t PSBT_IN_PARTIAL_SIG = 0x02; +inline constexpr uint8_t PSBT_IN_SIGHASH = 0x03; +inline constexpr uint8_t PSBT_IN_REDEEMSCRIPT = 0x04; +inline constexpr uint8_t PSBT_IN_WITNESSSCRIPT = 0x05; +inline constexpr uint8_t PSBT_IN_BIP32_DERIVATION = 0x06; +inline constexpr uint8_t PSBT_IN_SCRIPTSIG = 0x07; +inline constexpr uint8_t PSBT_IN_SCRIPTWITNESS = 0x08; +inline constexpr uint8_t PSBT_IN_RIPEMD160 = 0x0A; +inline constexpr uint8_t PSBT_IN_SHA256 = 0x0B; +inline constexpr uint8_t PSBT_IN_HASH160 = 0x0C; +inline constexpr uint8_t PSBT_IN_HASH256 = 0x0D; +inline constexpr uint8_t PSBT_IN_PREVIOUS_TXID = 0x0e; +inline constexpr uint8_t PSBT_IN_OUTPUT_INDEX = 0x0f; +inline constexpr uint8_t PSBT_IN_SEQUENCE = 0x10; +inline constexpr uint8_t PSBT_IN_REQUIRED_TIME_LOCKTIME = 0x11; +inline constexpr uint8_t PSBT_IN_REQUIRED_HEIGHT_LOCKTIME = 0x12; +inline constexpr uint8_t PSBT_IN_TAP_KEY_SIG = 0x13; +inline constexpr uint8_t PSBT_IN_TAP_SCRIPT_SIG = 0x14; +inline constexpr uint8_t PSBT_IN_TAP_LEAF_SCRIPT = 0x15; +inline constexpr uint8_t PSBT_IN_TAP_BIP32_DERIVATION = 0x16; +inline constexpr uint8_t PSBT_IN_TAP_INTERNAL_KEY = 0x17; +inline constexpr uint8_t PSBT_IN_TAP_MERKLE_ROOT = 0x18; +inline constexpr uint8_t PSBT_IN_MUSIG2_PARTICIPANT_PUBKEYS = 0x1a; +inline constexpr uint8_t PSBT_IN_MUSIG2_PUB_NONCE = 0x1b; +inline constexpr uint8_t PSBT_IN_MUSIG2_PARTIAL_SIG = 0x1c; +inline constexpr uint8_t PSBT_IN_PROPRIETARY = 0xFC; // Output types -static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT = 0x00; -static constexpr uint8_t PSBT_OUT_WITNESSSCRIPT = 0x01; -static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION = 0x02; -static constexpr uint8_t PSBT_OUT_AMOUNT = 0x03; -static constexpr uint8_t PSBT_OUT_SCRIPT = 0x04; -static constexpr uint8_t PSBT_OUT_TAP_INTERNAL_KEY = 0x05; -static constexpr uint8_t PSBT_OUT_TAP_TREE = 0x06; -static constexpr uint8_t PSBT_OUT_TAP_BIP32_DERIVATION = 0x07; -static constexpr uint8_t PSBT_OUT_MUSIG2_PARTICIPANT_PUBKEYS = 0x08; -static constexpr uint8_t PSBT_OUT_PROPRIETARY = 0xFC; +inline constexpr uint8_t PSBT_OUT_REDEEMSCRIPT = 0x00; +inline constexpr uint8_t PSBT_OUT_WITNESSSCRIPT = 0x01; +inline constexpr uint8_t PSBT_OUT_BIP32_DERIVATION = 0x02; +inline constexpr uint8_t PSBT_OUT_AMOUNT = 0x03; +inline constexpr uint8_t PSBT_OUT_SCRIPT = 0x04; +inline constexpr uint8_t PSBT_OUT_TAP_INTERNAL_KEY = 0x05; +inline constexpr uint8_t PSBT_OUT_TAP_TREE = 0x06; +inline constexpr uint8_t PSBT_OUT_TAP_BIP32_DERIVATION = 0x07; +inline constexpr uint8_t PSBT_OUT_MUSIG2_PARTICIPANT_PUBKEYS = 0x08; +inline constexpr uint8_t PSBT_OUT_PROPRIETARY = 0xFC; // The separator is 0x00. Reading this in means that the unserializer can interpret it // as a 0 length key which indicates that this is the separator. The separator has no value. -static constexpr uint8_t PSBT_SEPARATOR = 0x00; +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{100'000'000}; // 100 MB // PSBT version number -static constexpr uint32_t PSBT_HIGHEST_VERSION = 2; +inline constexpr uint32_t PSBT_HIGHEST_VERSION = 2; /** A structure for PSBT proprietary types */ struct PSBTProprietary 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 a3b8cb9d9ce..0e8f1909247 100644 --- a/src/qt/guiconstants.h +++ b/src/qt/guiconstants.h @@ -11,18 +11,18 @@ using namespace std::chrono_literals; /* A delay between model updates */ -static constexpr auto MODEL_UPDATE_DELAY{250ms}; +inline constexpr auto MODEL_UPDATE_DELAY{250ms}; /* A delay between shutdown pollings */ -static constexpr auto SHUTDOWN_POLLING_DELAY{200ms}; +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 @@ -55,9 +55,9 @@ static const int TOOLTIP_WRAP_THRESHOLD = 80; #define QAPP_APP_NAME_REGTEST "Bitcoin-Qt-regtest" /* One gigabyte (GB) in bytes */ -static constexpr uint64_t GB_BYTES{1000000000}; +inline constexpr uint64_t GB_BYTES{1'000'000'000}; // Default prune target displayed in GUI. -static constexpr int DEFAULT_PRUNE_TARGET_GB{2}; +inline constexpr int DEFAULT_PRUNE_TARGET_GB{2}; #endif // BITCOIN_QT_GUICONSTANTS_H 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/modaloverlay.h b/src/qt/modaloverlay.h index 7c4b7a4b85c..f434aaadc1e 100644 --- a/src/qt/modaloverlay.h +++ b/src/qt/modaloverlay.h @@ -10,7 +10,7 @@ #include //! The required delta of headers to the estimated number of available headers until we show the IBD progress -static constexpr int HEADER_HEIGHT_DELTA_SYNC = 24; +inline constexpr int HEADER_HEIGHT_DELTA_SYNC = 24; namespace Ui { class ModalOverlay; diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index feef00a3cf4..9d10694718b 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -22,7 +22,7 @@ class Node; } extern const char *DEFAULT_GUI_PROXY_HOST; -static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050; +inline constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050; /** * Convert configured prune target MiB to displayed GB. Round up to avoid underestimating max disk usage. diff --git a/src/qt/qrimagewidget.h b/src/qt/qrimagewidget.h index 844a6e031ab..6eb9bed2a75 100644 --- a/src/qt/qrimagewidget.h +++ b/src/qt/qrimagewidget.h @@ -9,12 +9,12 @@ #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 */ -static constexpr int QR_IMAGE_SIZE = 300; -static constexpr int QR_IMAGE_TEXT_MARGIN = 10; -static constexpr int QR_IMAGE_MARGIN = 2 * QR_IMAGE_TEXT_MARGIN; +inline constexpr int QR_IMAGE_SIZE = 300; +inline constexpr int QR_IMAGE_TEXT_MARGIN = 10; +inline constexpr int QR_IMAGE_MARGIN = 2 * QR_IMAGE_TEXT_MARGIN; QT_BEGIN_NAMESPACE class QMenu; diff --git a/src/rpc/blockchain.h b/src/rpc/blockchain.h index 45f62c628b0..1b7c34d945d 100644 --- a/src/rpc/blockchain.h +++ b/src/rpc/blockchain.h @@ -27,7 +27,7 @@ class BlockManager; struct NodeContext; } // namespace node -static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5; +inline constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5; /** * Get the difficulty of the net wrt to the given block index. diff --git a/src/rpc/mining.h b/src/rpc/mining.h index a6c243c22c5..26a4ab157f7 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{1'000'000}; #endif // BITCOIN_RPC_MINING_H diff --git a/src/rpc/util.h b/src/rpc/util.h index 2cb36488137..efb378c8f55 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -43,7 +43,7 @@ namespace node { enum class TransactionError; } // namespace node -static constexpr bool DEFAULT_RPC_DOC_CHECK{ +inline constexpr bool DEFAULT_RPC_DOC_CHECK{ #ifdef RPC_DOC_CHECK true #else diff --git a/src/script/interpreter.h b/src/script/interpreter.h index ff63a73f0fc..47d9bfb09c9 100644 --- a/src/script/interpreter.h +++ b/src/script/interpreter.h @@ -45,7 +45,7 @@ enum * flags (A | B) is a subset of the acceptable scripts under flag (A). */ -static constexpr script_verify_flags SCRIPT_VERIFY_NONE{0}; +inline constexpr script_verify_flags SCRIPT_VERIFY_NONE{0}; enum class script_verify_flag_name : uint8_t { // Evaluate P2SH subscripts (BIP16). @@ -152,12 +152,12 @@ enum class script_verify_flag_name : uint8_t { }; using enum script_verify_flag_name; -static constexpr int MAX_SCRIPT_VERIFY_FLAGS_BITS = static_cast(SCRIPT_VERIFY_END_MARKER); +inline constexpr int MAX_SCRIPT_VERIFY_FLAGS_BITS = static_cast(SCRIPT_VERIFY_END_MARKER); // assert there is still a spare bit static_assert(0 < MAX_SCRIPT_VERIFY_FLAGS_BITS && MAX_SCRIPT_VERIFY_FLAGS_BITS <= 63); -static constexpr script_verify_flags::value_type MAX_SCRIPT_VERIFY_FLAGS = ((script_verify_flags::value_type{1} << MAX_SCRIPT_VERIFY_FLAGS_BITS) - 1); +inline constexpr script_verify_flags::value_type MAX_SCRIPT_VERIFY_FLAGS = ((script_verify_flags::value_type{1} << MAX_SCRIPT_VERIFY_FLAGS_BITS) - 1); bool CheckSignatureEncoding(const std::vector &vchSig, script_verify_flags flags, ScriptError* serror); @@ -235,16 +235,16 @@ struct ScriptExecutionData }; /** Signature hash sizes */ -static constexpr size_t WITNESS_V0_SCRIPTHASH_SIZE = 32; -static constexpr size_t WITNESS_V0_KEYHASH_SIZE = 20; -static constexpr size_t WITNESS_V1_TAPROOT_SIZE = 32; +inline constexpr size_t WITNESS_V0_SCRIPTHASH_SIZE = 32; +inline constexpr size_t WITNESS_V0_KEYHASH_SIZE = 20; +inline constexpr size_t WITNESS_V1_TAPROOT_SIZE = 32; -static constexpr uint8_t TAPROOT_LEAF_MASK = 0xfe; -static constexpr uint8_t TAPROOT_LEAF_TAPSCRIPT = 0xc0; -static constexpr size_t TAPROOT_CONTROL_BASE_SIZE = 33; -static constexpr size_t TAPROOT_CONTROL_NODE_SIZE = 32; -static constexpr size_t TAPROOT_CONTROL_MAX_NODE_COUNT = 128; -static constexpr size_t TAPROOT_CONTROL_MAX_SIZE = TAPROOT_CONTROL_BASE_SIZE + TAPROOT_CONTROL_NODE_SIZE * TAPROOT_CONTROL_MAX_NODE_COUNT; +inline constexpr uint8_t TAPROOT_LEAF_MASK = 0xfe; +inline constexpr uint8_t TAPROOT_LEAF_TAPSCRIPT = 0xc0; +inline constexpr size_t TAPROOT_CONTROL_BASE_SIZE = 33; +inline constexpr size_t TAPROOT_CONTROL_NODE_SIZE = 32; +inline constexpr size_t TAPROOT_CONTROL_MAX_NODE_COUNT = 128; +inline constexpr size_t TAPROOT_CONTROL_MAX_SIZE = TAPROOT_CONTROL_BASE_SIZE + TAPROOT_CONTROL_NODE_SIZE * TAPROOT_CONTROL_MAX_NODE_COUNT; extern const HashWriter HASHER_TAPSIGHASH; //!< Hasher with tag "TapSighash" pre-fed to it. extern const HashWriter HASHER_TAPLEAF; //!< Hasher with tag "TapLeaf" pre-fed to it. diff --git a/src/script/miniscript.h b/src/script/miniscript.h index 4e8beb19e6b..eba2fe2e754 100644 --- a/src/script/miniscript.h +++ b/src/script/miniscript.h @@ -268,18 +268,18 @@ constexpr bool IsTapscript(MiniscriptContext ms_ctx) namespace internal { //! The maximum size of a witness item for a Miniscript under Tapscript context. (A BIP340 signature with a sighash type byte.) -static constexpr uint32_t MAX_TAPMINISCRIPT_STACK_ELEM_SIZE{65}; +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) { @@ -342,15 +342,15 @@ struct InputStack { }; /** A stack consisting of a single zero-length element (interpreted as 0 by the script interpreter in numeric context). */ -static const auto ZERO = InputStack(std::vector()); +inline const auto ZERO = InputStack(std::vector()); /** A stack consisting of a single malleable 32-byte 0x0000...0000 element (for dissatisfying hash challenges). */ -static const auto ZERO32 = InputStack(std::vector(32, 0)).SetMalleable(); +inline const auto ZERO32 = InputStack(std::vector(32, 0)).SetMalleable(); /** A stack consisting of a single 0x01 element (interpreted as 1 by the script interpreted in numeric context). */ -static const auto ONE = InputStack(Vector((unsigned char)1)); +inline const auto ONE = InputStack(Vector((unsigned char)1)); /** The empty stack. */ -static const auto EMPTY = InputStack(); +inline const auto EMPTY = InputStack(); /** A stack representing the lack of any (dis)satisfactions. */ -static const auto INVALID = InputStack().SetAvailable(Availability::NO); +inline const auto INVALID = InputStack().SetAvailable(Availability::NO); //! A pair of a satisfaction and a dissatisfaction InputStack. struct InputResult { diff --git a/src/script/script.h b/src/script/script.h index e23ad440490..08cd18f2a27 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -26,43 +26,43 @@ #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. */ -static constexpr unsigned int MAX_PUBKEYS_PER_MULTI_A = 999; +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{10'000}; // 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{500'000'000}; // 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 // has meanings independent of the script -static constexpr unsigned int ANNEX_TAG = 0x50; +inline constexpr unsigned int ANNEX_TAG = 0x50; // Validation weight per passing signature (Tapscript only, see BIP 342). -static constexpr int64_t VALIDATION_WEIGHT_PER_SIGOP_PASSED{50}; +inline constexpr int64_t VALIDATION_WEIGHT_PER_SIGOP_PASSED{50}; // How much weight budget is added to the witness size (Tapscript only, see BIP 342). -static constexpr int64_t VALIDATION_WEIGHT_OFFSET{50}; +inline constexpr int64_t VALIDATION_WEIGHT_OFFSET{50}; template std::vector ToByteVector(const T& in) @@ -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/script/sigcache.h b/src/script/sigcache.h index 092bbf3e8e1..d11c6ad316d 100644 --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -28,9 +28,9 @@ class XOnlyPubKey; // DoS prevention: limit cache size to 32MiB (over 1000000 entries on 64-bit // systems). Due to how we count cache size, actual memory usage is slightly // more (~32.25 MiB) -static constexpr size_t DEFAULT_VALIDATION_CACHE_BYTES{32_MiB}; -static constexpr size_t DEFAULT_SIGNATURE_CACHE_BYTES{DEFAULT_VALIDATION_CACHE_BYTES / 2}; -static constexpr size_t DEFAULT_SCRIPT_EXECUTION_CACHE_BYTES{DEFAULT_VALIDATION_CACHE_BYTES / 2}; +inline constexpr size_t DEFAULT_VALIDATION_CACHE_BYTES{32_MiB}; +inline constexpr size_t DEFAULT_SIGNATURE_CACHE_BYTES{DEFAULT_VALIDATION_CACHE_BYTES / 2}; +inline constexpr size_t DEFAULT_SCRIPT_EXECUTION_CACHE_BYTES{DEFAULT_VALIDATION_CACHE_BYTES / 2}; static_assert(DEFAULT_VALIDATION_CACHE_BYTES == DEFAULT_SIGNATURE_CACHE_BYTES + DEFAULT_SCRIPT_EXECUTION_CACHE_BYTES); /** diff --git a/src/serialize.h b/src/serialize.h index 5d38a510076..a1395c47223 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -32,10 +32,10 @@ * The maximum size of a serialized object in bytes or number of elements * (for eg vectors) when the size is encoded as CompactSize. */ -static constexpr uint64_t MAX_SIZE = 0x02000000; +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{5'000'000}; /** * Dummy data type to identify deserializing constructors. @@ -49,7 +49,7 @@ static const 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/chainstate.h b/src/test/util/chainstate.h index aeec14ccb19..7846726d360 100644 --- a/src/test/util/chainstate.h +++ b/src/test/util/chainstate.h @@ -17,7 +17,7 @@ #include -const auto NoMalleation = [](AutoFile& file, node::SnapshotMetadata& meta){}; +inline constexpr auto NoMalleation = [](AutoFile& file, node::SnapshotMetadata& meta){}; /** * Create and activate a UTXO snapshot, optionally providing a function to 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/test/util/script.h b/src/test/util/script.h index 44d9acd9197..e3b58118384 100644 --- a/src/test/util/script.h +++ b/src/test/util/script.h @@ -9,8 +9,8 @@ #include