diff --git a/packages/core-blockchain/src/blockchain.ts b/packages/core-blockchain/src/blockchain.ts index ef959d8f9f..a5590644ad 100644 --- a/packages/core-blockchain/src/blockchain.ts +++ b/packages/core-blockchain/src/blockchain.ts @@ -208,6 +208,8 @@ export class Blockchain implements blockchain.IBlockchain { * @return {void} */ public clearAndStopQueue() { + this.state.lastDownloadedBlock = this.getLastBlock(); + this.queue.pause(); this.queue.clear(); } diff --git a/packages/core-blockchain/src/state-machine.ts b/packages/core-blockchain/src/state-machine.ts index 10f0ed9ec1..a8d370eb92 100644 --- a/packages/core-blockchain/src/state-machine.ts +++ b/packages/core-blockchain/src/state-machine.ts @@ -319,6 +319,11 @@ blockchainMachine.actionMap = (blockchain: Blockchain) => ({ return; } + // Could have changed since entering this function, e.g. due to a rollback. + if (lastDownloadedBlock.data.id !== stateStorage.lastDownloadedBlock.data.id) { + return; + } + const empty = !blocks || blocks.length === 0; const chained = !empty && (isBlockChained(lastDownloadedBlock, { data: blocks[0] }) || isException(blocks[0]));