Skip to content

Commit 38f4b0d

Browse files
committed
Merge bitcoin#28562: AssumeUTXO follow-ups
5d227a6 rpc: Use Ensure(Any)Chainman in assumeutxo related RPCs (Fabian Jahr) 710e5db doc: Drop references to assumevalid in assumeutxo docs (Fabian Jahr) 1ff1c34 test: Rename wait_until_helper to wait_until_helper_internal (Fabian Jahr) a482f86 chain: Rename HaveTxsDownloaded to HaveNumChainTxs (Fabian Jahr) 82e48d2 blockstorage: Let FlushChainstateBlockFile return true in case of missing cursor (Fabian Jahr) 73700fb validation, test: Improve and document nChainTx check for testability (Fabian Jahr) 2c9354f doc: Add snapshot chainstate removal warning to reindexing documentation (Fabian Jahr) 4e915e9 test: Improvements of feature_assumeutxo (Fabian Jahr) a47fbe7 doc: Add and edit some comments around assumeutxo (Fabian Jahr) 0a39b8c validation: remove unused mempool param in DetectSnapshotChainstate (Fabian Jahr) Pull request description: Addressing what I consider to be non- or not-too-controversial comments from bitcoin#27596. Let me know if I missed anything among the many comments that can be easily included here. ACKs for top commit: ryanofsky: Code review ACK 5d227a6. Just suggested doc change and new EnsureChainman RPC cleanup commit since last review. Tree-SHA512: 6f7c762100e18f82946b881676db23e67da7dc3a8bf04e4999a183e90b4f150a0b1202bcb95920ba937a358867bbf2eca300bd84b9b1776c7c490410e707c267
2 parents 1472df6 + 5d227a6 commit 38f4b0d

18 files changed

+73
-73
lines changed

doc/design/assumeutxo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# assumeutxo
22

33
Assumeutxo is a feature that allows fast bootstrapping of a validating bitcoind
4-
instance with a very similar security model to assumevalid.
4+
instance.
55

66
The RPC commands `dumptxoutset` and `loadtxoutset` are used to
77
respectively generate and load UTXO snapshots. The utility script

doc/release-notes-27596.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RPC
1212
`loadtxoutset` has been added, which allows loading a UTXO snapshot of the format
1313
generated by `dumptxoutset`. Once this snapshot is loaded, its contents will be
1414
deserialized into a second chainstate data structure, which is then used to sync to
15-
the network's tip under a security model very much like `assumevalid`.
15+
the network's tip.
1616

1717
Meanwhile, the original chainstate will complete the initial block download process in
1818
the background, eventually validating up to the block that the snapshot is based upon.

src/chain.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,8 @@ class CBlockIndex
280280
* Note that this will be true for the snapshot base block, if one is loaded (and
281281
* all subsequent assumed-valid blocks) since its nChainTx value will have been set
282282
* manually based on the related AssumeutxoData entry.
283-
*
284-
* TODO: potentially change the name of this based on the fact above.
285283
*/
286-
bool HaveTxsDownloaded() const { return nChainTx != 0; }
284+
bool HaveNumChainTxs() const { return nChainTx != 0; }
287285

