mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-03 20:35:17 +02:00
rpc: take ownership of the file by WriteUTXOSnapshot()
Have `WriteUTXOSnapshot()` take rvalue reference to make it obvious that it takes ownership of the file.
This commit is contained in:
@@ -82,7 +82,7 @@ UniValue WriteUTXOSnapshot(
|
||||
CCoinsViewCursor* pcursor,
|
||||
CCoinsStats* maybe_stats,
|
||||
const CBlockIndex* tip,
|
||||
AutoFile& afile,
|
||||
AutoFile&& afile,
|
||||
const fs::path& path,
|
||||
const fs::path& temppath,
|
||||
const std::function<void()>& interruption_point = {});
|
||||
@@ -3114,7 +3114,14 @@ static RPCHelpMan dumptxoutset()
|
||||
}
|
||||
}
|
||||
|
||||
UniValue result = WriteUTXOSnapshot(*chainstate, cursor.get(), &stats, tip, afile, path, temppath, node.rpc_interruption_point);
|
||||
UniValue result = WriteUTXOSnapshot(*chainstate,
|
||||
cursor.get(),
|
||||
&stats,
|
||||
tip,
|
||||
std::move(afile),
|
||||
path,
|
||||
temppath,
|
||||
node.rpc_interruption_point);
|
||||
fs::rename(temppath, path);
|
||||
|
||||
result.pushKV("path", path.utf8string());
|
||||
@@ -3166,7 +3173,7 @@ UniValue WriteUTXOSnapshot(
|
||||
CCoinsViewCursor* pcursor,
|
||||
CCoinsStats* maybe_stats,
|
||||
const CBlockIndex* tip,
|
||||
AutoFile& afile,
|
||||
AutoFile&& afile,
|
||||
const fs::path& path,
|
||||
const fs::path& temppath,
|
||||
const std::function<void()>& interruption_point)
|
||||
@@ -3240,12 +3247,19 @@ UniValue WriteUTXOSnapshot(
|
||||
UniValue CreateUTXOSnapshot(
|
||||
node::NodeContext& node,
|
||||
Chainstate& chainstate,
|
||||
AutoFile& afile,
|
||||
AutoFile&& afile,
|
||||
const fs::path& path,
|
||||
const fs::path& tmppath)
|
||||
{
|
||||
auto [cursor, stats, tip]{WITH_LOCK(::cs_main, return PrepareUTXOSnapshot(chainstate, node.rpc_interruption_point))};
|
||||
return WriteUTXOSnapshot(chainstate, cursor.get(), &stats, tip, afile, path, tmppath, node.rpc_interruption_point);
|
||||
return WriteUTXOSnapshot(chainstate,
|
||||
cursor.get(),
|
||||
&stats,
|
||||
tip,
|
||||
std::move(afile),
|
||||
path,
|
||||
tmppath,
|
||||
node.rpc_interruption_point);
|
||||
}
|
||||
|
||||
static RPCHelpMan loadtxoutset()
|
||||
|
||||
@@ -51,7 +51,7 @@ void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES],
|
||||
UniValue CreateUTXOSnapshot(
|
||||
node::NodeContext& node,
|
||||
Chainstate& chainstate,
|
||||
AutoFile& afile,
|
||||
AutoFile&& afile,
|
||||
const fs::path& path,
|
||||
const fs::path& tmppath);
|
||||
|
||||
|
||||
@@ -47,8 +47,11 @@ CreateAndActivateUTXOSnapshot(
|
||||
FILE* outfile{fsbridge::fopen(snapshot_path, "wb")};
|
||||
AutoFile auto_outfile{outfile};
|
||||
|
||||
UniValue result = CreateUTXOSnapshot(
|
||||
node, node.chainman->ActiveChainstate(), auto_outfile, snapshot_path, snapshot_path);
|
||||
UniValue result = CreateUTXOSnapshot(node,
|
||||
node.chainman->ActiveChainstate(),
|
||||
std::move(auto_outfile), // Will close auto_outfile.
|
||||
snapshot_path,
|
||||
snapshot_path);
|
||||
LogPrintf(
|
||||
"Wrote UTXO snapshot to %s: %s\n", fs::PathToString(snapshot_path.make_preferred()), result.write());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user