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

feat(state-transition): make validators epochs handling close to Eth2.0 specs #2226

Merged
merged 16 commits into from
Dec 9, 2024

Conversation

abi87
Copy link
Collaborator

@abi87 abi87 commented Dec 7, 2024

  • Correctly handle validators epochs
  • Implement processRegistryUpdate, moving validators cap handling there
  • Drop useless processing (duly guarded by hard fork)
  • Improve diff calculations to use validators epochs only (wherever possible)

Summary by CodeRabbit

  • New Features

    • Enhanced validator management with new methods for eligibility and activation checks.
    • Introduced a mechanism to enforce a cap on the validator set.
    • Added functionality for processing rewards and penalties within the state processor.
  • Bug Fixes

    • Improved error handling and validation checks for validator activation and epochs.
  • Documentation

    • Updated comments and annotations for better clarity and future maintenance.
  • Tests

    • Refactored test cases to improve clarity and ensure robust validation of validator state transitions.

@abi87 abi87 self-assigned this Dec 7, 2024
Copy link
Contributor

coderabbitai bot commented Dec 7, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

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 involve significant modifications to the Validator struct and various methods related to state processing in a blockchain context. Key updates include renaming and restructuring methods for better clarity and functionality, introducing new methods for managing validator activation and epochs, and removing outdated logic that handled validator set sizes. The overall goal is to enhance the management of validators during state transitions, focusing on their eligibility, activation, and effective balance updates.

Changes

File Path Change Summary
consensus-types/types/validator.go Updated method signatures for IsEligibleForActivation and IsEligibleForActivationQueue, added getter/setter methods for activation-related epochs, and modified IsPartiallyWithdrawable for consistency.
state-transition/core/state_processor.go Removed valSetMu and valSetByEpoch from StateProcessor, updated processEpoch logic for validator management, and removed hollowProcessRewardsAndPenalties.
state-transition/core/state_processor_genesis.go Enhanced InitializePreminedBeaconStateFromEth1 with a call to processGenesisActivation, added error handling, and updated return statement logic.
state-transition/core/state_processor_genesis_test.go Modified test functions to include checks for validator activation eligibility and epochs, adjusted common checks, and updated parameter types for clarity.
state-transition/core/state_processor_rewards_penalties.go Introduced processRewardsAndPenalties method for handling rewards and penalties, currently structured to perform no operations.
state-transition/core/state_processor_slashing.go Removed processProposerSlashing and processSlashings, simplified processSlashingsReset, and updated logic for slashing checks.
state-transition/core/state_processor_staking.go Removed validator cap checks from addValidatorToRegistry and addValidatorInternal, streamlined validator addition logic, and updated error handling.
state-transition/core/state_processor_staking_test.go Renamed variables for clarity, refactored tests to utilize moveToEndOfEpoch, and ensured robust validation of effective balance updates and validator states.
state-transition/core/state_processor_validators.go Renamed processValidatorsSetUpdates to processRegistryUpdates, added processValidatorSetCap for enforcing validator caps, and introduced getActiveVals for retrieving active validators.
state-transition/core/types.go Added new methods to the Validator interface for activation eligibility and epoch management, enhancing the interface's functionality.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Validator
    participant StateProcessor

    User->>Validator: Check eligibility for activation
    Validator->>Validator: IsEligibleForActivation(finalizedEpoch)
    Validator-->>User: Return eligibility status

    User->>StateProcessor: Process epoch
    StateProcessor->>StateProcessor: processRegistryUpdates(st)
    StateProcessor-->>User: Update validator states
Loading

Possibly related PRs

Suggested labels

Ready for Review

Suggested reviewers

  • itsdevbear
  • calbera
  • nidhi-singh02

Poem

In the meadow, where rabbits play,
Validators hop in a bright ballet.
With epochs set and balances clear,
They dance through changes, year by year.
Hopping high, they never tire,
In a world of code, they leap and aspire! 🐇✨


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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 Dec 7, 2024

Codecov Report

Attention: Patch coverage is 57.44681% with 100 lines in your changes missing coverage. Please review.

Project coverage is 29.56%. Comparing base (5e1da04) to head (69c753e).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...tate-transition/core/state_processor_validators.go 72.03% 25 Missing and 8 partials ⚠️
...ansition/core/state_processor_rewards_penalties.go 22.22% 20 Missing and 1 partial ⚠️
state-transition/core/state_processor_genesis.go 59.45% 10 Missing and 5 partials ⚠️
state-transition/core/state_processor.go 26.31% 9 Missing and 5 partials ⚠️
consensus-types/types/validator.go 29.41% 12 Missing ⚠️
state-transition/core/state_processor_slashing.go 69.23% 4 Missing ⚠️
state-transition/core/state_processor_staking.go 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2226      +/-   ##
==========================================
+ Coverage   29.40%   29.56%   +0.15%     
==========================================
  Files         352      353       +1     
  Lines       16074    16103      +29     
  Branches       20       20              
==========================================
+ Hits         4727     4761      +34     
+ Misses      11037    11026      -11     
- Partials      310      316       +6     
Files with missing lines Coverage Δ
state-transition/core/state_processor_staking.go 62.50% <75.00%> (-4.02%) ⬇️
state-transition/core/state_processor_slashing.go 63.15% <69.23%> (+54.68%) ⬆️
consensus-types/types/validator.go 85.82% <29.41%> (-8.54%) ⬇️
state-transition/core/state_processor.go 39.13% <26.31%> (+2.83%) ⬆️
state-transition/core/state_processor_genesis.go 49.15% <59.45%> (+4.03%) ⬆️
...ansition/core/state_processor_rewards_penalties.go 22.22% <22.22%> (ø)
...tate-transition/core/state_processor_validators.go 77.63% <72.03%> (-9.32%) ⬇️

... and 1 file with indirect coverage changes

