diff --git a/app/modules/crawler/lib/constants.ts b/app/modules/crawler/lib/constants.ts index f53e6f6073b768a9deac61b8d77b8b84f1fcc915..da99667c9e32c2969b25a4fce5cb25e00a6e72ce 100644 --- a/app/modules/crawler/lib/constants.ts +++ b/app/modules/crawler/lib/constants.ts @@ -32,6 +32,7 @@ export const CrawlerConstants = { SANDBOX_CHECK_INTERVAL: 48, // Every 4 hours (288 blocks a day / 24 * 4) TEST_PEERS_INTERVAL: 10, // In seconds SYNC_PEERS_INTERVAL: 3, // Every 3 block average generation time + SYNC_CHUNKS_IN_ADVANCE: 10, // We want to have that much chunks in advance when syncing DURATIONS: { TEN_SECONDS: 10, diff --git a/app/modules/crawler/lib/sync/v2/DownloadStream.ts b/app/modules/crawler/lib/sync/v2/DownloadStream.ts index cae155f5a826d0e004631fe76a97aaafe9046f9d..7c392d2d6318db9c78a6d003cd129f35c0b0e5ef 100644 --- a/app/modules/crawler/lib/sync/v2/DownloadStream.ts +++ b/app/modules/crawler/lib/sync/v2/DownloadStream.ts @@ -132,13 +132,10 @@ export class DownloadStream extends Duplex { delete this.chunks[this.currentChunkNumber] // Let's start the download of next chunk this.currentChunkNumber++ - this.downloadChunk(this.currentChunkNumber) - .then(() => this.downloadChunk(this.currentChunkNumber + 1)) - .then(() => this.downloadChunk(this.currentChunkNumber + 2)) - .then(() => this.downloadChunk(this.currentChunkNumber + 3)) - .then(() => this.downloadChunk(this.currentChunkNumber + 4)) - .then(() => this.downloadChunk(this.currentChunkNumber + 5)) - .then(() => this.downloadChunk(this.currentChunkNumber + 6)) + let p = this.downloadChunk(this.currentChunkNumber) + for (let i = 1; i <= CrawlerConstants.SYNC_CHUNKS_IN_ADVANCE; i++) { + p = p.then(() => this.downloadChunk(this.currentChunkNumber + i)) + } } else { // We don't have it yet