Commit ad4b738b authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Fix #619 Proof-of-work engines were regularly killed

parent c723ece8
......@@ -180,7 +180,7 @@ function BlockGenerator(notifier) {
let onAlmostPoW = function() { throw 'Almost proof-of-work found, but no listener is attached.'; };
let onPoWSuccess = function() { throw 'Proof-of-work success, but no listener is attached.'; };
let onPoWError = function() { throw 'Proof-of-work error, but no listener is attached.'; };
let powProcess, readyPromise, readyResolver, lastInterval;
let powProcess, readyPromise, readyResolver;
newProcess();
......@@ -214,9 +214,6 @@ function BlockGenerator(notifier) {
// Canceled for a long time (not because of an incoming block)
onPoWError = null;
onPoWSuccess = null;
if (lastInterval) {
clearInterval(lastInterval); // Force engine killing after some time if stop failed
}
}
sendToProcess({ command: 'stop' });
return readyPromise;
......@@ -255,6 +252,7 @@ function BlockGenerator(notifier) {
powProcess.on('exit', function() {
onPoWError && onPoWError(POW_CANCELED);
onPoWError = null;
logger.trace('Engine engine %s exited unexpectedly', id);
if (interval) {
clearInterval(interval);
}
......@@ -305,8 +303,10 @@ function BlockGenerator(notifier) {
// Initialize the engine
sendToProcess({ command: 'id', pubkey: pub, identifier: id });
interval = setInterval(() => sendToProcess({ command: 'idle' }), constants.ENGINE_IDLE_INTERVAL);
lastInterval = interval;
interval = setInterval(() => {
logger.trace('%s interval to engine %s', pub.slice(0,6), id);
return sendToProcess({ command: 'idle' });
}, constants.ENGINE_IDLE_INTERVAL);
}
}
}
......@@ -217,7 +217,7 @@ function autoKillIfNoContact() {
}
// If the timeout is not cleared in some way, the process exits
timeoutAutoKill = setTimeout(() => {
console.log('Killing engine #%s', id);
console.log('Killing engine %s #%s', lastPub, id);
process.exit();
}, AUTOKILL_TIMEOUT_DELAY);
}
......@@ -381,6 +381,7 @@ function Server (dbConf, overrideConf) {
this.pullBlocks = that.PeeringService.pullBlocks;
// Unit Tests or Preview method
this.doMakeNextBlock = (manualValues) => that.BlockchainService.makeNextBlock(null, null, manualValues);
this.doCheckBlock = (block) => {
......
......@@ -90,4 +90,20 @@ describe("Continous proof-of-work", function() {
yield new Promise((resolve) => setTimeout(resolve, 100));
s1.permaProver.should.have.property('loops').equal(8);
}));
it('testing a network', () => co(function*() {
const res = yield toolbox.simpleNetworkOf2NodesAnd2Users({
participate: true,
powMin: 16
}), s2 = res.s1, s3 = res.s2;
yield s2.commit();
s2.conf.cpu = 0.5;
s3.conf.cpu = 0.5;
s2.startBlockComputation();
s3.startBlockComputation();
yield [
s2.until('block', 10),
s3.until('block', 10)
];
}));
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment