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

perf(state-transition): reduce amount of withdrawals processed #2110

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

abi87
Copy link
Collaborator

@abi87 abi87 commented Oct 28, 2024

No need to process for withdrawal validators that are not fully or partially withdrawable

Note: this PR (and those built on top) seems to break once we update erigon from 2.60.1 to 2.60.9.
Geth seems to give the following error:

WARN [11-02|12:18:20.162] Served engine_newPayloadV3               conn=192.168.65.1:43721 reqid=1 duration="93.25µs" err="Invalid parameters" errdata="{\"err\":\"nil withdrawals post-shanghai\"}"

Note: keep on investigating with @dezzeus. It looks like withdrawals are duly set to an empty slice when the block is built, but as soon as the block is returned from consensus to middleware for verification, the slice is nil. SSZ serialization seems to be responsible for this. Investigation ongoing
Investigation ongoing

Note: found a solution: expliciting make Withdrawals slice when SSZ unmarshalling.

@abi87 abi87 self-assigned this Oct 28, 2024
Copy link
Contributor

coderabbitai bot commented Oct 28, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes in this pull request focus on the StateDB struct and its methods within the statedb.go file. The ExpectedWithdrawals method has been significantly simplified by removing the intermediate amount variable, allowing for more direct appending of withdrawal objects. Other methods, such as IncreaseBalance, DecreaseBalance, and UpdateSlashingAtIndex, have improved clarity in error handling but retain their original logic. The GetMarshallable method remains structurally unchanged, ensuring state data integrity.

Changes

File Path Change Summary
mod/state-transition/pkg/core/state/statedb.go - Simplified ExpectedWithdrawals method by removing intermediate variables.
- Enhanced error handling clarity in IncreaseBalance, DecreaseBalance, and UpdateSlashingAtIndex methods.
- Maintained structure and functionality of GetMarshallable method.

Possibly related PRs

Suggested reviewers

  • itsdevbear
  • nidhi-singh02

Poem

🐇 In the meadow where bunnies play,
The code has changed in a clearer way.
Withdrawals now hop without a fuss,
Simplified paths, no need to rush!
With balances checked and errors in sight,
Our state management's feeling just right! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@abi87 abi87 changed the title chore(state-transition): reduce amount of withdrawals processed perf(state-transition): reduce amount of withdrawals processed Oct 28, 2024
Copy link

codecov bot commented Oct 28, 2024

Codecov Report

Attention: Patch coverage is 24.00000% with 19 lines in your changes missing coverage. Please review.

Project coverage is 26.41%. Comparing base (d66b298) to head (d8a267e).

Files with missing lines Patch % Lines
mod/state-transition/pkg/core/state/statedb.go 5.26% 18 Missing ⚠️
testing/e2e/config/config.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                     Coverage Diff                      @@
##           state-transition-add-UTs    #2110      +/-   ##
============================================================
+ Coverage                     24.82%   26.41%   +1.59%     
============================================================
  Files                           357      357              
  Lines                         16071    16075       +4     
  Branches                         12       12              
============================================================
+ Hits                           3990     4247     +257     
+ Misses                        11886    11560     -326     
- Partials                        195      268      +73     
Files with missing lines Coverage Δ
mod/consensus-types/pkg/types/payload.go 92.07% <100.00%> (+0.10%) ⬆️
testing/e2e/config/config.go 0.00% <0.00%> (ø)
mod/state-transition/pkg/core/state/statedb.go 43.63% <5.26%> (+35.03%) ⬆️

... and 7 files with indirect coverage changes

@abi87 abi87 marked this pull request as ready for review October 28, 2024 18:10
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 0ea12a8 and b4a1077.

📒 Files selected for processing (1)
  • mod/state-transition/pkg/core/state/statedb.go (1 hunks)
🔇 Additional comments (1)
mod/state-transition/pkg/core/state/statedb.go (1)

246-262: LGTM! Performance optimization achieved.

The changes successfully optimize withdrawal processing by:

  1. Eliminating unnecessary intermediate variables
  2. Reducing memory allocations
  3. Only processing withdrawals for eligible validators (fully or partially withdrawable)

This aligns well with the PR objective of reducing the amount of withdrawals processed.

@abi87 abi87 changed the base branch from main to state-transition-add-UTs November 1, 2024 09:11
Timestamp: 10,
ExtraData: []byte("testing"),
Transactions: [][]byte{},
Withdrawals: []*engineprimitives.Withdrawal{}, // no withdrawals
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is the point of the test here, which is different from the base branch here: the list of withdrawals is empty instead of containing two withdrawals with zero amount.

@abi87 abi87 force-pushed the fix-maximum-number-withdrawals branch 2 times, most recently from 2778c79 to 09eee8e Compare November 2, 2024 20:35
@abi87 abi87 requested a review from dezzeus November 4, 2024 14:21
Comment on lines +132 to +135
// TODO: hack to avoid failure of EL checks on withdrawals
if p.Withdrawals == nil {
p.Withdrawals = make([]*engineprimitives.Withdrawal, 0)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

post Shangai an EL explicitly check that Withdrawals are not nil (instead empty slices are fine).
Currently BeaconKit duly builds a block with Withdrawals set to empty slice (if not withdrawals are available) but as soon as the block is returned by CometBFT for verification, the SSZ decoding sets the empty slice to nil.
This code change solves the issue.

Copy link
Contributor

@calbera calbera left a comment

Choose a reason for hiding this comment

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

makes sense!

Base automatically changed from state-transition-add-UTs to main November 5, 2024 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants