0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

Merge bitcoin/bitcoin#29262: rpc: Fix race in loadtxoutset

5555d8db33 test: Use blocks_path where possible (MarcoFalke)
fa9108941f 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 https://github.com/bitcoin/bitcoin/pull/27596#discussion_r1344694600

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

Tree-SHA512: 23a82924a915b61bb1adab8ad20ec8914139c8ee647817af34ca27ee310a2e45833d8b285503e0feebe63e4667193d6d98cfcbbc1509bf40712225e04dd19e8b
This commit is contained in:
Ava Chow 2024-01-18 13:05:47 -05:00
commit 5f3a0574c4
No known key found for this signature in database
GPG key ID: 17565732E08E5E41
2 changed files with 3 additions and 5 deletions

View file

@ -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;
},

View file

@ -1021,5 +1021,4 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
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()