Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/core-blockchain/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class Blockchain implements blockchain.IBlockchain {
protected blockProcessor: BlockProcessor;
private actions: any;
private missedBlocks: number = 0;
private lastCheckNetworkHealthTs: number = 0;

/**
* Create a new blockchain manager instance.
Expand Down Expand Up @@ -577,6 +578,13 @@ export class Blockchain implements blockchain.IBlockchain {
) {
this.missedBlocks = 0;

// do not check network health here more than every 10 minutes
const nowTs = Date.now();
if (nowTs - this.lastCheckNetworkHealthTs < 10 * 60 * 1000) {
return;
}
this.lastCheckNetworkHealthTs = nowTs;

const networkStatus = await this.p2p.getMonitor().checkNetworkHealth();
if (networkStatus.forked) {
this.state.numberOfBlocksToRollback = networkStatus.blocksToRollback;
Expand Down
1 change: 1 addition & 0 deletions packages/core-blockchain/src/machines/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const blockchainMachine: any = Machine({
WAKEUP: "syncWithNetwork",
NEWBLOCK: "newBlock",
STOP: "stopped",
FORK: "fork",
},
},
newBlock: {
Expand Down