diff --git a/app/lib/blockchain/DuniterBlockchain.ts b/app/lib/blockchain/DuniterBlockchain.ts index 4bdee7568baafdde0ec680e027bf70f80b3421d5..08015ba1bdbb3ea9e4233120fff4bf195178f032 100644 --- a/app/lib/blockchain/DuniterBlockchain.ts +++ b/app/lib/blockchain/DuniterBlockchain.ts @@ -240,15 +240,7 @@ export class DuniterBlockchain { if (trim) { const TAIL = await dal.bindexDAL.tail(); - const bindexSize = [ - TAIL.issuersCount, - TAIL.issuersFrame, - conf.medianTimeBlocks, - conf.dtDiffEval - ].reduce((max, value) => { - return Math.max(max, value); - }, 0); - const MAX_BINDEX_SIZE = conf.forksize + bindexSize + const MAX_BINDEX_SIZE = requiredBindexSizeForTail(TAIL, conf) const currentSize = indexes.HEAD.number - TAIL.number + 1 if (currentSize > MAX_BINDEX_SIZE) { await dal.archiveBlocks() @@ -582,3 +574,15 @@ export class DuniterBlockchain { } } } + +export function requiredBindexSizeForTail(TAIL: { issuersCount: number, issuersFrame: number }, conf: { medianTimeBlocks: number, dtDiffEval: number, forksize: number }) { + const bindexSize = [ + TAIL.issuersCount, + TAIL.issuersFrame, + conf.medianTimeBlocks, + conf.dtDiffEval + ].reduce((max, value) => { + return Math.max(max, value); + }, 0); + return conf.forksize + bindexSize +} diff --git a/app/lib/indexer.ts b/app/lib/indexer.ts index 8e600814331437b5341678d0a45fa94ddcd14c11..cca42a91f56e0175db425989c1b49501ba365de1 100644 --- a/app/lib/indexer.ts +++ b/app/lib/indexer.ts @@ -585,15 +585,6 @@ export class Indexer { const HEAD_1 = await head(1); - if (HEAD.number == 0) { - HEAD.dividend = conf.ud0; - } - else if (!HEAD.dividend) { - HEAD.dividend = HEAD_1.dividend; - } else { - HEAD.new_dividend = HEAD.dividend; - } - // BR_G04 await Indexer.prepareIssuersCount(HEAD, range, HEAD_1); @@ -612,6 +603,12 @@ export class Indexer { // BR_G11 Indexer.prepareUDTime(HEAD, HEAD_1, conf) + // BR_G13 + Indexer.prepareDividend(HEAD, HEAD_1, conf) + + // BR_G14 + Indexer.prepareUnitBase(HEAD); + // BR_G15 Indexer.prepareMass(HEAD, HEAD_1); @@ -1148,7 +1145,7 @@ export class Indexer { } // BR_G13 - static prepareDividend(HEAD: DBHead, HEAD_1: DBHead, conf: ConfDTO) { + static prepareDividend(HEAD: DBHead, HEAD_1: DBHead, conf: CurrencyConfDTO) { // UD re-evaluation if (HEAD.number == 0) { HEAD.dividend = conf.ud0; diff --git a/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts b/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts index be25b7df20b36f64014c2849a6192f36747cb94f..c78f85eadd4e4afb0ce18b5c0cb782079a48ec56 100644 --- a/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts +++ b/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts @@ -11,7 +11,7 @@ import { } from "../../../../../lib/indexer" import {ConfDTO, CurrencyConfDTO} from "../../../../../lib/dto/ConfDTO" import {FileDAL} from "../../../../../lib/dal/fileDAL" -import {DuniterBlockchain} from "../../../../../lib/blockchain/DuniterBlockchain" +import {DuniterBlockchain, requiredBindexSizeForTail} from "../../../../../lib/blockchain/DuniterBlockchain" import {BlockDTO} from "../../../../../lib/dto/BlockDTO" import {Underscore} from "../../../../../lib/common-libs/underscore" import {MonitorExecutionTime} from "../../../../../lib/debug/MonitorExecutionTime" @@ -175,7 +175,8 @@ export class GlobalIndexStream extends Duplex { await DuniterBlockchain.saveParametersForRoot(block, this.conf, this.dal) } - if ((block.number <= this.to - this.conf.forksize || cliprogram.noSources) && !this.cautious) { // If we require nosources option, this blockchain can't be valid so we don't make checks + const bindexSize = requiredBindexSizeForTail(block, this.conf) + if ((block.number <= this.to - bindexSize - 1 || cliprogram.noSources) && !this.cautious) { // If we require nosources option, this blockchain can't be valid so we don't make checks const HEAD = await Indexer.quickCompleteGlobalScope(block, this.sync_currConf, sync_bindex, data.iindex, data.mindex, data.cindex, this.dal) sync_bindex.push(HEAD)