Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Only import block if it isn't already on the block chain #962

Merged

Conversation

jframe
Copy link
Contributor

@jframe jframe commented Feb 26, 2019

Leaving this as draft PR until ibft test nodes have been running for awhile to give confidence this fixes the high cpu issue.

PR description

This changes the block importer so that will only import the block if it is not already imported. This can happen when using an alternative consensus mechanism such as ibft which also imports blocks.

In the case of ibft, a block might already be importing when we get a new_block event and will unnecessarily import the same block twice. This means we will use more resources than necessary to import blocks.

Fixed Issue(s)

@@ -37,6 +37,9 @@ public synchronized boolean importBlock(
final Block block,
final HeaderValidationMode headerValidationMode,
final HeaderValidationMode ommerValidationMode) {
if (context.getBlockchain().contains(block.getHash())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the underlying BlockHashFunction that get's used for IBFT? ...is that hash going to match the hash from the mainnet BlockHashFunction, or could they be different due to the IBFT header funniness?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This importer is used by only IBFT when we are using IBFT despite the name. It won't be comparing a block hash from mainnet to a block hash from IBFT. The underlying hash function that will be used is different and the hash function that will be used is the IbftBlockHashing::calculateHashOfIbftBlockOnChain which takes cares of header funniness you mentioned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, that importer is used by MainNet and IBFT, just Pantheon can't be simultaneously doing Ethash and IBFT. So all blocks will use a consistent block hash function.

By definition, two blocks are equal if and only if their block hash matches. Most important application of that principal is the fact that block headers are stored by their hash in RocksDB.

Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jframe
Copy link
Contributor Author

jframe commented Feb 26, 2019

CPU use has remained low on the testnet since yesterday so removing the draft PR status

@jframe jframe marked this pull request as ready for review February 26, 2019 04:17
Copy link
Contributor

@rain-on rain-on left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jframe jframe merged commit 37e4f10 into PegaSysEng:master Feb 26, 2019
jframe added a commit to jframe/pantheon that referenced this pull request Feb 26, 2019
@jframe jframe deleted the block_importer_only_imports_unknown_blocks branch February 26, 2019 06:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants