Skip to content

Commit

Permalink
chore(io): move try/catch when fetching gateways to always return cur…
Browse files Browse the repository at this point in the history
…rent peer list

Cleans up logs and returns the current peer list if it fails to fetch from contract
  • Loading branch information
dtfiedler committed Sep 12, 2024
1 parent f765a76 commit 68240be
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/data/ar-io-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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<string, string> = {};
let cursor: string | undefined;
do {
const peers: Record<string, string> = {};
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
Expand All @@ -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 {
Expand Down

0 comments on commit 68240be

Please sign in to comment.