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..a8efeb2eb 100644 --- a/src/app/reconcilers.rs +++ b/src/app/reconcilers.rs @@ -226,12 +226,35 @@ 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. 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: TransientBanner, } impl ConnectionBanner { @@ -239,14 +262,21 @@ impl ConnectionBanner { Self { previous_state: None, handle: 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.track(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(); } + self.quorum_startup_error.reset(); self.previous_state = None; } @@ -263,6 +293,8 @@ impl ConnectionBanner { onboarding_active: bool, ) -> Option { let connection_status = app_context.connection_status(); + 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); @@ -361,6 +393,8 @@ impl ConnectionBanner { pub(super) struct MigrationReconciler { /// Handle to the current migration banner, if displayed. banner_handle: 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. @@ -379,6 +413,7 @@ impl MigrationReconciler { pub(super) fn new() -> Self { Self { banner_handle: None, + storage_startup_error: TransientBanner::default(), last_state: None, dispatched: BTreeSet::new(), backend_wait_since: BTreeMap::new(), @@ -388,6 +423,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.track(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 +435,7 @@ impl MigrationReconciler { if let Some(handle) = self.banner_handle.take() { handle.clear(); } + self.storage_startup_error.reset(); self.last_state = None; self.wallet_unlock_popup.close(); self.prompt_wallet = None; @@ -487,6 +528,13 @@ impl MigrationReconciler { frame_state: &MigrationState, ) { let state = frame_state.clone(); + let storage_guard_resolved = !matches!( + &state, + MigrationState::Idle + | MigrationState::Running { .. } + | MigrationState::AwaitingWalletPasswords { .. } + ) && 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; @@ -932,6 +980,79 @@ 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_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(); + 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()); + + 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 is ready and unlocked", + ); + } + #[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..a53f999ce 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,16 @@ 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( + 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 +3631,24 @@ 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(sdk_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..8265e0e89 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 @@ -138,8 +142,9 @@ 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 yet synced (quorums unavailable)".to_string(), + MASTERNODE_LIST_NOT_READY_DETAIL.to_string(), )); }