Skip to content

Commit

Permalink
Add -pausebackgroundsync startup option
Browse files Browse the repository at this point in the history
When a UTXO snapshot is loaded, this option lets the user pause the verification of historical blocks in the background.
  • Loading branch information
Sjors authored and josibake committed Oct 5, 2024
1 parent 1469952 commit 45dd943
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions doc/release-notes-31023.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Updated settings
------

- When loading an assumeutxo snapshot, the background sync can be paused with `-pausebackgroundsync`. (#31023)
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
argsman.AddArg("-minimumchainwork=<hex>", strprintf("Minimum work assumed to exist on a valid chain in hex (default: %s, testnet3: %s, testnet4: %s, signet: %s)", defaultChainParams->GetConsensus().nMinimumChainWork.GetHex(), testnetChainParams->GetConsensus().nMinimumChainWork.GetHex(), testnet4ChainParams->GetConsensus().nMinimumChainWork.GetHex(), signetChainParams->GetConsensus().nMinimumChainWork.GetHex()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
argsman.AddArg("-par=<n>", strprintf("Set the number of script verification threads (0 = auto, up to %d, <0 = leave that many cores free, default: %d)",
MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-pausebackgroundsync", strprintf("When a UTXO snapshot is loaded, pause the verification of historical blocks in the background (default: %u)", DEFAULT_PAUSE_BACKGROUND_SYNC), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-persistmempool", strprintf("Whether to save the mempool on shutdown and load on restart (default: %u)", DEFAULT_PERSIST_MEMPOOL), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-persistmempoolv1",
strprintf("Whether a mempool.dat file created by -persistmempool or the savemempool RPC will be written in the legacy format "
Expand Down
2 changes: 2 additions & 0 deletions src/kernel/chainstatemanager_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ struct ChainstateManagerOpts {
int worker_threads_num{0};
size_t script_execution_cache_bytes{DEFAULT_SCRIPT_EXECUTION_CACHE_BYTES};
size_t signature_cache_bytes{DEFAULT_SIGNATURE_CACHE_BYTES};
//! Whether to defer syncing the background chainstate after an assumeutxo snapshot is loaded
bool pause_background_sync{false};
};

} // namespace kernel
Expand Down
2 changes: 2 additions & 0 deletions src/node/chainstatemanager_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManage
opts.signature_cache_bytes = clamped_size_each;
}

opts.pause_background_sync = args.GetBoolArg("-pausebackgroundsync", DEFAULT_PAUSE_BACKGROUND_SYNC);

return {};
}
} // namespace node
2 changes: 2 additions & 0 deletions src/node/chainstatemanager_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ArgsManager;
static constexpr int MAX_SCRIPTCHECK_THREADS{15};
/** -par default (number of script-checking threads, 0 = auto) */
static constexpr int DEFAULT_SCRIPTCHECK_THREADS{0};
/** -pausebackgroundsync default */
static const bool DEFAULT_PAUSE_BACKGROUND_SYNC{false};

namespace node {
[[nodiscard]] util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManager::Options& opts);
Expand Down
6 changes: 6 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6387,6 +6387,12 @@ std::optional<int> ChainstateManager::GetSnapshotBaseHeight() const
return base ? std::make_optional(base->nHeight) : std::nullopt;
}

bool ChainstateManager::BackgroundSyncInProgress() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) {
if (!IsUsable(m_snapshot_chainstate.get())) return false;
if (!IsUsable(m_ibd_chainstate.get())) return false;
return !m_options.pause_background_sync;
}

bool ChainstateManager::ValidatedSnapshotCleanup()
{
AssertLockHeld(::cs_main);
Expand Down
4 changes: 1 addition & 3 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -1113,9 +1113,7 @@ class ChainstateManager
CBlockIndex* ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChain().Tip(); }

//! The state of a background sync (for net processing)
bool BackgroundSyncInProgress() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) {
return IsUsable(m_snapshot_chainstate.get()) && IsUsable(m_ibd_chainstate.get());
}
bool BackgroundSyncInProgress() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex());

//! The tip of the background sync chain
const CBlockIndex* GetBackgroundSyncTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) {
Expand Down

0 comments on commit 45dd943

Please sign in to comment.