Commit 93a06c6b authored by Cédric Moreau's avatar Cédric Moreau

Updated `powPeriod` interpretation in code

parent faa15343
......@@ -291,21 +291,7 @@ var tasks = {
async.apply(simpleInteger, "Certification validity duration", "sigValidity", conf),
async.apply(simpleInteger, "Number of valid certifications required to be a member", "sigQty", conf),
async.apply(simpleInteger, "Minimum number of leading zeros for a proof-of-work", "powZeroMin", conf),
function (next){
choose("Lowering proof-of-work difficulty using a percentage of WoT size", !conf.powPeriodC,
function ifPercentage () {
conf.powPeriodC = false;
async.waterfall([
async.apply(simpleInteger, "Number of blocks to wait for lowering difficulty = % members count, how much", "powPeriod", conf),
], next);
},
function ifConstant () {
conf.powPeriodC = true;
async.waterfall([
async.apply(simpleInteger, "Number of blocks to wait to lower proof-of-work difficulty", "powPeriod", conf),
], next);
});
},
async.apply(simplePercentOrPositiveInteger, "Number of blocks to wait for lowering difficulty", "powPeriod", conf),
function (next){
choose("Participate writing the keychain (when member)", conf.participate,
function participate () {
......@@ -356,4 +342,10 @@ function simpleFloat (question, property, conf, done) {
simpleValue(question, property, conf[property], conf, function (input) {
return input && input.toString().match(/^[0-9]+(\.[0-9]+)?$/) ? true : false;
}, done);
}
function simplePercentOrPositiveInteger (question, property, conf, done) {
simpleValue(question, property, conf[property], conf, function (input) {
return input && (input.toString().match(/^[1-9][0-9]*$/) || input.toString().match(/^0\.[0-9]+$/)) ? true : false;
}, done);
}
\ No newline at end of file
......@@ -23,7 +23,6 @@ var ConfigurationSchema = new Schema({
sigQty: {"type": Number, "default": 5},
powZeroMin: {"type": Number, "default": 4},
powPeriod: {"type": Number, "default": 1},
powPeriodC: {"type": Boolean, "default": true}, // Default using Constant value '1'
participate: {"type": Boolean, "default": true}, // Participate to writing the keychain
tsInterval: {"type": Number, "default": 30},
});
......@@ -46,10 +45,8 @@ ConfigurationSchema.virtual('createNext').set(function (create) {
ConfigurationSchema.pre('save', function (next) {
// Force sync saving
var sync = _({}).extend(this.sync);
this.sync = {};
this.sync = sync;
if (this.powPeriod >= 1)
this.powPeriod = parseInt(this.powPeriod);
if(!this.kmanagement || !this.kmanagement.match(/^(ALL|KEYS)$/)){
logger.error('Incorrect --kmanagement value, reset to default `KEYS` value');
......
......@@ -546,9 +546,9 @@ function KeyService (conn, conf, PublicKeyService, PeeringService) {
if (last) {
var leadingZeros = last.hash.match(/^0+/)[0];
lastBlockPenality = leadingZeros.length - conf.powZeroMin + 1;
var powPeriodIsContant = conf.powPeriodC;
var nbPeriodsToWait = (powPeriodIsContant ? conf.powPeriod : Math.floor(conf.powPeriod/100*currentWoTsize));
nbWaitedPeriods = Math.floor((nextBlockNumber - last.number) / nbPeriodsToWait);
var powPeriodIsPercentage = conf.powPeriod < 1;
var nbPeriodsToWait = powPeriodIsPercentage ? Math.floor(conf.powPeriod*currentWoTsize) : conf.powPeriod;
nbWaitedPeriods = Math.floor((nextBlockNumber - 1 - last.number) / nbPeriodsToWait); // -1 to say "excluded"
}
var nbZeros = Math.max(conf.powZeroMin, conf.powZeroMin + lastBlockPenality - nbWaitedPeriods);
next(null, nbZeros);
......
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