diff --git a/app/cli.ts b/app/cli.ts index e6ae5f105d800b0a16607b3b0017cacf17b8e5ed..cf82db86832e1874407a607b01b7df2d180cd831 100644 --- a/app/cli.ts +++ b/app/cli.ts @@ -74,6 +74,7 @@ export const ExecuteCommand = () => { .option('--isolate', 'Avoid the node to send peering or status informations to the network') .option('--forksize <size>', 'Maximum size of fork window', parseInt) .option('--notrim', 'Disable the INDEX trimming.') + .option('--notrimc', 'Disable the C_INDEX trimming specifically.') .option('--memory', 'Memory mode') ; diff --git a/app/lib/common-libs/programOptions.ts b/app/lib/common-libs/programOptions.ts index d90019f2a444509bcd27e951bdb4b314c10ec1f2..a845061ed951fbdedad44e81d56b9f50a5b91208 100644 --- a/app/lib/common-libs/programOptions.ts +++ b/app/lib/common-libs/programOptions.ts @@ -17,6 +17,7 @@ export interface ProgramOptions { mdb?: string home?: string notrim?: boolean + notrimc?: boolean // Specificaly disable for c_index nosbx?: boolean nopeers?: boolean nop2p?: boolean diff --git a/app/lib/dal/fileDAL.ts b/app/lib/dal/fileDAL.ts index 0f701ccb194eea9d00717f11d843f99a7f3e6e1b..ea1b100213a1502c204c14524932339f21644f40 100644 --- a/app/lib/dal/fileDAL.ts +++ b/app/lib/dal/fileDAL.ts @@ -1089,7 +1089,9 @@ export class FileDAL { await this.bindexDAL.trimBlocks(maxNumber) await this.iindexDAL.trimRecords(maxNumber) await this.mindexDAL.trimRecords(maxNumber) - await this.cindexDAL.trimExpiredCerts(maxNumber) + if (!cliprogram.notrimc) { + await this.cindexDAL.trimExpiredCerts(maxNumber) + } } await this.sindexDAL.trimConsumedSource(maxNumber) await this.dividendDAL.trimConsumedUDs(maxNumber) diff --git a/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts b/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts index 10017b3a8d63dadcf25f3cb90e9098231ffef2ae..c0efdb9d084c61cf3ac630e5ec0c4000cf92ffaf 100644 --- a/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts +++ b/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts @@ -275,8 +275,8 @@ export class GlobalIndexStream extends Duplex { }) } - if (data.cindex.length) { - await this.updateWotbLinks(data.cindex) + if (sync_cindex.length) { + await this.updateWotbLinks(sync_cindex) } gData.gindex.iindex = sync_iindex gData.gindex.mindex = sync_mindex diff --git a/app/modules/dump.ts b/app/modules/dump.ts index 79851e6c29c73b27b9b9c1c5ec2550c8a01f5a30..95148fd221bc4aad253f92de17595da9a70f3a1c 100644 --- a/app/modules/dump.ts +++ b/app/modules/dump.ts @@ -22,6 +22,7 @@ import {dumpWotWizard} from "./dump/wotwizard/wotwizard.dump" import {OtherConstants} from "../lib/other_constants" import {Querable, querablep} from "../lib/common-libs/querable" import {dumpBlocks, dumpForks} from "./dump/blocks/dump.blocks" +import {newResolveTimeoutPromise} from "../lib/common-libs/timeout-promise" const Table = require('cli-table') @@ -88,6 +89,10 @@ module.exports = { await dumpTable(server, name, cond) break + case 'wot': + await dumpWot(server) + break + case 'history': await dumpHistory(server, name) break @@ -181,7 +186,7 @@ async function dumpTable(server: Server, name: string, condition?: string) { break case 'c_index': rows = await server.dal.cindexDAL.findRawWithOrder(criterion, [['writtenOn', false], ['issuer', false], ['receiver', false]]) - dump(rows, ['op','issuer','receiver','created_on','written_on','sig','expires_on','expired_on','chainable_on','from_wid','to_wid']) + dump(rows, ['op','issuer','receiver','created_on','written_on','sig','expires_on','expired_on','chainable_on','from_wid','to_wid','replayable_on']) break case 's_index': const rowsTX = await server.dal.sindexDAL.findRawWithOrder(criterion, [['writtenOn', false], ['identifier', false], ['pos', false]]) @@ -256,6 +261,12 @@ async function dumpHistory(server: Server, pub: string) { } } +async function dumpWot(server: Server) { + const data = server.dal.wotb.dumpWoT() + console.log(data) + await newResolveTimeoutPromise(1000, null) +} + async function getDateFor(server: Server, blockstamp: string) { const b = (await server.dal.getAbsoluteBlockByBlockstamp(blockstamp)) as DBBlock const s = " " + b.number diff --git a/test/integration/certification/certification-replay.ts b/test/integration/certification/certification-replay.ts index 450eb99e88cf2e07432ba62993eac01dd4bd5aef..88ddce86fe94b0ae3a20bda300ecf305a19e41b5 100644 --- a/test/integration/certification/certification-replay.ts +++ b/test/integration/certification/certification-replay.ts @@ -72,6 +72,59 @@ describe('Certification replay', () => writeBasicTestWithConfAnd2Users({ assertEqual(reduce(reducableFromCat).expires_on, now + 4 + 10) // The expiration date should have changed! (this is the interest of a replay) }) + test('should correctly update wotb: current state', async (s1) => { + assertEqual(s1._server.dal.wotb.dumpWoT(), `[M] [E] [R] [I] -> Links[maxCert = 40] +[0] [1] [1] [1] -> 1 | +[1] [1] [1] [1] -> 0 | +`) + }) + + test('should correctly update wotb: toc joins (t + 6)', async (s1, cat, tac, toc) => { + await s1.commit({ time: now + 6 }) + await s1.commit({ time: now + 6 }) + await toc.createIdentity() + await cat.cert(toc) + await tac.cert(toc) + await toc.join() + await s1.commit({ time: now + 6 }) + assertEqual(s1._server.dal.wotb.dumpWoT(), `[M] [E] [R] [I] -> Links[maxCert = 40] +[0] [1] [1] [2] -> 1 | +[1] [1] [1] [2] -> 0 | +[2] [1] [2] [0] -> 0 | 1 | +`) + }) + + test('should correctly update wotb: toc => cat', async (s1, cat, tac, toc) => { + await s1.commit({ time: now + 6 }) + await toc.cert(cat) + await s1.commit({ time: now + 12 }) + assertEqual(s1._server.dal.wotb.dumpWoT(), `[M] [E] [R] [I] -> Links[maxCert = 40] +[0] [1] [2] [2] -> 1 | 2 | +[1] [1] [1] [2] -> 0 | +[2] [1] [2] [1] -> 0 | 1 | +`) + }) + + test('should correctly update wotb: cat loses 1 cert', async (s1) => { + await s1.commit({ time: now + 12 }) + assertEqual(s1._server.dal.wotb.dumpWoT(), `[M] [E] [R] [I] -> Links[maxCert = 40] +[0] [1] [1] [2] -> 2 | +[1] [1] [1] [1] -> 0 | +[2] [1] [2] [1] -> 0 | 1 | +`) + }) + + test('should correctly update wotb: tac loses 1 cert and gets kicked', async (s1) => { + await s1.commit({ time: now + 14 }) // Change `Time` + await s1.commit({ time: now + 14 }) // Change `MedianTime` + await s1.commit({ time: now + 14 }) // Kick + assertEqual(s1._server.dal.wotb.dumpWoT(), `[M] [E] [R] [I] -> Links[maxCert = 40] +[0] [1] [1] [1] -> 2 | +[1] [0] [0] [1] -> +[2] [1] [2] [1] -> 0 | 1 | +`) + }) + after(() => { CommonConstants.BLOCK_NEW_GENERATED_VERSION = 10 })