Skip to content

Commit

Permalink
refactor: Manage dumptxoutset RAII classes with std::optional
Browse files Browse the repository at this point in the history
Also removes unused UniValue error variable.
  • Loading branch information
fjahr committed Sep 5, 2024
1 parent 4b5bf33 commit c2b779d
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <condition_variable>
#include <memory>
#include <mutex>
#include <optional>

using kernel::CCoinsStats;
using kernel::CoinStatsHashType;
Expand Down Expand Up @@ -2786,8 +2787,8 @@ static RPCHelpMan dumptxoutset()

CConnman& connman = EnsureConnman(node);
const CBlockIndex* invalidate_index{nullptr};
std::unique_ptr<NetworkDisable> disable_network;
std::unique_ptr<TemporaryRollback> temporary_rollback;
std::optional<NetworkDisable> disable_network;
std::optional<TemporaryRollback> temporary_rollback;

// If the user wants to dump the txoutset of the current tip, we don't have
// to roll back at all
Expand All @@ -2812,18 +2813,16 @@ static RPCHelpMan dumptxoutset()
// automatically re-enables the network activity at the end of the
// process which may not be what the user wants.
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));
temporary_rollback = std::make_unique<TemporaryRollback>(*node.chainman, *invalidate_index);
temporary_rollback.emplace(*node.chainman, *invalidate_index);
}

Chainstate* chainstate;
std::unique_ptr<CCoinsViewCursor> cursor;
CCoinsStats stats;
UniValue result;
UniValue error;
{
// Lock the chainstate before calling PrepareUtxoSnapshot, to be able
// to get a UTXO database cursor while the chain is pointing at the
Expand All @@ -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);

result.pushKV("path", path.utf8string());
Expand Down

0 comments on commit c2b779d

Please sign in to comment.