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

[fix] #1126 Allow UP to 999999 nodes + clean commented code

parent 7df35aae
......@@ -206,6 +206,7 @@ export class BlockProver {
}
async changePoWPrefix(prefix:any) {
this.conf.prefix = prefix
const farm = await this.getWorker()
return farm.changePoWPrefix(prefix)
}
......
......@@ -7,6 +7,8 @@ export const Constants = {
POW_MINIMAL_TO_SHOW: 2,
DEFAULT_CPU: 0.6,
DEFAULT_PEER_ID: 1,
MIN_PEER_ID: 1,
MAX_PEER_ID: 999999,
NONCE_RANGE: 1000 * 1000 * 1000 * 100,
......
......@@ -17,9 +17,7 @@ export class Prover extends stream.Transform {
if (obj) {
if (obj.bcEvent && obj.bcEvent === OtherConstants.BC_EVENT.HEAD_CHANGED || obj.bcEvent === OtherConstants.BC_EVENT.SWITCHED) {
this.permaProver.blockchainChanged(obj.block);
} /*else if (obj.nodeIndexInPeers !== undefined) {
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) {
} else if (obj.cpu !== undefined) {
this.permaProver.prover.changeCPU(obj.cpu); // We multiply by 10 to give room to computers with < 100 cores
}
}
......
......@@ -161,16 +161,6 @@ export class PeeringService {
const localEndpoints = await this.server.getEndpoints()
const localNodeNotListed = !peerEntityOld.containsAllEndpoints(localEndpoints)
const current = localNodeNotListed && (await this.dal.getCurrentBlockOrNull());
/*if (!localNodeNotListed) {
const indexOfThisNode = PeerDTO.indexOfFirst(localEndpoints, peerEntity.endpoints)
if (indexOfThisNode !== -1) {
this.server.push({
nodeIndexInPeers: indexOfThisNode
});
} else {
logger.warn('This node has his interface listed in the peer document, but its index cannot be found.');
}
}*/
if (localNodeNotListed && (!current || current.number > blockNumber)) {
// Document with pubkey of local peer, but doesn't contain local interface: we must add it
this.generateSelfPeer(this.conf);
......
......@@ -7,6 +7,7 @@ import {KeypairDependency} from "./app/modules/keypair/index"
import {CrawlerDependency} from "./app/modules/crawler/index"
import {BmaDependency} from "./app/modules/bma/index"
import {WS2PDependency} from "./app/modules/ws2p/index"
import {Constants} from "./app/modules/prover/lib/constants"
const path = require('path');
const _ = require('underscore');
......@@ -468,7 +469,7 @@ function commandLineConf(program:any, conf:any = {}) {
if (cli.currency) conf.currency = cli.currency;
if (cli.server.port) conf.port = cli.server.port;
if (cli.cpu) conf.cpu = Math.max(0.01, Math.min(1.0, cli.cpu));
if (cli.prefix) conf.prefix = Math.max(1, Math.min(9, cli.prefix));
if (cli.prefix) conf.prefix = Math.max(Constants.MIN_PEER_ID, Math.min(Constants.MAX_PEER_ID, cli.prefix));
if (cli.logs.http) conf.httplogs = true;
if (cli.logs.nohttp) conf.httplogs = false;
if (cli.db.mport) conf.mport = cli.db.mport;
......
......@@ -68,6 +68,19 @@ describe('PoW block prover', () => {
});
}));
it('should be able to use a prefix with 6 digits', () => co(function*(){
const block = {
number: 1,
issuer: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'
}
const params = yield prover.changePoWPrefix('123456')
params.should.deepEqual({ prefix: '123456' })
const forcedTime = 1;
const proof = yield prover.prove(block, 1, forcedTime)
proof.nonce.should.equal(123456000000000000)
String(proof.nonce).should.have.length(18)
}));
it('should be able to stop a proof', () => co(function*(){
const block = {
number: 35,
......
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