Skip to content

Commit ba90b05

Browse files
committed
Merge bitcoin/bitcoin#29345: rpc: Do not wait for headers inside loadtxoutset
faa30a4 rpc: Do not wait for headers inside loadtxoutset (MarcoFalke) Pull request description: While the `loadtxoutset` default 10 minute timeout is convenient when it is sufficient, it may cause hassle where it is not. For example: * When P2P connections are missing, it seems better to abort early than wait for the timeout. * When the 10 minute timeout is not sufficient, the RPC will have to be called again, so a check or loop is needed outside the RPC either way. So might as well remove the loop inside the RPC. ACKs for top commit: fjahr: ACK faa30a4 theStack: Code-review ACK faa30a4 pablomartin4btc: tACK faa30a4 TheCharlatan: ACK faa30a4 Tree-SHA512: 9167c7d8b2889bb3fd369de4acd2cc4d24a2fe225018d82bd9568ecd737093f6e19be7cc62815b574137b61076a6f773c29bff75398991b5cd702423aab2322b
2 parents d0a9e33 + faa30a4 commit ba90b05

File tree

2 files changed

+7
-27
lines changed

2 files changed

+7
-27
lines changed

contrib/devtools/test_utxo_snapshots.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ echo "-- Initial state of the client:"
183183
client_rpc getchainstates
184184

185185
echo
186-
echo "-- Loading UTXO snapshot into client..."
187-
client_rpc loadtxoutset "$UTXO_DAT_FILE"
186+
echo "-- Loading UTXO snapshot into client. Calling RPC in a loop..."
187+
while ! client_rpc loadtxoutset "$UTXO_DAT_FILE" ; do sleep 10; done
188188

189189
watch -n 0.3 "( tail -n 14 $CLIENT_DATADIR/debug.log ; echo ; ./src/bitcoin-cli -rpcport=$CLIENT_RPC_PORT -datadir=$CLIENT_DATADIR getchainstates) | cat"
190190

src/rpc/blockchain.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,7 +2571,7 @@ static RPCHelpMan dumptxoutset()
25712571
{
25722572
return RPCHelpMan{
25732573
"dumptxoutset",
2574-
"Write the serialized UTXO set to disk.",
2574+
"Write the serialized UTXO set to a file.",
25752575
{
25762576
{"path", RPCArg::Type::STR, RPCArg::Optional::NO, "Path to the output file. If relative, will be prefixed by datadir."},
25772577
},
@@ -2699,7 +2699,7 @@ static RPCHelpMan loadtxoutset()
26992699
{
27002700
return RPCHelpMan{
27012701
"loadtxoutset",
2702-
"Load the serialized UTXO set from disk.\n"
2702+
"Load the serialized UTXO set from a file.\n"
27032703
"Once this snapshot is loaded, its contents will be "
27042704
"deserialized into a second chainstate data structure, which is then used to sync to "
27052705
"the network's tip. "
@@ -2753,34 +2753,14 @@ static RPCHelpMan loadtxoutset()
27532753
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Unable to load UTXO snapshot, "
27542754
"assumeutxo block hash in snapshot metadata not recognized (%s)", base_blockhash.ToString()));
27552755
}
2756-
int max_secs_to_wait_for_headers = 60 * 10;
2757-
CBlockIndex* snapshot_start_block = nullptr;
2758-
2759-
LogPrintf("[snapshot] waiting to see blockheader %s in headers chain before snapshot activation\n",
2760-
base_blockhash.ToString());
2761-
2762-
while (max_secs_to_wait_for_headers > 0) {
2763-
snapshot_start_block = WITH_LOCK(::cs_main,
2756+
CBlockIndex* snapshot_start_block = WITH_LOCK(::cs_main,
27642757
return chainman.m_blockman.LookupBlockIndex(base_blockhash));
2765-
max_secs_to_wait_for_headers -= 1;
2766-
2767-
if (!IsRPCRunning()) {
2768-
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
2769-
}
2770-
2771-
if (!snapshot_start_block) {
2772-
std::this_thread::sleep_for(std::chrono::seconds(1));
2773-
} else {
2774-
break;
2775-
}
2776-
}
27772758

27782759
if (!snapshot_start_block) {
2779-
LogPrintf("[snapshot] timed out waiting for snapshot start blockheader %s\n",
2780-
base_blockhash.ToString());
27812760
throw JSONRPCError(
27822761
RPC_INTERNAL_ERROR,
2783-
"Timed out waiting for base block header to appear in headers chain");
2762+
strprintf("The base block header (%s) must appear in the headers chain. Make sure all headers are syncing, and call this RPC again.",
2763+
base_blockhash.ToString()));
27842764
}
27852765
if (!chainman.ActivateSnapshot(afile, metadata, false)) {
27862766
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to load UTXO snapshot " + fs::PathToString(path));

0 commit comments

Comments
 (0)