0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-05 14:06:27 -05:00

refactor: Manage dumptxoutset RAII classes with std::optional

Also removes unused UniValue error variable.
This commit is contained in:
Fabian Jahr 2024-09-05 10:30:13 +02:00
parent 4b5bf335ad
commit c2b779da4e
No known key found for this signature in database
GPG key ID: F13D1E9D890798CD

View file

@ -56,6 +56,7 @@
#include <condition_variable> #include <condition_variable>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <optional>
using kernel::CCoinsStats; using kernel::CCoinsStats;
using kernel::CoinStatsHashType; using kernel::CoinStatsHashType;
@ -2786,8 +2787,8 @@ static RPCHelpMan dumptxoutset()
CConnman& connman = EnsureConnman(node); CConnman& connman = EnsureConnman(node);
const CBlockIndex* invalidate_index{nullptr}; const CBlockIndex* invalidate_index{nullptr};
std::unique_ptr<NetworkDisable> disable_network; std::optional<NetworkDisable> disable_network;
std::unique_ptr<TemporaryRollback> temporary_rollback; std::optional<TemporaryRollback> temporary_rollback;
// If the user wants to dump the txoutset of the current tip, we don't have // If the user wants to dump the txoutset of the current tip, we don't have
// to roll back at all // to roll back at all
@ -2812,18 +2813,16 @@ static RPCHelpMan dumptxoutset()
// automatically re-enables the network activity at the end of the // automatically re-enables the network activity at the end of the
// process which may not be what the user wants. // process which may not be what the user wants.
if (connman.GetNetworkActive()) { if (connman.GetNetworkActive()) {
disable_network = std::make_unique<NetworkDisable>(connman); disable_network.emplace(connman);
} }
invalidate_index = WITH_LOCK(::cs_main, return node.chainman->ActiveChain().Next(target_index)); invalidate_index = WITH_LOCK(::cs_main, return node.chainman->ActiveChain().Next(target_index));
temporary_rollback = std::make_unique<TemporaryRollback>(*node.chainman, *invalidate_index); temporary_rollback.emplace(*node.chainman, *invalidate_index);
} }
Chainstate* chainstate; Chainstate* chainstate;
std::unique_ptr<CCoinsViewCursor> cursor; std::unique_ptr<CCoinsViewCursor> cursor;
CCoinsStats stats; CCoinsStats stats;
UniValue result;
UniValue error;
{ {
// Lock the chainstate before calling PrepareUtxoSnapshot, to be able // Lock the chainstate before calling PrepareUtxoSnapshot, to be able
// to get a UTXO database cursor while the chain is pointing at the // to get a UTXO database cursor while the chain is pointing at the
@ -2847,7 +2846,7 @@ static RPCHelpMan dumptxoutset()
} }
} }
result = WriteUTXOSnapshot(*chainstate, cursor.get(), &stats, tip, afile, path, temppath, node.rpc_interruption_point); UniValue result = WriteUTXOSnapshot(*chainstate, cursor.get(), &stats, tip, 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());