Skip to content
Snippets Groups Projects
Commit 4416946b authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] loki data commiting and trimming should be triggered every 30 blocks

parent df868d27
No related branches found
No related tags found
No related merge requests found
...@@ -18,8 +18,8 @@ import { ...@@ -18,8 +18,8 @@ import {
IndexEntry, IndexEntry,
Indexer, Indexer,
MindexEntry, MindexEntry,
SimpleSindexEntryForWallet, SimpleTxEntryForWallet, SimpleUdEntryForWallet, SimpleTxEntryForWallet,
SindexEntry SimpleUdEntryForWallet
} from "../indexer" } from "../indexer"
import {ConfDTO} from "../dto/ConfDTO" import {ConfDTO} from "../dto/ConfDTO"
import {BlockDTO} from "../dto/BlockDTO" import {BlockDTO} from "../dto/BlockDTO"
...@@ -37,7 +37,6 @@ import {DataErrors} from "../common-libs/errors" ...@@ -37,7 +37,6 @@ import {DataErrors} from "../common-libs/errors"
import {NewLogger} from "../logger" import {NewLogger} from "../logger"
import {DBTx} from "../db/DBTx" import {DBTx} from "../db/DBTx"
import {Underscore} from "../common-libs/underscore" import {Underscore} from "../common-libs/underscore"
import {DividendEntry, UDSource} from "../dal/indexDAL/abstract/DividendDAO"
import {OtherConstants} from "../other_constants" import {OtherConstants} from "../other_constants"
export class DuniterBlockchain { export class DuniterBlockchain {
...@@ -205,6 +204,13 @@ 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)); 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) return BlockDTO.fromJSONObject(added)
} }
catch(err) { catch(err) {
......
...@@ -307,6 +307,8 @@ export const CommonConstants = { ...@@ -307,6 +307,8 @@ export const CommonConstants = {
MAX_AGE_OF_PEER_IN_BLOCKS: 200, // blocks MAX_AGE_OF_PEER_IN_BLOCKS: 200, // blocks
INITIAL_DOWNLOAD_SLOTS: 1, // 1 peer INITIAL_DOWNLOAD_SLOTS: 1, // 1 peer
BLOCKS_COLLECT_THRESHOLD: 30, // Number of blocks to wait before trimming the loki data
} }
function exact (regexpContent:string) { function exact (regexpContent:string) {
......
...@@ -147,11 +147,6 @@ export class BlockchainContext { ...@@ -147,11 +147,6 @@ export class BlockchainContext {
const block = forks[0]; const block = forks[0];
await this.checkAndAddBlock(BlockDTO.fromJSONObject(block)) await this.checkAndAddBlock(BlockDTO.fromJSONObject(block))
this.logger.debug('Applied block #%s', block.number); 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) { async checkAndAddBlock(block:BlockDTO, trim = true) {
......
...@@ -176,7 +176,6 @@ module.exports = { ...@@ -176,7 +176,6 @@ module.exports = {
NO_FORK_ALLOWED: false, NO_FORK_ALLOWED: false,
SAFE_FACTOR: 3, 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, MUTE_LOGS_DURING_UNIT_TESTS: OtherConstants.MUTE_LOGS_DURING_UNIT_TESTS,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment