From fa9108941fa1a0e83484114e2d8a99d264c2ad09 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Wed, 17 Jan 2024 16:42:15 +0100 Subject: [PATCH 1/2] rpc: Fix race in loadtxoutset The tip may have advanced, also if it did not, there is no reason to have two variables point to the same block. --- src/rpc/blockchain.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 7d04fb06d5d1a..34d308211b204 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2785,12 +2785,11 @@ static RPCHelpMan loadtxoutset() if (!chainman.ActivateSnapshot(afile, metadata, false)) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to load UTXO snapshot " + fs::PathToString(path)); } - CBlockIndex* new_tip{WITH_LOCK(::cs_main, return chainman.ActiveTip())}; UniValue result(UniValue::VOBJ); result.pushKV("coins_loaded", metadata.m_coins_count); - result.pushKV("tip_hash", new_tip->GetBlockHash().ToString()); - result.pushKV("base_height", new_tip->nHeight); + result.pushKV("tip_hash", snapshot_start_block->GetBlockHash().ToString()); + result.pushKV("base_height", snapshot_start_block->nHeight); result.pushKV("path", fs::PathToString(path)); return result; }, From 5555d8db3313f893609eb0cf549bb597361d4466 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Wed, 17 Jan 2024 16:49:36 +0100 Subject: [PATCH 2/2] test: Use blocks_path where possible --- test/functional/test_framework/test_framework.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 4baf12c3f9d86..d8ae20981da67 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -1021,5 +1021,4 @@ def is_bdb_compiled(self): return self.config["components"].getboolean("USE_BDB") def has_blockfile(self, node, filenum: str): - blocksdir = node.datadir_path / self.chain / 'blocks' - return (blocksdir / f"blk{filenum}.dat").is_file() + return (node.blocks_path/ f"blk{filenum}.dat").is_file()