Skip to content

fix(l1): added checks to newpayload and forkchoiceupdated #2831

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
merged 16 commits into from
May 22, 2025

Conversation

fedacking
Copy link
Contributor

Motivation

This should fix some sync and inconsistent behaviour problems with the hive engine tests. The problem was happening when a sync process had begun, and a block from that sync process entered the server. Some checks for that scenario have been added.

Also made some tests in the CI easier to read and edit, while adding a couple of them.

Description

  • Made the CI tests have 1 by 1.
  • Added some fixed CI tests to "Paris Engine tests" and "Engine withdrawal tests"
  • Added a check to forkchoiceupdatet for the body to be present before forking.
  • Added a check to execute_payload for the body of the parent to be present before executing.

Fixes some tests in #1285

fedacking added 2 commits May 16, 2025 12:13
Made it so that we check the parent body is there before adding new payloads and forking. If it's missing but the header is there, we are syncing.
@fedacking fedacking requested a review from a team as a code owner May 16, 2025 18:37
@fedacking fedacking changed the title Fix/newpayload sync check fix(l1): added checks to newpayload and forkchoiceupdated May 16, 2025
Copy link

github-actions bot commented May 16, 2025

Lines of code report

Total lines added: 10
Total lines removed: 0
Total lines changed: 10

Detailed view
+-----------------------------------------+-------+------+
| File                                    | Lines | Diff |
+-----------------------------------------+-------+------+
| ethrex/crates/blockchain/blockchain.rs  | 514   | +9   |
+-----------------------------------------+-------+------+
| ethrex/crates/blockchain/fork_choice.rs | 142   | +1   |
+-----------------------------------------+-------+------+

Copy link
Contributor

@fmoletta fmoletta left a comment

Choose a reason for hiding this comment

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

Could you comment in the code that the need to fetch the parent's block body is due to executing blocks in batch during full-sync? This will be relevant if we choose to remove it or put it under a feature in the near future

@fedacking fedacking marked this pull request as draft May 16, 2025 22:45
@fedacking fedacking marked this pull request as ready for review May 19, 2025 19:49
Transaction Re-Org|
Unique Payload ID|
Unknown|
Valid NewPayload->ForkchoiceUpdated" # |Invalid P9 -> flaky
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!

return Err(ChainError::ParentNotFound);
// Feda (#2831): We search for the entire block because during full/batch sync
// we can have the header without the body indicating it's still syncing.
let parent = self
Copy link
Collaborator

Choose a reason for hiding this comment

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

so let me get this straight: the only change is that you are searching for the whole block instead of just the header. Any reason you decided to do this inline instead of with a helper function? I think it was actually more readable before.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I see that the previous function was confusing and the comments outdated. Maybe the solution is a better name and a better comment instead of inlining and repeating code?

Copy link
Contributor Author

@fedacking fedacking May 20, 2025

Choose a reason for hiding this comment

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

I'll do that. Do I return the old function for the other places in the code where they were used? With a better comment

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, and maybe a better naming. But only if you think it makes the code more readable, this is a suggestion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After implementing it I didn't think it was more readable for this section, but the other places it actually was better, so I have reintroduced the function.

@fedacking fedacking added this pull request to the merge queue May 22, 2025
Merged via the queue into main with commit 490cd62 May 22, 2025
21 checks passed
@fedacking fedacking deleted the fix/newpayload-sync-check branch May 22, 2025 15:06
mpaulucci pushed a commit that referenced this pull request May 23, 2025
**Motivation**

This should fix some sync and inconsistent behaviour problems with the
hive engine tests. The problem was happening when a sync process had
begun, and a block from that sync process entered the server. Some
checks for that scenario have been added.

Also made some tests in the CI easier to read and edit, while adding a
couple of them.

**Description**

