Commit e4988bbd 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 907a2106
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)
// Remove the certification
entry.received = entry.received.filter(issuer => issuer !== e.issuer)
// Persist
await this.put(e.receiver, entry)
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
receiver.received = receiver.received.filter(issuer => issuer !== e.issuer)
// Persist
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))
......
......@@ -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(() => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment