Skip to content
Snippets Groups Projects

fix(sync): don't lose nodes on single download err

Closed pini requested to merge pini-dont-loose-node-on-single-error-when-syncing into release/1.8
1 file
+ 19
10
Compare changes
  • Side-by-side
  • Inline
@@ -90,21 +90,30 @@ export class P2pCandidate {
this.dlPromise = querablep(
(async () => {
// We try to download the blocks
let blocks: BlockDTO[] | null;
try {
blocks = await (this.api as IRemoteContacter).getBlocks(count, from);
} catch (e) {
// Unfortunately this can fail
blocks = null;
error = e;
let blocks: BlockDTO[] = [];
let tries = 5;
while (tries > 0) {
try {
blocks = await (this.api as IRemoteContacter).getBlocks(
count,
from
);
} catch (e) {
// Unfortunately this can fail
blocks = [];
this.logger.error(e);
}
if (blocks.length != count) {
this.logger.error("Wrong number of blocks from %s", this.hostName);
tries--;
} else {
break;
}
}
this.responseTimes.push(Date.now() - start);
// Only keep a flow of 5 ttas for the node
if (this.responseTimes.length > 5) this.responseTimes.shift();
this.nbSuccess++;
if (error) {
throw error;
}
return blocks;
})()
);
Loading