- Made the CI tests have 1 by 1.
- Added some fixed CI tests to "Paris Engine tests" and "Engine
withdrawal tests"
- Added a check to forkchoiceupdatet for the body to be present before
forking.
- Added a check to execute_payload for the body of the parent to be
present before executing.

Fixes some tests in #1285
fmoletta added a commit that referenced this pull request Jun 3, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jun 3, 2025
**Motivation**
When adding blocks in batches, transactions in blocks may need to read
the hash of a previous block in the batch. This poses an issue, as we
add all blocks after the full batch has been executed ad we don't have
those hashes stored.
Previously, this issue was tackled by storing the block headers before
executing and storing the full block batch. This also required us to
make the fixes on #2831 (as we might have the headers of blocks we have
not yet executed during full sync).
This stopped being a suitable solution once #3022 was merged, as block
hashes are now searched using the block the state is based on's
ancestors. As the state is based on the first block in the batch's
parents, later blocks are not able to access the hashes of previous
blocks in the batch.
This PR aims to fix both issues by adding a `block_hash_cache` to the
`StoreVmDatabase` were we would add the hashes of all blocks in the
batch, and use it when fetching block hashes before looking at the
Store. This way we can access block hashes for previously executed
blocks in the batch without prematurely adding data from blocks yet to
be executed to the state. Allowing us to rollback fixes from #2831
<!-- Why does this pull request exist? What are its goals? -->

**Description**
* Add `block_hash_cache` to `VmStoreDatabase`
* Cache block hashes of the full batch before executing in
`Blockchain::add_block_batch`
* No longer store block headers before execution during full sync
* Rollback fixes from #2831 (no longer needed due to the above change)
<!-- A clear and concise general description of the changes this PR
introduces -->

<!-- Link to issues: Resolves #111, Resolves #222 -->

Closes #issue_number
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
…s#2831)

**Motivation**

This should fix some sync and inconsistent behaviour problems with the
hive engine tests. The problem was happening when a sync process had
begun, and a block from that sync process entered the server. Some
checks for that scenario have been added.

Also made some tests in the CI easier to read and edit, while adding a
couple of them.

**Description**

- Made the CI tests have 1 by 1.
- Added some fixed CI tests to "Paris Engine tests" and "Engine
withdrawal tests"
- Added a check to forkchoiceupdatet for the body to be present before
forking.
- Added a check to execute_payload for the body of the parent to be
present before executing.

Fixes some tests in lambdaclass#1285
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
…3034)

**Motivation**
When adding blocks in batches, transactions in blocks may need to read
the hash of a previous block in the batch. This poses an issue, as we
add all blocks after the full batch has been executed ad we don't have
those hashes stored.
Previously, this issue was tackled by storing the block headers before
executing and storing the full block batch. This also required us to
make the fixes on lambdaclass#2831 (as we might have the headers of blocks we have
not yet executed during full sync).
This stopped being a suitable solution once lambdaclass#3022 was merged, as block
hashes are now searched using the block the state is based on's
ancestors. As the state is based on the first block in the batch's
parents, later blocks are not able to access the hashes of previous
blocks in the batch.
This PR aims to fix both issues by adding a `block_hash_cache` to the
`StoreVmDatabase` were we would add the hashes of all blocks in the
batch, and use it when fetching block hashes before looking at the
Store. This way we can access block hashes for previously executed
blocks in the batch without prematurely adding data from blocks yet to
be executed to the state. Allowing us to rollback fixes from lambdaclass#2831
<!-- Why does this pull request exist? What are its goals? -->

**Description**
* Add `block_hash_cache` to `VmStoreDatabase`
* Cache block hashes of the full batch before executing in
`Blockchain::add_block_batch`
* No longer store block headers before execution during full sync
* Rollback fixes from lambdaclass#2831 (no longer needed due to the above change)
<!-- A clear and concise general description of the changes this PR
introduces -->

<!-- Link to issues: Resolves lambdaclass#111, Resolves lambdaclass#222 -->

Closes #issue_number
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.

3 participants