diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index dd70c499fd7..241cc367105 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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& 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& 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() diff --git a/src/rpc/blockchain.h b/src/rpc/blockchain.h index b42fe96fd30..0e42bed9479 100644 --- a/src/rpc/blockchain.h +++ b/src/rpc/blockchain.h @@ -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); diff --git a/src/test/util/chainstate.h b/src/test/util/chainstate.h index e604b44c16a..d5100d15b16 100644 --- a/src/test/util/chainstate.h +++ b/src/test/util/chainstate.h @@ -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());