diff --git a/app/modules/crawler/lib/sync.ts b/app/modules/crawler/lib/sync.ts index 239be33cd32106dc25ce5920712ecb329e4ae5ef..fbb7432d132d5fed6d286b4605feb14a1c3496c4 100644 --- a/app/modules/crawler/lib/sync.ts +++ b/app/modules/crawler/lib/sync.ts @@ -206,7 +206,7 @@ export class Synchroniser extends stream.Duplex { // We use cautious mode if it is asked, or not particulary asked but blockchain has been started const cautious = (askedCautious === true || localNumber >= 0); const shuffledPeers = noShufflePeers ? peers : _.shuffle(peers); - const downloader = new P2PDownloader(rCurrent.currency, localNumber, to, rCurrent.hash, shuffledPeers, this.watcher, this.logger, hashf, this.dal, this.slowOption, this.otherDAL); + const downloader = new P2PDownloader(rCurrent.currency, localNumber, to, rCurrent.hash, shuffledPeers, this.watcher, this.logger, hashf, this.dal, this.slowOption, !cautious, this.otherDAL); downloader.start(); @@ -678,6 +678,7 @@ class P2PDownloader { private hashf:any, private dal:FileDAL, private slowOption:any, + private nocautious:boolean, private otherDAL?:FileDAL) { this.TOO_LONG_TIME_DOWNLOAD = "No answer after " + this.MAX_DELAY_PER_DOWNLOAD + "ms, will retry download later."; @@ -756,9 +757,12 @@ class P2PDownloader { // Chunk is COMPLETE this.logger.warn("Chunk #%s is COMPLETE from %s", realIndex, [this.handler[realIndex].host, this.handler[realIndex].port].join(':')); this.chunks[realIndex] = blocks; - await this.dal.blockDAL.insertBatch(blocks.map((b:any) => BlockDTO.fromJSONObject(b))) - this.writtenChunks++ - watcher.savedPercent(Math.round(this.writtenChunks / this.numberOfChunksToDownload * 100)); + // We pre-save blocks only for non-cautious sync + if (this.nocautious) { + await this.dal.blockDAL.insertBatch(blocks.map((b:any) => BlockDTO.fromJSONObject(b))) + this.writtenChunks++ + watcher.savedPercent(Math.round(this.writtenChunks / this.numberOfChunksToDownload * 100)); + } this.resultsDeferers[realIndex].resolve(this.chunks[realIndex]); } else { this.logger.warn("Chunk #%s DOES NOT CHAIN CORRECTLY from %s", realIndex, [this.handler[realIndex].host, this.handler[realIndex].port].join(':')); diff --git a/test/integration/cli.js b/test/integration/cli.js index 721c50726586f29deb4646153d03c71a37214989..766835cb5ab532e26ef9201cebd578417b3ada75 100644 --- a/test/integration/cli.js +++ b/test/integration/cli.js @@ -22,12 +22,11 @@ const toolbox = require('./tools/toolbox'); const duniter = require('../../index'); const merkleh = require('../../app/lib/helpers/merkle'); const hashf = require('../../app/lib/common-libs').hashf -const constants = require('../../app/lib/constants'); const MerkleDTO = require('../../app/lib/dto/MerkleDTO').MerkleDTO const DB_NAME = "unit_tests"; -describe.skip("CLI", function() { +describe("CLI", function() { let farmOfServers = [], fakeServer;