Commit f1a164d8 authored by Cédric Moreau's avatar Cédric Moreau

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

[fix] #1338 Quick sync UD computation might be incorrect sometimes (cherry-picked + adapted from dev)
parent 222c50ff
......@@ -226,15 +226,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
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.trimIndexes(indexes.HEAD.number - MAX_BINDEX_SIZE);
......@@ -554,3 +546,15 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
await indexRevert(head.number)
}
}
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
}
......@@ -12,7 +12,7 @@
// GNU Affero General Public License for more details.
"use strict"
import {DuniterBlockchain} from "../blockchain/DuniterBlockchain";
import {DuniterBlockchain, requiredBindexSizeForTail} from "../blockchain/DuniterBlockchain"
import {BlockDTO} from "../dto/BlockDTO";
import {DBTransaction} from "../db/DBTransaction";
import {Indexer} from "../indexer";
......@@ -121,7 +121,8 @@ export class QuickSynchronizer {
sync_currConf = BlockDTO.getConf(block);
}
if (block.number <= to - this.conf.forksize) {
const bindexSize = requiredBindexSizeForTail(block, this.conf)
if (block.number <= to - bindexSize - 1) {
blocksToSave.push(dto);
const index:any = Indexer.localIndex(dto, sync_currConf);
const local_iindex = Indexer.iindex(index);
......
......@@ -483,15 +483,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);
......@@ -510,6 +501,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);
......@@ -1032,7 +1029,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;
......
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