@abi87 abi87 force-pushed the introduce_validators_epochs branch from d31475d to 7409de1 Compare December 7, 2024 21:12
@abi87 abi87 force-pushed the introduce_validators_epochs branch from 5865607 to 51a12a0 Compare December 7, 2024 21:39
@abi87 abi87 force-pushed the introduce_validators_epochs branch from 158afbb to 763ed85 Compare December 8, 2024 00:01
// TODO: consider moving this to BeaconState directly
func (*StateProcessor[
_, _, _, _, _, _, _, _, _, _, _, _, ValidatorT, _, _, _, _,
]) lowestStakeVal(currentVals []ValidatorT) (
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed really

// validator set would be.
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, ValidatorT, _, _, _, _,
]) nextEpochValidatorSet(st BeaconStateT) ([]ValidatorT, error) {
Copy link
Collaborator Author

@abi87 abi87 Dec 8, 2024

Choose a reason for hiding this comment

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

moved to state-transition/core/state_processor_validators.go, as it should be

@@ -492,40 +474,6 @@ func (sp *StateProcessor[
return st.SetLatestBlockHeader(lbh)
}

func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) hollowProcessRewardsAndPenalties(st BeaconStateT) error {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moved to its own file to be out of the way

@abi87 abi87 marked this pull request as ready for review December 8, 2024 04:40
@abi87 abi87 requested a review from itsdevbear as a code owner December 8, 2024 04:40
@abi87 abi87 force-pushed the introduce_validators_epochs branch from bd3c44f to 7f8df44 Compare December 8, 2024 06:23
Comment on lines -103 to -115

// valSetMu protects valSetByEpoch from concurrent accesses
valSetMu sync.RWMutex

// valSetByEpoch tracks the set of validators active at the latest epochs.
// This is useful to optimize validators set updates.
// Note: Transition may be called multiple times on different,
// non/finalized blocks, so at some point valSetByEpoch may contain
// informations from blocks not finalized. This should be fine as long
// as a block is finalized eventually, and its changes will be the last
// ones.
// We prune the map to preserve only current and previous epoch
valSetByEpoch map[math.Epoch][]ValidatorT
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not needed anymore, once validators epochs are duly handled

Comment on lines -383 to -398
switch {
case sp.cs.DepositEth1ChainID() == spec.BartioChainID:
if err = sp.hollowProcessRewardsAndPenalties(st); err != nil {
return nil, err
}
case sp.cs.DepositEth1ChainID() == spec.BoonetEth1ChainID &&
slot < math.U64(spec.BoonetFork3Height):
// We cannot simply drop hollowProcessRewardsAndPenalties because
// appHash accounts for the list of operations carried out
// over the state even if the operations does not affect the state
// (rewards and penalties are always zero at this stage of beaconKit)
if err = sp.hollowProcessRewardsAndPenalties(st); err != nil {
return nil, err
}
default:
// no real need to perform hollowProcessRewardsAndPenalties
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moved into processRewardsAndPenalties to have fork switches less in the way of mostly read code

@abi87 abi87 requested a review from calbera December 8, 2024 16:57
@abi87
Copy link
Collaborator Author

abi87 commented Dec 8, 2024

@coderabbitai: review

Copy link
Contributor

coderabbitai bot commented Dec 8, 2024

@abi87: I will review the changes.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 5e1da04 and 9f30dd8.

📒 Files selected for processing (10)
  • consensus-types/types/validator.go (3 hunks)
  • state-transition/core/state_processor.go (2 hunks)
  • state-transition/core/state_processor_genesis.go (4 hunks)
  • state-transition/core/state_processor_genesis_test.go (3 hunks)
  • state-transition/core/state_processor_rewards_penalties.go (1 hunks)
  • state-transition/core/state_processor_slashing.go (2 hunks)
  • state-transition/core/state_processor_staking.go (2 hunks)
  • state-transition/core/state_processor_staking_test.go (19 hunks)
  • state-transition/core/state_processor_validators.go (2 hunks)
  • state-transition/core/types.go (1 hunks)
🧰 Additional context used
📓 Learnings (4)
state-transition/core/state_processor_staking.go (3)
Learnt from: abi87
PR: berachain/beacon-kit#2142
File: mod/state-transition/pkg/core/state_processor_committee.go:48-50
Timestamp: 2024-11-12T11:12:56.774Z
Learning: In `mod/state-transition/pkg/core/state_processor_committee.go`, the TODO comment about optimizing the process to send only updated validators to consensus is already tracked and does not require creating a new issue.
Learnt from: abi87
PR: berachain/beacon-kit#2119
File: mod/state-transition/pkg/core/state_processor_validators.go:40-43
Timestamp: 2024-11-29T12:00:20.998Z
Learning: The developer prefers not to add specific error handling for validator cap scenarios in the `processValidatorsSetUpdates` function.
Learnt from: abi87
PR: berachain/beacon-kit#2119
File: mod/state-transition/pkg/core/state_processor_staking.go:202-207
Timestamp: 2024-11-12T11:12:56.773Z
Learning: In `mod/state-transition/pkg/core/state_processor_staking.go`, within the `addValidatorToRegistry` function, when a new validator's effective balance is less than or equal to the smallest current validator's effective balance, it's acceptable to mark the new validator as withdrawable and add it to the registry.
state-transition/core/state_processor_validators.go (1)
Learnt from: abi87
PR: berachain/beacon-kit#2119
File: mod/state-transition/pkg/core/state_processor_validators.go:40-43
Timestamp: 2024-11-29T12:00:20.998Z
Learning: The developer prefers not to add specific error handling for validator cap scenarios in the `processValidatorsSetUpdates` function.
state-transition/core/state_processor_genesis.go (2)
Learnt from: abi87
PR: berachain/beacon-kit#2142
File: mod/state-transition/pkg/core/state_processor_genesis.go:46-159
Timestamp: 2024-11-12T11:12:56.773Z
Learning: When reviewing the `InitializePreminedBeaconStateFromEth1` function in `mod/state-transition/pkg/core/state_processor_genesis.go`, additional documentation of the initialization sequence is not necessary as per the user's preference.
Learnt from: abi87
PR: berachain/beacon-kit#2119
File: mod/state-transition/pkg/core/state_processor_genesis.go:109-118
Timestamp: 2024-11-12T11:12:56.773Z
Learning: In `InitializePreminedBeaconStateFromEth1` in `mod/state-transition/pkg/core/state_processor_genesis.go`, we enforce that there is a single deposit per validator in the genesis format; therefore, handling multiple deposits per validator is not necessary.
state-transition/core/state_processor_staking_test.go (4)
Learnt from: abi87
PR: berachain/beacon-kit#2119
File: mod/state-transition/pkg/core/state_processor_genesis.go:109-118
Timestamp: 2024-11-12T11:12:56.773Z
Learning: In `InitializePreminedBeaconStateFromEth1` in `mod/state-transition/pkg/core/state_processor_genesis.go`, we enforce that there is a single deposit per validator in the genesis format; therefore, handling multiple deposits per validator is not necessary.
Learnt from: abi87
PR: berachain/beacon-kit#2119
File: mod/state-transition/pkg/core/state_processor_staking_test.go:424-440
Timestamp: 2024-11-12T11:12:56.773Z
Learning: In the `TestTransitionHittingValidatorsCap` function in `mod/state-transition/pkg/core/state_processor_staking_test.go`, adding additional assertions to verify validator set size after initialization is unnecessary.
Learnt from: abi87
PR: berachain/beacon-kit#2142
File: mod/state-transition/pkg/core/state_processor_staking_test.go:154-168
Timestamp: 2024-11-12T11:12:56.774Z
Learning: In the `TestTransitionUpdateValidators` function in `mod/state-transition/pkg/core/state_processor_staking_test.go`, adding additional assertions for balance relationships is not necessary.
Learnt from: abi87
PR: berachain/beacon-kit#2142
File: mod/state-transition/pkg/core/state_processor_staking_test.go:175-197
Timestamp: 2024-11-12T11:12:56.774Z
Learning: In Go test files within the `mod/state-transition/pkg/core/` directory, when a test is already substantial in size, avoid adding verbose code or comments that increase its length further.
🔇 Additional comments (15)
state-transition/core/state_processor_genesis.go (2)

109-111: Confirm Proper Activation of Validators at Genesis

The addition of sp.processGenesisActivation(st) enhances the genesis state initialization by activating validators appropriately. Ensure that this method sets activation and eligibility epochs in compliance with the Eth2.0 specifications.


164-196: Verify Activation Epoch Values in processGenesisActivation

In the processGenesisActivation method, activation eligibility and activation epochs are set to 0. Verify that setting these epochs to 0 aligns with the protocol specifications and does not introduce unintended behavior.

Run the following script to check for protocol compliance regarding activation epochs:

✅ Verification successful

Based on the search results, I can now provide a definitive response about the activation epoch values in the genesis state:

Setting activation epochs to 0 in genesis state is correct

The codebase evidence confirms that setting both ActivationEligibilityEpoch and ActivationEpoch to 0 for genesis validators is the correct implementation:

  • Test cases in state_processor_genesis_test.go explicitly verify that genesis validators have both epochs set to 0
  • The validator lifecycle implementation shows that a validator is considered active when ActivationEpoch <= currentEpoch < ExitEpoch
  • Setting these values to 0 ensures genesis validators are active from the very first epoch, which is the expected behavior for initial validators
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that setting activation epochs to 0 is compliant with the specifications.

# Test: Search for protocol documentation or code comments related to activation epochs.
# Expected Result: Confirmation that 0 is the correct value for initial activation epochs.

rg "activation.?epoch" docs/ specs/ comments/ code/

Length of output: 196


Script:

#!/bin/bash
# Let's search for activation epoch related code in the entire codebase
rg -i "activation.?epoch|genesis.?activation" -A 3 -B 3

# Also search for any genesis state initialization patterns
ast-grep --pattern 'func $$$Genesis$$$($$$) {
  $$$
}'

Length of output: 27959

state-transition/core/state_processor_staking.go (1)

215-215: Ensure Balance Increase Matches Deposit Amount

When increasing the validator's balance, ensure that the amount added matches the deposit amount to maintain consistency.

state-transition/core/state_processor.go (2)

Line range hint 367-403: Ensure Correct Processing Order in processEpoch

The updates in processEpoch correctly enforce the validator set cap after processing rewards, penalties, and registry updates. This ensures that all validator states are up to date before applying the cap.


375-377: Implement Actual Rewards and Penalties Processing

The call to sp.processRewardsAndPenalties(st) suggests that rewards and penalties are now being processed. Ensure that this method is properly implemented and aligns with the protocol specifications.

Run the following script to check for the implementation of processRewardsAndPenalties:

state-transition/core/state_processor_slashing.go (2)

37-41: LGTM! Clear documentation of implementation rationale.

The comment effectively explains why this seemingly no-op function is maintained, highlighting its importance for state consistency through appHash.


59-60: Verify the epoch calculation's correctness.

The epoch calculation and slashing vector index update appear correct, but let's verify there are no other dependencies on this operation.

✅ Verification successful

Let me analyze the slashing vector operations further by checking for any additional dependencies.

Let me analyze the results to provide a comprehensive verification of the epoch calculation and its dependencies.


Let me try one more verification to check the slashing-related state transitions.


Epoch calculation and slashing vector index update are correctly implemented

Based on the verification results:

  1. The epoch calculation (sp.cs.SlotToEpoch(slot).Unwrap() + 1) % sp.cs.EpochsPerSlashingsVector() follows the same pattern as other vector index calculations in the codebase
  2. The slashing vector is properly bounded by EpochsPerSlashingsVector (set to 8 in base config)
  3. The UpdateSlashingAtIndex operation is consistently implemented across the state interfaces
  4. No conflicting or inconsistent usage patterns were found in the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other references to slashing vector operations
rg -A 3 "EpochsPerSlashingsVector|UpdateSlashingAtIndex"

Length of output: 3044


Script:

#!/bin/bash
# Search for any references to slashing calculations or index manipulations
ast-grep --pattern 'SlotToEpoch($$$).Unwrap() % $$$'

# Also check for any direct slashing vector access patterns
ast-grep --pattern 'GetSlashingAtIndex($$$)'

Length of output: 101


Script:

#!/bin/bash
# Search for slashing-related state transitions and calculations
rg -A 5 "func.*[Ss]lashing" 

# Also check for epoch calculations in state transitions
rg -A 3 "SlotToEpoch.*Unwrap"

Length of output: 15794

state-transition/core/state_processor_rewards_penalties.go (1)

37-41: LGTM! Clear documentation of implementation rationale.

The comment effectively explains why this seemingly no-op function is maintained, highlighting its importance for state consistency through appHash.

state-transition/core/state_processor_genesis_test.go (3)

148-154: LGTM! Clear validator retrieval and verification.

The sequence of operations (get index by pubkey, then get validator by index) is correct and includes proper error handling.


159-160: LGTM! Proper activation epoch verification for non-Bartio validators.

The checks correctly verify that non-Bartio validators have their activation epochs set to 0, aligning with the PR's objective of improving validator epochs handling.


288-297: LGTM! Proper activation epoch verification for Bartio validators.

The checks correctly verify that Bartio validators have their activation epochs set to FarFutureEpoch, with clear formatting and proper constant usage.

state-transition/core/types.go (1)

245-248: LGTM! Interface changes align with Eth2.0 specifications.

The new methods enhance the Validator interface with proper eligibility checks and epoch management capabilities, following the Ethereum 2.0 specifications for validator state transitions.

Also applies to: 258-265

consensus-types/types/validator.go (2)

258-260: LGTM! Improved eligibility check logic.

The modification to use a threshold parameter instead of maxEffectiveBalance provides more flexibility in determining validator eligibility, while maintaining the core functionality.


320-342: LGTM! Clean implementation of epoch management methods.

The getter and setter implementations follow Go best practices and provide proper encapsulation of validator state.

state-transition/core/state_processor_staking_test.go (1)

1086-1121: LGTM! Well-structured helper function.

The moveToEndOfEpoch helper effectively reduces code duplication and provides clear epoch transition logic with proper error handling.

@@ -1211,3 +1082,40 @@ func generateTestPK(t *testing.T, rndSeed int) (bytes.B48, int) {
rndSeed++
return key, rndSeed
}

func moveToEndOfEpoch(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

minor test consolidation

func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, ValidatorT, _, _, _, _,
]) processValidatorsSetUpdates(
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 basically being replace by the following processing:

  • at the beginning of processEpoch we not the currently active validator set
  • we carry out all Eth like transitions
  • at the end of processEpoch we pick again the active validator set (which will be active next epoch) and compute the diff to send back to consensus

Comment on lines +182 to +184
if val.GetEffectiveBalance() < minEffectiveBalance {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

just a sanity check for myself: this case should only happen if we include a genesis deposit under min stake? In which case we don't set the activation epoch

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 correct. I synced the first 2000 blocks and had no issue, so we should be good

@abi87 abi87 requested a review from calbera December 9, 2024 18:06
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.

utACK

@abi87 abi87 merged commit b00e245 into main Dec 9, 2024
16 checks passed
@abi87 abi87 deleted the introduce_validators_epochs branch December 9, 2024 18:47
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.

2 participants