Skip to content

Commit fa177d7

Browse files
author
MarcoFalke
committed
Move ::fPruneMode into BlockManager
1 parent fa721f1 commit fa177d7

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

src/init.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ using node::ShouldPersistMempool;
123123
using node::NodeContext;
124124
using node::ThreadImport;
125125
using node::VerifyLoadedChainstate;
126-
using node::fPruneMode;
127126
using node::fReindex;
128127

129128
static constexpr bool DEFAULT_PROXYRANDOMIZE{true};

src/node/blockmanager_args.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& args, BlockM
1818
uint64_t nPruneTarget{uint64_t(nPruneArg) * 1024 * 1024};
1919
if (nPruneArg == 1) { // manual pruning: -prune=1
2020
nPruneTarget = std::numeric_limits<uint64_t>::max();
21-
fPruneMode = true;
2221
} else if (nPruneTarget) {
2322
if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) {
2423
return strprintf(_("Prune configured below the minimum of %d MiB. Please use a higher number."), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024);
2524
}
26-
fPruneMode = true;
2725
}
2826
opts.prune_target = nPruneTarget;
2927

src/node/blockstorage.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
namespace node {
2929
std::atomic_bool fImporting(false);
3030
std::atomic_bool fReindex(false);
31-
bool fPruneMode = false;
3231

3332
bool CBlockIndexWorkComparator::operator()(const CBlockIndex* pa, const CBlockIndex* pb) const
3433
{
@@ -153,7 +152,7 @@ void BlockManager::PruneOneBlockFile(const int fileNumber)
153152

154153
void BlockManager::FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPruneHeight, int chain_tip_height)
155154
{
156-
assert(fPruneMode && nManualPruneHeight > 0);
155+
assert(IsPruneMode() && nManualPruneHeight > 0);
157156

158157
LOCK2(cs_main, cs_LastBlockFile);
159158
if (chain_tip_height < 0) {
@@ -656,7 +655,7 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
656655
if (out_of_space) {
657656
return AbortNode("Disk space is too low!", _("Disk space is too low!"));
658657
}
659-
if (bytes_allocated != 0 && fPruneMode) {
658+
if (bytes_allocated != 0 && IsPruneMode()) {
660659
m_check_for_pruning = true;
661660
}
662661
}
@@ -680,7 +679,7 @@ bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFileP
680679
if (out_of_space) {
681680
return AbortNode(state, "Disk space is too low!", _("Disk space is too low!"));
682681
}
683-
if (bytes_allocated != 0 && fPruneMode) {
682+
if (bytes_allocated != 0 && IsPruneMode()) {
684683
m_check_for_pruning = true;
685684
}
686685

src/node/blockstorage.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE = CMessageHeader::MESSAG
4949

5050
extern std::atomic_bool fImporting;
5151
extern std::atomic_bool fReindex;
52-
extern bool fPruneMode;
5352

5453
// Because validation code takes pointers to the map's CBlockIndex objects, if
5554
// we ever switch to another associative container, we need to either use a
@@ -124,6 +123,8 @@ class BlockManager
124123
*/
125124
bool m_check_for_pruning = false;
126125

126+
const bool m_prune_mode;
127+
127128
/** Dirty block index entries. */
128129
std::set<CBlockIndex*> m_dirty_blockindex;
129130

@@ -143,7 +144,9 @@ class BlockManager
143144
public:
144145
using Options = kernel::BlockManagerOpts;
145146

146-
explicit BlockManager(Options opts) : m_opts{std::move(opts)} {};
147+
explicit BlockManager(Options opts)
148+
: m_prune_mode{opts.prune_target > 0},
149+
m_opts{std::move(opts)} {};
147150

148151
BlockMap m_block_index GUARDED_BY(cs_main);
149152

@@ -187,7 +190,7 @@ class BlockManager
187190
FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp);
188191

189192
/** Whether running in -prune mode. */
190-
[[nodiscard]] bool IsPruneMode() const { return fPruneMode; }
193+
[[nodiscard]] bool IsPruneMode() const { return m_prune_mode; }
191194

192195
/** Attempt to stay below this number of bytes of block files. */
193196
[[nodiscard]] uint64_t GetPruneTarget() const { return m_opts.prune_target; }

0 commit comments

Comments
 (0)