diff --git a/app/lib/blockchain/DuniterBlockchain.ts b/app/lib/blockchain/DuniterBlockchain.ts index a12d9cbaefec8614b314ff5d4486f1efc629d307..fd683b19e792829704a3bac3d1015d654d12e3a0 100644 --- a/app/lib/blockchain/DuniterBlockchain.ts +++ b/app/lib/blockchain/DuniterBlockchain.ts @@ -18,8 +18,8 @@ import { IndexEntry, Indexer, MindexEntry, - SimpleSindexEntryForWallet, SimpleTxEntryForWallet, SimpleUdEntryForWallet, - SindexEntry + SimpleTxEntryForWallet, + SimpleUdEntryForWallet } from "../indexer" import {ConfDTO} from "../dto/ConfDTO" import {BlockDTO} from "../dto/BlockDTO" @@ -37,7 +37,6 @@ import {DataErrors} from "../common-libs/errors" import {NewLogger} from "../logger" import {DBTx} from "../db/DBTx" import {Underscore} from "../common-libs/underscore" -import {DividendEntry, UDSource} from "../dal/indexDAL/abstract/DividendDAO" import {OtherConstants} from "../other_constants" export class DuniterBlockchain { @@ -205,6 +204,13 @@ export class DuniterBlockchain { } logger.info('Block #' + block.number + ' added to the blockchain in %s ms', (Date.now() - start)); + + // Periodically, we trim the blockchain + if (block.number % CommonConstants.BLOCKS_COLLECT_THRESHOLD === 0)Â { + // Database trimming + await dal.loki.flushAndTrimData() + } + return BlockDTO.fromJSONObject(added) } catch(err) { diff --git a/app/lib/common-libs/constants.ts b/app/lib/common-libs/constants.ts index ff000fb76ee3d2b477b01bcddf5af2c3c8dee1bd..3b16ff3e87429ced051393a61703a58f250746cb 100755 --- a/app/lib/common-libs/constants.ts +++ b/app/lib/common-libs/constants.ts @@ -307,6 +307,8 @@ export const CommonConstants = { MAX_AGE_OF_PEER_IN_BLOCKS: 200, // blocks INITIAL_DOWNLOAD_SLOTS: 1, // 1 peer + + BLOCKS_COLLECT_THRESHOLD: 30, // Number of blocks to wait before trimming the loki data } function exact (regexpContent:string) { diff --git a/app/lib/computation/BlockchainContext.ts b/app/lib/computation/BlockchainContext.ts index b99cb96c827f08ef95c7fafc291ab691892f355a..9705c2eed46e09205fe7bda3268414a6c9858772 100644 --- a/app/lib/computation/BlockchainContext.ts +++ b/app/lib/computation/BlockchainContext.ts @@ -147,11 +147,6 @@ export class BlockchainContext { const block = forks[0]; await this.checkAndAddBlock(BlockDTO.fromJSONObject(block)) this.logger.debug('Applied block #%s', block.number); - // Periodically, we trim the blockchain - if (block.number % 30 === 0)Â { - // Database trimming - await this.dal.loki.flushAndTrimData() - } } async checkAndAddBlock(block:BlockDTO, trim = true) { diff --git a/app/lib/constants.ts b/app/lib/constants.ts index bc605076ac85c60270d61ab1a2fbe995e7814e37..7092d69e5ff3ccb15b66161198ad571936edd2ac 100644 --- a/app/lib/constants.ts +++ b/app/lib/constants.ts @@ -176,7 +176,6 @@ module.exports = { NO_FORK_ALLOWED: false, SAFE_FACTOR: 3, - BLOCKS_COLLECT_THRESHOLD: 30, // Blocks to collect from memory and persist MUTE_LOGS_DURING_UNIT_TESTS: OtherConstants.MUTE_LOGS_DURING_UNIT_TESTS,