Skip to content

Commit

Permalink
fix(core-blockchain): return if last downloaded block changed (#2216)
Browse files Browse the repository at this point in the history
  • Loading branch information
spkjp authored and faustbrian committed Mar 9, 2019
1 parent 6526856 commit 37aaa33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/core-blockchain/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
5 changes: 5 additions & 0 deletions packages/core-blockchain/src/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]));

Expand Down

0 comments on commit 37aaa33

Please sign in to comment.