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