mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-26 00:41:23 +02:00
gui: Fix regression in GUI console
This change prevents "Shutting down" message during "dumptxoutset", "gettxoutsetinfo" and "scantxoutset" calls.
This commit is contained in:
parent
abdfd2d0e3
commit
314b49bd50
@ -775,13 +775,14 @@ static bool InitSanityCheck()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool AppInitServers(const util::Ref& context)
|
static bool AppInitServers(const util::Ref& context, NodeContext& node)
|
||||||
{
|
{
|
||||||
RPCServer::OnStarted(&OnRPCStarted);
|
RPCServer::OnStarted(&OnRPCStarted);
|
||||||
RPCServer::OnStopped(&OnRPCStopped);
|
RPCServer::OnStopped(&OnRPCStopped);
|
||||||
if (!InitHTTPServer())
|
if (!InitHTTPServer())
|
||||||
return false;
|
return false;
|
||||||
StartRPC();
|
StartRPC();
|
||||||
|
node.rpc_interruption_point = RpcInterruptionPoint;
|
||||||
if (!StartHTTPRPC(context))
|
if (!StartHTTPRPC(context))
|
||||||
return false;
|
return false;
|
||||||
if (gArgs.GetBoolArg("-rest", DEFAULT_REST_ENABLE)) StartREST(context);
|
if (gArgs.GetBoolArg("-rest", DEFAULT_REST_ENABLE)) StartREST(context);
|
||||||
@ -1352,7 +1353,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
|
|||||||
if (gArgs.GetBoolArg("-server", false))
|
if (gArgs.GetBoolArg("-server", false))
|
||||||
{
|
{
|
||||||
uiInterface.InitMessage_connect(SetRPCWarmupStatus);
|
uiInterface.InitMessage_connect(SetRPCWarmupStatus);
|
||||||
if (!AppInitServers(context))
|
if (!AppInitServers(context, node))
|
||||||
return InitError(_("Unable to start HTTP server. See debug log for details."));
|
return InitError(_("Unable to start HTTP server. See debug log for details."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#define BITCOIN_NODE_CONTEXT_H
|
#define BITCOIN_NODE_CONTEXT_H
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ struct NodeContext {
|
|||||||
std::unique_ptr<interfaces::Chain> chain;
|
std::unique_ptr<interfaces::Chain> chain;
|
||||||
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
|
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
|
||||||
std::unique_ptr<CScheduler> scheduler;
|
std::unique_ptr<CScheduler> scheduler;
|
||||||
|
std::function<void()> rpc_interruption_point = [] {};
|
||||||
|
|
||||||
//! Declare default constructor and destructor that are not inline, so code
|
//! Declare default constructor and destructor that are not inline, so code
|
||||||
//! instantiating the NodeContext struct doesn't need to #include class
|
//! instantiating the NodeContext struct doesn't need to #include class
|
||||||
|
@ -1004,7 +1004,8 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
|
|||||||
const CoinStatsHashType hash_type = ParseHashType(request.params[0], CoinStatsHashType::HASH_SERIALIZED);
|
const CoinStatsHashType hash_type = ParseHashType(request.params[0], CoinStatsHashType::HASH_SERIALIZED);
|
||||||
|
|
||||||
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, hash_type, RpcInterruptionPoint)) {
|
NodeContext& node = EnsureNodeContext(request.context);
|
||||||
|
if (GetUTXOStats(coins_view, stats, hash_type, node.rpc_interruption_point)) {
|
||||||
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);
|
||||||
@ -1974,8 +1975,10 @@ static UniValue savemempool(const JSONRPCRequest& request)
|
|||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
//! Search for a given set of pubkey scripts
|
//! Search for a given set of pubkey scripts
|
||||||
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) {
|
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)
|
||||||
|
{
|
||||||
scan_progress = 0;
|
scan_progress = 0;
|
||||||
count = 0;
|
count = 0;
|
||||||
while (cursor->Valid()) {
|
while (cursor->Valid()) {
|
||||||
@ -1983,7 +1986,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();
|
interruption_point();
|
||||||
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;
|
||||||
@ -2002,6 +2005,7 @@ bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>&
|
|||||||
scan_progress = 100;
|
scan_progress = 100;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
/** RAII object to prevent concurrency issue when scanning the txout set */
|
/** RAII object to prevent concurrency issue when scanning the txout set */
|
||||||
static std::atomic<int> g_scan_progress;
|
static std::atomic<int> g_scan_progress;
|
||||||
@ -2150,7 +2154,8 @@ UniValue scantxoutset(const JSONRPCRequest& request)
|
|||||||
tip = ::ChainActive().Tip();
|
tip = ::ChainActive().Tip();
|
||||||
CHECK_NONFATAL(tip);
|
CHECK_NONFATAL(tip);
|
||||||
}
|
}
|
||||||
bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, pcursor.get(), needles, coins);
|
NodeContext& node = EnsureNodeContext(request.context);
|
||||||
|
bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, pcursor.get(), needles, coins, node.rpc_interruption_point);
|
||||||
result.pushKV("success", res);
|
result.pushKV("success", res);
|
||||||
result.pushKV("txouts", count);
|
result.pushKV("txouts", count);
|
||||||
result.pushKV("height", tip->nHeight);
|
result.pushKV("height", tip->nHeight);
|
||||||
@ -2305,6 +2310,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
|
|||||||
std::unique_ptr<CCoinsViewCursor> pcursor;
|
std::unique_ptr<CCoinsViewCursor> pcursor;
|
||||||
CCoinsStats stats;
|
CCoinsStats stats;
|
||||||
CBlockIndex* tip;
|
CBlockIndex* tip;
|
||||||
|
NodeContext& node = EnsureNodeContext(request.context);
|
||||||
|
|
||||||
{
|
{
|
||||||
// We need to lock cs_main to ensure that the coinsdb isn't written to
|
// We need to lock cs_main to ensure that the coinsdb isn't written to
|
||||||
@ -2323,7 +2329,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
::ChainstateActive().ForceFlushStateToDisk();
|
::ChainstateActive().ForceFlushStateToDisk();
|
||||||
|
|
||||||
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, CoinStatsHashType::NONE, RpcInterruptionPoint)) {
|
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, CoinStatsHashType::NONE, node.rpc_interruption_point)) {
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2341,7 +2347,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
|
|||||||
unsigned int iter{0};
|
unsigned int iter{0};
|
||||||
|
|
||||||
while (pcursor->Valid()) {
|
while (pcursor->Valid()) {
|
||||||
if (iter % 5000 == 0) RpcInterruptionPoint();
|
if (iter % 5000 == 0) node.rpc_interruption_point();
|
||||||
++iter;
|
++iter;
|
||||||
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
|
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
|
||||||
afile << key;
|
afile << key;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user