Commit 18eef657 authored by Cédric Moreau's avatar Cédric Moreau

Update to match UCP's proof-of-work rule

parent 34ec350e
......@@ -47,7 +47,7 @@ function GlobalValidator (conf, dao) {
{ name: 'checkCertificationsAreMadeToMembers', func: check(checkCertificationsAreMadeToMembers) },
{ name: 'checkCertificationsDelayIsRespected', func: check(checkCertificationsDelayIsRespected) },
{ name: 'checkMembersCountIsGood', func: check(checkMembersCountIsGood) },
{ name: 'checkProofOfWork', func: check(checkFingerprint) },
{ name: 'checkProofOfWork', func: check(checkProofOfWork) },
{ name: 'checkUD', func: check(checkUD) },
{ name: 'checkTransactions', func: check(checkSourcesAvailability) }
];
......@@ -289,7 +289,7 @@ function GlobalValidator (conf, dao) {
], done);
}
function checkFingerprint (block, done) {
function checkProofOfWork (block, done) {
async.waterfall([
function (next){
dao.getCurrent(next);
......@@ -485,14 +485,68 @@ function GlobalValidator (conf, dao) {
}
});
interBlocksCount = issuers.length;
next();
} else {
// Number of blocks between 2 last blocks of issuer
interBlocksCount = Math.abs(lasts[0].number - lasts[1].number - 1);
// Number of different issuers between 2 last blocks of issuer
async.waterfall([
function (next) {
//----- Interblocks -----
var issuers = [];
var i = lasts[0].number - 1; // Start excluding last block of issuer
async.whilst(
function(){ return i > lasts[1].number && issuers.length < 40 - conf.powZeroMin; }, // End exluding first block of issuer
function (next) {
async.waterfall([
function (next){
dao.getBlock(i, next);
},
function (block, next){
if (issuers.indexOf(block.issuer) == -1) {
issuers.push(block.issuer);
}
i--;
next();
},
], next);
}, function (err) {
interBlocksCount = issuers.length;
next();
});
},
function (next) {
//----- Following blocks -----
var issuers = [];
var neededMax = interBlocksCount;
var i = current.number; // Start INCLUDING current number
async.whilst(
function(){ return i > lasts[0].number && issuers.length < neededMax; }, // End exluding last block, stop if reaches 0 difficulty
function (next) {
async.waterfall([
function (next){
dao.getBlock(i, next);
},
function (block, next){
if (issuers.indexOf(block.issuer) == -1) {
issuers.push(block.issuer);
}
i--;
next();
},
], next);
}, function (err) {
followingBlocksCount = issuers.length;
next();
});
}
], next);
}
}
else next(); // No block for issuer
},
function (next) {
var nbZeros = Math.max(conf.powZeroMin, lastBlockNbZeros + interBlocksCount - followingBlocksCount);
next(null, nbZeros);
},
}
], done);
}
......
......@@ -1542,8 +1542,8 @@ module.exports = {
"Version: 1\n" +
"Type: Block\n" +
"Currency: beta_brousouf\n" +
"Nonce: 10\n" +
"Number: 62\n" +
"Nonce: 3\n" +
"Number: 67\n" +
"Date: 1411776000\n" +
"ConfirmedDate: 1411776000\n" +
"Issuer: HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd\n" +
......
......@@ -519,7 +519,7 @@ function BlockCheckerDao (block) {
else if (block.number == 83)
done(null, { date: 1411777000, confirmedDate: 1411777000, confirmedDateChanged: true });
// Tests for TrialLevel
else if (block.number >= 60 && block.number <= 66)
else if (block.number >= 60 && block.number <= 67)
done(null, { number: block.number - 1 });
else if (block.number == 90)
done(null, { date: 1443333600, confirmedDate: 1443333600, confirmedDateChanged: true });
......@@ -532,6 +532,20 @@ function BlockCheckerDao (block) {
done(null, { hash: 'DA39A3EE5E6B4B0D3255BFEF95601890AFD80709', confirmedDate: 1411773000 });
else if (number == 70)
done(null, { confirmedDate: 1411775000 });
else if (number == 59)
done(null, { issuer: 'G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU' });
else if (number == 61)
done(null, { issuer: 'G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU' });
else if (number == 62)
done(null, { issuer: 'AbCCJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd' });
else if (number == 63)
done(null, { issuer: 'AbCCJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd' });
else if (number == 64)
done(null, { issuer: 'G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU' });
else if (number == 65)
done(null, { issuer: 'AbCCJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd' });
else if (number == 66)
done(null, { issuer: 'AbCCJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd' });
else
done('No block found', null);
}
......@@ -551,7 +565,7 @@ function BlockCheckerDao (block) {
if (block.number == 60 && issuer == 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd') {
done(null, [{
number: 59,
hash: '0000AB8A955B2196FB8560DCDA7A70B19DDB3433' // 4 zeros + 2 blocks following - 0 since = 4 required zeros
hash: '0000AB8A955B2196FB8560DCDA7A70B19DDB3433' // 4 zeros + 0 interblock - 0 block since = 4 required zeros
},{
number: 58,
}]);
......@@ -562,18 +576,18 @@ function BlockCheckerDao (block) {
},{
number: 58,
}]);
} else if (block.number == 62 && issuer == 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd') {
} else if (block.number == 66 && issuer == 'AbCCJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd') {
done(null, [{
number: 65,
hash: '0123458A955B2196FB8560DCDA7A70B19DDB3433'
}]);
} else if (block.number == 67 && issuer == 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd') {
done(null, [{
number: 60,
hash: '0000008A955B2196FB8560DCDA7A70B19DDB3433' // 6 zeros + 1 interblock - 1 block since = 6 required zeros
hash: '0000008A955B2196FB8560DCDA7A70B19DDB3433' // 6 zeros + 2 (3 blocks with 2 diff. issuers) interblock - 2 (3 blocks with 2 diff. issuers) block since = 6 required zeros
},{
number: 58,
}]);
}else if (block.number == 66 && issuer == 'AbCCJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd') {
done(null, [{
number: 65,
hash: '0123458A955B2196FB8560DCDA7A70B19DDB3433'
}]);
} else {
done(null, null);
}
......
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