fix(startup): surface a "taking too long" notice when the daemon won't come up
F3: the daemon connect loop retried forever with only an animated spinner when the daemon was reachable-but-never-ready (stuck in RPC warmup / -28, or an external daemon that never finishes init) -- no error, no guidance, no escape. It now stamps connect_stall_since_ the moment the daemon first goes "reachable but not ready" (the warmup branch + applyDaemonInitStatus) and clears it on connect / disconnect / warmup-complete. A pure, unit-testable util::connectHasStalled() helper (new util/connect_stall.h, 45s default from ui.toml [screens.loading].stall-timeout-sec) drives a "Taking longer than expected" notice in renderLoadingOverlay(): a title, a reassuring body with elapsed seconds, and a full-node hint to Settings > Restart Daemon or the Console. The background retry keeps running underneath, so the notice self-clears the instant it connects. Guarded off while the daemon is in State::Error (that case is owned by the existing crash-count hint). The overlay is a pure draw-list layer with no interactive widgets, so this follows the existing crash-hint idiom (guidance text, not injected buttons); the stalled state is computed locally in the overlay, so the only new App member is connect_stall_since_. Adds testConnectHasStalled to test_phase4.cpp and three i18n keys to i18n.cpp (English source of truth; the res/lang/*.json back-fill is deferred to a single add_missing_translations.py run at the end of the batch). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
50
src/app.cpp
50
src/app.cpp
@@ -69,6 +69,7 @@
|
||||
#include "ui/widgets/copy_field.h"
|
||||
#include "ui/notifications.h"
|
||||
#include "util/i18n.h"
|
||||
#include "util/connect_stall.h"
|
||||
#include "util/platform.h"
|
||||
#include "util/text_format.h"
|
||||
#include "util/payment_uri.h"
|
||||
@@ -5296,6 +5297,55 @@ void App::renderLoadingOverlay(float contentH)
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// 3d. "Taking longer than expected" notice — the daemon is reachable/launching but
|
||||
// hasn't become ready within the stall threshold. The connect loop keeps retrying
|
||||
// underneath (this notice clears itself the instant it connects); it just stops the
|
||||
// user staring at a silent spinner forever. Guarded off while the daemon is in the
|
||||
// Error state — that case is owned by the crash block (3c) above.
|
||||
// -------------------------------------------------------------------
|
||||
if (connect_stall_since_ > 0.0 &&
|
||||
!(daemon_controller_ &&
|
||||
daemon_controller_->state() == daemon::EmbeddedDaemon::State::Error) &&
|
||||
util::connectHasStalled(connect_stall_since_, ImGui::GetTime(),
|
||||
loadElem("stall-timeout-sec", util::kConnectStallDefaultSeconds))) {
|
||||
curY += gap;
|
||||
ImFont* bodyFont2 = Type().body2();
|
||||
if (!bodyFont2) bodyFont2 = ImGui::GetFont();
|
||||
ImFont* capFont = Type().caption();
|
||||
if (!capFont) capFont = ImGui::GetFont();
|
||||
|
||||
// Title
|
||||
const char* title = TR("loading_stall_title");
|
||||
ImVec2 ts = bodyFont2->CalcTextSizeA(bodyFont2->LegacySize, FLT_MAX, 0.0f, title);
|
||||
dl->AddText(bodyFont2, bodyFont2->LegacySize,
|
||||
ImVec2(wp.x + cx - ts.x * 0.5f, curY),
|
||||
IM_COL32(255, 210, 90, 235), title);
|
||||
curY += ts.y + gap * 0.5f;
|
||||
|
||||
// Body (wrapped) — reassure + show elapsed seconds
|
||||
char stallBody[256];
|
||||
snprintf(stallBody, sizeof(stallBody), TR("loading_stall_body"),
|
||||
(float)(ImGui::GetTime() - connect_stall_since_));
|
||||
float wrapW = ws.x * 0.8f;
|
||||
if (wrapW > 640.0f) wrapW = 640.0f;
|
||||
ImVec2 bs = capFont->CalcTextSizeA(capFont->LegacySize, FLT_MAX, wrapW, stallBody);
|
||||
dl->AddText(capFont, capFont->LegacySize,
|
||||
ImVec2(wp.x + cx - wrapW * 0.5f, curY),
|
||||
IM_COL32(200, 200, 200, 210), stallBody, nullptr, wrapW);
|
||||
curY += bs.y + gap * 0.5f;
|
||||
|
||||
// Actionable guidance (full-node only — lite has no daemon to restart)
|
||||
if (supportsFullNodeLifecycleActions()) {
|
||||
const char* hint = TR("loading_stall_hint");
|
||||
ImVec2 hs = capFont->CalcTextSizeA(capFont->LegacySize, FLT_MAX, 0.0f, hint);
|
||||
dl->AddText(capFont, capFont->LegacySize,
|
||||
ImVec2(wp.x + cx - hs.x * 0.5f, curY),
|
||||
IM_COL32(180, 180, 180, 190), hint);
|
||||
curY += hs.y + gap;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// 4. Daemon output snippet (last few lines, if embedded)
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
@@ -1023,6 +1023,7 @@ private:
|
||||
std::uint64_t clipboard_secret_hash_ = 0;
|
||||
double clipboard_clear_deadline_ = 0.0;
|
||||
float loading_timer_ = 0.0f; // spinner animation for loading overlay
|
||||
double connect_stall_since_ = 0.0; // ImGui::GetTime() when the daemon first went "reachable but not ready"; 0 = not stalling (see util/connect_stall.h)
|
||||
|
||||
// Current page (sidebar navigation)
|
||||
ui::NavPage current_page_ = ui::NavPage::Overview;
|
||||
|
||||
@@ -396,6 +396,7 @@ void App::tryConnect()
|
||||
// fail until warmup completes. Set the warmup state so
|
||||
// the UI shows status instead of a blocking overlay.
|
||||
state_.warming_up = true;
|
||||
if (connect_stall_since_ <= 0.0) connect_stall_since_ = ImGui::GetTime(); // start the "taking too long" clock
|
||||
auto wt = translateWarmup(warmupStatus);
|
||||
state_.warmup_status = wt.title;
|
||||
state_.warmup_description = wt.description;
|
||||
@@ -537,6 +538,7 @@ void App::onConnected()
|
||||
}
|
||||
state_.daemon_initializing = false; // RPC is answering now; clear the "initializing" overlay
|
||||
daemon_wait_attempts_ = 0; // re-arm the port-busy / start-failure notifications
|
||||
connect_stall_since_ = 0.0; // connected — clear the "taking too long" clock
|
||||
daemon_start_error_shown_ = false;
|
||||
daemon_last_seen_crashes_ = 0; // (onConnected resets the daemon's crash count too)
|
||||
connection_status_ = TR("connected");
|
||||
@@ -617,6 +619,7 @@ void App::onDisconnected(const std::string& reason)
|
||||
state_.connected = false;
|
||||
state_.warming_up = false;
|
||||
state_.warmup_status.clear();
|
||||
connect_stall_since_ = 0.0; // reset the "taking too long" clock (App member, untouched by state_.clear())
|
||||
state_.clear();
|
||||
connection_status_ = reason;
|
||||
|
||||
@@ -671,6 +674,7 @@ void App::onDisconnected(const std::string& reason)
|
||||
std::string App::applyDaemonInitStatus(bool reachableButBusy)
|
||||
{
|
||||
state_.daemon_initializing = true;
|
||||
if (connect_stall_since_ <= 0.0) connect_stall_since_ = ImGui::GetTime(); // start the "taking too long" clock
|
||||
|
||||
// Find the most recent console line that names an init phase, so we can tell the user exactly
|
||||
// what the node is doing (loading the block index, verifying, activating best chain, …).
|
||||
@@ -1499,6 +1503,7 @@ void App::refreshCoreData()
|
||||
state_.warming_up = false;
|
||||
state_.warmup_status.clear();
|
||||
state_.warmup_description.clear();
|
||||
connect_stall_since_ = 0.0; // warmup finished — clear the "taking too long" clock
|
||||
connection_status_ = TR("connected");
|
||||
VERBOSE_LOGF("[warmup] Daemon ready, warmup complete\n");
|
||||
|
||||
|
||||
27
src/util/connect_stall.h
Normal file
27
src/util/connect_stall.h
Normal file
@@ -0,0 +1,27 @@
|
||||
// DragonX Wallet - ImGui Edition
|
||||
// Copyright 2024-2026 The Hush Developers
|
||||
// Released under the GPLv3
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace dragonx {
|
||||
namespace util {
|
||||
|
||||
// Default "taking longer than expected" threshold (seconds) for the daemon connect loop,
|
||||
// overridable via ui.toml [screens.loading].stall-timeout-sec. Kept as a free function with
|
||||
// no ImGui/App dependency so it is directly unit-testable from tests/test_phase4.cpp.
|
||||
constexpr float kConnectStallDefaultSeconds = 45.0f;
|
||||
|
||||
// True once a daemon that is reachable-but-not-ready has stayed that way past the threshold.
|
||||
// stallSince : timestamp (same clock as `now`) when the stall began; <= 0 means "not stalling".
|
||||
// now : current time in the same units as stallSince.
|
||||
// thresholdSec: how long to wait before considering it stalled; <= 0 disables the feature.
|
||||
inline bool connectHasStalled(double stallSince, double now, float thresholdSec)
|
||||
{
|
||||
if (stallSince <= 0.0) return false; // not currently in a stall-tracked state
|
||||
if (thresholdSec <= 0.0f) return false; // 0/negative disables the notice defensively
|
||||
return (now - stallSince) >= static_cast<double>(thresholdSec);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace dragonx
|
||||
@@ -1318,6 +1318,9 @@ void I18n::loadBuiltinEnglish()
|
||||
strings_["sb_sapling_not_found"] = "Sapling parameters not found.";
|
||||
strings_["sb_daemon_extract_failed"] = "Failed to write daemon files — check free disk space and permissions.";
|
||||
strings_["sb_daemon_files_failed"] = "Failed to write daemon files to %s — check free disk space and permissions.";
|
||||
strings_["loading_stall_title"] = "Taking longer than expected";
|
||||
strings_["loading_stall_body"] = "The daemon has been initializing for %.0fs. This can be normal after an update or on first launch (loading the block index or rescanning) — it will connect automatically once ready.";
|
||||
strings_["loading_stall_hint"] = "Still stuck? Open Settings and use Restart Daemon, or check the Console for details.";
|
||||
strings_["sb_dragonxd_running"] = "dragonxd running";
|
||||
strings_["sb_dragonxd_stopping"] = "Stopping dragonxd...";
|
||||
strings_["sb_dragonxd_stopped"] = "dragonxd stopped";
|
||||
|
||||
Reference in New Issue
Block a user