mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
Move ::nPruneTarget into BlockManager
This commit is contained in:
32
src/node/blockmanager_args.cpp
Normal file
32
src/node/blockmanager_args.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2023 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <node/blockmanager_args.h>
|
||||
|
||||
#include <util/system.h>
|
||||
#include <validation.h>
|
||||
|
||||
namespace node {
|
||||
std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& args, BlockManager::Options& opts)
|
||||
{
|
||||
// block pruning; get the amount of disk space (in MiB) to allot for block & undo files
|
||||
int64_t nPruneArg{args.GetIntArg("-prune", opts.prune_target)};
|
||||
if (nPruneArg < 0) {
|
||||
return _("Prune cannot be configured with a negative value.");
|
||||
}
|
||||
uint64_t nPruneTarget{uint64_t(nPruneArg) * 1024 * 1024};
|
||||
if (nPruneArg == 1) { // manual pruning: -prune=1
|
||||
nPruneTarget = std::numeric_limits<uint64_t>::max();
|
||||
fPruneMode = true;
|
||||
} else if (nPruneTarget) {
|
||||
if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) {
|
||||
return strprintf(_("Prune configured below the minimum of %d MiB. Please use a higher number."), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024);
|
||||
}
|
||||
fPruneMode = true;
|
||||
}
|
||||
opts.prune_target = nPruneTarget;
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
} // namespace node
|
||||
20
src/node/blockmanager_args.h
Normal file
20
src/node/blockmanager_args.h
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
// Copyright (c) 2023 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_NODE_BLOCKMANAGER_ARGS_H
|
||||
#define BITCOIN_NODE_BLOCKMANAGER_ARGS_H
|
||||
|
||||
#include <node/blockstorage.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
class ArgsManager;
|
||||
struct bilingual_str;
|
||||
|
||||
namespace node {
|
||||
std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& args, BlockManager::Options& opts);
|
||||
} // namespace node
|
||||
|
||||
#endif // BITCOIN_NODE_BLOCKMANAGER_ARGS_H
|
||||
@@ -29,7 +29,6 @@ namespace node {
|
||||
std::atomic_bool fImporting(false);
|
||||
std::atomic_bool fReindex(false);
|
||||
bool fPruneMode = false;
|
||||
uint64_t nPruneTarget = 0;
|
||||
|
||||
bool CBlockIndexWorkComparator::operator()(const CBlockIndex* pa, const CBlockIndex* pb) const
|
||||
{
|
||||
@@ -178,7 +177,7 @@ void BlockManager::FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nM
|
||||
void BlockManager::FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight, int chain_tip_height, int prune_height, bool is_ibd)
|
||||
{
|
||||
LOCK2(cs_main, cs_LastBlockFile);
|
||||
if (chain_tip_height < 0 || nPruneTarget == 0) {
|
||||
if (chain_tip_height < 0 || GetPruneTarget() == 0) {
|
||||
return;
|
||||
}
|
||||
if ((uint64_t)chain_tip_height <= nPruneAfterHeight) {
|
||||
@@ -194,14 +193,14 @@ void BlockManager::FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPr
|
||||
uint64_t nBytesToPrune;
|
||||
int count = 0;
|
||||
|
||||
if (nCurrentUsage + nBuffer >= nPruneTarget) {
|
||||
if (nCurrentUsage + nBuffer >= GetPruneTarget()) {
|
||||
// On a prune event, the chainstate DB is flushed.
|
||||
// To avoid excessive prune events negating the benefit of high dbcache
|
||||
// values, we should not prune too rapidly.
|
||||
// So when pruning in IBD, increase the buffer a bit to avoid a re-prune too soon.
|
||||
if (is_ibd) {
|
||||
// Since this is only relevant during IBD, we use a fixed 10%
|
||||
nBuffer += nPruneTarget / 10;
|
||||
nBuffer += GetPruneTarget() / 10;
|
||||
}
|
||||
|
||||
for (int fileNumber = 0; fileNumber < m_last_blockfile; fileNumber++) {
|
||||
@@ -211,7 +210,7 @@ void BlockManager::FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPr
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nCurrentUsage + nBuffer < nPruneTarget) { // are we below our target?
|
||||
if (nCurrentUsage + nBuffer < GetPruneTarget()) { // are we below our target?
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -229,9 +228,9 @@ void BlockManager::FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPr
|
||||
}
|
||||
|
||||
LogPrint(BCLog::PRUNE, "target=%dMiB actual=%dMiB diff=%dMiB max_prune_height=%d removed %d blk/rev pairs\n",
|
||||
nPruneTarget/1024/1024, nCurrentUsage/1024/1024,
|
||||
((int64_t)nPruneTarget - (int64_t)nCurrentUsage)/1024/1024,
|
||||
nLastBlockWeCanPrune, count);
|
||||
GetPruneTarget() / 1024 / 1024, nCurrentUsage / 1024 / 1024,
|
||||
(int64_t(GetPruneTarget()) - int64_t(nCurrentUsage)) / 1024 / 1024,
|
||||
nLastBlockWeCanPrune, count);
|
||||
}
|
||||
|
||||
void BlockManager::UpdatePruneLock(const std::string& name, const PruneLockInfo& lock_info) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <attributes.h>
|
||||
#include <chain.h>
|
||||
#include <fs.h>
|
||||
#include <kernel/blockmanager_opts.h>
|
||||
#include <kernel/cs_main.h>
|
||||
#include <protocol.h>
|
||||
#include <sync.h>
|
||||
@@ -49,7 +50,6 @@ static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE = CMessageHeader::MESSAG
|
||||
extern std::atomic_bool fImporting;
|
||||
extern std::atomic_bool fReindex;
|
||||
extern bool fPruneMode;
|
||||
extern uint64_t nPruneTarget;
|
||||
|
||||
// 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
|
||||
@@ -138,7 +138,13 @@ private:
|
||||
*/
|
||||
std::unordered_map<std::string, PruneLockInfo> m_prune_locks GUARDED_BY(::cs_main);
|
||||
|
||||
const kernel::BlockManagerOpts m_opts;
|
||||
|
||||
public:
|
||||
using Options = kernel::BlockManagerOpts;
|
||||
|
||||
explicit BlockManager(Options opts) : m_opts{std::move(opts)} {};
|
||||
|
||||
BlockMap m_block_index GUARDED_BY(cs_main);
|
||||
|
||||
std::vector<CBlockIndex*> GetAllBlockIndices() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
@@ -184,7 +190,7 @@ public:
|
||||
[[nodiscard]] bool IsPruneMode() const { return fPruneMode; }
|
||||
|
||||
/** Attempt to stay below this number of bytes of block files. */
|
||||
[[nodiscard]] uint64_t GetPruneTarget() const { return nPruneTarget; }
|
||||
[[nodiscard]] uint64_t GetPruneTarget() const { return m_opts.prune_target; }
|
||||
|
||||
[[nodiscard]] bool LoadingBlocks() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user