Skip to content
Snippets Groups Projects
Commit 3fce8a17 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

fix(sync): don't lose nodes on single download err - cherry-pick of commit...

fix(sync): don't lose nodes on single download err - cherry-pick of commit 7a59f46f from branch `dev`
parent 85e63ece
No related branches found
No related tags found
No related merge requests found
......@@ -155,21 +155,17 @@ export class RemoteSynchronizer extends AbstractSynchronizer {
// If we know this is a WS2P connection, don't try BMA
if (access.isWS2P !== true) {
try {
endpoint =
[port == 443 ? "BMAS" : "BASIC_MERKLED_API", host, port].join(" ") +
(path ? (" " + path) : "");
const contacter = await connect(
PeerDTO.fromJSONObject({
endpoints: [
[port == 443 ? "BMAS" : "BASIC_MERKLED_API", host, port].join(
" "
) + (path ? " " + path : ""),
],
endpoints: [endpoint],
}),
3000
);
peering = await contacter.getPeer();
api = new BMARemoteContacter(contacter);
endpoint =
[port == 443 ? "BMAS" : "BASIC_MERKLED_API", host, port].join(" ") +
(path ? " " + path : "");
} catch (e) {}
}
......
......@@ -90,21 +90,30 @@ export class P2pCandidate {
this.dlPromise = querablep(
(async () => {
// We try to download the blocks
let blocks: BlockDTO[] | null;
let blocks: BlockDTO[] = [];
let tries = 5;
while (tries > 0) {
try {
blocks = await (this.api as IRemoteContacter).getBlocks(count, from);
blocks = await (this.api as IRemoteContacter).getBlocks(
count,
from
);
} catch (e) {
// Unfortunately this can fail
blocks = null;
error = e;
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;
})()
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment