Move ::fPruneMode into BlockManager

This commit is contained in:
MarcoFalke 2023-01-03 12:47:38 +01:00
parent fa721f1cab
commit fa177d7b6b
No known key found for this signature in database
4 changed files with 9 additions and 10 deletions

View File

@ -123,7 +123,6 @@ using node::ShouldPersistMempool;
using node::NodeContext;
using node::ThreadImport;
using node::VerifyLoadedChainstate;
using node::fPruneMode;
using node::fReindex;
static constexpr bool DEFAULT_PROXYRANDOMIZE{true};

View File

@ -18,12 +18,10 @@ std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& args, BlockM
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;

View File

@ -28,7 +28,6 @@
namespace node {
std::atomic_bool fImporting(false);
std::atomic_bool fReindex(false);
bool fPruneMode = false;
bool CBlockIndexWorkComparator::operator()(const CBlockIndex* pa, const CBlockIndex* pb) const
{
@ -153,7 +152,7 @@ void BlockManager::PruneOneBlockFile(const int fileNumber)
void BlockManager::FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPruneHeight, int chain_tip_height)
{
assert(fPruneMode && nManualPruneHeight > 0);
assert(IsPruneMode() && nManualPruneHeight > 0);
LOCK2(cs_main, cs_LastBlockFile);
if (chain_tip_height < 0) {
@ -656,7 +655,7 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
if (out_of_space) {
return AbortNode("Disk space is too low!", _("Disk space is too low!"));
}
if (bytes_allocated != 0 && fPruneMode) {
if (bytes_allocated != 0 && IsPruneMode()) {
m_check_for_pruning = true;
}
}
@ -680,7 +679,7 @@ bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFileP
if (out_of_space) {
return AbortNode(state, "Disk space is too low!", _("Disk space is too low!"));
}
if (bytes_allocated != 0 && fPruneMode) {
if (bytes_allocated != 0 && IsPruneMode()) {
m_check_for_pruning = true;
}

View File

@ -49,7 +49,6 @@ static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE = CMessageHeader::MESSAG
extern std::atomic_bool fImporting;
extern std::atomic_bool fReindex;
extern bool fPruneMode;
// 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
@ -124,6 +123,8 @@ private:
*/
bool m_check_for_pruning = false;
const bool m_prune_mode;
/** Dirty block index entries. */
std::set<CBlockIndex*> m_dirty_blockindex;
@ -143,7 +144,9 @@ private:
public:
using Options = kernel::BlockManagerOpts;
explicit BlockManager(Options opts) : m_opts{std::move(opts)} {};
explicit BlockManager(Options opts)
: m_prune_mode{opts.prune_target > 0},
m_opts{std::move(opts)} {};
BlockMap m_block_index GUARDED_BY(cs_main);
@ -187,7 +190,7 @@ public:
FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp);
/** Whether running in -prune mode. */
[[nodiscard]] bool IsPruneMode() const { return fPruneMode; }
[[nodiscard]] bool IsPruneMode() const { return m_prune_mode; }
/** Attempt to stay below this number of bytes of block files. */
[[nodiscard]] uint64_t GetPruneTarget() const { return m_opts.prune_target; }