Mise à jour de GitLab prévue ce samedi 23 octobre 2021 à partir de 9h00 CET

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

[fix] #1338 Quick sync UD computation might be incorrect sometimes

parent a1567bb2
......@@ -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
}
......@@ -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;
......
......@@ -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)
......
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