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

Merged
merged 31 commits into from
Nov 6, 2024

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

Warning

Rate limit exceeded

@abi87 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b4a1077 and 3cfb23e.

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 43.75000% with 18 lines in your changes missing coverage. Please review.

Project coverage is 26.07%. Comparing base (6e119fa) to head (3cfb23e).
Report is 7 commits behind head on main.

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

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2110      +/-   ##
==========================================
- Coverage   26.46%   26.07%   -0.39%     
==========================================
  Files         357      360       +3     
  Lines       16155    16580     +425     
  Branches       12       12              
==========================================
+ Hits         4276     4324      +48     
- Misses      11609    11978     +369     
- Partials      270      278       +8     
Files with missing lines Coverage Δ
mod/consensus-types/pkg/types/payload.go 92.17% <100.00%> (+0.20%) ⬆️
...ate-transition/pkg/core/state_processor_staking.go 54.78% <100.00%> (-4.04%) ⬇️
mod/state-transition/pkg/core/state/statedb.go 43.63% <5.26%> (-8.86%) ⬇️

... and 23 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
@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
@abi87 abi87 force-pushed the fix-maximum-number-withdrawals branch from 765cc61 to 6dde55a Compare November 6, 2024 11:11
@@ -131,11 +132,12 @@ func (sp *StateProcessor[
}

// TODO: Modify balance here and then effective balance once per epoch.
newBalance := min(
updatedBalance := types.ComputeEffectiveBalance(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixing faulty merge conflict from previous merge

@abi87 abi87 force-pushed the fix-maximum-number-withdrawals branch from eb5bedc to 6574f67 Compare November 6, 2024 11:25
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