288286
NodeSeconds Time() const
289287
{

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ void SetupServerArgs(ArgsManager& argsman)
462462
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. "
463463
"Warning: Reverting this setting requires re-downloading the entire blockchain. "
464464
"(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);
465-
argsman.AddArg("-reindex", "Rebuild chain state and block index from the blk*.dat files on disk. This will also rebuild active optional indexes.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
466-
argsman.AddArg("-reindex-chainstate", "Rebuild chain state from the currently indexed blocks. When in pruning mode or if blocks on disk might be corrupted, use full -reindex instead.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
465+
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);
466+
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);
467467
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);
468468
#if HAVE_SYSTEM
469469
argsman.AddArg("-startupnotify=<cmd>", "Execute command on startup.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);

src/kernel/chainparams.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ class CRegTestParams : public CChainParams
495495
{
496496
.height = 110,
497497
.hash_serialized = AssumeutxoHash{uint256S("0x1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618")},
498-
.nChainTx = 110,
498+
.nChainTx = 111,
499499
.blockhash = uint256S("0x696e92821f65549c7ee134edceeeeaaa4105647a3c4fd9f298c0aec0ab50425c")
500500
},
501501
{

src/net_processing.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ void PeerManagerImpl::FindNextBlocks(std::vector<const CBlockIndex*>& vBlocks, c
14481448
return;
14491449
}
14501450
if (pindex->nStatus & BLOCK_HAVE_DATA || (activeChain && activeChain->Contains(pindex))) {
1451-
if (activeChain && pindex->HaveTxsDownloaded())
1451+
if (activeChain && pindex->HaveNumChainTxs())
14521452
state->pindexLastCommonBlock = pindex;
14531453
} else if (!IsBlockRequested(pindex->GetBlockHash())) {
14541454
// The block is not already downloaded, and not yet in flight.
@@ -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
}
@@ -2231,7 +2233,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
22312233
LOCK(cs_main);
22322234
const CBlockIndex* pindex = m_chainman.m_blockman.LookupBlockIndex(inv.hash);
22332235
if (pindex) {
2234-
if (pindex->HaveTxsDownloaded() && !pindex->IsValid(BLOCK_VALID_SCRIPTS) &&
2236+
if (pindex->HaveNumChainTxs() && !pindex->IsValid(BLOCK_VALID_SCRIPTS) &&
22352237
pindex->IsValid(BLOCK_VALID_TREE)) {
22362238
// If we have the block and all of its parents, but have not yet validated it,
22372239
// we might be in the middle of connecting it (ie in the unlock of cs_main

src/node/blockstorage.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,12 +761,14 @@ 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
}
769-
return false;
770+
// No need to log warnings in this case.
771+
return true;
770772
}
771773

772774
uint64_t BlockManager::CalculateCurrentUsage()

src/node/chainstate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
185185
chainman.InitializeChainstate(options.mempool);
186186

187187
// Load a chain created from a UTXO snapshot, if any exist.
188-
bool has_snapshot = chainman.DetectSnapshotChainstate(options.mempool);
188+
bool has_snapshot = chainman.DetectSnapshotChainstate();
189189

190190
if (has_snapshot && (options.reindex || options.reindex_chainstate)) {
191191
LogPrintf("[snapshot] deleting snapshot chainstate due to reindexing\n");

src/rpc/blockchain.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ static RPCHelpMan getchaintips()
14551455
} else if (block->nStatus & BLOCK_FAILED_MASK) {
14561456
// This block or one of its ancestors is invalid.
14571457
status = "invalid";
1458-
} else if (!block->HaveTxsDownloaded()) {
1458+
} else if (!block->HaveNumChainTxs()) {
14591459
// This block cannot be connected because full block data for it or one of its parents is missing.
14601460
status = "headers-only";
14611461
} else if (block->IsValid(BLOCK_VALID_SCRIPTS)) {
@@ -2707,7 +2707,7 @@ static RPCHelpMan loadtxoutset()
27072707
"Load the serialized UTXO set from disk.\n"
27082708
"Once this snapshot is loaded, its contents will be "
27092709
"deserialized into a second chainstate data structure, which is then used to sync to "
2710-
"the network's tip under a security model very much like `assumevalid`. "
2710+
"the network's tip. "
27112711
"Meanwhile, the original chainstate will complete the initial block download process in "
27122712
"the background, eventually validating up to the block that the snapshot is based upon.\n\n"
27132713

@@ -2759,7 +2759,7 @@ static RPCHelpMan loadtxoutset()
27592759
LogPrintf("[snapshot] waiting to see blockheader %s in headers chain before snapshot activation\n",
27602760
base_blockhash.ToString());
27612761

2762-
ChainstateManager& chainman = *node.chainman;
2762+
ChainstateManager& chainman = EnsureChainman(node);
27632763

27642764
while (max_secs_to_wait_for_headers > 0) {
27652765
snapshot_start_block = WITH_LOCK(::cs_main,
@@ -2831,8 +2831,7 @@ return RPCHelpMan{
28312831
LOCK(cs_main);
28322832
UniValue obj(UniValue::VOBJ);
28332833

2834-
NodeContext& node = EnsureAnyNodeContext(request.context);
2835-
ChainstateManager& chainman = *node.chainman;
2834+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
28362835

28372836
auto make_chain_data = [&](const Chainstate& cs, bool validated) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
28382837
AssertLockHeld(::cs_main);

src/test/fuzz/chain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ FUZZ_TARGET(chain)
2929
(void)disk_block_index->GetBlockTimeMax();
3030
(void)disk_block_index->GetMedianTimePast();
3131
(void)disk_block_index->GetUndoPos();
32-
(void)disk_block_index->HaveTxsDownloaded();
32+
(void)disk_block_index->HaveNumChainTxs();
3333
(void)disk_block_index->IsValid();
3434
}
3535

0 commit comments

Comments
 (0)