From 9ac720a8c90036e79bc5fc6d86a45bf1de042edf Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Tue, 21 Jul 2026 09:03:53 +0000 Subject: [PATCH 1/2] fix(ui): clear startup transient banners when ready MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Transfer startup-only error banner handles to the connection and migration reconcilers so readiness transitions clear them reactively. 🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent Co-Authored-By: Codex GPT-5 --- src/app.rs | 9 ++++ src/app/reconcilers.rs | 97 +++++++++++++++++++++++++++++++++++++++ src/backend_task/error.rs | 36 +++++++++++++++ src/context_provider.rs | 6 ++- 4 files changed, 147 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 1e525fbb5..10a33d2d2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2350,6 +2350,15 @@ impl App for AppState { // TaskError Debug output is shown to users, deliberately. // Ensure inner error types don't expose secrets. handle.with_details(&err); + match &err { + TaskError::WalletStorageNotReady => { + self.migration.track_storage_startup_error(handle); + } + TaskError::MasternodeListNotReady { .. } => { + self.connection_banner.track_quorum_startup_error(handle); + } + _ => {} + } if !is_database_clear { self.visible_screen_mut() .display_message(&msg, MessageType::Error); diff --git a/src/app/reconcilers.rs b/src/app/reconcilers.rs index 7ac9cf39c..ca6444a2a 100644 --- a/src/app/reconcilers.rs +++ b/src/app/reconcilers.rs @@ -232,6 +232,8 @@ pub(super) struct ConnectionBanner { previous_state: Option, /// Handle to the current connection banner, if displayed. handle: Option, + /// Startup proof error cleared once quorum keys become available. + quorum_startup_error: Option, } impl ConnectionBanner { @@ -239,14 +241,23 @@ impl ConnectionBanner { Self { previous_state: None, handle: None, + quorum_startup_error: None, } } + /// Adopt a quorum-not-ready error banner from the generic task fallback. + pub(super) fn track_quorum_startup_error(&mut self, handle: BannerHandle) { + self.quorum_startup_error = Some(handle); + } + /// Clear the banner and force re-evaluation next frame (network switch). pub(super) fn reset(&mut self) { if let Some(handle) = self.handle.take() { handle.clear(); } + if let Some(handle) = self.quorum_startup_error.take() { + handle.clear(); + } self.previous_state = None; } @@ -263,6 +274,11 @@ impl ConnectionBanner { onboarding_active: bool, ) -> Option { let connection_status = app_context.connection_status(); + if connection_status.masternodes_ready() + && let Some(handle) = self.quorum_startup_error.take() + { + handle.clear(); + } let current_state = connection_status.overall_state(); let state_changed = self.previous_state != Some(current_state); @@ -361,6 +377,8 @@ impl ConnectionBanner { pub(super) struct MigrationReconciler { /// Handle to the current migration banner, if displayed. banner_handle: Option, + /// Wallet-storage guard error cleared when migration leaves progress state. + storage_startup_error: Option, /// Last-seen migration state so reconciliation fires only on change. last_state: Option, /// Networks whose cold-start `FinishUnwire` has been dispatched this process. @@ -379,6 +397,7 @@ impl MigrationReconciler { pub(super) fn new() -> Self { Self { banner_handle: None, + storage_startup_error: None, last_state: None, dispatched: BTreeSet::new(), backend_wait_since: BTreeMap::new(), @@ -388,6 +407,11 @@ impl MigrationReconciler { } } + /// Adopt a storage-not-ready error banner from the generic task fallback. + pub(super) fn track_storage_startup_error(&mut self, handle: BannerHandle) { + self.storage_startup_error = Some(handle); + } + /// Clear the migration banner and force re-evaluation (network switch). The /// per-network dispatch guard is intentionally NOT reset — it is scoped per /// network so a return to a seen network never re-drains. @@ -395,6 +419,9 @@ impl MigrationReconciler { if let Some(handle) = self.banner_handle.take() { handle.clear(); } + if let Some(handle) = self.storage_startup_error.take() { + handle.clear(); + } self.last_state = None; self.wallet_unlock_popup.close(); self.prompt_wallet = None; @@ -487,6 +514,15 @@ impl MigrationReconciler { frame_state: &MigrationState, ) { let state = frame_state.clone(); + let storage_guard_resolved = !matches!( + &state, + MigrationState::Idle + | MigrationState::Running { .. } + | MigrationState::AwaitingWalletPasswords { .. } + ); + if storage_guard_resolved && let Some(handle) = self.storage_startup_error.take() { + handle.clear(); + } self.update_password_prompt(ctx, app_context, &state); if self.last_state.as_ref() == Some(&state) { return; @@ -932,6 +968,67 @@ mod tests { ); } + #[test] + fn connection_banner_clears_quorum_startup_error_when_masternodes_become_ready() { + let tmp = tempfile::tempdir().expect("tempdir"); + let app_context = test_app_context(tmp.path()); + let message = "The network is still syncing. Please wait a moment and try again."; + let mut reconciler = ConnectionBanner::new(); + let mut harness = Harness::builder() + .with_size(egui::vec2(700.0, 260.0)) + .build_ui(MessageBanner::show_global); + + let handle = MessageBanner::set_global(&harness.ctx, message, MessageType::Error); + handle.disable_auto_dismiss(); + reconciler.track_quorum_startup_error(handle); + reconciler.update(&harness.ctx, &app_context, false, false); + harness.run(); + assert!(harness.query_by_label(message).is_some()); + + app_context.connection_status().set_masternodes_ready(true); + reconciler.update(&harness.ctx, &app_context, false, false); + harness.run(); + assert!( + harness.query_by_label(message).is_none(), + "the startup error must clear when quorum keys become available", + ); + } + + #[test] + fn migration_reconciler_clears_storage_startup_error_when_ready() { + let tmp = tempfile::tempdir().expect("tempdir"); + let app_context = test_app_context(tmp.path()); + let message = TaskError::WalletStorageNotReady.to_string(); + let mut reconciler = MigrationReconciler::new(); + let mut harness = Harness::builder() + .with_size(egui::vec2(700.0, 260.0)) + .build_ui(MessageBanner::show_global); + + app_context + .migration_status() + .set_state(MigrationState::Running { + step: crate::context::migration_status::MigrationStep::Detecting, + }); + let handle = MessageBanner::set_global(&harness.ctx, &message, MessageType::Error); + handle.disable_auto_dismiss(); + reconciler.track_storage_startup_error(handle); + let state = app_context.migration_status().state(); + reconciler.update_banner(&harness.ctx, &app_context, state.as_ref()); + harness.run(); + assert!(harness.query_by_label(&message).is_some()); + + app_context + .migration_status() + .set_state(MigrationState::Ready); + let state = app_context.migration_status().state(); + reconciler.update_banner(&harness.ctx, &app_context, state.as_ref()); + harness.run(); + assert!( + harness.query_by_label(&message).is_none(), + "the startup error must clear when the storage update becomes ready", + ); + } + #[test] fn connection_banner_restores_recurring_error_after_onboarding_suppression() { let tmp = tempfile::tempdir().expect("tempdir"); diff --git a/src/backend_task/error.rs b/src/backend_task/error.rs index c6b2a55c1..f866eb2bb 100644 --- a/src/backend_task/error.rs +++ b/src/backend_task/error.rs @@ -1218,6 +1218,13 @@ pub enum TaskError { source_error: Box, }, + /// Proof verification ran before SPV had synchronized quorum keys. + #[error("The network is still syncing. Please wait a moment and try again.")] + MasternodeListNotReady { + #[source] + source_error: Box, + }, + // ────────────────────────────────────────────────────────────────────────── // Wallet / platform-address operation errors // ────────────────────────────────────────────────────────────────────────── @@ -2732,6 +2739,12 @@ impl From for TaskError { impl From for TaskError { fn from(error: SdkError) -> Self { + if sdk_error_is_masternode_list_not_ready(&error) { + return TaskError::MasternodeListNotReady { + source_error: Box::new(error), + }; + } + // Check DapiClientError for domain errors carried as gRPC Internal status. // The SDK's From decodes `dash-serialized-consensus-error-bin` // metadata, but some platform errors arrive as plain Internal with descriptive @@ -3032,6 +3045,15 @@ impl From for TaskError { } } +fn sdk_error_is_masternode_list_not_ready(error: &SdkError) -> bool { + matches!( + error, + SdkError::Proof(dash_sdk::ProofVerifierError::ContextProviderError( + dash_sdk::error::ContextProviderError::Config(detail) + )) if detail == crate::context_provider::MASTERNODE_LIST_NOT_READY_DETAIL + ) +} + fn sdk_error_is_dapi_reachability_failure(error: &SdkError) -> bool { match error { SdkError::DapiClientError(DapiClientError::Transport(TransportError::Grpc(status))) => { @@ -3608,6 +3630,20 @@ mod tests { ); } + #[test] + fn quorum_startup_error_maps_to_transient_task_error() { + let sdk_error = SdkError::Proof(dash_sdk::ProofVerifierError::ContextProviderError( + dash_sdk::error::ContextProviderError::Config( + crate::context_provider::MASTERNODE_LIST_NOT_READY_DETAIL.to_string(), + ), + )); + + assert!(matches!( + TaskError::from(sdk_error), + TaskError::MasternodeListNotReady { .. } + )); + } + #[test] fn from_sdk_error_broadcast_cause_none_message_duplicate_remains_unconfirmed() { let broadcast_err = dash_sdk::error::StateTransitionBroadcastError { diff --git a/src/context_provider.rs b/src/context_provider.rs index 7389c3a2c..4b200c7e6 100644 --- a/src/context_provider.rs +++ b/src/context_provider.rs @@ -15,6 +15,10 @@ use std::sync::Arc; /// will reject a mismatch, catching forgotten additions at build time. pub(crate) const SYSTEM_CONTRACT_COUNT: usize = 5; +/// Diagnostic carried by the SDK while quorum keys are unavailable at startup. +pub(crate) const MASTERNODE_LIST_NOT_READY_DETAIL: &str = + "masternode list not yet synced (quorums unavailable)"; + /// Resolve a data contract by ID: check cached system contracts first, then DB. /// /// All system contracts are listed in `cached` — adding a new one is a single @@ -139,7 +143,7 @@ impl ContextProvider for SpvProvider { // gracefully instead of triggering the self-ban storm. if !app_ctx.connection_status().masternodes_ready() { return Err(ContextProviderError::Config( - "masternode list not yet synced (quorums unavailable)".to_string(), + MASTERNODE_LIST_NOT_READY_DETAIL.to_string(), )); } From 841b70d98d6d0d4c24594db826b43c1df7431ace Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Tue, 21 Jul 2026 11:47:29 +0000 Subject: [PATCH 2/2] fix: gate storage-banner clear on the real migration_run lock, dedupe reconciler banner tracking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The reactive storage-error banner cleared as soon as MigrationState went terminal, but the detached best-effort DAPI-node refresh can still hold migration_run for a real busy window after that point — a retry in that window failed silently with the banner already gone. Gate the clear on both the terminal state AND a non-blocking migration_run.try_lock() probe. Also extracts the repeated adopt/reset/conditional-clear banner-handle pattern shared by ConnectionBanner and MigrationReconciler into a small TransientBanner newtype, and hardens the SDK error-string sentinel test to pin the literal upstream string shape instead of round-tripping the same constant through itself. Addresses grumpy-review findings CODE-001, CODE-003, PROJ-001. Co-Authored-By: Codex Sol Co-Authored-By: Claude Sonnet 5 --- src/app/reconcilers.rs | 72 ++++++++++++++++++++++++++------------- src/backend_task/error.rs | 11 ++++-- src/context_provider.rs | 1 + 3 files changed, 57 insertions(+), 27 deletions(-) diff --git a/src/app/reconcilers.rs b/src/app/reconcilers.rs index ca6444a2a..a8efeb2eb 100644 --- a/src/app/reconcilers.rs +++ b/src/app/reconcilers.rs @@ -226,6 +226,27 @@ impl SpvBlockReconciler { } } +#[derive(Default)] +struct TransientBanner(Option); + +impl TransientBanner { + fn track(&mut self, handle: BannerHandle) { + self.0 = Some(handle); + } + + fn reset(&mut self) { + if let Some(handle) = self.0.take() { + handle.clear(); + } + } + + fn clear_if(&mut self, condition: bool) { + if condition { + self.reset(); + } + } +} + /// Reconciles the connection-status banner with the overall connection state. pub(super) struct ConnectionBanner { /// Previous state, to detect transitions. `None` forces re-evaluation. @@ -233,7 +254,7 @@ pub(super) struct ConnectionBanner { /// Handle to the current connection banner, if displayed. handle: Option, /// Startup proof error cleared once quorum keys become available. - quorum_startup_error: Option, + quorum_startup_error: TransientBanner, } impl ConnectionBanner { @@ -241,13 +262,13 @@ impl ConnectionBanner { Self { previous_state: None, handle: None, - quorum_startup_error: None, + quorum_startup_error: TransientBanner::default(), } } /// Adopt a quorum-not-ready error banner from the generic task fallback. pub(super) fn track_quorum_startup_error(&mut self, handle: BannerHandle) { - self.quorum_startup_error = Some(handle); + self.quorum_startup_error.track(handle); } /// Clear the banner and force re-evaluation next frame (network switch). @@ -255,9 +276,7 @@ impl ConnectionBanner { if let Some(handle) = self.handle.take() { handle.clear(); } - if let Some(handle) = self.quorum_startup_error.take() { - handle.clear(); - } + self.quorum_startup_error.reset(); self.previous_state = None; } @@ -274,11 +293,8 @@ impl ConnectionBanner { onboarding_active: bool, ) -> Option { let connection_status = app_context.connection_status(); - if connection_status.masternodes_ready() - && let Some(handle) = self.quorum_startup_error.take() - { - handle.clear(); - } + self.quorum_startup_error + .clear_if(connection_status.masternodes_ready()); let current_state = connection_status.overall_state(); let state_changed = self.previous_state != Some(current_state); @@ -377,8 +393,8 @@ impl ConnectionBanner { pub(super) struct MigrationReconciler { /// Handle to the current migration banner, if displayed. banner_handle: Option, - /// Wallet-storage guard error cleared when migration leaves progress state. - storage_startup_error: Option, + /// Wallet-storage error cleared once migration is terminal and its run guard is free. + storage_startup_error: TransientBanner, /// Last-seen migration state so reconciliation fires only on change. last_state: Option, /// Networks whose cold-start `FinishUnwire` has been dispatched this process. @@ -397,7 +413,7 @@ impl MigrationReconciler { pub(super) fn new() -> Self { Self { banner_handle: None, - storage_startup_error: None, + storage_startup_error: TransientBanner::default(), last_state: None, dispatched: BTreeSet::new(), backend_wait_since: BTreeMap::new(), @@ -409,7 +425,7 @@ impl MigrationReconciler { /// Adopt a storage-not-ready error banner from the generic task fallback. pub(super) fn track_storage_startup_error(&mut self, handle: BannerHandle) { - self.storage_startup_error = Some(handle); + self.storage_startup_error.track(handle); } /// Clear the migration banner and force re-evaluation (network switch). The @@ -419,9 +435,7 @@ impl MigrationReconciler { if let Some(handle) = self.banner_handle.take() { handle.clear(); } - if let Some(handle) = self.storage_startup_error.take() { - handle.clear(); - } + self.storage_startup_error.reset(); self.last_state = None; self.wallet_unlock_popup.close(); self.prompt_wallet = None; @@ -519,10 +533,8 @@ impl MigrationReconciler { MigrationState::Idle | MigrationState::Running { .. } | MigrationState::AwaitingWalletPasswords { .. } - ); - if storage_guard_resolved && let Some(handle) = self.storage_startup_error.take() { - handle.clear(); - } + ) && app_context.migration_run.try_lock().is_ok(); + self.storage_startup_error.clear_if(storage_guard_resolved); self.update_password_prompt(ctx, app_context, &state); if self.last_state.as_ref() == Some(&state) { return; @@ -995,7 +1007,7 @@ mod tests { } #[test] - fn migration_reconciler_clears_storage_startup_error_when_ready() { + fn migration_reconciler_waits_for_storage_guard_before_clearing_startup_error() { let tmp = tempfile::tempdir().expect("tempdir"); let app_context = test_app_context(tmp.path()); let message = TaskError::WalletStorageNotReady.to_string(); @@ -1017,15 +1029,27 @@ mod tests { harness.run(); assert!(harness.query_by_label(&message).is_some()); + let migration_guard = app_context + .migration_run + .try_lock() + .expect("migration guard"); app_context .migration_status() .set_state(MigrationState::Ready); let state = app_context.migration_status().state(); reconciler.update_banner(&harness.ctx, &app_context, state.as_ref()); harness.run(); + assert!( + harness.query_by_label(&message).is_some(), + "terminal state must not clear the startup error while storage remains locked", + ); + + drop(migration_guard); + reconciler.update_banner(&harness.ctx, &app_context, state.as_ref()); + harness.run(); assert!( harness.query_by_label(&message).is_none(), - "the startup error must clear when the storage update becomes ready", + "the startup error must clear when the storage update is ready and unlocked", ); } diff --git a/src/backend_task/error.rs b/src/backend_task/error.rs index f866eb2bb..a53f999ce 100644 --- a/src/backend_task/error.rs +++ b/src/backend_task/error.rs @@ -3046,6 +3046,7 @@ impl From for TaskError { } fn sdk_error_is_masternode_list_not_ready(error: &SdkError) -> bool { + // Matches the `SpvProvider::get_quorum_public_key` payload from `context_provider`. matches!( error, SdkError::Proof(dash_sdk::ProofVerifierError::ContextProviderError( @@ -3632,10 +3633,14 @@ mod tests { #[test] fn quorum_startup_error_maps_to_transient_task_error() { + // Recheck this upstream-format contract on every dash-sdk bump. + let sdk_detail = "masternode list not yet synced (quorums unavailable)"; + assert_eq!( + crate::context_provider::MASTERNODE_LIST_NOT_READY_DETAIL, + sdk_detail + ); let sdk_error = SdkError::Proof(dash_sdk::ProofVerifierError::ContextProviderError( - dash_sdk::error::ContextProviderError::Config( - crate::context_provider::MASTERNODE_LIST_NOT_READY_DETAIL.to_string(), - ), + dash_sdk::error::ContextProviderError::Config(sdk_detail.to_string()), )); assert!(matches!( diff --git a/src/context_provider.rs b/src/context_provider.rs index 4b200c7e6..8265e0e89 100644 --- a/src/context_provider.rs +++ b/src/context_provider.rs @@ -142,6 +142,7 @@ impl ContextProvider for SpvProvider { // pre-unlock guard below uses. Any stray early proof call thus degrades // gracefully instead of triggering the self-ban storm. if !app_ctx.connection_status().masternodes_ready() { + // Consumed by `sdk_error_is_masternode_list_not_ready` in `backend_task::error`. return Err(ContextProviderError::Config( MASTERNODE_LIST_NOT_READY_DETAIL.to_string(), ));