mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
Merge bitcoin/bitcoin#30214: refactor: Improve assumeutxo state representation
82be652e40doc: Improve ChainstateManager documentation, use consistent terms (Ryan Ofsky)af455dcb39refactor: Simplify pruning functions (TheCharlatan)ae85c495f1refactor: Delete ChainstateManager::GetAll() method (Ryan Ofsky)6a572dbda9refactor: Add ChainstateManager::ActivateBestChains() method (Ryan Ofsky)491d827d52refactor: Add ChainstateManager::m_chainstates member (Ryan Ofsky)e514fe6116refactor: Delete ChainstateManager::SnapshotBlockhash() method (Ryan Ofsky)ee35250683refactor: Delete ChainstateManager::IsSnapshotValidated() method (Ryan Ofsky)d9e82299fcrefactor: Delete ChainstateManager::IsSnapshotActive() method (Ryan Ofsky)4dfe383912refactor: Convert ChainstateRole enum to struct (Ryan Ofsky)352ad27fc1refactor: Add ChainstateManager::ValidatedChainstate() method (Ryan Ofsky)a229cb9477refactor: Add ChainstateManager::CurrentChainstate() method (Ryan Ofsky)a9b7f5614crefactor: Add Chainstate::StoragePath() method (Ryan Ofsky)840bd2ef23refactor: Pass chainstate parameters to MaybeCompleteSnapshotValidation (Ryan Ofsky)1598a15aedrefactor: Deduplicate Chainstate activation code (Ryan Ofsky)9fe927b6d6refactor: Add Chainstate m_assumeutxo and m_target_utxohash members (Ryan Ofsky)6082c84713refactor: Add Chainstate::m_target_blockhash member (Ryan Ofsky)de00e87548test: Fix broken chainstatemanager_snapshot_init check (Ryan Ofsky) Pull request description: This PR contains the first part of #28608, which tries to make assumeutxo code more maintainable, and improve it by not locking `cs_main` for a long time when the snapshot block is connected, and by deleting the snapshot validation chainstate when it is no longer used, instead of waiting until the next restart. The changes in this PR are just refactoring. They make `Chainstate` objects self-contained, so for example, it is possible to determine what blocks to connect to a chainstate without querying `ChainstateManager`, and to determine whether a Chainstate is validated without basing it on inferences like `&cs != &ActiveChainstate()` or `GetAll().size() == 1`. The PR also tries to make assumeutxo terminology less confusing, using "current chainstate" to refer to the chainstate targeting the current network tip, and "historical chainstate" to refer to the chainstate downloading old blocks and validating the assumeutxo snapshot. It removes uses of the terms "active chainstate," "usable chainstate," "disabled chainstate," "ibd chainstate," and "snapshot chainstate" which are confusing for various reasons. ACKs for top commit: maflcko: re-review ACK82be652e40🕍 fjahr: re-ACK82be652e40sedited: Re-ACK82be652e40Tree-SHA512: 81c67abba9fc5bb170e32b7bf8a1e4f7b5592315b4ef720be916d5f1f5a7088c0c59cfb697744dd385552f58aa31ee36176bae6a6e465723e65861089a1252e5
This commit is contained in:
10
src/init.cpp
10
src/init.cpp
@@ -345,7 +345,7 @@ void Shutdown(NodeContext& node)
|
||||
// FlushStateToDisk generates a ChainStateFlushed callback, which we should avoid missing
|
||||
if (node.chainman) {
|
||||
LOCK(cs_main);
|
||||
for (Chainstate* chainstate : node.chainman->GetAll()) {
|
||||
for (const auto& chainstate : node.chainman->m_chainstates) {
|
||||
if (chainstate->CanFlushToDisk()) {
|
||||
chainstate->ForceFlushStateToDisk();
|
||||
}
|
||||
@@ -371,7 +371,7 @@ void Shutdown(NodeContext& node)
|
||||
|
||||
if (node.chainman) {
|
||||
LOCK(cs_main);
|
||||
for (Chainstate* chainstate : node.chainman->GetAll()) {
|
||||
for (const auto& chainstate : node.chainman->m_chainstates) {
|
||||
if (chainstate->CanFlushToDisk()) {
|
||||
chainstate->ForceFlushStateToDisk();
|
||||
chainstate->ResetCoinsViews();
|
||||
@@ -1877,14 +1877,14 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
if (chainman.m_blockman.IsPruneMode()) {
|
||||
if (chainman.m_blockman.m_blockfiles_indexed) {
|
||||
LOCK(cs_main);
|
||||
for (Chainstate* chainstate : chainman.GetAll()) {
|
||||
for (const auto& chainstate : chainman.m_chainstates) {
|
||||
uiInterface.InitMessage(_("Pruning blockstore…"));
|
||||
chainstate->PruneAndFlush();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Prior to setting NODE_NETWORK, check if we can provide historical blocks.
|
||||
if (!WITH_LOCK(chainman.GetMutex(), return chainman.BackgroundSyncInProgress())) {
|
||||
if (!WITH_LOCK(chainman.GetMutex(), return chainman.HistoricalChainstate())) {
|
||||
LogInfo("Setting NODE_NETWORK in non-prune mode");
|
||||
g_local_services = ServiceFlags(g_local_services | NODE_NETWORK);
|
||||
} else {
|
||||
@@ -2233,7 +2233,7 @@ bool StartIndexBackgroundSync(NodeContext& node)
|
||||
std::optional<const CBlockIndex*> indexes_start_block;
|
||||
std::string older_index_name;
|
||||
ChainstateManager& chainman = *Assert(node.chainman);
|
||||
const Chainstate& chainstate = WITH_LOCK(::cs_main, return chainman.GetChainstateForIndexing());
|
||||
const Chainstate& chainstate = WITH_LOCK(::cs_main, return chainman.ValidatedChainstate());
|
||||
const CChain& index_chain = chainstate.m_chain;
|
||||
|
||||
for (auto index : node.indexes) {
|
||||
|
||||
Reference in New Issue
Block a user