fix(daemon): reset the console offset to the watermark on restart
When the daemon was restarted, the output-parse offset was reset to 0. The daemon's output buffer is retained across runs, so the next poll re-read the whole retained tail of the previous run and fed it to the busy tracker as if it were fresh. A witness rebuild or rescan line left over from the old run could then be mistaken for activity in the new one. - On restart the offset is now reset to the absolute end of the output at that moment, captured on the lifecycle thread after the stop and before the start, so the UI resumes parsing only the new run's output rather than replaying the old tail. - The capture is handed to the UI thread through a pending flag and applied there before the next read, both on the normal poll and when skipping the backlog, so the offset is only ever moved on the thread that owns it. Tests cover reading from the captured watermark (only the new run is seen) versus the old reset-to-0 behaviour (the previous run replays). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+12
-1
@@ -333,7 +333,10 @@ public:
|
||||
bool startDaemon() override { return app_.startEmbeddedDaemon(); }
|
||||
void resetOutputOffset() override
|
||||
{
|
||||
app_.daemon_output_offset_ = 0;
|
||||
// Capture the absolute end NOW (lifecycle thread, after stop / before start) so the UI resumes
|
||||
// parsing only this run's output, not the retained tail of the previous run.
|
||||
app_.daemon_output_reset_to_.store(app_.daemon_controller_ ? app_.daemon_controller_->outputEnd() : 0);
|
||||
app_.daemon_output_reset_pending_.store(true);
|
||||
app_.resetDaemonBusy();
|
||||
}
|
||||
|
||||
@@ -1280,6 +1283,7 @@ void App::update()
|
||||
|
||||
// Check daemon output for rescan progress (offloaded to worker)
|
||||
if (daemon_controller_ && daemon_controller_->isRunning()) {
|
||||
applyPendingDaemonOutputReset();
|
||||
std::string newOutput = daemon_controller_->outputSince(daemon_output_offset_);
|
||||
if (!newOutput.empty()) {
|
||||
feedDaemonBusy(newOutput); // witness rebuild / startup replay, for the quit guard + stop loop
|
||||
@@ -5741,10 +5745,17 @@ void App::skipDaemonOutputBacklog()
|
||||
if (daemon_controller_ && daemon_controller_->isRunning()) {
|
||||
// Advances daemon_output_offset_ to the end. The busy tracker still sees it: whether the node is
|
||||
// mid-rebuild must not depend on whether the window was minimized while the rebuild started.
|
||||
applyPendingDaemonOutputReset();
|
||||
feedDaemonBusy(daemon_controller_->outputSince(daemon_output_offset_));
|
||||
}
|
||||
}
|
||||
|
||||
void App::applyPendingDaemonOutputReset()
|
||||
{
|
||||
if (daemon_output_reset_pending_.exchange(false))
|
||||
daemon_output_offset_ = daemon_output_reset_to_.load();
|
||||
}
|
||||
|
||||
void App::handlePaymentURI(const std::string& uri)
|
||||
{
|
||||
auto payment = util::parsePaymentURI(uri);
|
||||
|
||||
@@ -569,6 +569,7 @@ public:
|
||||
// output parser skips while the wallet is locked), so a background witness rebuild that started and
|
||||
// finished meanwhile isn't parsed in one batch and mistaken for a completed rescan (spurious toast).
|
||||
void skipDaemonOutputBacklog();
|
||||
void applyPendingDaemonOutputReset();
|
||||
// A real user input event (key, text, mouse, touch, pen, gamepad button) was ingested. Main thread only.
|
||||
// Called from main.cpp's noteEvent; do NOT call from an SDL event watch/filter (resizeWatcher).
|
||||
void noteUserInput() { idle_.noteActivity(); }
|
||||
@@ -1452,6 +1453,8 @@ private:
|
||||
void setDaemonStatus(std::string s);
|
||||
mutable std::string daemon_mem_diag_; // diagnostic info for daemon memory detection
|
||||
size_t daemon_output_offset_ = 0; // for incremental output parsing (rescan detection)
|
||||
std::atomic<bool> daemon_output_reset_pending_{false}; // lifecycle thread -> UI thread
|
||||
std::atomic<size_t> daemon_output_reset_to_{0};
|
||||
// What the node's own output says it is doing (witness rebuild / startup replay). Fed on the UI thread
|
||||
// from the captured output; node_rebuilding_ is its snapshot for the shutdown thread's stop loop.
|
||||
daemon::DaemonBusyTracker daemon_busy_;
|
||||
|
||||
@@ -109,6 +109,8 @@ std::vector<std::string> DaemonController::recentLines(std::size_t count) const
|
||||
return daemon_ ? daemon_->getRecentLines(count) : std::vector<std::string>{};
|
||||
}
|
||||
|
||||
std::size_t DaemonController::outputEnd() const { return daemon_ ? daemon_->getOutputEnd() : 0; }
|
||||
|
||||
std::string DaemonController::outputSince(std::size_t& offset) const
|
||||
{
|
||||
return daemon_ ? daemon_->getOutputSince(offset) : std::string{};
|
||||
|
||||
@@ -110,6 +110,7 @@ public:
|
||||
std::function<double()> memoryProbe() const; // EmbeddedDaemon::memoryProbe(); empty without a daemon
|
||||
std::vector<std::string> recentLines(std::size_t count) const;
|
||||
std::string outputSince(std::size_t& offset) const;
|
||||
std::size_t outputEnd() const;
|
||||
|
||||
void resetCrashCount();
|
||||
void setRescanOnNextStart(bool enabled);
|
||||
|
||||
@@ -176,6 +176,12 @@ public:
|
||||
return outputWindowSince(buffer, total, offset);
|
||||
}
|
||||
|
||||
/** Absolute end of everything ever appended (a valid getOutputSince() offset). */
|
||||
size_t getOutputEnd() const {
|
||||
std::lock_guard<std::mutex> lk(output_mutex_);
|
||||
return output_total_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get current output size (thread-safe, no copy)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user