Skip to content
Snippets Groups Projects
Commit 31b62d6a authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[enh] sync: usage of `--nopeers` and `--nosbx`

parent 8544f1ff
Branches
Tags
No related merge requests found
...@@ -17,6 +17,8 @@ export interface ProgramOptions { ...@@ -17,6 +17,8 @@ export interface ProgramOptions {
mdb?: string mdb?: string
home?: string home?: string
notrim?: boolean notrim?: boolean
nosbx?: boolean
nopeers?: boolean
syncTrace?: string syncTrace?: string
} }
...@@ -24,5 +26,7 @@ export const cliprogram: ProgramOptions = { ...@@ -24,5 +26,7 @@ export const cliprogram: ProgramOptions = {
mdb: opts.mdb, mdb: opts.mdb,
home: opts.home, home: opts.home,
notrim: opts.notrim, notrim: opts.notrim,
nosbx: opts.nosbx,
nopeers: opts.nopeers,
syncTrace: opts['sync-trace'], syncTrace: opts['sync-trace'],
} }
...@@ -65,6 +65,7 @@ export const CrawlerDependency = { ...@@ -65,6 +65,7 @@ export const CrawlerDependency = {
{ value: '--nocautious', desc: 'Do not check blocks validity during sync.'}, { value: '--nocautious', desc: 'Do not check blocks validity during sync.'},
{ value: '--cautious', desc: 'Check blocks validity during sync (overrides --nocautious option).'}, { value: '--cautious', desc: 'Check blocks validity during sync (overrides --nocautious option).'},
{ value: '--nopeers', desc: 'Do not retrieve peers during sync.'}, { value: '--nopeers', desc: 'Do not retrieve peers during sync.'},
{ value: '--nosbx', desc: 'Do not retrieve sandboxes during sync.'},
{ value: '--onlypeers', desc: 'Will only try to sync peers.'}, { value: '--onlypeers', desc: 'Will only try to sync peers.'},
{ value: '--slow', desc: 'Download slowly the blokchcain (for low connnections).'}, { value: '--slow', desc: 'Download slowly the blokchcain (for low connnections).'},
{ value: '--readfilesystem',desc: 'Also read the filesystem to speed up block downloading.'}, { value: '--readfilesystem',desc: 'Also read the filesystem to speed up block downloading.'},
...@@ -98,7 +99,6 @@ export const CrawlerDependency = { ...@@ -98,7 +99,6 @@ export const CrawlerDependency = {
const chunkLength = 0; const chunkLength = 0;
const interactive = !program.nointeractive; const interactive = !program.nointeractive;
const askedCautious = cautious; const askedCautious = cautious;
const nopeers = program.nopeers;
const noShufflePeers = program.noshuffle; const noShufflePeers = program.noshuffle;
let otherDAL = undefined let otherDAL = undefined
...@@ -112,9 +112,9 @@ export const CrawlerDependency = { ...@@ -112,9 +112,9 @@ export const CrawlerDependency = {
const remote = new Synchroniser(server, onHost, onPort, interactive === true, program.slow === true, otherDAL); const remote = new Synchroniser(server, onHost, onPort, interactive === true, program.slow === true, otherDAL);
if (program.onlypeers === true) { if (program.onlypeers === true) {
return remote.syncPeers(nopeers, true, onHost, onPort) return remote.syncPeers(true, onHost, onPort)
} else { } else {
return remote.sync(upTo, chunkLength, askedCautious, nopeers, noShufflePeers === true) return remote.sync(upTo, chunkLength, askedCautious, noShufflePeers === true)
} }
} }
}, { }, {
......
...@@ -34,6 +34,7 @@ import {CommonConstants} from "../../../lib/common-libs/constants" ...@@ -34,6 +34,7 @@ import {CommonConstants} from "../../../lib/common-libs/constants"
import {Underscore} from "../../../lib/common-libs/underscore" import {Underscore} from "../../../lib/common-libs/underscore"
import {HttpMerkleOfPeers} from "../../bma/lib/dtos" import {HttpMerkleOfPeers} from "../../bma/lib/dtos"
import {DBPeer, JSONDBPeer} from "../../../lib/db/DBPeer" import {DBPeer, JSONDBPeer} from "../../../lib/db/DBPeer"
import {cliprogram} from "../../../lib/common-libs/programOptions"
const multimeter = require('multimeter'); const multimeter = require('multimeter');
const makeQuerablePromise = require('querablep'); const makeQuerablePromise = require('querablep');
...@@ -131,7 +132,7 @@ export class Synchroniser extends stream.Duplex { ...@@ -131,7 +132,7 @@ export class Synchroniser extends stream.Duplex {
return node.getCurrent(); return node.getCurrent();
} }
async sync(to:number, chunkLen:number, askedCautious = false, nopeers = false, noShufflePeers = false) { async sync(to:number, chunkLen:number, askedCautious = false, noShufflePeers = false) {
try { try {
...@@ -164,7 +165,7 @@ export class Synchroniser extends stream.Duplex { ...@@ -164,7 +165,7 @@ export class Synchroniser extends stream.Duplex {
// Peers (just for P2P download) // Peers (just for P2P download)
//======= //=======
let peers:(JSONDBPeer|null)[] = []; let peers:(JSONDBPeer|null)[] = [];
if (!nopeers && (to - localNumber > 1000)) { // P2P download if more than 1000 blocs if (!cliprogram.nopeers && (to - localNumber > 1000)) { // P2P download if more than 1000 blocs
this.watcher.writeStatus('Peers...'); this.watcher.writeStatus('Peers...');
const merkle = await this.dal.merkleForPeers(); const merkle = await this.dal.merkleForPeers();
const getPeers:(params:any) => Promise<HttpMerkleOfPeers> = node.getPeers.bind(node); const getPeers:(params:any) => Promise<HttpMerkleOfPeers> = node.getPeers.bind(node);
...@@ -320,16 +321,20 @@ export class Synchroniser extends stream.Duplex { ...@@ -320,16 +321,20 @@ export class Synchroniser extends stream.Duplex {
await this.BlockchainService.saveParametersForRootBlock(BlockDTO.fromJSONObject(rootBlock)) await this.BlockchainService.saveParametersForRootBlock(BlockDTO.fromJSONObject(rootBlock))
this.server.dal.blockDAL.cleanCache(); this.server.dal.blockDAL.cleanCache();
if (!cliprogram.nosbx) {
//======= //=======
// Sandboxes // Sandboxes
//======= //=======
this.watcher.writeStatus('Synchronizing the sandboxes...'); this.watcher.writeStatus('Synchronizing the sandboxes...');
await pullSandboxToLocalServer(this.conf.currency, node, this.server, this.server.logger, this.watcher, 1, false) await pullSandboxToLocalServer(this.conf.currency, node, this.server, this.server.logger, this.watcher, 1, false)
}
if (!cliprogram.nopeers) {
//======= //=======
// Peers // Peers
//======= //=======
await this.syncPeers(nopeers, fullSync, this.host, this.port, to) await this.syncPeers(fullSync, this.host, this.port, to)
}
// Trim the loki data // Trim the loki data
await this.server.dal.loki.flushAndTrimData() await this.server.dal.loki.flushAndTrimData()
...@@ -345,8 +350,8 @@ export class Synchroniser extends stream.Duplex { ...@@ -345,8 +350,8 @@ export class Synchroniser extends stream.Duplex {
} }
} }
async syncPeers(nopeers:boolean, fullSync:boolean, host:string, port:number, to?:number) { async syncPeers(fullSync:boolean, host:string, port:number, to?:number) {
if (!nopeers && fullSync) { if (!cliprogram.nopeers && fullSync) {
const peering = await Contacter.fetchPeer(host, port, this.contacterOptions); const peering = await Contacter.fetchPeer(host, port, this.contacterOptions);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment