mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-05 20:49:19 +01:00
rpc: various fixups for dumptxoutset
- Actually generate an assumeutxo hash and display it - Add nchaintx to output (necessary for use in chainparams entry) - Add path of serialized UTXO file to output
This commit is contained in:
committed by
James O'Beirne
parent
ab25ef8c7f
commit
ffd09281fe
@@ -15,10 +15,12 @@
|
||||
#include <core_io.h>
|
||||
#include <deploymentinfo.h>
|
||||
#include <deploymentstatus.h>
|
||||
#include <fs.h>
|
||||
#include <hash.h>
|
||||
#include <index/blockfilterindex.h>
|
||||
#include <index/coinstatsindex.h>
|
||||
#include <node/blockstorage.h>
|
||||
#include <logging/timer.h>
|
||||
#include <node/coinstats.h>
|
||||
#include <node/context.h>
|
||||
#include <node/utxo_snapshot.h>
|
||||
@@ -2547,6 +2549,8 @@ static RPCHelpMan dumptxoutset()
|
||||
{RPCResult::Type::STR_HEX, "base_hash", "the hash of the base of the snapshot"},
|
||||
{RPCResult::Type::NUM, "base_height", "the height of the base of the snapshot"},
|
||||
{RPCResult::Type::STR, "path", "the absolute path that the snapshot was written to"},
|
||||
{RPCResult::Type::STR_HEX, "txoutset_hash", "the hash of the UTXO set contents"},
|
||||
{RPCResult::Type::NUM, "nchaintx", "the number of transactions in the chain up to and including the base block"},
|
||||
}
|
||||
},
|
||||
RPCExamples{
|
||||
@@ -2569,7 +2573,8 @@ static RPCHelpMan dumptxoutset()
|
||||
FILE* file{fsbridge::fopen(temppath, "wb")};
|
||||
CAutoFile afile{file, SER_DISK, CLIENT_VERSION};
|
||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
UniValue result = CreateUTXOSnapshot(node, node.chainman->ActiveChainstate(), afile);
|
||||
UniValue result = CreateUTXOSnapshot(
|
||||
node, node.chainman->ActiveChainstate(), afile, path, temppath);
|
||||
fs::rename(temppath, path);
|
||||
|
||||
result.pushKV("path", path.u8string());
|
||||
@@ -2578,10 +2583,15 @@ static RPCHelpMan dumptxoutset()
|
||||
};
|
||||
}
|
||||
|
||||
UniValue CreateUTXOSnapshot(NodeContext& node, CChainState& chainstate, CAutoFile& afile)
|
||||
UniValue CreateUTXOSnapshot(
|
||||
NodeContext& node,
|
||||
CChainState& chainstate,
|
||||
CAutoFile& afile,
|
||||
const fs::path& path,
|
||||
const fs::path& temppath)
|
||||
{
|
||||
std::unique_ptr<CCoinsViewCursor> pcursor;
|
||||
CCoinsStats stats{CoinStatsHashType::NONE};
|
||||
CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED};
|
||||
CBlockIndex* tip;
|
||||
|
||||
{
|
||||
@@ -2610,6 +2620,10 @@ UniValue CreateUTXOSnapshot(NodeContext& node, CChainState& chainstate, CAutoFil
|
||||
CHECK_NONFATAL(tip);
|
||||
}
|
||||
|
||||
LOG_TIME_SECONDS(strprintf("writing UTXO snapshot at height %s (%s) to file %s (via %s)",
|
||||
tip->nHeight, tip->GetBlockHash().ToString(),
|
||||
fs::PathToString(path), fs::PathToString(temppath)));
|
||||
|
||||
SnapshotMetadata metadata{tip->GetBlockHash(), stats.coins_count, tip->nChainTx};
|
||||
|
||||
afile << metadata;
|
||||
@@ -2635,7 +2649,11 @@ UniValue CreateUTXOSnapshot(NodeContext& node, CChainState& chainstate, CAutoFil
|
||||
result.pushKV("coins_written", stats.coins_count);
|
||||
result.pushKV("base_hash", tip->GetBlockHash().ToString());
|
||||
result.pushKV("base_height", tip->nHeight);
|
||||
|
||||
result.pushKV("path", path.u8string());
|
||||
result.pushKV("txoutset_hash", stats.hashSerialized.ToString());
|
||||
// Cast required because univalue doesn't have serialization specified for
|
||||
// `unsigned int`, nChainTx's type.
|
||||
result.pushKV("nchaintx", uint64_t{tip->nChainTx});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user