mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Merge bitcoin/bitcoin#19521: Coinstats Index
5f96d7d22drpc: gettxoutsetinfo rejects hash_serialized_2 for specific height (Fabian Jahr)23fe50436btest: Add test for coinstatsindex behavior in reorgs (Fabian Jahr)90c966b0f3rpc: Allow gettxoutsetinfo and getblockstats for stale blocks (Fabian Jahr)b9362392aeindex, rpc: Add use_index option for gettxoutsetinfo (Fabian Jahr)bb7788b121test: Test coinstatsindex robustness across restarts (Fabian Jahr)e0938c2909test: Add tests for block_info in gettxoutsetinfo (Fabian Jahr)2501576eccrpc, index: Add verbose amounts tracking to Coinstats index (Fabian Jahr)655d929836test: add coinstatsindex getindexinfo coverage, improve current tests (Jon Atack)ca01bb8d68rpc: Add Coinstats index to getindexinfo (Fabian Jahr)57a026c30ftest: Add unit test for Coinstats index (Fabian Jahr)6a4c0c09abtest: Add functional test for Coinstats index (Fabian Jahr)3f166ecc12rpc: gettxoutsetinfo can be requested for specific blockheights (Fabian Jahr)3c914d58ffindex: Coinstats index can be activated with command line flag (Fabian Jahr)dd58a4de21index: Add Coinstats index (Fabian Jahr)a8a46c4b3crefactor: Simplify ApplyStats and ApplyHash (Fabian Jahr)9c8a265fd2refactor: Pass hash_type to CoinsStats in stats object (Fabian Jahr)2e2648a902crypto: Make MuHash Remove method efficient (Fabian Jahr) Pull request description: This is part of the coinstats index project tracked in #18000 While the review of the new UTXO set hash algorithm (MuHash) takes longer recently #19328 was merged which added the possibility to run `gettxoutsetinfo` with a specific hash type. As the first type it added `hash_type=none` which skips the hashing of the UTXO set altogether. This alone did not make `gettxoutsetinfo` much faster but it allows the use of an index for the remaining coin statistics even before a new hashing algorithm has been added. Credit to Sjors for the idea to take this intermediate step. Features summary: - Users can start their node with the option `-coinstatsindex` which syncs the index in the background - After the index is synced the user can use `gettxoutsetinfo` with `hash_type=none` or `hash_type=muhash` and will get the response instantly out of the index - The user can specify a height or block hash when calling `gettxoutsetinfo` to see coin statistics at a specific block height ACKs for top commit: Sjors: re-tACK5f96d7d22djonatack: Code review re-ACK5f96d7d22dper `git range-diff13d27b407201d3 5f96d7d` promag: Tested ACK5f96d7d22d. Light code review ACK5f96d7d22d. Tree-SHA512: cbca78bee8e9605c19da4fbcd184625fb280200718396c694a56c7daab6f44ad23ca9fb5456d09f245d8b8d9659fdc2b3f3ce5e953c1c6cf4003dbc74c0463c2
This commit is contained in:
20
src/init.cpp
20
src/init.cpp
@@ -21,6 +21,7 @@
|
||||
#include <httprpc.h>
|
||||
#include <httpserver.h>
|
||||
#include <index/blockfilterindex.h>
|
||||
#include <index/coinstatsindex.h>
|
||||
#include <index/txindex.h>
|
||||
#include <init/common.h>
|
||||
#include <interfaces/chain.h>
|
||||
@@ -165,6 +166,9 @@ void Interrupt(NodeContext& node)
|
||||
g_txindex->Interrupt();
|
||||
}
|
||||
ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Interrupt(); });
|
||||
if (g_coin_stats_index) {
|
||||
g_coin_stats_index->Interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
void Shutdown(NodeContext& node)
|
||||
@@ -237,6 +241,10 @@ void Shutdown(NodeContext& node)
|
||||
g_txindex->Stop();
|
||||
g_txindex.reset();
|
||||
}
|
||||
if (g_coin_stats_index) {
|
||||
g_coin_stats_index->Stop();
|
||||
g_coin_stats_index.reset();
|
||||
}
|
||||
ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Stop(); });
|
||||
DestroyAllBlockFilterIndexes();
|
||||
|
||||
@@ -376,6 +384,7 @@ void SetupServerArgs(NodeContext& node)
|
||||
#endif
|
||||
argsman.AddArg("-blockreconstructionextratxn=<n>", strprintf("Extra transactions to keep in memory for compact block reconstructions (default: %u)", DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-blocksonly", strprintf("Whether to reject transactions from network peers. Automatic broadcast and rebroadcast of any transactions from inbound peers is disabled, unless the peer has the 'forcerelay' permission. RPC transactions are not affected. (default: %u)", DEFAULT_BLOCKSONLY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-coinstatsindex", strprintf("Maintain coinstats index used by the gettxoutset RPC (default: %u)", DEFAULT_COINSTATSINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-conf=<file>", strprintf("Specify path to read-only configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
|
||||
@@ -391,7 +400,7 @@ void SetupServerArgs(NodeContext& node)
|
||||
-GetNumCores(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-persistmempool", strprintf("Whether to save the mempool on shutdown and load on restart (default: %u)", DEFAULT_PERSIST_MEMPOOL), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-pid=<file>", strprintf("Specify pid file. Relative paths will be prefixed by a net-specific datadir location. (default: %s)", BITCOIN_PID_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-prune=<n>", strprintf("Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks, and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex and -rescan. "
|
||||
argsman.AddArg("-prune=<n>", strprintf("Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks, and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex, -coinstatsindex and -rescan. "
|
||||
"Warning: Reverting this setting requires re-downloading the entire blockchain. "
|
||||
"(default: 0 = disable pruning blocks, 1 = allow manual pruning via RPC, >=%u = automatically prune block files to stay under the specified target size in MiB)", MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-reindex", "Rebuild chain state and block index from the blk*.dat files on disk", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
@@ -876,10 +885,12 @@ bool AppInitParameterInteraction(const ArgsManager& args)
|
||||
nLocalServices = ServiceFlags(nLocalServices | NODE_COMPACT_FILTERS);
|
||||
}
|
||||
|
||||
// if using block pruning, then disallow txindex
|
||||
// if using block pruning, then disallow txindex and coinstatsindex
|
||||
if (args.GetArg("-prune", 0)) {
|
||||
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX))
|
||||
return InitError(_("Prune mode is incompatible with -txindex."));
|
||||
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX))
|
||||
return InitError(_("Prune mode is incompatible with -coinstatsindex."));
|
||||
}
|
||||
|
||||
// -bind and -whitebind can't be set when not listening
|
||||
@@ -1587,6 +1598,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
GetBlockFilterIndex(filter_type)->Start();
|
||||
}
|
||||
|
||||
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {
|
||||
g_coin_stats_index = std::make_unique<CoinStatsIndex>(/* cache size */ 0, false, fReindex);
|
||||
g_coin_stats_index->Start();
|
||||
}
|
||||
|
||||
// ********************************************************* Step 9: load wallet
|
||||
for (const auto& client : node.chain_clients) {
|
||||
if (!client->load()) {
|
||||
|
||||
Reference in New Issue
Block a user