Skip to content
Snippets Groups Projects
Commit 4ca160dc authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] #842 Critical bug on member's exclusion

parent 586bc765
No related branches found
No related tags found
No related merge requests found
...@@ -196,9 +196,9 @@ function BlockchainContext() { ...@@ -196,9 +196,9 @@ function BlockchainContext() {
// BR_G85 // BR_G85
if (indexer.ruleMembershipExcludedIsMember(iindex) === false) throw Error('ruleMembershipExcludedIsMember'); if (indexer.ruleMembershipExcludedIsMember(iindex) === false) throw Error('ruleMembershipExcludedIsMember');
// BR_G86 // BR_G86
if (indexer.ruleToBeKickedArePresent(mindex, dal) === false) throw Error('ruleToBeKickedArePresent'); if ((yield indexer.ruleToBeKickedArePresent(iindex, dal)) === false) throw Error('ruleToBeKickedArePresent');
// BR_G103 // BR_G103
if (indexer.ruleTxWritability(sindex) === false) throw Error('ruleToBeKickedArePresent'); if (indexer.ruleTxWritability(sindex) === false) throw Error('ruleTxWritability');
// BR_G87 // BR_G87
if (indexer.ruleInputIsAvailable(sindex) === false) throw Error('ruleInputIsAvailable'); if (indexer.ruleInputIsAvailable(sindex) === false) throw Error('ruleInputIsAvailable');
// BR_G88 // BR_G88
......
...@@ -1198,10 +1198,10 @@ const indexer = module.exports = { ...@@ -1198,10 +1198,10 @@ const indexer = module.exports = {
}, },
// BR_G86 // BR_G86
ruleToBeKickedArePresent: (mindex, dal) => co(function*() { ruleToBeKickedArePresent: (iindex, dal) => co(function*() {
const toBeKicked = yield dal.iindexDAL.getToBeKickedPubkeys(); const toBeKicked = yield dal.iindexDAL.getToBeKickedPubkeys();
for (const toKick of toBeKicked) { for (const toKick of toBeKicked) {
if (count(_.where(mindex, { pub: toKick, isBeingKicked: true })) !== 1) { if (count(_.where(iindex, { pub: toKick, isBeingKicked: true })) !== 1) {
return false; return false;
} }
} }
...@@ -1395,7 +1395,7 @@ const indexer = module.exports = { ...@@ -1395,7 +1395,7 @@ const indexer = module.exports = {
for (const CERT of expiredCerts) { for (const CERT of expiredCerts) {
const just_expired = _.filter(cindex, (c) => c.receiver == CERT.receiver && c.expired_on > 0); const just_expired = _.filter(cindex, (c) => c.receiver == CERT.receiver && c.expired_on > 0);
const just_received = _.filter(cindex, (c) => c.receiver == CERT.receiver && c.expired_on == 0); const just_received = _.filter(cindex, (c) => c.receiver == CERT.receiver && c.expired_on == 0);
const non_expired_global = yield dal.cindexDAL.sqlFind({ receiver: CERT.receiver, expired_on: 0 }); const non_expired_global = yield dal.cindexDAL.getValidLinksTo(CERT.receiver);
if ((count(non_expired_global) - count(just_expired) + count(just_received)) < conf.sigQty) { if ((count(non_expired_global) - count(just_expired) + count(just_received)) < conf.sigQty) {
exclusions.push({ exclusions.push({
op: 'UPDATE', op: 'UPDATE',
......
...@@ -2446,7 +2446,11 @@ For each `LOCAL_MINDEX[expired_on!=0] as MS`, add a new LOCAL_IINDEX entry: ...@@ -2446,7 +2446,11 @@ For each `LOCAL_MINDEX[expired_on!=0] as MS`, add a new LOCAL_IINDEX entry:
For each `LOCAL_CINDEX[expired_on!=0] as CERT`: For each `LOCAL_CINDEX[expired_on!=0] as CERT`:
If `COUNT(GLOBAL_CINDEX[receiver=CERT.receiver]) + COUNT(LOCAL_CINDEX[receiver=CERT.receiver,expired_on=0]) - COUNT(LOCAL_CINDEX[receiver=CERT.receiver,expired_on!=0]) < sigQty`, add a new LOCAL_IINDEX entry: Set:
CURRENT_VALID_CERTS = REDUCE_BY(GLOBAL_CINDEX[receiver=CERT.receiver], 'issuer', 'receiver', 'created_on')[expired_on=0]
If `COUNT(CURRENT_VALID_CERTS) + COUNT(LOCAL_CINDEX[receiver=CERT.receiver,expired_on=0]) - COUNT(LOCAL_CINDEX[receiver=CERT.receiver,expired_on!=0]) < sigQty`, add a new LOCAL_IINDEX entry:
IINDEX ( IINDEX (
op = 'UPDATE' op = 'UPDATE'
......
"use strict";
const _ = require('underscore');
const co = require('co');
const assert = require('assert');
const duniter = require('../../index');
const bma = require('duniter-bma').duniter.methods.bma;
const user = require('./tools/user');
const constants = require('../../app/lib/constants');
const toolbox = require('./tools/toolbox');
const now = 1480000000;
const s1 = toolbox.server({
pair: {
pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd',
sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'
},
dt: 3600,
ud0: 1200,
xpercent: 0.9,
sigValidity: 5, // 5 second of duration
sigQty: 2
});
const cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 });
const tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 });
const tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 });
const toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 });
const tuc = user('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 });
describe("Identities kicking by certs", function() {
before(() => co(function *() {
yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections());
yield cat.createIdentity();
yield tac.createIdentity();
yield toc.createIdentity();
yield cat.cert(tac);
yield cat.cert(toc);
yield tac.cert(cat);
yield tac.cert(toc);
yield toc.cert(cat);
yield toc.cert(tac);
yield cat.join();
yield tac.join();
yield toc.join();
yield s1.commit({ time: now });
yield s1.commit({ time: now + 3 });
yield s1.commit({ time: now + 5 });
yield tic.createIdentity();
yield cat.cert(tic);
yield tac.cert(tic);
yield tic.cert(cat);
yield tic.join();
yield tuc.createIdentity();
yield s1.commit({ time: now + 8 });
yield cat.cert(tuc);
yield tac.cert(tuc);
yield tuc.cert(cat);
yield tuc.join();
yield s1.commit({ time: now + 10 });
yield s1.commit({ time: now + 10 });
yield s1.commit({ time: now + 10 });
}));
it('block#6 should have kicked 2 member', () => s1.expectThat('/blockchain/block/6', (res) => {
assert.equal(res.excluded.length, 2);
}));
});
...@@ -184,9 +184,11 @@ module.exports = { ...@@ -184,9 +184,11 @@ module.exports = {
remoteipv4: HOST, remoteipv4: HOST,
currency: conf.currency || CURRENCY_NAME, currency: conf.currency || CURRENCY_NAME,
httpLogs: true, httpLogs: true,
forksize: 3, forksize: 3
sigQty: 1
}; };
if (conf.sigQty === undefined) {
conf.sigQty = 1;
}
const server = duniter( const server = duniter(
'~/.config/duniter/' + (conf.homename || 'dev_unit_tests'), '~/.config/duniter/' + (conf.homename || 'dev_unit_tests'),
conf.memory !== undefined ? conf.memory : MEMORY_MODE, conf.memory !== undefined ? conf.memory : MEMORY_MODE,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment