loadtxoutset shrinks the active chainstate's UTXO caches to 1% before opening the snapshot database, but installs its cleanup afterward. If opening throws (as when chainstate_snapshot is a file), the RPC fails and the caches stay at 1% until a later load succeeds, the node leaves IBD, or it restarts.
<details> <summary>Reproducer</summary>
diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp
index e150f317f4b..d18c15feea8 100644
--- a/src/test/validation_chainstatemanager_tests.cpp
+++ b/src/test/validation_chainstatemanager_tests.cpp
@@ -4,6 +4,7 @@
//
#include <chainparams.h>
#include <consensus/validation.h>
+#include <dbwrapper.h>
#include <kernel/disconnected_transactions.h>
#include <node/block_template_manager.h>
#include <node/chainstatemanager_args.h>
@@ -278,6 +279,30 @@ struct SnapshotTestSetup : TestChain100Setup {
initial_size += 10;
initial_total_coins += 10;
+ // A database-open exception occurs after ActivateSnapshot has reduced the active cache,
+ // but before its normal failure-cleanup lambda is installed.
+ {
+ Chainstate& active{chainman.ActiveChainstate()};
+ const size_t coinstip_before{active.m_coinstip_cache_size_bytes};
+ const size_t coinsdb_before{active.m_coinsdb_cache_size_bytes};
+ CBlockIndex* tip_before{active.m_chain.Tip()};
+ const fs::path snapshot_dir{chainman.m_options.datadir / "chainstate_snapshot"};
+ {
+ AutoFile blocker{fsbridge::fopen(snapshot_dir, "wb")};
+ BOOST_REQUIRE(!blocker.IsNull());
+ }
+ BOOST_CHECK_THROW(CreateAndActivateUTXOSnapshot(this), fs::filesystem_error);
+ BOOST_CHECK_LT(active.m_coinstip_cache_size_bytes, coinstip_before);
+ BOOST_CHECK_LT(active.m_coinsdb_cache_size_bytes, coinsdb_before);
+
+ // Restore the fixture after proving the exceptional-path state leak.
+ active.m_chain.SetTip(*tip_before);
+ fs::remove(snapshot_dir);
+ WITH_LOCK(::cs_main, chainman.MaybeRebalanceCaches());
+ BOOST_CHECK_EQUAL(active.m_coinstip_cache_size_bytes, coinstip_before);
+ BOOST_CHECK_EQUAL(active.m_coinsdb_cache_size_bytes, coinsdb_before);
+ }
+
// Should not load malleated snapshots
BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot(
this, [](AutoFile& auto_infile, SnapshotMetadata& metadata) {
</details>
The direct fix would be to restore the caches when activation throws, but given that AssumeUTXO fixes haven't attracted much review, I'm proposing to remove AssumeUTXO entirely in #36598 instead (see also #36499 and #36778).