From fe79d0a6dfa0812def2aebd6d951b193b146980c Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Wed, 12 Feb 2020 19:38:47 +0100
Subject: [PATCH] [fix] #1394: implement DUBP v12

---
 app/lib/dal/indexDAL/leveldb/LevelDBCindex.ts     |  3 ++-
 .../coming-back-with-less-than-sigqty.ts          | 15 ++++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/app/lib/dal/indexDAL/leveldb/LevelDBCindex.ts b/app/lib/dal/indexDAL/leveldb/LevelDBCindex.ts
index b776a4ea7..cdc57532e 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/test/integration/fork-resolution/coming-back-with-less-than-sigqty.ts b/test/integration/fork-resolution/coming-back-with-less-than-sigqty.ts
index a6afdc65b..11b0e48f1 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 #1) 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)
   })
 
-- 
GitLab