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 authored and djwhitt committed Sep 13, 2024
1 parent 0806fab commit 23b7280
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/data/ar-io-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ 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 {
try {
// 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 +106,21 @@ 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,
},
);
break;
}
} while (cursor !== undefined);
log.debug('Updated peer list from ArIO contract', {
peers: Object.keys(peers),
});
this.peers = peers;
}

selectPeer(): string {
Expand Down

0 comments on commit 23b7280

Please sign in to comment.