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

[fix] #1091 The fork window must be taken into account during `sync`

parent cd024a95
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
}
......@@ -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)
......
......@@ -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)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment