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:
1 parent
52e6e93c3f
commit
a69c4098b2
3 files changed
+25
-8
No files matched your search
+19
-5
@@ -82,7 +82,7 @@ UniValue WriteUTXOSnapshot(
|
|||||||
CCoinsViewCursor* pcursor,
|
CCoinsViewCursor* pcursor,
|
||||||
CCoinsStats* maybe_stats,
|
CCoinsStats* maybe_stats,
|
||||||
const CBlockIndex* tip,
|
const CBlockIndex* tip,
|
||||||
AutoFile& afile,
|
AutoFile&& afile,
|
||||||
const fs::path& path,
|
const fs::path& path,
|
||||||
const fs::path& temppath,
|
const fs::path& temppath,
|
||||||
const std::function<void()>& interruption_point = {});
|
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);
|
fs::rename(temppath, path);
|
||||||
|
|
||||||
result.pushKV("path", path.utf8string());
|
result.pushKV("path", path.utf8string());
|
||||||
@@ -3166,7 +3173,7 @@ UniValue WriteUTXOSnapshot(
|
|||||||
CCoinsViewCursor* pcursor,
|
CCoinsViewCursor* pcursor,
|
||||||
CCoinsStats* maybe_stats,
|
CCoinsStats* maybe_stats,
|
||||||
const CBlockIndex* tip,
|
const CBlockIndex* tip,
|
||||||
AutoFile& afile,
|
AutoFile&& afile,
|
||||||
const fs::path& path,
|
const fs::path& path,
|
||||||
const fs::path& temppath,
|
const fs::path& temppath,
|
||||||
const std::function<void()>& interruption_point)
|
const std::function<void()>& interruption_point)
|
||||||
@@ -3240,12 +3247,19 @@ UniValue WriteUTXOSnapshot(
|
|||||||
UniValue CreateUTXOSnapshot(
|
UniValue CreateUTXOSnapshot(
|
||||||
node::NodeContext& node,
|
node::NodeContext& node,
|
||||||
Chainstate& chainstate,
|
Chainstate& chainstate,
|
||||||
AutoFile& afile,
|
AutoFile&& afile,
|
||||||
const fs::path& path,
|
const fs::path& path,
|
||||||
const fs::path& tmppath)
|
const fs::path& tmppath)
|
||||||
{
|
{
|
||||||
auto [cursor, stats, tip]{WITH_LOCK(::cs_main, return PrepareUTXOSnapshot(chainstate, node.rpc_interruption_point))};
|
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()
|
static RPCHelpMan loadtxoutset()
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES],
|
|||||||
UniValue CreateUTXOSnapshot(
|
UniValue CreateUTXOSnapshot(
|
||||||
node::NodeContext& node,
|
node::NodeContext& node,
|
||||||
Chainstate& chainstate,
|
Chainstate& chainstate,
|
||||||
AutoFile& afile,
|
AutoFile&& afile,
|
||||||
const fs::path& path,
|
const fs::path& path,
|
||||||
const fs::path& tmppath);
|
const fs::path& tmppath);
|
||||||
|
|
||||||
|
|||||||
@@ -47,8 +47,11 @@ CreateAndActivateUTXOSnapshot(
|
|||||||
FILE* outfile{fsbridge::fopen(snapshot_path, "wb")};
|
FILE* outfile{fsbridge::fopen(snapshot_path, "wb")};
|
||||||
AutoFile auto_outfile{outfile};
|
AutoFile auto_outfile{outfile};
|
||||||
|
|
||||||
UniValue result = CreateUTXOSnapshot(
|
UniValue result = CreateUTXOSnapshot(node,
|
||||||
node, node.chainman->ActiveChainstate(), auto_outfile, snapshot_path, snapshot_path);
|
node.chainman->ActiveChainstate(),
|
||||||
|
std::move(auto_outfile), // Will close auto_outfile.
|
||||||
|
snapshot_path,
|
||||||
|
snapshot_path);
|
||||||
LogPrintf(
|
LogPrintf(
|
||||||
"Wrote UTXO snapshot to %s: %s\n", fs::PathToString(snapshot_path.make_preferred()), result.write());
|
"Wrote UTXO snapshot to %s: %s\n", fs::PathToString(snapshot_path.make_preferred()), result.write());
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user