Commit f74f9414 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] #1396: ensure that the bug is fixed => now the revert is neutral again

parent a5bf0786
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
import {MonitorExecutionTime} from "../../../debug/MonitorExecutionTime"
import {CindexEntry, FullCindexEntry, Indexer, reduceBy} from "../../../indexer"
import {CindexEntry, FullCindexEntry, Indexer, reduce, reduceBy} from "../../../indexer"
import {LevelUp} from 'levelup'
import {LevelDBTable} from "./LevelDBTable"
import {Underscore} from "../../../common-libs/underscore"
@@ -147,11 +147,18 @@ export class LevelDBCindex extends LevelDBTable<LevelDBCindexEntry> implements C
    }
    // Remove the "received" arrays
    for (const e of toRemove) {
      const entry = await this.get(e.receiver)
      const receiver = await this.get(e.receiver)
      const issuer = await this.get(e.issuer)
      const certification = reduce(issuer.issued.filter(i => i.receiver === e.receiver))
      // We remove ONLY IF no valid link still exist, i.e. we remove if the link **has expired** (we may be here because
      // of a certification replay before term that is being reverted ==> in such case, even after the revert, the link
      // between issuer and receiver is still valid. So don't remove it.
      if (certification.expired_on) {
        // Remove the certification
      entry.received = entry.received.filter(issuer => issuer !== e.issuer)
        receiver.received = receiver.received.filter(issuer => issuer !== e.issuer)
        // Persist
      await this.put(e.receiver, entry)
        await this.put(e.receiver, receiver)
      }
    }
    // Remove the expires_on index entries
    const expires = Underscore.uniq(toRemove.filter(e => e.expires_on).map(e => e.expires_on))
+3 −4
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@
// GNU Affero General Public License for more details.

import {assertEqual, writeBasicTestWithConfAnd2Users} from "../tools/test-framework"
import {assertThrows} from "../../unit-tools"
import {CommonConstants} from "../../../app/lib/common-libs/constants"

const currentVersion = CommonConstants.BLOCK_GENERATED_VERSION
@@ -105,10 +104,10 @@ describe('Block revert with a comebacker in it', () => writeBasicTestWithConfAnd
  })

  test('(t = 12 #3) resolution should work', async (s1) => {
    await assertThrows(s1.resolve(), 'BLOCK_WASNT_COMMITTED')
    await s1.resolve()
    const b = await s1.dal.getBlockCurrent()
    assertEqual(b.membersCount, 2)
    assertEqual(b.number, 21)
    assertEqual(b.membersCount, 3)
    assertEqual(b.number, 22)
  })

  after(() => {