Skip to content
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

Orphaned block exception in SuggestBlock #5152

Merged
merged 11 commits into from
Feb 14, 2023
Merged

Conversation

deffrian
Copy link
Contributor

@deffrian deffrian commented Jan 17, 2023

Fixes Closes Resolves #

In some Ethereum merge tests difficulty for all blocks is zero. In this case we failing in td calculation.
Fixes hive/consensus UncleFromSideChain_Merge test

Changes

  • Now we check if td for all blocks will be zero
  • Some tests were adjasted
  • BackFillTotalDifficulty removed

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a fix or a feature that would cause existing functionality not to work as expected)
  • Documentation update
  • Code style update (formatting, renaming)
  • Refactoring (no functional or API changes)
  • Build-related changes
  • Other: description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

@deffrian deffrian marked this pull request as ready for review January 23, 2023 10:13
@deffrian
Copy link
Contributor Author

posdao and engine hive tests are green

@marcindsobczak
Copy link
Contributor

What about hive consensus tests, there is no regression?

@deffrian
Copy link
Contributor Author

What about hive consensus tests, there is no regression?

I'm still running them. Will let you know when ended

@deffrian deffrian requested a review from Demuirgos January 24, 2023 12:04
Copy link
Contributor

@marcindsobczak marcindsobczak left a comment

Choose a reason for hiding this comment

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

This branch is fixing hive consensus test UncleFromSideChain_Merge:
https://github.com/NethermindEth/nethermind/actions/runs/4045495974/jobs/6957042719
Which fails on master:
https://github.com/NethermindEth/nethermind/actions/runs/4045499712/jobs/6957050455

There is no regression in other tests so IMO ready to be merged

@@ -1962,7 +1962,7 @@ private void SetTotalDifficulty(BlockHeader header)
void SetTotalDifficultyDeep(BlockHeader current)
{
Stack<BlockHeader> stack = new();
while (!current.IsNonZeroTotalDifficulty())
while (current.TotalDifficulty is null)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is quite a big logical change. I think it has been done only to handle TotalDifficulty = 0 in the genesis block. Could we break while when we reach the genesis block instead of logic change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case every computation of td will require a computation of td for every previous block. It's too slow I think

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right but I'm also right :)

Your fix is for the edge case situation when we start with genesis.Difficulty = 0, TTD = 0

The current code is working fine in the transition period. The total difficulty in DB is not nullable, because of that we have to save TD as 0 zero in DB. However, TD = 0 means that we don't have the current total difficulty. Basically, in this context TD=0 means the same as null.

Could you think about how to resolve both fixes? I believe good condition (with some reference to genesis) will handle both cases

Copy link
Contributor

@MarekM25 MarekM25 left a comment

Choose a reason for hiding this comment

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

Was it developed to handle genesisBlock.Difficulty ==0 ? If yes, let's handle only the genesis block in this way

@@ -227,7 +227,7 @@ private bool ValidateTimestamp(BlockHeader parent, BlockHeader header)
protected virtual bool ValidateTotalDifficulty(BlockHeader parent, BlockHeader header)
{
bool totalDifficultyCorrect = true;
if (header.IsNonZeroTotalDifficulty())
if (header.TotalDifficulty is not null)
Copy link
Contributor

Choose a reason for hiding this comment

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

IsNonZeroTotalDifficulty has this impl : header.TotalDifficulty is not null && header.TotalDifficulty != UInt256.Zero, so why does the new code not check if it's a Zero as well ?

@deffrian deffrian merged commit 0e837ab into master Feb 14, 2023
@deffrian deffrian deleted the fix/genesis-zero-difficulty branch February 14, 2023 15:32
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.

5 participants