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

[fix] #1098 Proof-of-work should be decoupled from BMA pulls

parent 1316c5b5
No related branches found
No related tags found
No related merge requests found
export const Constants = {
PULLING_MAX_DURATION: 10 * 1000, // 10 seconds
CORES_MAXIMUM_USE_IN_PARALLEL: 8,
MINIMAL_ZEROS_TO_SHOW_IN_LOGS: 3,
......
import {BlockGeneratorWhichProves} from "./blockGenerator"
import {ConfDTO} from "../../../lib/dto/ConfDTO"
import {BlockProver} from "./blockProver"
import {Constants} from "./constants"
import {DBBlock} from "../../../lib/db/DBBlock"
import {dos2unix} from "../../../lib/common-libs/dos2unix"
import {parsers} from "../../../lib/common-libs/parsers/index"
......@@ -29,10 +28,6 @@ export class PermanentProver {
private lastComputedBlock:any = null
private resolveContinuePromise:any = null
private continuePromise:any = null
private pullingResolveCallback:any = null
private timeoutPullingCallback:any = null
private pullingFinishedPromise:Querable<any>|null = null
private timeoutPulling:any = null
constructor(private server:any) {
this.logger = server.logger;
......@@ -43,9 +38,6 @@ export class PermanentProver {
// Promises triggering the prooving lopp
this.resolveContinuePromise = null;
this.continuePromise = new Promise((resolve) => this.resolveContinuePromise = resolve);
this.pullingResolveCallback = null
this.timeoutPullingCallback = null
this.pullingFinishedPromise = querablep(Promise.resolve());
this.loops = 0;
......@@ -59,30 +51,6 @@ export class PermanentProver {
this.resolveContinuePromise(true);
}
// When we detected a pulling, we stop the PoW loop
pullingDetected() {
if (this.pullingFinishedPromise && this.pullingFinishedPromise.isResolved()) {
this.pullingFinishedPromise = querablep(Promise.race([
// We wait for end of pulling signal
new Promise((res) => this.pullingResolveCallback = res),
// Security: if the end of pulling signal is not emitted after some, we automatically trigger it
new Promise((res) => this.timeoutPullingCallback = () => {
this.logger.warn('Pulling not finished after %s ms, continue PoW', Constants.PULLING_MAX_DURATION);
res();
})
]));
}
// Delay the triggering of pulling timeout
if (this.timeoutPulling) {
clearTimeout(this.timeoutPulling);
}
this.timeoutPulling = setTimeout(this.timeoutPullingCallback, Constants.PULLING_MAX_DURATION);
}
pullingFinished() {
return this.pullingResolveCallback && this.pullingResolveCallback()
}
async startPermanence() {
let permanenceResolve = () => {}
......@@ -120,11 +88,6 @@ export class PermanentProver {
const trial = await this.server.getBcContext().getIssuerPersonalizedDifficulty(selfPubkey);
this.checkTrialIsNotTooHigh(trial, current, selfPubkey);
const lastIssuedByUs = current.issuer == selfPubkey;
if (this.pullingFinishedPromise && !this.pullingFinishedPromise.isFulfilled()) {
this.logger.warn('Waiting for the end of pulling...');
await this.pullingFinishedPromise;
this.logger.warn('Pulling done. Continue proof-of-work loop.');
}
if (lastIssuedByUs && !this.promiseOfWaitingBetween2BlocksOfOurs) {
this.promiseOfWaitingBetween2BlocksOfOurs = new Promise((resolve) => setTimeout(resolve, theConf.powDelay));
this.logger.warn('Waiting ' + theConf.powDelay + 'ms before starting to compute next block...');
......
......@@ -21,13 +21,6 @@ export class Prover extends stream.Transform {
this.permaProver.prover.changePoWPrefix((obj.nodeIndexInPeers + 1) * 10); // We multiply by 10 to give room to computers with < 100 cores
} else if (obj.cpu !== undefined) {
this.permaProver.prover.changeCPU(obj.cpu); // We multiply by 10 to give room to computers with < 100 cores
} else if (obj.pulling !== undefined) {
if (obj.pulling === 'processing') {
this.permaProver.pullingDetected();
}
else if (obj.pulling === 'finished') {
this.permaProver.pullingFinished();
}
}
}
done && done();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment