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

chore(state-transition): Dropped unused code #2144

Closed
wants to merge 1 commit into from

Conversation

abi87
Copy link
Collaborator

@abi87 abi87 commented Nov 10, 2024

This is simple code to implement (straight from Eth 2.0 specs) but it's not active.
Keeping this in gives no advantages and make marginally harder to read code.
Will reimplement once we have slashing in

Summary by CodeRabbit

  • New Features

    • Restructured state processing logic for improved efficiency.
  • Bug Fixes

    • Removed obsolete methods related to attestation deltas and rewards processing, streamlining state transitions.
  • Chores

    • Deleted the slashing processor file to eliminate unused functionalities, aligning with current project requirements.

Copy link
Contributor

coderabbitai bot commented Nov 10, 2024

Walkthrough

The changes in this pull request involve significant modifications to the state processing logic within the Ethereum 2.0 framework. Key alterations include the removal of several methods related to attestation deltas, rewards, penalties, and slashing events from the state_processor.go and state_processor_slashing.go files. This restructuring indicates a shift in how the state processor will manage these functionalities, with some methods being commented out for future implementation, while others have been completely eliminated.

Changes

File Path Change Summary
mod/state-transition/pkg/core/state_processor.go Removed methods: getAttestationDeltas, processRewardsAndPenalties; commented out calls in processEpoch.
mod/state-transition/pkg/core/state_processor_slashing.go Deleted file; removed methods: processSlashingsReset, processProposerSlashing, processSlashings, processSlash.

Possibly related PRs

Suggested labels

Ready for Review

Suggested reviewers

  • itsdevbear
  • ocnc
  • nidhi-singh02

🐇 In the meadow where changes bloom,
The state processor sheds its gloom.
With methods gone, a path anew,
Awaiting tasks for us to pursue.
Hops of progress, leaps of cheer,
In code we trust, our vision clear! 🌼


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.

Copy link

codecov bot commented Nov 10, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 26.43%. Comparing base (9cbce04) to head (c1743c9).

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

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2144      +/-   ##
==========================================
+ Coverage   26.24%   26.43%   +0.18%     
==========================================
  Files         360      359       -1     
  Lines       16241    16128     -113     
  Branches       12       12              
==========================================
  Hits         4263     4263              
+ Misses      11709    11596     -113     
  Partials      269      269              
Files with missing lines Coverage Δ
mod/state-transition/pkg/core/state_processor.go 34.25% <0.00%> (+7.87%) ⬆️

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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 9cbce04 and c1743c9.

📒 Files selected for processing (2)
  • mod/state-transition/pkg/core/state_processor.go (1 hunks)
  • mod/state-transition/pkg/core/state_processor_slashing.go (0 hunks)
💤 Files with no reviewable changes (1)
  • mod/state-transition/pkg/core/state_processor_slashing.go

Comment on lines +335 to +336
// TODO: implement processRewardsAndPenalties
// TODO: implement processSlashingsReset
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Document the rationale for removing these functions

The TODOs indicate that processRewardsAndPenalties and processSlashingsReset functionality will need to be reimplemented. Consider adding more context in the TODO comments about:

  • When these functions will be reimplemented (e.g., "TODO: implement when slashing is integrated")
  • Any specific requirements or dependencies needed for reimplementation
-	// TODO: implement processRewardsAndPenalties
-	// TODO: implement processSlashingsReset
+	// TODO(slashing): Implement processRewardsAndPenalties when slashing is integrated
+	// TODO(slashing): Implement processSlashingsReset when slashing is integrated
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// TODO: implement processRewardsAndPenalties
// TODO: implement processSlashingsReset
// TODO(slashing): Implement processRewardsAndPenalties when slashing is integrated
// TODO(slashing): Implement processSlashingsReset when slashing is integrated

Comment on lines 334 to 339
) (transition.ValidatorUpdates, error) {
if err := sp.processRewardsAndPenalties(st); err != nil {
return nil, err
}
if err := sp.processSlashingsReset(st); err != nil {
return nil, err
}
// TODO: implement processRewardsAndPenalties
// TODO: implement processSlashingsReset
if err := sp.processRandaoMixesReset(st); err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

💡 Codebase verification

Based on the search results, I can now generate the final response:

Slashing functionality is still integral to the codebase

The removal of these TODOs requires careful consideration as slashing is deeply integrated in the system:

  • Core slashing interfaces and types are defined and used throughout:

    • mod/consensus-types/pkg/types/validator.go defines slashing-related validator states
    • mod/storage/pkg/beacondb/slashing.go implements slashing storage
    • mod/node-core/pkg/components/interfaces.go defines slashing-related interfaces
    • examples/berad/pkg/state-transition/state_processor_slashing.go contains reference implementation
  • The codebase maintains slashing-related state:

    • Validator slashing status tracking
    • Slashing history storage
    • Total slashing amounts

Rather than removing these TODOs, they should be implemented to maintain consistency with the rest of the system's slashing capabilities.

🔗 Analysis chain

Consider architectural implications of removing slashing functionality

The removal of slashing-related code (processRewardsAndPenalties, processSlashingsReset) has architectural implications:

  1. Ensure that no other parts of the system depend on these removed functionalities
  2. Consider adding validation to prevent slashable behaviors until slashing is reimplemented
  3. Document the temporary limitations in the system's documentation

Let's verify if there are any remaining references to the removed functionality:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for references to removed slashing-related functions
echo "Searching for references to removed functions..."
rg "processRewardsAndPenalties|processSlashingsReset|getAttestationDeltas|processProposerSlashing|processSlashings|processSlash"

# Search for any remaining slashing-related code
echo "Searching for slashing-related code..."
rg -i "slash|penalty|reward|attestation.*delta"

Length of output: 41797

Comment on lines -450 to -456
// TODO: implement this function forreal
validators, err := st.GetValidators()
if err != nil {
return nil, nil, err
}
placeholder := make([]math.Gwei, len(validators))
return placeholder, placeholder, nil
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we load the full validator list to do absolutely nothing with it. Better avoid this until we explicitly handle slashing

]) processRewardsAndPenalties(
st BeaconStateT,
) error {
slot, err := st.GetSlot()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

with getAttestationDeltas gone, this is pointless

Copy link
Contributor

@dezzeus dezzeus left a comment

Choose a reason for hiding this comment

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

I would prefer to keep the code if it matches the Ethereum 2.0 specification and just mark it with some convention-defined comment, but I can confirm that – apart from the examples/berad module – it's not used anymore.

//nolint:lll
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) getAttestationDeltas(
Copy link
Contributor

Choose a reason for hiding this comment

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

Still used by the examples/berad module.

Provided by examples/berad/pkg/state-transition/state_processor.go row 458.

Called in examples/berad/pkg/state-transition/state_processor.go row 488.

//nolint:lll
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) processRewardsAndPenalties(
Copy link
Contributor

Choose a reason for hiding this comment

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

Still used by the examples/berad module.

Provided by examples/berad/pkg/state-transition/state_processor.go row 476.

Called in examples/berad/pkg/state-transition/state_processor.go row 338.

//nolint:lll
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) processSlashingsReset(
Copy link
Contributor

Choose a reason for hiding this comment

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

Still used by the examples/berad module.

Provided by examples/berad/pkg/state-transition/state_processor_slashing.go row 29.

Called in examples/berad/pkg/state-transition/state_processor.go row 340.

@abi87
Copy link
Collaborator Author

abi87 commented Nov 11, 2024

@dezzeus ok, keeping code as is

@abi87 abi87 closed this Nov 11, 2024
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.

2 participants