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

[enh] Allow full transactions history storage

parent 4cd799e7
......@@ -27,6 +27,7 @@ export interface ProgramOptions {
loglevel?: string
sqlTraces?: boolean
memory?: boolean
storeTxs?: boolean
}
export const cliprogram: ProgramOptions = {
......
......@@ -22,6 +22,12 @@ export interface Keypair {
sec: string
}
export interface StorageDTO {
storage?: {
transactions?:boolean
}
}
export interface PowDTO {
powNoSecurity:boolean
}
......@@ -103,7 +109,7 @@ export interface WS2PConfDTO {
}
}
export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, BranchingDTO, WS2PConfDTO, PowDTO {
export class ConfDTO implements StorageDTO, CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, BranchingDTO, WS2PConfDTO, PowDTO {
constructor(
public loglevel: string,
......@@ -182,7 +188,10 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO,
maxPrivate?:number
syncLimit?:number
},
public powNoSecurity = false
public powNoSecurity = false,
public storage = {
transactions: false
},
) {}
static mock() {
......
......@@ -17,21 +17,43 @@ import {Server} from "../../server"
import {CommonConstants} from "../lib/common-libs/constants"
import {Directory} from "../lib/system/directory"
import {Underscore} from "../lib/common-libs/underscore"
import {ProgramOptions} from "../lib/common-libs/programOptions"
module.exports = {
duniter: {
cliOptions: [
{ value: '--store-txs', desc: 'Enable full transaction history storage.' },
],
config: {
onLoading: async (conf:ConfDTO) => {
onLoading: async (conf:ConfDTO, program: ProgramOptions) => {
conf.msPeriod = conf.msWindow
conf.switchOnHeadAdvance = CommonConstants.SWITCH_ON_BRANCH_AHEAD_BY_X_BLOCKS
// Transactions storage
if (program.storeTxs) {
if (!conf.storage) {
conf.storage = { transactions: true }
}
else {
conf.storage.transactions = true
}
}
},
beforeSave: async (conf:ConfDTO) => {
conf.msPeriod = conf.msWindow
conf.switchOnHeadAdvance = CommonConstants.SWITCH_ON_BRANCH_AHEAD_BY_X_BLOCKS
if (!conf.storage) {
conf.storage = {
transactions: false
}
}
}
},
cli: [{
name: 'config',
desc: 'Register configuration in database',
......
......@@ -9,7 +9,7 @@ import {
SimpleUdEntryForWallet,
SindexEntry
} from "../../../../../lib/indexer"
import {CurrencyConfDTO} from "../../../../../lib/dto/ConfDTO"
import {ConfDTO, CurrencyConfDTO} from "../../../../../lib/dto/ConfDTO"
import {FileDAL} from "../../../../../lib/dal/fileDAL"
import {DuniterBlockchain} from "../../../../../lib/blockchain/DuniterBlockchain"
import {BlockDTO} from "../../../../../lib/dto/BlockDTO"
......@@ -80,7 +80,7 @@ export class GlobalIndexStream extends Duplex {
private mapInjection: { [k: string]: any } = {}
constructor(private conf: any,
constructor(private conf: ConfDTO,
private dal:FileDAL,
private to: number,
private localNumber:number,
......@@ -332,6 +332,10 @@ export class GlobalIndexStream extends Duplex {
return block
}))
if (this.conf.storage && this.conf.storage.transactions) {
await Promise.all(blocks.map(block => this.dal.saveTxsInFiles(block.transactions, block.number, block.medianTime)))
}
// We only keep a bunch of days of blocks in memory, so memory consumption keeps approximately constant during the sync
await this.dal.blockDAL.trimBlocks(blocks[blocks.length - 1].number - CommonConstants.BLOCKS_IN_MEMORY_MAX)
}
......
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