Compare commits

...

4 commits

Author SHA1 Message Date
Luke Dashjr
52f95f582b
Merge d4a3abf6d4 into c5e44a0435 2025-04-29 11:49:19 +02:00
merge-script
c5e44a0435
Merge bitcoin/bitcoin#32369: test: Use the correct node for doubled keypath test
Some checks are pending
CI / macOS 14 native, arm64, fuzz (push) Waiting to run
CI / Windows native, VS 2022 (push) Waiting to run
CI / Windows native, fuzz, VS 2022 (push) Waiting to run
CI / Linux->Windows cross, no tests (push) Waiting to run
CI / Windows, test cross-built (push) Blocked by required conditions
CI / ASan + LSan + UBSan + integer, no depends, USDT (push) Waiting to run
CI / test each commit (push) Waiting to run
CI / macOS 14 native, arm64, no depends, sqlite only, gui (push) Waiting to run
32d55e28af test: Use the correct node for doubled keypath test (Ava Chow)

Pull request description:

  #29124 had a silent merge conflict with #32350 which resulted in it using the wrong node. Fix the test to use the correct v22 node.

ACKs for top commit:
  maflcko:
    lgtm ACK 32d55e28af
  rkrux:
    ACK 32d55e28af
  BrandonOdiwuor:
    Code Review ACK 32d55e28af

Tree-SHA512: 1e0231985beb382b16e1d608c874750423d0502388db0c8ad450b22d17f9d96f5e16a6b44948ebda5efc750f62b60d0de8dd20131f449427426a36caf374af92
2025-04-29 09:59:42 +01:00
Ava Chow
32d55e28af test: Use the correct node for doubled keypath test 2025-04-28 14:44:17 -07:00
Luke Dashjr
d4a3abf6d4 Add -pruneduringinit option to temporarily use another prune target during IBD 2025-02-12 18:55:10 +00:00
6 changed files with 60 additions and 13 deletions

View file

@ -508,6 +508,9 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
argsman.AddArg("-prune=<n>", 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);
argsman.AddArg("-pruneduringinit", "Temporarily adjusts the -prune setting until initial sync completes."
" Ignored if pruning is disabled."
" (default: -1 = same value as -prune)", 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=<file>", 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);

View file

@ -25,6 +25,7 @@ struct BlockManagerOpts {
const CChainParams& chainparams;
bool use_xor{DEFAULT_XOR_BLOCKSDIR};
uint64_t prune_target{0};
int64_t prune_target_during_init{-1};
bool fast_prune{false};
const fs::path blocks_dir;
Notifications& notifications;

View file

@ -12,26 +12,50 @@
#include <util/translation.h>
#include <validation.h>
#include <algorithm>
#include <cstdint>
#include <string_view>
namespace node {
util::Result<uint64_t> ParsePruneOption(const int64_t nPruneArg, const std::string_view opt_name)
{
// block pruning; get the amount of disk space (in MiB) to allot for block & undo files
if (nPruneArg < 0) {
return util::Error{strprintf(_("%s cannot be configured with a negative value."), opt_name)};
} else if (nPruneArg == 0) { // pruning disabled
return 0;
} else if (nPruneArg == 1) { // manual pruning: -prune=1
return BlockManager::PRUNE_TARGET_MANUAL;
}
const uint64_t nPruneTarget{uint64_t(nPruneArg) * 1024 * 1024};
if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) {
return util::Error{strprintf(_("%s configured below the minimum of %d MiB. Please use a higher number."), opt_name, MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024)};
}
return nPruneTarget;
}
util::Result<void> ApplyArgsManOptions(const ArgsManager& args, BlockManager::Options& opts)
{
if (auto value{args.GetBoolArg("-blocksxor")}) opts.use_xor = *value;
// 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 util::Error{_("Prune cannot be configured with a negative value.")};
if (const auto prune_parsed = ParsePruneOption(nPruneArg, "Prune")) {
opts.prune_target = *prune_parsed;
} else {
return util::Error{util::ErrorString(prune_parsed)};
}
uint64_t nPruneTarget{uint64_t(nPruneArg) * 1024 * 1024};
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)};
if (const auto prune_during_init{args.GetIntArg("-pruneduringinit")}) {
if (*prune_during_init == -1) {
opts.prune_target_during_init = -1;
} else if (const auto prune_parsed = ParsePruneOption(*prune_during_init, "-pruneduringinit")) {
// NOTE: PRUNE_TARGET_MANUAL is >int64 max
opts.prune_target_during_init = std::min(std::numeric_limits<int64_t>::max(), (int64_t)*prune_parsed);
} else {
return util::Error{util::ErrorString(prune_parsed)};
}
}
opts.prune_target = nPruneTarget;
if (auto value{args.GetBoolArg("-fastprune")}) opts.fast_prune = *value;

View file

@ -299,6 +299,26 @@ void BlockManager::FindFilesToPruneManual(
chain.GetRole(), last_block_can_prune, count);
}
uint64_t BlockManager::GetPruneTargetForChainstate(const Chainstate& chain, ChainstateManager& chainman) const
{
const auto number_of_chainstates{chainman.GetAll().size()};
const uint64_t min_overall_target{MIN_DISK_SPACE_FOR_BLOCK_FILES * number_of_chainstates};
auto target = std::max(min_overall_target, GetPruneTarget());
uint64_t target_boost{0};
if (m_opts.prune_target_during_init > -1 && chainman.IsInitialBlockDownload()) {
if ((uint64_t)m_opts.prune_target_during_init <= target) {
target = std::max(min_overall_target, (uint64_t)m_opts.prune_target_during_init);
} else if (chain.GetRole() != ChainstateRole::ASSUMEDVALID) {
// Only the background/normal gets the benefit
// NOTE: This assumes only one such chainstate exists
target_boost = m_opts.prune_target_during_init - target;
}
}
// Distribute our -prune budget over all chainstates.
target = (target / number_of_chainstates) + target_boost;
return target;
}
void BlockManager::FindFilesToPrune(
std::set<int>& setFilesToPrune,
int last_prune,
@ -306,9 +326,7 @@ void BlockManager::FindFilesToPrune(
ChainstateManager& chainman)
{
LOCK2(cs_main, cs_LastBlockFile);
// Distribute our -prune budget over all chainstates.
const auto target = std::max(
MIN_DISK_SPACE_FOR_BLOCK_FILES, GetPruneTarget() / chainman.GetAll().size());
const auto target{GetPruneTargetForChainstate(chain, chainman)};
const uint64_t target_sync_height = chainman.m_best_header->nHeight;
if (chain.m_chain.Height() < 0 || target == 0) {

View file

@ -350,6 +350,7 @@ public:
/** Attempt to stay below this number of bytes of block files. */
[[nodiscard]] uint64_t GetPruneTarget() const { return m_opts.prune_target; }
[[nodiscard]] uint64_t GetPruneTargetForChainstate(const Chainstate& chain, ChainstateManager& chainman) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
static constexpr auto PRUNE_TARGET_MANUAL{std::numeric_limits<uint64_t>::max()};
[[nodiscard]] bool LoadingBlocks() const { return m_importing || !m_blockfiles_indexed; }

View file

@ -87,7 +87,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
# 0.21.x and 22.x would both produce bad derivation paths when topping up an inactive hd chain
# Make sure that this is being automatically cleaned up by migration
node_master = self.nodes[1]
node_v22 = self.nodes[self.num_nodes - 5]
node_v22 = self.nodes[self.num_nodes - 3]
wallet_name = "bad_deriv_path"
node_v22.createwallet(wallet_name=wallet_name, descriptors=False)
bad_deriv_wallet = node_v22.get_wallet_rpc(wallet_name)