mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 15:39:05 +01:00
rpc: Make gettxoutsetinfo/GetUTXOStats interruptible
Also, add interruption points to scantxoutset
This commit is contained in:
@@ -33,7 +33,7 @@ static void ApplyStats(CCoinsStats &stats, CHashWriter& ss, const uint256& hash,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Calculate statistics about the unspent transaction output set
|
//! 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();
|
stats = CCoinsStats();
|
||||||
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
|
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
|
||||||
@@ -49,6 +49,7 @@ bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
|
|||||||
uint256 prevkey;
|
uint256 prevkey;
|
||||||
std::map<uint32_t, Coin> outputs;
|
std::map<uint32_t, Coin> outputs;
|
||||||
while (pcursor->Valid()) {
|
while (pcursor->Valid()) {
|
||||||
|
interruption_point();
|
||||||
COutPoint key;
|
COutPoint key;
|
||||||
Coin coin;
|
Coin coin;
|
||||||
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
|
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
class CCoinsView;
|
class CCoinsView;
|
||||||
|
|
||||||
@@ -29,6 +30,6 @@ struct CCoinsStats
|
|||||||
};
|
};
|
||||||
|
|
||||||
//! Calculate statistics about the unspent transaction output set
|
//! 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
|
#endif // BITCOIN_NODE_COINSTATS_H
|
||||||
|
|||||||
@@ -990,7 +990,7 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
|
|||||||
::ChainstateActive().ForceFlushStateToDisk();
|
::ChainstateActive().ForceFlushStateToDisk();
|
||||||
|
|
||||||
CCoinsView* coins_view = WITH_LOCK(cs_main, return &ChainstateActive().CoinsDB());
|
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("height", (int64_t)stats.nHeight);
|
||||||
ret.pushKV("bestblock", stats.hashBlock.GetHex());
|
ret.pushKV("bestblock", stats.hashBlock.GetHex());
|
||||||
ret.pushKV("transactions", (int64_t)stats.nTransactions);
|
ret.pushKV("transactions", (int64_t)stats.nTransactions);
|
||||||
@@ -1968,6 +1968,7 @@ bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>&
|
|||||||
Coin coin;
|
Coin coin;
|
||||||
if (!cursor->GetKey(key) || !cursor->GetValue(coin)) return false;
|
if (!cursor->GetKey(key) || !cursor->GetValue(coin)) return false;
|
||||||
if (++count % 8192 == 0) {
|
if (++count % 8192 == 0) {
|
||||||
|
RpcInterruptionPoint();
|
||||||
if (should_abort) {
|
if (should_abort) {
|
||||||
// allow to abort the scan via the abort reference
|
// allow to abort the scan via the abort reference
|
||||||
return false;
|
return false;
|
||||||
@@ -2311,7 +2312,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
::ChainstateActive().ForceFlushStateToDisk();
|
::ChainstateActive().ForceFlushStateToDisk();
|
||||||
|
|
||||||
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats)) {
|
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, RpcInterruptionPoint)) {
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user