diff --git a/src/bench/chacha20.cpp b/src/bench/chacha20.cpp index 371651771f7..b5a333d0026 100644 --- a/src/bench/chacha20.cpp +++ b/src/bench/chacha20.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ /* Number of bytes to process per iteration */ static const uint64_t BUFFER_SIZE_TINY = 64; static const uint64_t BUFFER_SIZE_SMALL = 256; -static const uint64_t BUFFER_SIZE_LARGE = 1024*1024; +static const uint64_t BUFFER_SIZE_LARGE{1_MiB}; static void CHACHA20(benchmark::Bench& bench, size_t buffersize) { diff --git a/src/bench/lockedpool.cpp b/src/bench/lockedpool.cpp index 27fd609a52d..61b35cce2bb 100644 --- a/src/bench/lockedpool.cpp +++ b/src/bench/lockedpool.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #define ASIZE 2048 @@ -15,7 +16,7 @@ static void BenchLockedPool(benchmark::Bench& bench) { void *synth_base = reinterpret_cast(0x08000000); - const size_t synth_size = 1024*1024; + const size_t synth_size{1_MiB}; Arena b(synth_base, synth_size, 16); std::vector addr{ASIZE, nullptr}; diff --git a/src/bench/poly1305.cpp b/src/bench/poly1305.cpp index e782164ad93..ef5a573d9b4 100644 --- a/src/bench/poly1305.cpp +++ b/src/bench/poly1305.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -14,7 +15,7 @@ /* Number of bytes to process per iteration */ static constexpr uint64_t BUFFER_SIZE_TINY = 64; static constexpr uint64_t BUFFER_SIZE_SMALL = 256; -static constexpr uint64_t BUFFER_SIZE_LARGE = 1024*1024; +static constexpr uint64_t BUFFER_SIZE_LARGE{1_MiB}; static void POLY1305(benchmark::Bench& bench, size_t buffersize) { diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index eb222078b5e..3212f6d3701 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -280,12 +281,12 @@ void CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync) const bool log_memory = LogAcceptCategory(BCLog::LEVELDB, util::log::Level::Debug); double mem_before = 0; if (log_memory) { - mem_before = DynamicMemoryUsage() / 1024.0 / 1024; + mem_before = DynamicMemoryUsage() / double(1_MiB); } leveldb::Status status = DBContext().pdb->Write(fSync ? DBContext().syncoptions : DBContext().writeoptions, &batch.m_impl_batch->batch); HandleError(status); if (log_memory) { - double mem_after = DynamicMemoryUsage() / 1024.0 / 1024; + double mem_after{DynamicMemoryUsage() / double(1_MiB)}; LogDebug(BCLog::LEVELDB, "WriteBatch memory usage: db=%s, before=%.1fMiB, after=%.1fMiB\n", m_name, mem_before, mem_after); } diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 2eee6c1c023..f0cfe2dcfee 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -21,7 +22,7 @@ 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 << 20; // 32 MiB +static const size_t DBWRAPPER_MAX_FILE_SIZE{32_MiB}; //! User-controlled performance and debug options. struct DBOptions { diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp index e63aa4a332c..d4fd7025981 100644 --- a/src/index/blockfilterindex.cpp +++ b/src/index/blockfilterindex.cpp @@ -49,9 +49,9 @@ */ constexpr uint8_t DB_FILTER_POS{'P'}; -constexpr unsigned int MAX_FLTR_FILE_SIZE = 0x1000000; // 16 MiB +constexpr unsigned int MAX_FLTR_FILE_SIZE{16_MiB}; /** The pre-allocation chunk size for fltr?????.dat files */ -constexpr unsigned int FLTR_FILE_CHUNK_SIZE = 0x100000; // 1 MiB +constexpr unsigned int FLTR_FILE_CHUNK_SIZE{1_MiB}; /** Maximum size of the cfheaders cache * We have a limit to prevent a bug in filling this cache * potentially turning into an OOM. At 2000 entries, this cache diff --git a/src/init.cpp b/src/init.cpp index 4b6e00bdf6f..a9445754288 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -77,6 +77,7 @@ #include #include #include +#include #include #include #include @@ -525,7 +526,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc) argsman.AddArg("-pid=", strprintf("Specify pid file. Relative paths will be prefixed by a net-specific datadir location. (default: %s)", BITCOIN_PID_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-prune=", strprintf("Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex. " "Warning: Reverting this setting requires re-downloading the entire blockchain. " - "(default: 0 = disable pruning blocks, 1 = allow manual pruning via RPC, >=%u = automatically prune block files to stay under the specified target size in MiB)", MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + "(default: 0 = disable pruning blocks, 1 = allow manual pruning via RPC, >=%u = automatically prune block files to stay under the specified target size in MiB)", MIN_DISK_SPACE_FOR_BLOCK_FILES / 1_MiB), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-reindex", "If enabled, wipe chain state and block index, and rebuild them from blk*.dat files on disk. Also wipe and rebuild other optional indexes that are active. If an assumeutxo snapshot was loaded, its chainstate will be wiped as well. The snapshot can then be reloaded via RPC.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-reindex-chainstate", "If enabled, wipe chain state, and rebuild it from blk*.dat files on disk. If an assumeutxo snapshot was loaded, its chainstate will be wiped as well. The snapshot can then be reloaded via RPC.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-settings=", strprintf("Specify path to dynamic settings data file. Can be disabled with -nosettings. File is written at runtime and not meant to be edited by users (use %s instead for custom settings). Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME, BITCOIN_SETTINGS_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); @@ -1328,8 +1329,8 @@ static ChainstateLoadResult InitAndLoadChainstate( return {ChainstateLoadStatus::FAILURE_FATAL, mempool_error}; } LogInfo("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)", - cache_sizes.coins * (1.0 / 1024 / 1024), - mempool_opts.max_size_bytes * (1.0 / 1024 / 1024)); + cache_sizes.coins / double(1_MiB), + mempool_opts.max_size_bytes / double(1_MiB)); ChainstateManager::Options chainman_opts{ .chainparams = chainparams, .datadir = args.GetDataDirNet(), @@ -1467,7 +1468,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) // Check disk space every 5 minutes to avoid db corruption. scheduler.scheduleEvery([&args, &node]{ - constexpr uint64_t min_disk_space = 50 << 20; // 50 MB + constexpr uint64_t min_disk_space{50_MiB}; if (!CheckDiskSpace(args.GetBlocksDirPath(), min_disk_space)) { LogError("Shutting down due to lack of disk space!\n"); if (!(Assert(node.shutdown_request))()) { @@ -1835,18 +1836,18 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) const auto [index_cache_sizes, kernel_cache_sizes] = CalculateCacheSizes(args, g_enabled_filter_types.size()); LogInfo("Cache configuration:"); - LogInfo("* Using %.1f MiB for block index database", kernel_cache_sizes.block_tree_db * (1.0 / 1024 / 1024)); + LogInfo("* Using %.1f MiB for block index database", kernel_cache_sizes.block_tree_db / double(1_MiB)); if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) { - LogInfo("* Using %.1f MiB for transaction index database", index_cache_sizes.tx_index * (1.0 / 1024 / 1024)); + LogInfo("* Using %.1f MiB for transaction index database", index_cache_sizes.tx_index / double(1_MiB)); } if (args.GetBoolArg("-txospenderindex", DEFAULT_TXOSPENDERINDEX)) { - LogInfo("* Using %.1f MiB for transaction output spender index database", index_cache_sizes.txospender_index * (1.0 / 1024 / 1024)); + LogInfo("* Using %.1f MiB for transaction output spender index database", index_cache_sizes.txospender_index / double(1_MiB)); } for (BlockFilterType filter_type : g_enabled_filter_types) { LogInfo("* Using %.1f MiB for %s block filter index database", - index_cache_sizes.filter_index * (1.0 / 1024 / 1024), BlockFilterTypeName(filter_type)); + index_cache_sizes.filter_index / double(1_MiB), BlockFilterTypeName(filter_type)); } - LogInfo("* Using %.1f MiB for chain state database", kernel_cache_sizes.coins_db * (1.0 / 1024 / 1024)); + LogInfo("* Using %.1f MiB for chain state database", kernel_cache_sizes.coins_db / double(1_MiB)); assert(!node.mempool); assert(!node.chainman); diff --git a/src/logging.h b/src/logging.h index 1f0e8889bb7..3417b4b7fd2 100644 --- a/src/logging.h +++ b/src/logging.h @@ -9,6 +9,7 @@ #include #include // IWYU pragma: export #include +#include #include #include // IWYU pragma: export #include @@ -62,7 +63,7 @@ struct LogCategory { namespace BCLog { constexpr auto DEFAULT_LOG_LEVEL{Level::Debug}; constexpr size_t DEFAULT_MAX_LOG_BUFFER{1'000'000}; // buffer up to 1MB of log data prior to StartLogging - constexpr uint64_t RATELIMIT_MAX_BYTES{1024 * 1024}; // maximum number of bytes per source location that can be logged within the RATELIMIT_WINDOW + constexpr uint64_t RATELIMIT_MAX_BYTES{1_MiB}; // maximum number of bytes per source location that can be logged within the RATELIMIT_WINDOW constexpr auto RATELIMIT_WINDOW{1h}; // time window after which log ratelimit stats are reset constexpr bool DEFAULT_LOGRATELIMIT{true}; diff --git a/src/node/blockmanager_args.cpp b/src/node/blockmanager_args.cpp index 1f84819bff7..3a5f4d75f81 100644 --- a/src/node/blockmanager_args.cpp +++ b/src/node/blockmanager_args.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -23,12 +24,12 @@ util::Result ApplyArgsManOptions(const ArgsManager& args, BlockManager::Op if (nPruneArg < 0) { return util::Error{_("Prune cannot be configured with a negative value.")}; } - uint64_t nPruneTarget{uint64_t(nPruneArg) * 1024 * 1024}; + uint64_t nPruneTarget{uint64_t(nPruneArg) * 1_MiB}; if (nPruneArg == 1) { // manual pruning: -prune=1 nPruneTarget = BlockManager::PRUNE_TARGET_MANUAL; } else if (nPruneTarget) { if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) { - return util::Error{strprintf(_("Prune configured below the minimum of %d MiB. Please use a higher number."), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024)}; + return util::Error{strprintf(_("Prune configured below the minimum of %d MiB. Please use a higher number."), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1_MiB)}; } } opts.prune_target = nPruneTarget; diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 27394e0d2ce..b0842a00505 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -394,8 +394,8 @@ void BlockManager::FindFilesToPrune( } LogDebug(BCLog::PRUNE, "[%s] target=%dMiB actual=%dMiB diff=%dMiB min_height=%d max_prune_height=%d removed %d blk/rev pairs\n", - chain.GetRole(), target / 1024 / 1024, nCurrentUsage / 1024 / 1024, - (int64_t(target) - int64_t(nCurrentUsage)) / 1024 / 1024, + chain.GetRole(), target / 1_MiB, nCurrentUsage / 1_MiB, + (int64_t(target) - int64_t(nCurrentUsage)) / int64_t(1_MiB), min_block_to_prune, last_block_can_prune, count); } diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h index d46db3fb4a8..a081b954735 100644 --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -18,6 +18,7 @@ #include #include #include +#include // IWYU pragma: keep #include #include #include @@ -116,11 +117,11 @@ using kernel::CBlockFileInfo; using kernel::BlockTreeDB; /** The pre-allocation chunk size for blk?????.dat files (since 0.8) */ -static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB +static const 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 = 0x100000; // 1 MiB +static const 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 = 0x8000000; // 128 MiB +static const 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)}; diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index 0738c00aef8..1725fe70bd9 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -163,7 +164,7 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize LogInfo("Block pruning enabled. Use RPC call pruneblockchain(height) to manually prune block and undo files."); } else if (chainman.m_blockman.GetPruneTarget()) { LogInfo("Prune configured to target %u MiB on disk for block and undo files.", - chainman.m_blockman.GetPruneTarget() / 1024 / 1024); + chainman.m_blockman.GetPruneTarget() / 1_MiB); } LOCK(cs_main); diff --git a/src/node/chainstatemanager_args.cpp b/src/node/chainstatemanager_args.cpp index 640fe128fc8..bf91a750c14 100644 --- a/src/node/chainstatemanager_args.cpp +++ b/src/node/chainstatemanager_args.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -64,7 +65,7 @@ util::Result ApplyArgsManOptions(const ArgsManager& args, ChainstateManage // script execution cache create the minimum possible cache (2 // elements). Therefore, we can use 0 as a floor here. // 2. Multiply first, divide after to avoid integer truncation. - size_t clamped_size_each = std::max(*max_size, 0) * (1 << 20) / 2; + size_t clamped_size_each{size_t(std::max(*max_size, 0) * 1_MiB / 2)}; opts.script_execution_cache_bytes = clamped_size_each; opts.signature_cache_bytes = clamped_size_each; } diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 4cbd5319229..feef00a3cf4 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -26,12 +27,12 @@ static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050; /** * Convert configured prune target MiB to displayed GB. Round up to avoid underestimating max disk usage. */ -static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES; } +static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1_MiB + GB_BYTES - 1) / GB_BYTES; } /** * Convert displayed prune target GB to configured MiB. Round down so roundtrip GB -> MiB -> GB conversion is stable. */ -static inline int64_t PruneGBtoMiB(int gb) { return gb * GB_BYTES / 1024 / 1024; } +static inline int64_t PruneGBtoMiB(int gb) { return gb * GB_BYTES / 1_MiB; } /** Interface from Qt to configuration data structure for Bitcoin client. To Qt, the options are presented as a list with the different options diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index d30a8acff62..a00eb181c0f 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -21,6 +21,7 @@ #endif // ENABLE_WALLET #include #include +#include #include #include #include @@ -529,7 +530,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty // Install event filter for up and down arrow ui->lineEdit->installEventFilter(this); - ui->lineEdit->setMaxLength(16 * 1024 * 1024); + ui->lineEdit->setMaxLength(16_MiB); ui->messagesWidget->installEventFilter(this); connect(ui->hidePeersDetailButton, &QAbstractButton::clicked, this, &RPCConsole::clearSelectedNode); diff --git a/src/randomenv.cpp b/src/randomenv.cpp index 662625b527d..c85e9181047 100644 --- a/src/randomenv.cpp +++ b/src/randomenv.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -113,7 +114,7 @@ void AddFile(CSHA512& hasher, const char *path) if (n > 0) hasher.Write(fbuf, n); total += n; /* not bothering with EINTR handling. */ - } while (n == sizeof(fbuf) && total < 1048576); // Read only the first 1 Mbyte + } while (n == sizeof(fbuf) && total < 1_MiB); // Read only the first 1 Mbyte close(f); } } diff --git a/src/script/sigcache.h b/src/script/sigcache.h index fb3880966d4..fe9a3562507 100644 --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -12,6 +12,7 @@ #include