Skip to content

[ETCM-1058] Replace block import by consensus #1078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

leo-bogastry
Copy link
Contributor

Description

Replace class BlockImport by a Consensus class, reusing current code.

Important Changes Introduced

Added a new trait Consensus and class ConsensusImpl
ConsensusImpl reuses existing code (with some refactoring)
The refactoring is done is on separate commits to make it easier to evaluate

Testing

Regular Sync was tested with mainnet
Regular Sync / mining still to be tested in staging

@leo-bogastry leo-bogastry force-pushed the feature/ETCM-1058-replace-BlockImport-by-Consensus branch 2 times, most recently from c41b1fe to 13bf68d Compare August 2, 2021 07:46
Copy link
Contributor

@jvdp jvdp left a comment

Choose a reason for hiding this comment

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

Do have some questions but wouldn't want to block further work on this.

*/
def importBlock(
override def evaluateBranchBlock(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it called evaluate, the term for this elsewhere is execute, right?

Also, the comments and result type still talk of "importing", while we should probably drop that term everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The term elsewhere is execute, right? No. Where did you get that idea from? Actually me and Aurelién are struggling to give this method a proper name, because it can have several outcomes. I removed the name import exactly because as said in the description it Tries to import

Copy link
Contributor

Choose a reason for hiding this comment

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

There is the BlockExecution class for example. So this could be considered "branch execution"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not guaranteed that there will be a block or branch execution, the block may end up by just being added to the BlockQueue

)
}

private def returnNoBestBlock(): Task[BlockImportFailed] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this split out into a method? Doesn't seem to do much.

(If anything should be split out: BlockImportFailed("Couldn't find the current best block") could be a val.)

Perhaps we can reuse these error descriptions as log messages as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was mainly to make the main method evaluateBranchBlock more readable, by moving the detail of logging the error and creating the actual error description

Copy link
Contributor

Choose a reason for hiding this comment

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

So I would argue it is less readable now since those methods actually do so little.

import io.iohk.ethereum.mpt.MerklePatriciaTrie.MissingNodeException
import io.iohk.ethereum.utils.BlockchainConfig
import io.iohk.ethereum.utils.ByteStringUtils
import io.iohk.ethereum.utils.Logger

class BlockImport(
class ConsensusImpl(
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it need to be split into Consensus and ConsensusImpl?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One is a trait the other a class. It will help with testing

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it though? It didn't get in the way with BlockImport before.

This way does make code navigation a lot more annoying.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just look at the private[ledger] val blockExecution: BlockExecution (previous line 28). That was being accessed directly in the tests.
Hopefully we can improve the tests much more in the future

@leo-bogastry leo-bogastry force-pushed the feature/ETCM-1058-replace-BlockImport-by-Consensus branch 2 times, most recently from 1ac7040 to ae639d1 Compare August 4, 2021 07:23
@leo-bogastry leo-bogastry force-pushed the feature/ETCM-1058-replace-BlockImport-by-Consensus branch from ae639d1 to b8a4882 Compare August 4, 2021 08:26
@leo-bogastry leo-bogastry merged commit e27f251 into develop Aug 4, 2021
@leo-bogastry leo-bogastry deleted the feature/ETCM-1058-replace-BlockImport-by-Consensus branch August 4, 2021 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants