Skip to content

Commit fa75692

Browse files
author
MarcoFalke
committed
rpc: Make gettxoutsetinfo/GetUTXOStats interruptible
Also, add interruption points to scantxoutset
1 parent fa7fc5a commit fa75692

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/node/coinstats.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void ApplyStats(CCoinsStats &stats, CHashWriter& ss, const uint256& hash,
3333
}
3434

3535
//! Calculate statistics about the unspent transaction output set
36-
bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
36+
bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats, const std::function<void()>& interruption_point)
3737
{
3838
stats = CCoinsStats();
3939
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
@@ -49,6 +49,7 @@ bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
4949
uint256 prevkey;
5050
std::map<uint32_t, Coin> outputs;
5151
while (pcursor->Valid()) {
52+
interruption_point();
5253
COutPoint key;
5354
Coin coin;
5455
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {

src/node/coinstats.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <uint256.h>
1111

1212
#include <cstdint>
13+
#include <functional>
1314

1415
class CCoinsView;
1516

@@ -29,6 +30,6 @@ struct CCoinsStats
2930
};
3031

3132
//! Calculate statistics about the unspent transaction output set
32-
bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats);
33+
bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats, const std::function<void()>& interruption_point = {});
3334

3435
#endif // BITCOIN_NODE_COINSTATS_H

src/rpc/blockchain.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
990990
::ChainstateActive().ForceFlushStateToDisk();
991991

992992
CCoinsView* coins_view = WITH_LOCK(cs_main, return &ChainstateActive().CoinsDB());
993-
if (GetUTXOStats(coins_view, stats)) {
993+
if (GetUTXOStats(coins_view, stats, RpcInterruptionPoint)) {
994994
ret.pushKV("height", (int64_t)stats.nHeight);
995995
ret.pushKV("bestblock", stats.hashBlock.GetHex());
996996
ret.pushKV("transactions", (int64_t)stats.nTransactions);
@@ -1968,6 +1968,7 @@ bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>&
19681968
Coin coin;
19691969
if (!cursor->GetKey(key) || !cursor->GetValue(coin)) return false;
19701970
if (++count % 8192 == 0) {
1971+
RpcInterruptionPoint();
19711972
if (should_abort) {
19721973
// allow to abort the scan via the abort reference
19731974
return false;
@@ -2311,7 +2312,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
23112312

23122313
::ChainstateActive().ForceFlushStateToDisk();
23132314

2314-
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats)) {
2315+
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, RpcInterruptionPoint)) {
23152316
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
23162317
}
23172318

0 commit comments

Comments
 (0)