Skip to content

Commit

Permalink
fix(core-blockchain): always attempt to download blocks after start (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
spkjp authored and faustbrian committed Jun 25, 2019
1 parent 66ecd74 commit 2633741
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core-blockchain/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ export class Blockchain implements blockchain.IBlockchain {
* Get the last downloaded block of the blockchain.
*/
public getLastDownloadedBlock(): Interfaces.IBlockData {
return this.state.lastDownloadedBlock;
return this.state.lastDownloadedBlock || this.getLastBlock().data;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions packages/core-blockchain/src/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ blockchainMachine.actionMap = (blockchain: Blockchain) => ({
}
}

if (blockchain.isSynced(stateStorage.lastDownloadedBlock)) {
if (stateStorage.lastDownloadedBlock && blockchain.isSynced(stateStorage.lastDownloadedBlock)) {
stateStorage.noBlockCounter = 0;
stateStorage.p2pUpdateCounter = 0;

Expand Down Expand Up @@ -152,7 +152,6 @@ blockchainMachine.actionMap = (blockchain: Blockchain) => ({
* state machine data init *
******************************* */
stateStorage.setLastBlock(block);
stateStorage.lastDownloadedBlock = block.data;

// Delete all rounds from the future due to shutdown before processBlocks finished writing the blocks.
const roundInfo = roundCalculator.calculateRound(block.data.height);
Expand Down Expand Up @@ -208,7 +207,7 @@ blockchainMachine.actionMap = (blockchain: Blockchain) => ({
}

// Could have changed since entering this function, e.g. due to a rollback.
if (lastDownloadedBlock.id !== stateStorage.lastDownloadedBlock.id) {
if (stateStorage.lastDownloadedBlock && lastDownloadedBlock.id !== stateStorage.lastDownloadedBlock.id) {
return;
}

Expand Down

0 comments on commit 2633741

Please sign in to comment.