From 60266f5d25cb95d69bb199177b5c26d73bab9278 Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Wed, 29 Apr 2020 16:46:23 +0200 Subject: [PATCH] [fix]computation:checkHaveEnoughLinks must never count same issuer twice #1402 --- app/lib/computation/BlockchainContext.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/lib/computation/BlockchainContext.ts b/app/lib/computation/BlockchainContext.ts index 3348fa911..9ca3e66e5 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 " + -- GitLab