From 9b9a8a39be7c653627692455b829734c81ec5ab3 Mon Sep 17 00:00:00 2001 From: bludnic Date: Thu, 21 Dec 2023 18:37:44 +0000 Subject: [PATCH] fix(nodes): can't login when no online nodes available --- src/lib/nodes/abstract.client.ts | 6 +++++- src/lib/nodes/utils/filterSyncedNodes.ts | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/nodes/abstract.client.ts b/src/lib/nodes/abstract.client.ts index 6895317ab..d454c0239 100644 --- a/src/lib/nodes/abstract.client.ts +++ b/src/lib/nodes/abstract.client.ts @@ -53,7 +53,10 @@ export abstract class Client { const node = this.useFastest ? this.getFastestNode() : this.getRandomNode() if (!node) { - throw new Error('No available nodes at the moment') + console.warn(`${this.type}: No online nodes at the moment`) + + // Return a random one from the full list hopefully is online + return this.nodes[Math.floor(Math.random() * this.nodes.length)].client } return node.client @@ -127,6 +130,7 @@ export abstract class Client { // Finally, all the nodes from the winner list are considered to be in sync, all the // others are not + console.log('nodes', nodes) for (const node of nodes) { node.outOfSync = !nodesInSync.nodes.includes(node) } diff --git a/src/lib/nodes/utils/filterSyncedNodes.ts b/src/lib/nodes/utils/filterSyncedNodes.ts index a01564e33..ba176195f 100644 --- a/src/lib/nodes/utils/filterSyncedNodes.ts +++ b/src/lib/nodes/utils/filterSyncedNodes.ts @@ -22,7 +22,10 @@ type GroupNodes = { */ export function filterSyncedNodes(nodes: N[]): GroupNodes { if (nodes.length === 0) { - throw new Error('filterSyncedNodes: No nodes provided') + return { + height: 0, + nodes: [] + } } // For each node we take its height and list of nodes that have the same height ± epsilon