15
15
#include < core_io.h>
16
16
#include < deploymentinfo.h>
17
17
#include < deploymentstatus.h>
18
+ #include < fs.h>
18
19
#include < hash.h>
19
20
#include < index/blockfilterindex.h>
20
21
#include < index/coinstatsindex.h>
21
22
#include < node/blockstorage.h>
23
+ #include < logging/timer.h>
22
24
#include < node/coinstats.h>
23
25
#include < node/context.h>
24
26
#include < node/utxo_snapshot.h>
@@ -2547,6 +2549,8 @@ static RPCHelpMan dumptxoutset()
2547
2549
{RPCResult::Type::STR_HEX, " base_hash" , " the hash of the base of the snapshot" },
2548
2550
{RPCResult::Type::NUM, " base_height" , " the height of the base of the snapshot" },
2549
2551
{RPCResult::Type::STR, " path" , " the absolute path that the snapshot was written to" },
2552
+ {RPCResult::Type::STR_HEX, " txoutset_hash" , " the hash of the UTXO set contents" },
2553
+ {RPCResult::Type::NUM, " nchaintx" , " the number of transactions in the chain up to and including the base block" },
2550
2554
}
2551
2555
},
2552
2556
RPCExamples{
@@ -2569,7 +2573,8 @@ static RPCHelpMan dumptxoutset()
2569
2573
FILE* file{fsbridge::fopen (temppath, " wb" )};
2570
2574
CAutoFile afile{file, SER_DISK, CLIENT_VERSION};
2571
2575
NodeContext& node = EnsureAnyNodeContext (request.context );
2572
- UniValue result = CreateUTXOSnapshot (node, node.chainman ->ActiveChainstate (), afile);
2576
+ UniValue result = CreateUTXOSnapshot (
2577
+ node, node.chainman ->ActiveChainstate (), afile, path, temppath);
2573
2578
fs::rename (temppath, path);
2574
2579
2575
2580
result.pushKV (" path" , path.u8string ());
@@ -2578,10 +2583,15 @@ static RPCHelpMan dumptxoutset()
2578
2583
};
2579
2584
}
2580
2585
2581
- UniValue CreateUTXOSnapshot (NodeContext& node, CChainState& chainstate, CAutoFile& afile)
2586
+ UniValue CreateUTXOSnapshot (
2587
+ NodeContext& node,
2588
+ CChainState& chainstate,
2589
+ CAutoFile& afile,
2590
+ const fs::path& path,
2591
+ const fs::path& temppath)
2582
2592
{
2583
2593
std::unique_ptr<CCoinsViewCursor> pcursor;
2584
- CCoinsStats stats{CoinStatsHashType::NONE };
2594
+ CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED };
2585
2595
CBlockIndex* tip;
2586
2596
2587
2597
{
@@ -2610,6 +2620,10 @@ UniValue CreateUTXOSnapshot(NodeContext& node, CChainState& chainstate, CAutoFil
2610
2620
CHECK_NONFATAL (tip);
2611
2621
}
2612
2622
2623
+ LOG_TIME_SECONDS (strprintf (" writing UTXO snapshot at height %s (%s) to file %s (via %s)" ,
2624
+ tip->nHeight , tip->GetBlockHash ().ToString (),
2625
+ fs::PathToString (path), fs::PathToString (temppath)));
2626
+
2613
2627
SnapshotMetadata metadata{tip->GetBlockHash (), stats.coins_count , tip->nChainTx };
2614
2628
2615
2629
afile << metadata;
@@ -2635,7 +2649,11 @@ UniValue CreateUTXOSnapshot(NodeContext& node, CChainState& chainstate, CAutoFil
2635
2649
result.pushKV (" coins_written" , stats.coins_count );
2636
2650
result.pushKV (" base_hash" , tip->GetBlockHash ().ToString ());
2637
2651
result.pushKV (" base_height" , tip->nHeight );
2638
-
2652
+ result.pushKV (" path" , path.u8string ());
2653
+ result.pushKV (" txoutset_hash" , stats.hashSerialized .ToString ());
2654
+ // Cast required because univalue doesn't have serialization specified for
2655
+ // `unsigned int`, nChainTx's type.
2656
+ result.pushKV (" nchaintx" , uint64_t {tip->nChainTx });
2639
2657
return result;
2640
2658
}
2641
2659
0 commit comments