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

[fix] Disable the trimming within fork resolution

(cherry picked from commit 7104a89)
parent 45278c7d
......@@ -174,13 +174,13 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
return { index, HEAD }
}
async pushTheBlock(obj:BlockDTO, index:IndexEntry[], HEAD:DBHead | null, conf:ConfDTO, dal:any, logger:any) {
async pushTheBlock(obj: BlockDTO, index: IndexEntry[], HEAD: DBHead | null, conf: ConfDTO, dal: any, logger: any, trim = true) {
const start = Date.now();
const block = BlockDTO.fromJSONObject(obj)
try {
const currentBlock = await dal.getCurrentBlockOrNull();
block.fork = false;
const added = await this.saveBlockData(currentBlock, block, conf, dal, logger, index, HEAD);
const added = await this.saveBlockData(currentBlock, block, conf, dal, logger, index, HEAD, trim);
try {
await DuniterBlockchain.pushStatsForBlocks([block], dal);
......@@ -201,7 +201,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
// await supra.recordIndex(index)
}
async saveBlockData(current:DBBlock, block:BlockDTO, conf:ConfDTO, dal:any, logger:any, index:IndexEntry[], HEAD:DBHead | null) {
async saveBlockData(current: DBBlock, block: BlockDTO, conf: ConfDTO, dal: any, logger: any, index: IndexEntry[], HEAD: DBHead | null, trim: boolean) {
if (block.number == 0) {
await this.saveParametersForRoot(block, conf, dal);
}
......@@ -224,19 +224,21 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
// Update the wallets' blances
await this.updateWallets(indexes.sindex, dal)
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 currentSize = indexes.HEAD.number - TAIL.number + 1
if (currentSize > MAX_BINDEX_SIZE) {
await dal.trimIndexes(indexes.HEAD.number - MAX_BINDEX_SIZE);
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 currentSize = indexes.HEAD.number - TAIL.number + 1
if (currentSize > MAX_BINDEX_SIZE) {
await dal.trimIndexes(indexes.HEAD.number - MAX_BINDEX_SIZE);
}
}
const dbb = DBBlock.fromBlockDTO(block)
......
......@@ -118,8 +118,8 @@ export class BlockchainContext {
return DuniterBlockchain.checkBlock(block, withPoWAndSignature, this.conf, this.dal)
}
private async addBlock(obj: BlockDTO, index: any = null, HEAD: DBHead | null = null): Promise<any> {
const block = await this.blockchain.pushTheBlock(obj, index, HEAD, this.conf, this.dal, this.logger)
private async addBlock(obj: BlockDTO, index: any = null, HEAD: DBHead | null = null, trim: boolean): Promise<any> {
const block = await this.blockchain.pushTheBlock(obj, index, HEAD, this.conf, this.dal, this.logger, trim)
this.vHEAD_1 = this.vHEAD = this.HEADrefreshed = null
return block
}
......@@ -150,9 +150,9 @@ export class BlockchainContext {
this.logger.debug('Applied block #%s', block.number);
}
async checkAndAddBlock(block:BlockDTO) {
async checkAndAddBlock(block:BlockDTO, trim = true) {
const { index, HEAD } = await this.checkBlock(block, constants.WITH_SIGNATURES_AND_POW);
return await this.addBlock(block, index, HEAD);
return await this.addBlock(block, index, HEAD, trim);
}
current(): Promise<any> {
......
......@@ -104,7 +104,7 @@ export class BlockchainService extends FIFOService {
}
async addBlock(block: BlockDTO): Promise<BlockDTO> {
return await this.bcService.mainContext.checkAndAddBlock(block)
return await this.bcService.mainContext.checkAndAddBlock(block, false)
}
})(this)
......
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