Skip to content

Commit 314b49b

Browse files
committed
gui: Fix regression in GUI console
This change prevents "Shutting down" message during "dumptxoutset", "gettxoutsetinfo" and "scantxoutset" calls.
1 parent abdfd2d commit 314b49b

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/init.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,14 @@ static bool InitSanityCheck()
775775
return true;
776776
}
777777

778-
static bool AppInitServers(const util::Ref& context)
778+
static bool AppInitServers(const util::Ref& context, NodeContext& node)
779779
{
780780
RPCServer::OnStarted(&OnRPCStarted);
781781
RPCServer::OnStopped(&OnRPCStopped);
782782
if (!InitHTTPServer())
783783
return false;
784784
StartRPC();
785+
node.rpc_interruption_point = RpcInterruptionPoint;
785786
if (!StartHTTPRPC(context))
786787
return false;
787788
if (gArgs.GetBoolArg("-rest", DEFAULT_REST_ENABLE)) StartREST(context);
@@ -1352,7 +1353,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
13521353
if (gArgs.GetBoolArg("-server", false))
13531354
{
13541355
uiInterface.InitMessage_connect(SetRPCWarmupStatus);
1355-
if (!AppInitServers(context))
1356+
if (!AppInitServers(context, node))
13561357
return InitError(_("Unable to start HTTP server. See debug log for details."));
13571358
}
13581359

src/node/context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_NODE_CONTEXT_H
77

88
#include <cassert>
9+
#include <functional>
910
#include <memory>
1011
#include <vector>
1112

@@ -41,6 +42,7 @@ struct NodeContext {
4142
std::unique_ptr<interfaces::Chain> chain;
4243
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
4344
std::unique_ptr<CScheduler> scheduler;
45+
std::function<void()> rpc_interruption_point = [] {};
4446

4547
//! Declare default constructor and destructor that are not inline, so code
4648
//! instantiating the NodeContext struct doesn't need to #include class

src/rpc/blockchain.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,8 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
10041004
const CoinStatsHashType hash_type = ParseHashType(request.params[0], CoinStatsHashType::HASH_SERIALIZED);
10051005

10061006
CCoinsView* coins_view = WITH_LOCK(cs_main, return &ChainstateActive().CoinsDB());
1007-
if (GetUTXOStats(coins_view, stats, hash_type, RpcInterruptionPoint)) {
1007+
NodeContext& node = EnsureNodeContext(request.context);
1008+
if (GetUTXOStats(coins_view, stats, hash_type, node.rpc_interruption_point)) {
10081009
ret.pushKV("height", (int64_t)stats.nHeight);
10091010
ret.pushKV("bestblock", stats.hashBlock.GetHex());
10101011
ret.pushKV("transactions", (int64_t)stats.nTransactions);
@@ -1974,16 +1975,18 @@ static UniValue savemempool(const JSONRPCRequest& request)
19741975
return NullUniValue;
19751976
}
19761977

1978+
namespace {
19771979
//! Search for a given set of pubkey scripts
1978-
bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>& should_abort, int64_t& count, CCoinsViewCursor* cursor, const std::set<CScript>& needles, std::map<COutPoint, Coin>& out_results) {
1980+
bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>& should_abort, int64_t& count, CCoinsViewCursor* cursor, const std::set<CScript>& needles, std::map<COutPoint, Coin>& out_results, std::function<void()>& interruption_point)
1981+
{
19791982
scan_progress = 0;
19801983
count = 0;
19811984
while (cursor->Valid()) {
19821985
COutPoint key;
19831986
Coin coin;
19841987
if (!cursor->GetKey(key) || !cursor->GetValue(coin)) return false;
19851988
if (++count % 8192 == 0) {
1986-
RpcInterruptionPoint();
1989+
interruption_point();
19871990
if (should_abort) {
19881991
// allow to abort the scan via the abort reference
19891992
return false;
@@ -2002,6 +2005,7 @@ bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>&
20022005
scan_progress = 100;
20032006
return true;
20042007
}
2008+
} // namespace
20052009

20062010
/** RAII object to prevent concurrency issue when scanning the txout set */
20072011
static std::atomic<int> g_scan_progress;
@@ -2150,7 +2154,8 @@ UniValue scantxoutset(const JSONRPCRequest& request)
21502154
tip = ::ChainActive().Tip();
21512155
CHECK_NONFATAL(tip);
21522156
}
2153-
bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, pcursor.get(), needles, coins);
2157+
NodeContext& node = EnsureNodeContext(request.context);
2158+
bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, pcursor.get(), needles, coins, node.rpc_interruption_point);
21542159
result.pushKV("success", res);
21552160
result.pushKV("txouts", count);
21562161
result.pushKV("height", tip->nHeight);
@@ -2305,6 +2310,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
23052310
std::unique_ptr<CCoinsViewCursor> pcursor;
23062311
CCoinsStats stats;
23072312
CBlockIndex* tip;
2313+
NodeContext& node = EnsureNodeContext(request.context);
23082314

23092315
{
23102316
// We need to lock cs_main to ensure that the coinsdb isn't written to
@@ -2323,7 +2329,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
23232329

23242330
::ChainstateActive().ForceFlushStateToDisk();
23252331

2326-
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, CoinStatsHashType::NONE, RpcInterruptionPoint)) {
2332+
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, CoinStatsHashType::NONE, node.rpc_interruption_point)) {
23272333
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
23282334
}
23292335

@@ -2341,7 +2347,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
23412347
unsigned int iter{0};
23422348

23432349
while (pcursor->Valid()) {
2344-
if (iter % 5000 == 0) RpcInterruptionPoint();
2350+
if (iter % 5000 == 0) node.rpc_interruption_point();
23452351
++iter;
23462352
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
23472353
afile << key;

0 commit comments

Comments
 (0)