diff --git a/app/lib/computation/BlockchainContext.ts b/app/lib/computation/BlockchainContext.ts index 3348fa911860bc0c8b96a0e906ea410f893e1062..9ca3e66e5281a46cf6e4edc19a098c96a861d277 100644 --- a/app/lib/computation/BlockchainContext.ts +++ b/app/lib/computation/BlockchainContext.ts @@ -18,6 +18,7 @@ import { FileDAL } from "../dal/fileDAL"; import { DBBlock } from "../db/DBBlock"; import { Underscore } from "../common-libs/underscore"; import { DataErrors } from "../common-libs/errors"; +import { Map } from "../common-libs/crypto/map"; const indexer = require("../indexer").Indexer; const constants = require("../constants"); @@ -213,12 +214,21 @@ export class BlockchainContext { return this.dal.getCurrentBlockOrNull(); } - async checkHaveEnoughLinks(target: string, newLinks: any): Promise<any> { - const links = await this.dal.getValidLinksTo(target); - let count = links.length; + async checkHaveEnoughLinks( + target: string, + newLinks: Map<string[]> + ): Promise<void> { + const existingLinks = await this.dal.getValidLinksTo(target); + const existingIssuers = existingLinks.map((value) => value.issuer); + let count = existingIssuers.length; + if (newLinks[target] && newLinks[target].length) { - count += newLinks[target].length; + const uniqIssuers = Underscore.uniq( + existingIssuers.concat(newLinks[target]) + ); + count = uniqIssuers.length; } + if (count < this.conf.sigQty) { throw ( "Key " + 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 e89ba363726d1f0e346eaa82ccbd699c4a65db51..a534c57514696ae9d56f0e453aa0526d3d140d68 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 @@ -81,8 +81,17 @@ describe('A member coming back with less than `sigQty` valid certs total', () => 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') - // toc is **NOT** coming back! not enough certs + const join = await toc.makeMembership('IN'); + + // Inject c1 & join in mempool + await cat.sendCert(c1) + await toc.sendMembership(join) + + // Generate potential next bloc, must NOT include toc join (#1402) + const b_gen = s1.generateNext({ time: now + 13 }) + assertEqual((await b_gen).joiners.length, 0); + + // Try to force toc coming back, must be fail because toc not have enough certs (#1394) await assertThrows(s1.commit({ time: now + 13, joiners: [join], @@ -90,13 +99,13 @@ describe('A member coming back with less than `sigQty` valid certs total', () => }), 'BLOCK_WASNT_COMMITTED') // BUT is coming back with 1 more cert const c2 = await tac.makeCert(toc) - const b = await s1.commit({ + const b2 = await s1.commit({ time: now + 13, joiners: [join], certifications: [c1, c2] }) - assertEqual(b.membersCount, 3) // <--- toc is welcome back :) - assertEqual(b.number, 12) + assertEqual(b2.membersCount, 3) // <--- toc is welcome back :) + assertEqual(b2.number, 12) }) after(() => { diff --git a/test/integration/tools/TestUser.ts b/test/integration/tools/TestUser.ts index 375b7b1071c1333ac11d6ac372ce118704c829a7..86619853e5d7637128ea72e4e9935174c69185f8 100644 --- a/test/integration/tools/TestUser.ts +++ b/test/integration/tools/TestUser.ts @@ -98,7 +98,7 @@ export class TestUser { return this.createdIdentity } - public async makeCert(user:TestUser, fromServer?:TestingServer, overrideProps?:any) { + public async makeCert(user:TestUser, fromServer?:TestingServer, overrideProps?:any): Promise<CertificationDTO> { const lookup = await this.lookup(user.pub, fromServer) const current = await this.node.server.BlockchainService.current() const idty = Underscore.filter(lookup.results[0].uids, uidEntry => uidEntry.uid === user.uid)[0] diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts index 4ffb3d58debc3afc0a651664eef340c199e504b6..312b7f8c08eb559c22cf84743a79803d2c263c9c 100644 --- a/test/integration/tools/toolbox.ts +++ b/test/integration/tools/toolbox.ts @@ -528,7 +528,7 @@ export class TestingServer { return blocksResolved } - private generateNext(options:any) { + async generateNext(options:any) { const server = this.server as any // Brings a priver to the server if (!server._utProver) {