diff --git a/src/data/ar-io-data-source.ts b/src/data/ar-io-data-source.ts index 1d2db038..db8a7e75 100644 --- a/src/data/ar-io-data-source.ts +++ b/src/data/ar-io-data-source.ts @@ -68,7 +68,6 @@ export class ArIODataSource implements ContiguousDataSource { this.requestTimeoutMs = requestTimeoutMs; this.updatePeersRefreshIntervalMs = updatePeersRefreshIntervalMs; this.arIO = arIO; - this.updatePeerList(); this.intervalId = setInterval( this.updatePeerList.bind(this), @@ -84,13 +83,13 @@ export class ArIODataSource implements ContiguousDataSource { const log = this.log.child({ method: 'updatePeerList' }); log.debug('Updating peers from ArIO contract'); - try { - const peers: Record = {}; - let cursor: string | undefined; - do { + const peers: Record = {}; + let cursor: string | undefined; + do { +: // depending on how often this is called, we may want to add a circuit breaker const { nextCursor, items } = await this.arIO.getGateways({ cursor, - }); // TODO: better error handling if one paged request fails we may want to still update the rest + }); for (const gateway of items) { // skip our own node wallet @@ -105,16 +104,22 @@ export class ArIODataSource implements ContiguousDataSource { `${gateway.settings.protocol}://${gateway.settings.fqdn}`; } cursor = nextCursor; - } while (cursor !== undefined); - - this.peers = peers; - log.debug('Updated peer list from ArIO contract'); - } catch (error: any) { - log.error('Failed to update peer list', { - message: error.message, - stack: error.stack, - }); - } + } catch (error: any) { + log.error( + 'Failed to fetch gateways from IO. Returning current peer list.', + { + message: error.message, + stack: error.stack, + peerList: peers, + }, + ); + break; + } + } while (cursor !== undefined); + log.debug('Updated peer list from ArIO contract', { + peerList: peers, + }); + this.peers = peers; } selectPeer(): string {