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

Bad blocks - potential fix #6212

Merged
merged 6 commits into from Oct 23, 2023
Merged

Bad blocks - potential fix #6212

merged 6 commits into from Oct 23, 2023

Conversation

MarekM25
Copy link
Contributor

@MarekM25 MarekM25 commented Oct 21, 2023

Changes

We've identified invalid blocks on the Gnosis network, but the same issue can happen on Ethereum Mainnet. During our debugging session, we uncovered that we were building on an incorrect state root (grandparent) rather than the parent state root.

The TrySetState function in BlockProducerBase ensures that we have the required state, so within the context of block production, we don't need to go through a loop. However, without this change, and in the event of a loop (or "branch") in the blockchainProcessor, we might end up building on top of an incorrect state root. This is because InitBranch sets the state root, and it could lead to the creation of an invalid block. The loop essentially goes backward in an attempt to align with the main chain, so if the main chain undergoes changes during block improvement, we might encounter this issue.

The loop scenario can occur as follows:

  1. FCU with payload attributes for block 1000A (block building process initiated).
  2. FCU block 1000B.
  3. Main chain changed. (1000B)
  4. A new block improvement for block 1000A begins.
  5. Building on an incorrect state root. (999A instead of 1000A)
  6. Resulting in an invalid block.

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 change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • Not yet

@MarekM25 MarekM25 changed the title Bad blocks potential fix Bad blocks - potential fix Oct 21, 2023
@asdacap
Copy link
Contributor

asdacap commented Oct 23, 2023

Can you add a description on step 4. Main chain changed to which block? And on step 6, which state root is it building on top off?

@MarekM25
Copy link
Contributor Author

MarekM25 commented Oct 23, 2023

Can you add a description on step 4. Main chain changed to which block? And on step 6, which state root is it building on top off?

Updated steps + you can check unit test to understand it.

@MarekM25 MarekM25 marked this pull request as ready for review October 23, 2023 12:28
@@ -665,12 +665,13 @@ private ProcessingBranch PrepareProcessingBranch(Block suggestedBlock, Processin
// otherwise some nodes would be missing
bool notFoundTheBranchingPointYet = !_blockTree.IsMainChain(branchingPoint.Hash!);
bool notReachedTheReorgBoundary = branchingPoint.Number > (_blockTree.Head?.Header.Number ?? 0);
preMergeFinishBranchingCondition = (notFoundTheBranchingPointYet || notReachedTheReorgBoundary);
bool notInBlockProduction = !options.ContainsFlag(ProcessingOptions.ProducingBlock);
Copy link
Member

Choose a reason for hiding this comment

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

notInForceProcessing?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

notInForceProcessing?

thx, changed.

oh yeah. This code looks unnecessary now, but I am not going to touch it in this PR. Let's analyze it more

@MarekM25 MarekM25 merged commit 94ae34f into master Oct 23, 2023
61 of 62 checks passed
@MarekM25 MarekM25 deleted the bad_blocks_potential_fix branch October 23, 2023 13:05
brbrr pushed a commit that referenced this pull request Oct 23, 2023
* Potential bad blocks fix

* Revert "Potential bad blocks fix"

This reverts commit 9be4bd3.

* Potential fix

* Integration tests with iInvalid block and fix

* cleanup tests

* notInForceProcessing
brbrr pushed a commit that referenced this pull request Oct 24, 2023
* Potential bad blocks fix

* Revert "Potential bad blocks fix"

This reverts commit 9be4bd3.

* Potential fix

* Integration tests with iInvalid block and fix

* cleanup tests

* notInForceProcessing
jakubgs added a commit to status-im/infra-role-nethermind that referenced this pull request Oct 27, 2023
To address invalid block production bug:
NethermindEth/nethermind#6212
https://github.com/NethermindEth/nethermind/releases/tag/1.21.1

Signed-off-by: Jakub Sokołowski <jakub@status.im>
Copy link

@Felperez02 Felperez02 left a comment

Choose a reason for hiding this comment

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

Quiero saber bien de esto

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.

None yet

5 participants