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
Branches
Tags
No related merge requests found
...@@ -403,6 +403,8 @@ export class BlockCrawler { ...@@ -403,6 +403,8 @@ export class BlockCrawler {
return block; return block;
} }
async applyMainBranch(block: BlockDTO): Promise<boolean> { 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) let addedBlock = await server.writeBlock(block, false)
if (!this.lastDownloaded) { if (!this.lastDownloaded) {
this.lastDownloaded = await dao.remoteCurrent(node); this.lastDownloaded = await dao.remoteCurrent(node);
...@@ -415,6 +417,10 @@ export class BlockCrawler { ...@@ -415,6 +417,10 @@ export class BlockCrawler {
server.streamPush(addedBlock); 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 return true
} }
async removeForks(): Promise<boolean> { async removeForks(): Promise<boolean> {
......
...@@ -169,6 +169,13 @@ export class BlockchainService extends FIFOService { ...@@ -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) { private async eventuallySwitchOnSideChain(current:DBBlock) {
const branches = await this.branches() const branches = await this.branches()
const blocksAdvanceInBlocks = this.conf.switchOnHeadAdvance 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