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

[fix] #1062 Proof-of-work was always restarting during a sync

parent a87d38eb
Branches
Tags
No related merge requests found
......@@ -4,7 +4,6 @@ import {Contacter} from "./lib/contacter"
import {Crawler} from "./lib/crawler"
import {Synchroniser} from "./lib/sync"
import {req2fwd} from "./lib/req2fwd"
import {CrawlerConstants} from "./lib/constants"
import {rawer} from "../../lib/common-libs/index"
import {PeerDTO} from "../../lib/dto/PeerDTO"
import {Buid} from "../../lib/common-libs/buid"
......@@ -13,7 +12,7 @@ export const CrawlerDependency = {
duniter: {
service: {
input: (server:Server, conf:ConfDTO, logger:any) => new Crawler(server, conf, logger)
process: (server:Server, conf:ConfDTO, logger:any) => new Crawler(server, conf, logger)
},
methods: {
......
......@@ -360,6 +360,7 @@ export class BlockCrawler {
this.logger && this.logger.trace("Try with %s %s", p.getURL(), p.pubkey.substr(0, 6));
try {
let node:any = await connect(p);
let nodeCurrent:BlockDTO|null = null
node.pubkey = p.pubkey;
await checkPeerValidity(server, p, node);
......@@ -375,7 +376,8 @@ export class BlockCrawler {
return server.dal.getCurrentBlockOrNull()
}
async remoteCurrent(source?: any): Promise<BlockDTO | null> {
return source.getCurrent()
nodeCurrent = await source.getCurrent()
return nodeCurrent
}
async remotePeers(source?: any): Promise<PeerDTO[]> {
return Promise.resolve([node])
......@@ -396,15 +398,18 @@ export class BlockCrawler {
return block;
}
async applyMainBranch(block: BlockDTO): Promise<boolean> {
let addedBlock = await server.BlockchainService.submitBlock(block, true, CrawlerConstants.FORK_ALLOWED);
let addedBlock = await server.writeBlock(block, false)
if (!this.lastDownloaded) {
this.lastDownloaded = await dao.remoteCurrent(node);
}
this.crawler.pullingEvent(server, 'applying', {number: block.number, last: this.lastDownloaded && this.lastDownloaded.number});
if (addedBlock) {
current = addedBlock;
// Emit block events (for sharing with the network) only in forkWindowSize
if (nodeCurrent && nodeCurrent.number - addedBlock.number < server.conf.forksize) {
server.streamPush(addedBlock);
}
}
return true
}
async removeForks(): Promise<boolean> {
......
......@@ -74,6 +74,7 @@
"heapdump": "^0.3.9",
"inquirer": "3.0.6",
"jison": "0.4.17",
"js-yaml": "3.8.2",
"merkle": "0.5.1",
"moment": "2.18.1",
"morgan": "1.8.1",
......
......@@ -192,9 +192,11 @@ export class Server extends stream.Duplex implements HookableServer {
return await this.writeBlock(obj)
}
async writeBlock(obj:any) {
async writeBlock(obj:any, notify = true) {
const res = await this.BlockchainService.submitBlock(obj, true, CrawlerConstants.FORK_ALLOWED)
if (notify) {
this.emitDocument(res, DuniterDocument.ENTITY_BLOCK)
}
return res
}
......@@ -242,9 +244,11 @@ export class Server extends stream.Duplex implements HookableServer {
return await this.writeRevocation(obj)
}
async writeRevocation(obj:any) {
async writeRevocation(obj:any, notify = true) {
const res = await this.IdentityService.submitRevocation(obj)
if (notify) {
this.emitDocument(res, DuniterDocument.ENTITY_REVOCATION)
}
return res
}
......@@ -253,9 +257,11 @@ export class Server extends stream.Duplex implements HookableServer {
return await this.writeTransaction(obj)
}
async writeTransaction(obj:any) {
async writeTransaction(obj:any, notify = true) {
const res = await this.TransactionsService.processTx(obj)
if (notify) {
this.emitDocument(res, DuniterDocument.ENTITY_TRANSACTION)
}
return res
}
......@@ -264,9 +270,11 @@ export class Server extends stream.Duplex implements HookableServer {
return await this.writePeer(obj)
}
async writePeer(obj:any) {
async writePeer(obj:any, notify = true) {
const res = await this.PeeringService.submitP(obj)
if (notify) {
this.emitDocument(res, DuniterDocument.ENTITY_PEER)
}
return res
}
......
......@@ -803,13 +803,13 @@ debug-log@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debug-log/-/debug-log-1.0.1.tgz#2307632d4c04382b8df8a32f70b895046d52745f"
debug@2.6.1:
debug@2.6.1, debug@^2.1.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.1.tgz#79855090ba2c4e3115cc7d8769491d58f0491351"
dependencies:
ms "0.7.2"
debug@2.6.8, debug@^2.1.1, debug@^2.2.0, debug@^2.6.3:
debug@2.6.8, debug@^2.2.0, debug@^2.6.3:
version "2.6.8"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
dependencies:
......@@ -1108,9 +1108,9 @@ esprima@1.1.x, esprima@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-1.1.1.tgz#5b6f1547f4d102e670e140c509be6771d6aeb549"
esprima@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804"
esprima@^3.1.1:
version "3.1.3"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633"
"esprima@~ 1.0.2":
version "1.0.4"
......@@ -2008,12 +2008,12 @@ js-yaml@3.0.1:
argparse "~ 0.1.11"
esprima "~ 1.0.2"
js-yaml@^3.2.5, js-yaml@^3.5.1:
version "3.9.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.9.1.tgz#08775cebdfdd359209f0d2acd383c8f86a6904a0"
js-yaml@3.8.2, js-yaml@^3.2.5, js-yaml@^3.5.1:
version "3.8.2"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.2.tgz#02d3e2c0f6beab20248d412c352203827d786721"
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"
esprima "^3.1.1"
jsbn@~0.1.0:
version "0.1.1"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment