Skip to content

Commit

Permalink
Merge bitcoin#29262: rpc: Fix race in loadtxoutset
Browse files Browse the repository at this point in the history
5555d8d test: Use blocks_path where possible (MarcoFalke)
fa91089 rpc: Fix race in loadtxoutset (MarcoFalke)

Pull request description:

  The tip may have advanced, also if it did not, there is no reason to
  have two variables point to the same block.

  Fixes bitcoin#27596 (comment)

ACKs for top commit:
  achow101:
    ACK 5555d8d
  pablomartin4btc:
    ACK 5555d8d
  BrandonOdiwuor:
    Code Review ACK 5555d8d

Tree-SHA512: 23a82924a915b61bb1adab8ad20ec8914139c8ee647817af34ca27ee310a2e45833d8b285503e0feebe63e4667193d6d98cfcbbc1509bf40712225e04dd19e8b
  • Loading branch information
achow101 committed Jan 18, 2024
2 parents ac3901e + 5555d8d commit 5f3a057
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
3 changes: 1 addition & 2 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 5f3a057

Please sign in to comment.