Merge 712a2b5453 into merged_master (Bitcoin PR bitcoin/bitcoin#30817)

This commit is contained in:
ivanlele 2026-03-25 12:28:44 +00:00
commit e84e7cc49d
No known key found for this signature in database
2 changed files with 17 additions and 8 deletions

View file

@ -59,6 +59,7 @@
#include <condition_variable>
#include <memory>
#include <mutex>
#include <optional>
using kernel::CCoinsStats;
using kernel::CoinStatsHashType;
@ -3062,8 +3063,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
@ -3088,18 +3089,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
@ -3123,7 +3122,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());

View file

@ -28,7 +28,7 @@ class DumptxoutsetTest(BitcoinTestFramework):
FILENAME = 'txoutset.dat'
out = node.dumptxoutset(FILENAME, "latest")
expected_path = node.datadir_path / self.chain / FILENAME
expected_path = node.chain_path / FILENAME
assert expected_path.is_file()
@ -60,6 +60,16 @@ class DumptxoutsetTest(BitcoinTestFramework):
assert_raises_rpc_error(
-8, 'Invalid snapshot type "bogus" specified. Please specify "rollback" or "latest"', node.dumptxoutset, 'utxos.dat', "bogus")
self.log.info(f"Test that dumptxoutset failure does not leave the network activity suspended")
rev_file = node.blocks_path / "rev00000.dat"
bogus_file = node.blocks_path / "bogus.dat"
rev_file.rename(bogus_file)
assert_raises_rpc_error(
-1, 'Could not roll back to requested height.', node.dumptxoutset, 'utxos.dat', rollback=99)
assert_equal(node.getnetworkinfo()['networkactive'], True)
# Cleanup
bogus_file.rename(rev_file)
if __name__ == '__main__':
DumptxoutsetTest(__file__).main()