diff --git a/ironfish-cli/src/multisigBroker/clients/client.ts b/ironfish-cli/src/multisigBroker/clients/client.ts index bf4c2dd7b7..750ae2767b 100644 --- a/ironfish-cli/src/multisigBroker/clients/client.ts +++ b/ironfish-cli/src/multisigBroker/clients/client.ts @@ -59,6 +59,7 @@ export abstract class MultisigClient { private tryConnectUntil: number | null = null readonly onConnected = new Event<[]>() + readonly onDisconnected = new Event<[]>() readonly onDkgStatus = new Event<[DkgStatusMessage]>() readonly onSigningStatus = new Event<[SigningStatusMessage]>() readonly onConnectedMessage = new Event<[ConnectedMessage]>() @@ -288,6 +289,8 @@ export abstract class MultisigClient { this.logger.warn('Disconnected from server unexpectedly. Reconnecting.') this.connectTimeout = setTimeout(() => void this.startConnecting(), 5000) } + + this.onDisconnected.emit() } protected onError = (error: unknown): void => { diff --git a/ironfish-cli/src/multisigBroker/sessionManagers/dkgSessionManager.ts b/ironfish-cli/src/multisigBroker/sessionManagers/dkgSessionManager.ts index 008e115c44..83c94bd9cd 100644 --- a/ironfish-cli/src/multisigBroker/sessionManagers/dkgSessionManager.ts +++ b/ironfish-cli/src/multisigBroker/sessionManagers/dkgSessionManager.ts @@ -143,9 +143,11 @@ export class MultisigClientDkgSessionManager identities = message.identities }) - ux.action.start('Waiting for Identities from server') while (identities.length < totalParticipants) { this.client.getDkgStatus() + if (!ux.action.running) { + ux.action.start('Waiting for Identities from server') + } ux.action.status = `${identities.length}/${totalParticipants}` await PromiseUtils.sleep(3000) } @@ -169,9 +171,11 @@ export class MultisigClientDkgSessionManager round1PublicPackages = message.round1PublicPackages }) - ux.action.start('Waiting for Round 1 Public Packages from server') while (round1PublicPackages.length < totalParticipants) { this.client.getDkgStatus() + if (!ux.action.running) { + ux.action.start('Waiting for Round 1 Public Packages from server') + } ux.action.status = `${round1PublicPackages.length}/${totalParticipants}` await PromiseUtils.sleep(3000) } @@ -195,9 +199,11 @@ export class MultisigClientDkgSessionManager round2PublicPackages = message.round2PublicPackages }) - ux.action.start('Waiting for Round 2 Public Packages from server') while (round2PublicPackages.length < totalParticipants) { this.client.getDkgStatus() + if (!ux.action.running) { + ux.action.start('Waiting for Round 2 Public Packages from server') + } ux.action.status = `${round2PublicPackages.length}/${totalParticipants}` await PromiseUtils.sleep(3000) } diff --git a/ironfish-cli/src/multisigBroker/sessionManagers/sessionManager.ts b/ironfish-cli/src/multisigBroker/sessionManagers/sessionManager.ts index cf6b3b9f69..4a3c450008 100644 --- a/ironfish-cli/src/multisigBroker/sessionManagers/sessionManager.ts +++ b/ironfish-cli/src/multisigBroker/sessionManagers/sessionManager.ts @@ -58,13 +58,22 @@ export abstract class MultisigClientSessionManager extends MultisigSessionManage return } + this.client.start() + + await this.waitForConnectedMessage() + + this.client.onDisconnected.on(async () => { + await this.waitForConnectedMessage() + await this.waitForJoinedSession() + }) + } + + protected async waitForConnectedMessage(): Promise { let confirmed = false ux.action.start( `Connecting to multisig broker server: ${this.client.hostname}:${this.client.port}`, ) - this.client.start() - this.client.onConnectedMessage.on(() => { confirmed = true }) diff --git a/ironfish-cli/src/multisigBroker/sessionManagers/signingSessionManager.ts b/ironfish-cli/src/multisigBroker/sessionManagers/signingSessionManager.ts index 0add8079ef..8551c45c03 100644 --- a/ironfish-cli/src/multisigBroker/sessionManagers/signingSessionManager.ts +++ b/ironfish-cli/src/multisigBroker/sessionManagers/signingSessionManager.ts @@ -144,9 +144,11 @@ export class MultisigClientSigningSessionManager identities = message.identities }) - ux.action.start('Waiting for Identities from server') while (identities.length < numSigners) { this.client.getSigningStatus() + if (!ux.action.running) { + ux.action.start('Waiting for Identities from server') + } ux.action.status = `${identities.length}/${numSigners}` await PromiseUtils.sleep(3000) } @@ -171,9 +173,11 @@ export class MultisigClientSigningSessionManager signingCommitments = message.signingCommitments }) - ux.action.start('Waiting for Signing Commitments from server') while (signingCommitments.length < numSigners) { this.client.getSigningStatus() + if (!ux.action.running) { + ux.action.start('Waiting for Signing Commitments from server') + } ux.action.status = `${signingCommitments.length}/${numSigners}` await PromiseUtils.sleep(3000) } @@ -198,9 +202,11 @@ export class MultisigClientSigningSessionManager signatureShares = message.signatureShares }) - ux.action.start('Waiting for Signature Shares from server') while (signatureShares.length < numSigners) { this.client.getSigningStatus() + if (!ux.action.running) { + ux.action.start('Waiting for Signature Shares from server') + } ux.action.status = `${signatureShares.length}/${numSigners}` await PromiseUtils.sleep(3000) }