Skip to content

Commit 834ac4c

Browse files
author
MarcoFalke
committed
Merge #19323: gui: Fix regression in *txoutset* in GUI console
314b49b gui: Fix regression in GUI console (Hennadii Stepanov) Pull request description: The regression was introduced in #19056: if the GUI is running without `-server=1`, the `*txoutset*` call in the console returns "Shutting down". Fix #19255. ACKs for top commit: ryanofsky: Code review ACK 314b49b. Only change since last review is rebase Tree-SHA512: 8ff85641a5c249858fecb1ab69c7a1b2850af651ff2a94aa41ce352b5b5bc95bc45c41e1767e871b51e647612d09e4d54ede3e20c313488afef5678826c51b62
2 parents a924f61 + 314b49b commit 834ac4c

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
@@ -774,13 +774,14 @@ static bool InitSanityCheck()
774774
return true;
775775
}
776776

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

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
@@ -1002,7 +1002,8 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
10021002
const CoinStatsHashType hash_type = ParseHashType(request.params[0], CoinStatsHashType::HASH_SERIALIZED);
10031003

10041004
CCoinsView* coins_view = WITH_LOCK(cs_main, return &ChainstateActive().CoinsDB());
1005-
if (GetUTXOStats(coins_view, stats, hash_type, RpcInterruptionPoint)) {
1005+
NodeContext& node = EnsureNodeContext(request.context);
1006+
if (GetUTXOStats(coins_view, stats, hash_type, node.rpc_interruption_point)) {
10061007
ret.pushKV("height", (int64_t)stats.nHeight);
10071008
ret.pushKV("bestblock", stats.hashBlock.GetHex());
10081009
ret.pushKV("transactions", (int64_t)stats.nTransactions);
@@ -1972,16 +1973,18 @@ static UniValue savemempool(const JSONRPCRequest& request)
19721973
return NullUniValue;
19731974
}
19741975

1976+
namespace {
19751977
//! Search for a given set of pubkey scripts
1976-
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) {
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, std::function<void()>& interruption_point)
1979+
{
19771980
scan_progress = 0;
19781981
count = 0;
19791982
while (cursor->Valid()) {
19801983
COutPoint key;
19811984
Coin coin;
19821985
if (!cursor->GetKey(key) || !cursor->GetValue(coin)) return false;
19831986
if (++count % 8192 == 0) {
1984-
RpcInterruptionPoint();
1987+
interruption_point();
19851988
if (should_abort) {
19861989
// allow to abort the scan via the abort reference
19871990
return false;
@@ -2000,6 +2003,7 @@ bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>&
20002003
scan_progress = 100;
20012004
return true;
20022005
}
2006+
} // namespace
20032007

20042008
/** RAII object to prevent concurrency issue when scanning the txout set */
20052009
static std::atomic<int> g_scan_progress;
@@ -2148,7 +2152,8 @@ UniValue scantxoutset(const JSONRPCRequest& request)
21482152
tip = ::ChainActive().Tip();
21492153
CHECK_NONFATAL(tip);
21502154
}
2151-
bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, pcursor.get(), needles, coins);
2155+
NodeContext& node = EnsureNodeContext(request.context);
2156+
bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, pcursor.get(), needles, coins, node.rpc_interruption_point);
21522157
result.pushKV("success", res);
21532158
result.pushKV("txouts", count);
21542159
result.pushKV("height", tip->nHeight);
@@ -2303,6 +2308,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
23032308
std::unique_ptr<CCoinsViewCursor> pcursor;
23042309
CCoinsStats stats;
23052310
CBlockIndex* tip;
2311+
NodeContext& node = EnsureNodeContext(request.context);
23062312

23072313
{
23082314
// We need to lock cs_main to ensure that the coinsdb isn't written to
@@ -2321,7 +2327,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
23212327

23222328
::ChainstateActive().ForceFlushStateToDisk();
23232329

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

@@ -2339,7 +2345,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
23392345
unsigned int iter{0};
23402346

23412347
while (pcursor->Valid()) {
2342-
if (iter % 5000 == 0) RpcInterruptionPoint();
2348+
if (iter % 5000 == 0) node.rpc_interruption_point();
23432349
++iter;
23442350
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
23452351
afile << key;

0 commit comments

Comments
 (0)