diff --git a/packages/sdk/src/protocols/base_protocol.ts b/packages/sdk/src/protocols/base_protocol.ts index 7101a1789f..f7b79241f6 100644 --- a/packages/sdk/src/protocols/base_protocol.ts +++ b/packages/sdk/src/protocols/base_protocol.ts @@ -100,28 +100,19 @@ export class BaseProtocolSDK implements IBaseProtocolSDK { `Checking for peers. forceUseAllPeers: ${forceUseAllPeers}, maxAttempts: ${maxAttempts}` ); - if (!forceUseAllPeers && this.connectedPeers.length > 0) { - this.log.debug( - `At least one peer connected (${this.connectedPeers.length}), not forcing use of all peers` - ); - return true; - } - - if (!forceUseAllPeers) { - await this.maintainPeers(); - const hasPeers = this.connectedPeers.length > 0; - this.log.debug( - `After maintenance, connected peers: ${this.connectedPeers.length}` - ); - return hasPeers; - } - for (let attempts = 0; attempts < maxAttempts; attempts++) { this.log.debug( `Attempt ${attempts + 1}/${maxAttempts} to reach required number of peers` ); await this.maintainPeers(); + if (!forceUseAllPeers && this.connectedPeers.length > 0) { + this.log.debug( + `At least one peer connected (${this.connectedPeers.length}), not forcing use of all peers` + ); + return true; + } + if (this.connectedPeers.length >= this.numPeersToUse) { this.log.info( `Required number of peers (${this.numPeersToUse}) reached`