diff --git a/app/modules/prover/index.ts b/app/modules/prover/index.ts index 7bdd83464fbadb89784356ce724eb13ff643e0eb..a6016eaf74bcf1bf1521fc68a780e015f0249894 100644 --- a/app/modules/prover/index.ts +++ b/app/modules/prover/index.ts @@ -1,6 +1,6 @@ import {ConfDTO} from "../../lib/dto/ConfDTO" import {BlockGenerator, BlockGeneratorWhichProves} from "./lib/blockGenerator" -import {Constants} from "./lib/constants" +import {ProverConstants} from "./lib/constants" import {BlockProver} from "./lib/blockProver" import {Prover} from "./lib/prover" import {Contacter} from "../crawler/lib/contacter" @@ -19,13 +19,13 @@ export const ProverDependency = { config: { onLoading: async (conf:ConfDTO) => { if (conf.cpu === null || conf.cpu === undefined) { - conf.cpu = Constants.DEFAULT_CPU; + conf.cpu = ProverConstants.DEFAULT_CPU; } if (conf.prefix === null || conf.prefix === undefined) { - conf.prefix = Constants.DEFAULT_PEER_ID; + conf.prefix = ProverConstants.DEFAULT_PEER_ID; } - conf.powSecurityRetryDelay = Constants.POW_SECURITY_RETRY_DELAY; - conf.powMaxHandicap = Constants.POW_MAXIMUM_ACCEPTABLE_HANDICAP; + conf.powSecurityRetryDelay = ProverConstants.POW_SECURITY_RETRY_DELAY; + conf.powMaxHandicap = ProverConstants.POW_MAXIMUM_ACCEPTABLE_HANDICAP; }, beforeSave: async (conf:ConfDTO) => { delete conf.powSecurityRetryDelay; diff --git a/app/modules/prover/lib/blockProver.ts b/app/modules/prover/lib/blockProver.ts index 1c68518f7947d2fd0eb71c009488eec5250b02ae..9cd215d98d478a456857b52f9f5c5388e1afa153 100644 --- a/app/modules/prover/lib/blockProver.ts +++ b/app/modules/prover/lib/blockProver.ts @@ -1,4 +1,4 @@ -import {Constants} from "./constants" +import {ProverConstants} from "./constants" import {Server} from "../../../../server" import {PowEngine} from "./engine" import {DBBlock} from "../../../lib/db/DBBlock" @@ -165,7 +165,7 @@ export class BlockProver { // Start powFarm.setOnAlmostPoW((pow:any, matches:any, aBlock:any, found:boolean) => { this.powEvent(found, pow); - if (matches && matches[1].length >= Constants.MINIMAL_ZEROS_TO_SHOW_IN_LOGS) { + if (matches && matches[1].length >= ProverConstants.MINIMAL_ZEROS_TO_SHOW_IN_LOGS) { this.logger.info('Matched %s zeros %s with Nonce = %s for block#%s by %s', matches[1].length, pow, aBlock.nonce, aBlock.number, aBlock.issuer.slice(0,6)); } }); diff --git a/app/modules/prover/lib/constants.ts b/app/modules/prover/lib/constants.ts index 0602e7de87009833c41fccff032fd1c6b9d8e137..0a454d38fd9c85e58115c2f971bbb6cb1cea812e 100644 --- a/app/modules/prover/lib/constants.ts +++ b/app/modules/prover/lib/constants.ts @@ -1,4 +1,4 @@ -export const Constants = { +export const ProverConstants = { CORES_MAXIMUM_USE_IN_PARALLEL: 8, diff --git a/app/modules/prover/lib/engine.ts b/app/modules/prover/lib/engine.ts index 12d2751d6c45f522027ce96c88de942cd9f0c62a..2be351a91b61bf8a2208b7f167fd4eac48af871a 100644 --- a/app/modules/prover/lib/engine.ts +++ b/app/modules/prover/lib/engine.ts @@ -1,4 +1,4 @@ -import {Constants} from "./constants" +import {ProverConstants} from "./constants" import {Master as PowCluster} from "./powCluster" import {ConfDTO} from "../../../lib/dto/ConfDTO" @@ -20,7 +20,7 @@ export class PowEngine { constructor(private conf:ConfDTO, logger:any) { // We use as much cores as available, but not more than CORES_MAXIMUM_USE_IN_PARALLEL - this.nbWorkers = (conf && conf.nbCores) || Math.min(Constants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length) + this.nbWorkers = (conf && conf.nbCores) || Math.min(ProverConstants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length) this.cluster = new PowCluster(this.nbWorkers, logger) this.id = this.cluster.clusterId } diff --git a/app/modules/prover/lib/powCluster.ts b/app/modules/prover/lib/powCluster.ts index 1e1a6ad3d42afadf5c750a378426d8e7ab50df70..4d4820777cb9b279aebea2d09680d1be0b3aab1f 100644 --- a/app/modules/prover/lib/powCluster.ts +++ b/app/modules/prover/lib/powCluster.ts @@ -1,5 +1,5 @@ import {ConfDTO} from "../../../lib/dto/ConfDTO" -import {Constants} from "./constants" +import {ProverConstants} from "./constants" const _ = require('underscore') const nuuid = require('node-uuid'); @@ -84,7 +84,7 @@ export class Master { })(), // Each worker has his own chunk of possible nonces - nonceBeginning: this.nbCores === 1 ? 0 : (index + 1) * Constants.NONCE_RANGE + nonceBeginning: this.nbCores === 1 ? 0 : (index + 1) * ProverConstants.NONCE_RANGE } return this.slavesMap[worker.id] }) diff --git a/app/modules/prover/lib/proof.ts b/app/modules/prover/lib/proof.ts index cc60a584fec95dae212da94306d05c828ffcff1a..9b15c0be5aaff08b078c5dd495dbb0432be983ea 100644 --- a/app/modules/prover/lib/proof.ts +++ b/app/modules/prover/lib/proof.ts @@ -2,7 +2,7 @@ import {LOCAL_RULES_HELPERS} from "../../../lib/rules/local_rules" import {hashf} from "../../../lib/common" import {DBBlock} from "../../../lib/db/DBBlock" import {ConfDTO} from "../../../lib/dto/ConfDTO" -import {Constants} from "./constants" +import {ProverConstants} from "./constants" import {KeyGen} from "../../../lib/common-libs/crypto/keyring" import {dos2unix} from "../../../lib/common-libs/dos2unix" import {rawer} from "../../../lib/common-libs/index" @@ -84,10 +84,10 @@ function beginNewProofOfWork(stuff:any) { const nbZeros = stuff.zeros; const pair = stuff.pair; const forcedTime = stuff.forcedTime; - currentCPU = conf.cpu || Constants.DEFAULT_CPU; + currentCPU = conf.cpu || ProverConstants.DEFAULT_CPU; prefix = parseInt(conf.prefix || prefix) - if (prefix && prefix < Constants.NONCE_RANGE) { - prefix *= 100 * Constants.NONCE_RANGE + if (prefix && prefix < ProverConstants.NONCE_RANGE) { + prefix *= 100 * ProverConstants.NONCE_RANGE } const highMark = stuff.highMark; const turnDuration = stuff.turnDuration || TURN_DURATION_IN_MILLISEC @@ -184,7 +184,7 @@ function beginNewProofOfWork(stuff:any) { if (charOK) { found = !!(pow[nbZeros].match(new RegExp('[0-' + highMark + ']'))) } - if (!found && nbZeros > 0 && j - 1 >= Constants.POW_MINIMAL_TO_SHOW) { + if (!found && nbZeros > 0 && j - 1 >= ProverConstants.POW_MINIMAL_TO_SHOW) { pSend({ pow: { pow: pow, block: block, nbZeros: nbZeros }}); } diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 4c991070b7f0dd946e44aa8ecb268917d2f73541..766e83eee23cef0df98410e1b325b62ed0f28baa 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -15,7 +15,7 @@ import {WS2PServerMessageHandler} from "./interface/WS2PServerMessageHandler" import {WS2PMessageHandler} from "./impl/WS2PMessageHandler" import { CommonConstants } from "../../../lib/common-libs/constants"; import { Package } from "../../../lib/common/package"; -import { Constants } from "../../prover/lib/constants"; +import { ProverConstants } from "../../prover/lib/constants"; const es = require('event-stream') const nuuid = require('node-uuid') @@ -426,7 +426,7 @@ export class WS2PCluster { const software = 'duniter' const softVersion = Package.getInstance().version const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '00000000' - const prefix = this.server.conf.prefix || Constants.DEFAULT_PEER_ID + const prefix = this.server.conf.prefix || ProverConstants.DEFAULT_PEER_ID const message = `WS2P:HEAD:1:${pub}:${number}-${hash}:${ws2pId}:${software}:${softVersion}:${prefix}` const sig = key.signSync(message) return { sig, message, pub }