diff --git a/app/lib/dal/indexDAL/leveldb/LevelDBCindex.ts b/app/lib/dal/indexDAL/leveldb/LevelDBCindex.ts index b776a4ea7155ea9f803bb6f56cadc0b5fa699dbb..cdc57532eb168939e6e87a2169a53466a29d4f53 100644 --- a/app/lib/dal/indexDAL/leveldb/LevelDBCindex.ts +++ b/app/lib/dal/indexDAL/leveldb/LevelDBCindex.ts @@ -223,7 +223,8 @@ export class LevelDBCindex extends LevelDBTable<LevelDBCindexEntry> implements C const receiver = (await this.getOrNull(pub)) || { issued: [], received: [] } const issuers = receiver.received return (await Promise.all(issuers.map(async issuer => { - return (await this.get(issuer)).issued.filter(e => e.receiver === pub && e.expired_on === 0) + const fullEntries = Indexer.DUP_HELPERS.reduceBy((await this.get(issuer)).issued, ['issuer', 'receiver']) + return fullEntries.filter(e => e.receiver === pub && e.expired_on === 0) }))).reduce(reduceConcat, []) } diff --git a/app/lib/indexer.ts b/app/lib/indexer.ts index 72377e871226a29aeef88e60116f5b9a7b83fe90..bb6a18363c4bffbbbc4bcad9bb8c71fa81d6ecf1 100644 --- a/app/lib/indexer.ts +++ b/app/lib/indexer.ts @@ -883,9 +883,10 @@ export class Indexer { // BR_G27 await Promise.all(mindex.map(async (ENTRY: MindexEntry) => { if (ENTRY.type == 'JOIN' || ENTRY.type == 'ACTIVE') { - const existing = count(await dal.cindexDAL.findByReceiverAndExpiredOn(ENTRY.pub, 0)) - const pending = count(Underscore.filter(cindex, (c:CindexEntry) => c.receiver == ENTRY.pub && c.expired_on == 0)) - ENTRY.enoughCerts = (existing + pending) >= conf.sigQty; + const existing = (await dal.cindexDAL.findByReceiverAndExpiredOn(ENTRY.pub, 0)).map(value => value.issuer) + const pending = Underscore.filter(cindex, (c:CindexEntry) => c.receiver == ENTRY.pub && c.expired_on == 0).map(value => value.issuer) + const uniqIssuers = Underscore.uniq(existing.concat(pending)) + ENTRY.enoughCerts = count(uniqIssuers) >= conf.sigQty; } else { ENTRY.enoughCerts = true; } diff --git a/test/integration/fork-resolution/coming-back-with-less-than-sigqty.ts b/test/integration/fork-resolution/coming-back-with-less-than-sigqty.ts index a6afdc65b285c86af47facb8a721088d79a77b2c..e89ba363726d1f0e346eaa82ccbd699c4a65db51 100644 --- a/test/integration/fork-resolution/coming-back-with-less-than-sigqty.ts +++ b/test/integration/fork-resolution/coming-back-with-less-than-sigqty.ts @@ -13,6 +13,7 @@ import {assertEqual, writeBasicTestWithConfAnd2Users} from "../tools/test-framework" import {CommonConstants} from "../../../app/lib/common-libs/constants" +import {assertThrows} from "../../unit-tools" const currentVersion = CommonConstants.BLOCK_GENESIS_VERSION @@ -76,17 +77,25 @@ describe('A member coming back with less than `sigQty` valid certs total', () => assertEqual(b.excluded[0], toc.pub) }) - test('(t = 13 #1) toc is coming back with 1 cert only! a renewal counted twice', async (s1, cat, tac, toc) => { + test('(t = 13) toc is NOT coming back with 1 cert only!', async (s1, cat, tac, toc) => { await s1.commit({ time: now + 13 }) await s1.commit({ time: now + 13 }) const c1 = await cat.makeCert(toc) // <-- a renewal ==> this is what we want to observe const join = await toc.makeMembership('IN') - const b = await s1.commit({ + // toc is **NOT** coming back! not enough certs + await assertThrows(s1.commit({ time: now + 13, joiners: [join], certifications: [c1] + }), 'BLOCK_WASNT_COMMITTED') + // BUT is coming back with 1 more cert + const c2 = await tac.makeCert(toc) + const b = await s1.commit({ + time: now + 13, + joiners: [join], + certifications: [c1, c2] }) - assertEqual(b.membersCount, 3) + assertEqual(b.membersCount, 3) // <--- toc is welcome back :) assertEqual(b.number, 12) })