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

Electra alpha8 spec updates #6496

Open
wants to merge 17 commits into
base: unstable
Choose a base branch
from

Conversation

pawanjay176
Copy link
Member

Issue Addressed

N/A

Proposed Changes

Implements changes for electra from https://github.com/ethereum/consensus-specs/releases/tag/v1.5.0-alpha.7 and https://github.com/ethereum/consensus-specs/releases/tag/v1.5.0-alpha.8

  1. Fixed partial withdrawals count eip7251: Fix partial withdrawals count ethereum/consensus-specs#3943
  2. Remove get_active_balance EIP-7251: Flatten get_active_balance ethereum/consensus-specs#3949
  3. Remove queue_entire_balance_and_reset_validator Remove queue_entire_balance_and_reset_validator ethereum/consensus-specs#3951
  4. Switch to compounding when consolidating with source==target eip7251: Switch to compounding when consolidating with source==target ethereum/consensus-specs#3918
  5. Queue deposit requests and apply them during epoch processing eip6110: Queue deposit requests and apply them during epoch processing ethereum/consensus-specs#3818

Other changes from the releases are mostly cosmetic/ do not require changes on our end.
Can be reviewed per commit for each change. However, b28d010 contains bug fixes from all the changes

@@ -36,7 +36,7 @@ impl DepositRequest {
pubkey: PublicKeyBytes::empty(),
withdrawal_credentials: Hash256::ZERO,
amount: 0,
signature: Signature::empty(),
signature: SignatureBytes::empty(),
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we change the type to SignatureBytes for the other request types as well for consistency?

Copy link
Member

Choose a reason for hiding this comment

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

curious why we did this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we need to allow for invalid bls signature bytes to be sent over the engine api. Otherwise, it becomes a deserialization error when we get the payload from the EL instead of an invalid deposit during processing

@pawanjay176 pawanjay176 added the ready-for-review The code is ready for review label Oct 16, 2024
@@ -120,6 +120,9 @@ pub fn initialize_beacon_state_from_eth1<E: EthSpec>(
let post = upgrade_state_to_electra(&mut state, Epoch::new(0), Epoch::new(0), spec)?;
state = post;

// TODO(electra): do we need to iterate over an empty pending_deposits list here and increase balance?
// in accordance with `initialize_beacon_state_from_eth1` function from the spec
Copy link
Collaborator

Choose a reason for hiding this comment

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

No because we have already populated the validators array in line 42 and 45

Copy link
Member Author

Choose a reason for hiding this comment

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

was talking about this

    # Process deposit balance updates
    validator_pubkeys = [v.pubkey for v in state.validators]
    for deposit in state.pending_deposits:
        validator_index = ValidatorIndex(validator_pubkeys.index(deposit.pubkey))
        increase_balance(state, validator_index, deposit.amount)
    state.pending_deposits = []

Added in b2b728d

consensus/state_processing/src/upgrade/electra.rs Outdated Show resolved Hide resolved
AsMut::<[u8; 32]>::as_mut(&mut validator.withdrawal_credentials)[0] =
spec.compounding_withdrawal_prefix_byte;
AsMut::<[u8; 32]>::as_mut(&mut validator.withdrawal_credentials)[0] =
spec.compounding_withdrawal_prefix_byte;
Copy link
Member

Choose a reason for hiding this comment

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

hmmm we should probably refactor the change_withdrawal_credentials() method on the Validator so that it accepts a prefix.

Copy link
Member Author

Choose a reason for hiding this comment

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

This way seems cleaner to me tbh, we are changing it in place instead of creating the entire byte array from scratch

Copy link
Member

Choose a reason for hiding this comment

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

Can the change_withdrawal_credentials() function not be refactored to also do it in place?

Copy link
Member Author

Choose a reason for hiding this comment

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

that function also changes the execution address, not just the prefix. Can do it, but i'm not sure what it adds 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. I guess I'm just arguing for encapsulating it as a function on the validator. Honestly just realizing the naming of this sucks. 0x01 is eth1 credentials (despite wanting to move away from "eth1" and towards "execution") but "execution" now means and both 0x01 and 0x02 😩

I suppose we could fix this in a future PR.. but like what do you think about being explicit:
eth1 -> 0x01 for example has_0x01_withdrawal_credentials

and we could rename change_withdrawal_credentials to change_to_0x01_credentials and add a new function change_to_0x02_credentials which encapsulates what you have above. has_execution_withdrawal_credentials remains the same and is more consistent now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I agree the naming is super confusing, agree with doing the renaming in a future PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-review The code is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants