diff --git a/app/lib/computation/blockchainContext.js b/app/lib/computation/blockchainContext.js index 62469c38de20fc30f8cfd02a957b1d32574a9e2f..90dffbbf0837318ab091869865ce0974cbbfd319 100644 --- a/app/lib/computation/blockchainContext.js +++ b/app/lib/computation/blockchainContext.js @@ -196,9 +196,9 @@ function BlockchainContext() { // BR_G85 if (indexer.ruleMembershipExcludedIsMember(iindex) === false) throw Error('ruleMembershipExcludedIsMember'); // BR_G86 - if (indexer.ruleToBeKickedArePresent(mindex, dal) === false) throw Error('ruleToBeKickedArePresent'); + if ((yield indexer.ruleToBeKickedArePresent(iindex, dal)) === false) throw Error('ruleToBeKickedArePresent'); // BR_G103 - if (indexer.ruleTxWritability(sindex) === false) throw Error('ruleToBeKickedArePresent'); + if (indexer.ruleTxWritability(sindex) === false) throw Error('ruleTxWritability'); // BR_G87 if (indexer.ruleInputIsAvailable(sindex) === false) throw Error('ruleInputIsAvailable'); // BR_G88 diff --git a/app/lib/dup/indexer.js b/app/lib/dup/indexer.js index ef596902a93a7b4a834a2d0e544a217bc7799a01..09f34517530b44d5022a04df2c2155012f9f3a80 100644 --- a/app/lib/dup/indexer.js +++ b/app/lib/dup/indexer.js @@ -1198,10 +1198,10 @@ const indexer = module.exports = { }, // BR_G86 - ruleToBeKickedArePresent: (mindex, dal) => co(function*() { + ruleToBeKickedArePresent: (iindex, dal) => co(function*() { const toBeKicked = yield dal.iindexDAL.getToBeKickedPubkeys(); 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; } } @@ -1395,7 +1395,7 @@ const indexer = module.exports = { for (const CERT of expiredCerts) { 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 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) { exclusions.push({ op: 'UPDATE', diff --git a/doc/Protocol.md b/doc/Protocol.md index bdf596fe52d30254fc078de0b36f7a92f08317cb..379382a289c7c88f7ff280768abf35d001f4b9ae 100644 --- a/doc/Protocol.md +++ b/doc/Protocol.md @@ -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`: -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 ( op = 'UPDATE' diff --git a/test/integration/identity-kicking-by-certs.js b/test/integration/identity-kicking-by-certs.js new file mode 100644 index 0000000000000000000000000000000000000000..97e08cfeef1fee648ceb3671cb9b205adb129a48 --- /dev/null +++ b/test/integration/identity-kicking-by-certs.js @@ -0,0 +1,70 @@ +"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); + })); +}); diff --git a/test/integration/tools/toolbox.js b/test/integration/tools/toolbox.js index 5d8b3a8013e7cefdce3ee26b566e73666a22788e..0ab854ec46155b7a18c46a1cf235cca37294476a 100644 --- a/test/integration/tools/toolbox.js +++ b/test/integration/tools/toolbox.js @@ -184,9 +184,11 @@ module.exports = { remoteipv4: HOST, currency: conf.currency || CURRENCY_NAME, httpLogs: true, - forksize: 3, - sigQty: 1 + forksize: 3 }; + if (conf.sigQty === undefined) { + conf.sigQty = 1; + } const server = duniter( '~/.config/duniter/' + (conf.homename || 'dev_unit_tests'), conf.memory !== undefined ? conf.memory : MEMORY_MODE,