@@ -177,7 +177,11 @@ function mapProviderState(
177177 ? null
178178 : normalizeMiningStateRecord ( localState . state . miningState ) ;
179179
180- if ( existingRuntime ?. currentPhase === "waiting-provider" && existingRuntime . providerState !== null ) {
180+ if (
181+ existingRuntime ?. currentPhase === "waiting-provider"
182+ && existingRuntime . providerState !== null
183+ && ( miningState === null || miningState . state === "idle" )
184+ ) {
181185 return existingRuntime . providerState ;
182186 }
183187
@@ -200,6 +204,15 @@ function mapProviderState(
200204 return "unavailable" ;
201205}
202206
207+ function shouldReuseExistingProviderWait ( options : {
208+ existingRuntime : MiningRuntimeStatusV1 | null ;
209+ miningState : ReturnType < typeof normalizeMiningStateRecord > | null ;
210+ } ) : boolean {
211+ return options . existingRuntime ?. currentPhase === "waiting-provider"
212+ && options . existingRuntime . providerState !== null
213+ && ( options . miningState === null || options . miningState . state === "idle" ) ;
214+ }
215+
203216function mapIndexerDaemonState ( indexer : WalletIndexerStatus ) : MiningRuntimeStatusV1 [ "indexerDaemonState" ] {
204217 if ( indexer . health === "wallet-root-mismatch" ) {
205218 return "wallet-root-mismatch" ;
@@ -329,6 +342,10 @@ async function buildMiningRuntimeSnapshot(options: {
329342 const indexerDaemonState = mapIndexerDaemonState ( options . indexer ) ;
330343 const corePublishState = mapCorePublishState ( options . nodeHealth , options . nodeStatus ) ;
331344 const existing = options . existingRuntime ;
345+ const reuseExistingProviderWait = shouldReuseExistingProviderWait ( {
346+ existingRuntime : existing ,
347+ miningState : state ,
348+ } ) ;
332349
333350 return {
334351 schemaVersion : 1 ,
@@ -396,12 +413,16 @@ async function buildMiningRuntimeSnapshot(options: {
396413 indexerHealth : options . indexer . health ,
397414 tipsAligned : options . tipsAligned ,
398415 lastEventAtUnixMs : options . lastEventAtUnixMs ,
399- lastError : existing ?. lastError ?? options . provider . message ?? options . indexer . message ?? null ,
416+ lastError : reuseExistingProviderWait
417+ ? existing ?. lastError ?? null
418+ : existing ?. currentPhase === "waiting-bitcoin-network" || existing ?. currentPhase === "waiting-indexer"
419+ ? existing ?. lastError ?? options . provider . message ?? options . indexer . message ?? null
420+ : options . provider . message ?? options . indexer . message ?? null ,
400421 note : state ?. pauseReason === "zero-reward"
401422 ? "Mining is disabled because the target block reward is zero."
402423 : existing ?. currentPhase === "resuming"
403424 ? "Mining discarded stale in-flight work after a large local runtime gap and is rechecking health."
404- : existing ?. currentPhase === "waiting-provider"
425+ : reuseExistingProviderWait
405426 ? "Mining is waiting for the sentence provider to recover."
406427 : existing ?. currentPhase === "waiting-indexer"
407428 ? "Mining is waiting for Bitcoin Core and the indexer to align."
0 commit comments