mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
Merge 13397dc78f into merged_master (Bitcoin PR #19056)
This commit is contained in:
commit
cac993d7e9
5 changed files with 18 additions and 9 deletions
|
|
@ -37,7 +37,7 @@ static void ApplyStats(CCoinsStats &stats, CHashWriter& ss, const uint256& hash,
|
|||
}
|
||||
|
||||
//! Calculate statistics about the unspent transaction output set
|
||||
bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
|
||||
bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats, const std::function<void()>& interruption_point)
|
||||
{
|
||||
stats = CCoinsStats();
|
||||
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
|
||||
|
|
@ -53,6 +53,7 @@ bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
|
|||
uint256 prevkey;
|
||||
std::map<uint32_t, Coin> outputs;
|
||||
while (pcursor->Valid()) {
|
||||
interruption_point();
|
||||
COutPoint key;
|
||||
Coin coin;
|
||||
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <uint256.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
class CCoinsView;
|
||||
|
||||
|
|
@ -29,6 +30,6 @@ struct CCoinsStats
|
|||
};
|
||||
|
||||
//! Calculate statistics about the unspent transaction output set
|
||||
bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats);
|
||||
bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats, const std::function<void()>& interruption_point = {});
|
||||
|
||||
#endif // BITCOIN_NODE_COINSTATS_H
|
||||
|
|
|
|||
|
|
@ -1075,7 +1075,7 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
|
|||
::ChainstateActive().ForceFlushStateToDisk();
|
||||
|
||||
CCoinsView* coins_view = WITH_LOCK(cs_main, return &ChainstateActive().CoinsDB());
|
||||
if (GetUTXOStats(coins_view, stats)) {
|
||||
if (GetUTXOStats(coins_view, stats, RpcInterruptionPoint)) {
|
||||
ret.pushKV("height", (int64_t)stats.nHeight);
|
||||
ret.pushKV("bestblock", stats.hashBlock.GetHex());
|
||||
ret.pushKV("transactions", (int64_t)stats.nTransactions);
|
||||
|
|
@ -2134,6 +2134,7 @@ bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>&
|
|||
Coin coin;
|
||||
if (!cursor->GetKey(key) || !cursor->GetValue(coin)) return false;
|
||||
if (++count % 8192 == 0) {
|
||||
RpcInterruptionPoint();
|
||||
if (should_abort) {
|
||||
// allow to abort the scan via the abort reference
|
||||
return false;
|
||||
|
|
@ -2580,7 +2581,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
|
|||
|
||||
::ChainstateActive().ForceFlushStateToDisk();
|
||||
|
||||
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats)) {
|
||||
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, RpcInterruptionPoint)) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
|
||||
}
|
||||
|
||||
|
|
@ -2598,9 +2599,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
|
|||
unsigned int iter{0};
|
||||
|
||||
while (pcursor->Valid()) {
|
||||
if (iter % 5000 == 0 && !IsRPCRunning()) {
|
||||
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
|
||||
}
|
||||
if (iter % 5000 == 0) RpcInterruptionPoint();
|
||||
++iter;
|
||||
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
|
||||
afile << key;
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
#include <util/strencodings.h>
|
||||
#include <util/system.h>
|
||||
|
||||
#include <boost/signals2/signal.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/signals2/signal.hpp>
|
||||
|
||||
#include <memory> // for unique_ptr
|
||||
#include <unordered_map>
|
||||
|
|
@ -309,6 +309,11 @@ bool IsRPCRunning()
|
|||
return g_rpc_running;
|
||||
}
|
||||
|
||||
void RpcInterruptionPoint()
|
||||
{
|
||||
if (!IsRPCRunning()) throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
|
||||
}
|
||||
|
||||
void SetRPCWarmupStatus(const std::string& newStatus)
|
||||
{
|
||||
LOCK(cs_rpcWarmup);
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@
|
|||
#include <amount.h>
|
||||
#include <rpc/request.h>
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
|
|
@ -29,6 +29,9 @@ namespace RPCServer
|
|||
/** Query whether RPC is running */
|
||||
bool IsRPCRunning();
|
||||
|
||||
/** Throw JSONRPCError if RPC is not running */
|
||||
void RpcInterruptionPoint();
|
||||
|
||||
/**
|
||||
* Set the RPC warmup status. When this is done, all RPC calls will error out
|
||||
* immediately with RPC_IN_WARMUP.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue