Commit cb1b2abe authored by Éloïs's avatar Éloïs
Browse files

[mod] rename prover/Constants -> ProverConstants

parent 988cf543
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;
......
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));
}
});
......
export const Constants = {
export const ProverConstants = {
CORES_MAXIMUM_USE_IN_PARALLEL: 8,
......
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
}
......
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]
})
......
......@@ -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 }});
}
......
......@@ -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 }
......
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