Skip to content

Commit

Permalink
SAM-73 don't cache empty p2p bootstrap list (#53)
Browse files Browse the repository at this point in the history
Don't cache empty p2p bootstrap list
  • Loading branch information
JoshuaCWebDeveloper committed Nov 18, 2022
1 parent 2c4154b commit e3c44ee
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/gateway-client/src/worker/p2p-client/bootstrap-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ export class BootstrapList extends Bootstrap {
}

private async dumpCache() {
// don't dump if the list is empty
if (!Object.keys(this.addresses).length) {
this.log.error('Declining to cache empty bootstrap list.');
return;
}
// dump our bootstrap list to cache
return localforage.setItem(
'p2p:bootstrap-list',
Expand Down Expand Up @@ -308,9 +313,6 @@ export class BootstrapList extends Bootstrap {
this.log.info('Loaded bootstrap addresses: ', addressList);
status.relays.push(...addressList);

// update our cache
await this.dumpCache();

// if we have no addresses
if (!Object.keys(this.addresses).length) {
// this isn't good
Expand All @@ -320,6 +322,9 @@ export class BootstrapList extends Bootstrap {
return;
}

// update our cache
await this.dumpCache();

// create a bootstrap discovery list grouped by peer
const addressesByPeer: Record<string, BootstrapAddress[]> = {};
Object.values(this.addresses).forEach(address => {
Expand Down

0 comments on commit e3c44ee

Please sign in to comment.