Skip to content

Commit a47fbe7

Browse files
fjahrryanofsky
andcommitted
doc: Add and edit some comments around assumeutxo
Co-authored-by: Ryan Ofsky <[email protected]>
1 parent 0a39b8c commit a47fbe7

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

src/net_processing.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,8 @@ void PeerManagerImpl::BlockConnected(
19371937
}
19381938
}
19391939

1940+
// The following task can be skipped since we don't maintain a mempool for
1941+
// the ibd/background chainstate.
19401942
if (role == ChainstateRole::BACKGROUND) {
19411943
return;
19421944
}

src/node/blockstorage.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,10 @@ bool BlockManager::FlushChainstateBlockFile(int tip_height)
761761
{
762762
LOCK(cs_LastBlockFile);
763763
auto& cursor = m_blockfile_cursors[BlockfileTypeForHeight(tip_height)];
764+
// If the cursor does not exist, it means an assumeutxo snapshot is loaded,
765+
// but no blocks past the snapshot height have been written yet, so there
766+
// is no data associated with the chainstate, and it is safe not to flush.
764767
if (cursor) {
765-
// The cursor may not exist after a snapshot has been loaded but before any
766-
// blocks have been downloaded.
767768
return FlushBlockFile(cursor->file_num, /*fFinalize=*/false, /*finalize_undo=*/false);
768769
}
769770
return false;

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
#include <numeric>
6969
#include <optional>
7070
#include <string>
71-
#include <utility>
7271
#include <tuple>
72+
#include <utility>
7373

7474
using kernel::CCoinsStats;
7575
using kernel::CoinStatsHashType;
@@ -5367,7 +5367,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
53675367
// ActivateSnapshot(), but is done so that we avoid doing the long work of staging
53685368
// a snapshot that isn't actually usable.
53695369
if (WITH_LOCK(::cs_main, return !CBlockIndexWorkComparator()(ActiveTip(), snapshot_start_block))) {
5370-
LogPrintf("[snapshot] activation failed - height does not exceed active chainstate\n");
5370+
LogPrintf("[snapshot] activation failed - work does not exceed active chainstate\n");
53715371
return false;
53725372
}
53735373

src/validation.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,10 @@ class ChainstateManager
836836
//! Once this pointer is set to a corresponding chainstate, it will not
837837
//! be reset until init.cpp:Shutdown().
838838
//!
839-
//! This is especially important when, e.g., calling ActivateBestChain()
840-
//! on all chainstates because we are not able to hold ::cs_main going into
841-
//! that call.
839+
//! It is important for the pointer to not be deleted until shutdown,
840+
//! because cs_main is not always held when the pointer is accessed, for
841+
//! example when calling ActivateBestChain, so there's no way you could
842+
//! prevent code from using the pointer while deleting it.
842843
std::unique_ptr<Chainstate> m_ibd_chainstate GUARDED_BY(::cs_main);
843844

844845
//! A chainstate initialized on the basis of a UTXO snapshot. If this is
@@ -847,17 +848,14 @@ class ChainstateManager
847848
//! Once this pointer is set to a corresponding chainstate, it will not
848849
//! be reset until init.cpp:Shutdown().
849850
//!
850-
//! This is especially important when, e.g., calling ActivateBestChain()
851-
//! on all chainstates because we are not able to hold ::cs_main going into
852-
//! that call.
851+
//! It is important for the pointer to not be deleted until shutdown,
852+
//! because cs_main is not always held when the pointer is accessed, for
853+
//! example when calling ActivateBestChain, so there's no way you could
854+
//! prevent code from using the pointer while deleting it.
853855
std::unique_ptr<Chainstate> m_snapshot_chainstate GUARDED_BY(::cs_main);
854856

855857
//! Points to either the ibd or snapshot chainstate; indicates our
856858
//! most-work chain.
857-
//!
858-
//! This is especially important when, e.g., calling ActivateBestChain()
859-
//! on all chainstates because we are not able to hold ::cs_main going into
860-
//! that call.
861859
Chainstate* m_active_chainstate GUARDED_BY(::cs_main) {nullptr};
862860

863861
CBlockIndex* m_best_invalid GUARDED_BY(::cs_main){nullptr};

0 commit comments

Comments
 (0)