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

[fix] #1068 Branch rebasing might fail with already known fork blocks

parent 9411e51b
No related branches found
No related tags found
No related merge requests found
......@@ -403,6 +403,8 @@ export class BlockCrawler {
return block;
}
async applyMainBranch(block: BlockDTO): Promise<boolean> {
const existing = await server.dal.getAbsoluteBlockByNumberAndHash(block.number, block.hash)
if (!existing) {
let addedBlock = await server.writeBlock(block, false)
if (!this.lastDownloaded) {
this.lastDownloaded = await dao.remoteCurrent(node);
......@@ -415,6 +417,10 @@ export class BlockCrawler {
server.streamPush(addedBlock);
}
}
} else {
this.crawler.logger && this.crawler.logger.info('Downloaded already known block#%s-%s, try to fork...', block.number, block.hash)
await server.BlockchainService.tryToFork()
}
return true
}
async removeForks(): Promise<boolean> {
......
......@@ -169,6 +169,13 @@ export class BlockchainService extends FIFOService {
}
}
async tryToFork() {
return this.pushFIFO("tryToFork", async () => {
const current = await this.mainContext.current()
await this.eventuallySwitchOnSideChain(current)
})
}
private async eventuallySwitchOnSideChain(current:DBBlock) {
const branches = await this.branches()
const blocksAdvanceInBlocks = this.conf.switchOnHeadAdvance
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment