diff --git a/app/lib/computation/BlockchainContext.ts b/app/lib/computation/BlockchainContext.ts index 35be72791a1dfbfdf5f91042272a90690b5f6ba3..426ed2dc8c8b0bfcca4ccd6b6c37bee22d58ab1b 100644 --- a/app/lib/computation/BlockchainContext.ts +++ b/app/lib/computation/BlockchainContext.ts @@ -157,7 +157,7 @@ export class BlockchainContext { } } - quickApplyBlocks(blocks:BlockDTO[], to: number | null): Promise<any> { + quickApplyBlocks(blocks:BlockDTO[], to: number): Promise<any> { return this.quickSynchronizer.quickApplyBlocks(blocks, to) } } diff --git a/app/lib/computation/QuickSync.ts b/app/lib/computation/QuickSync.ts index 1047aeda6980129863794dfd8ed0485f36fb7454..0bf46bd7b74caa056a3106c7a94e9297ecc3c49e 100644 --- a/app/lib/computation/QuickSync.ts +++ b/app/lib/computation/QuickSync.ts @@ -88,7 +88,7 @@ export class QuickSynchronizer { return this.dal.updateTransactions(txs); } - async quickApplyBlocks(blocks:BlockDTO[], to: number | null): Promise<void> { + async quickApplyBlocks(blocks:BlockDTO[], to: number): Promise<void> { sync_memoryDAL.sindexDAL = { getAvailableForConditions: (conditions:string) => this.dal.sindexDAL.getAvailableForConditions(conditions) } let blocksToSave: BlockDTO[] = []; @@ -103,7 +103,7 @@ export class QuickSynchronizer { sync_currConf = BlockDTO.getConf(block); } - if (block.number != to) { + if (block.number <= to - this.conf.forksize) { blocksToSave.push(dto); const index:any = Indexer.localIndex(dto, sync_currConf); const local_iindex = Indexer.iindex(index); @@ -239,6 +239,9 @@ export class QuickSynchronizer { const nonEmptyKeys = _.filter(conditions, (k: any) => sync_memoryWallets[k] && sync_memoryWallets[k].balance > 0) const walletsToRecord = nonEmptyKeys.map((k: any) => sync_memoryWallets[k]) await this.dal.walletDAL.insertBatch(walletsToRecord) + for (const cond of conditions) { + delete sync_memoryWallets[cond] + } // Last block: cautious mode to trigger all the INDEX expiry mechanisms const { index, HEAD } = await DuniterBlockchain.checkBlock(dto, constants.WITH_SIGNATURES_AND_POW, this.conf, this.dal) diff --git a/app/service/BlockchainService.ts b/app/service/BlockchainService.ts index dade3d0e1484e8fc7cb37b9c3d9223d3fa471a55..9631d6fdd2969214ddd28ebc427b924ba0695e2b 100644 --- a/app/service/BlockchainService.ts +++ b/app/service/BlockchainService.ts @@ -399,7 +399,7 @@ export class BlockchainService extends FIFOService { * @param blocks An array of blocks to insert. * @param to The final block number of the fast insertion. */ - fastBlockInsertions(blocks:BlockDTO[], to:number | null) { + fastBlockInsertions(blocks:BlockDTO[], to:number) { return this.mainContext.quickApplyBlocks(blocks, to) } }