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

Merged
merged 33 commits into from
Dec 17, 2024
Merged

Electra alpha8 spec updates #6496

merged 33 commits into from
Dec 17, 2024

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
@michaelsproul michaelsproul added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Dec 13, 2024
@pawanjay176
Copy link
Member Author

Great find 🙌 Turns out there was a spec test to catch this specific case, but it was written incorrectly. This has been fixed in the linked consensus specs PR above

@michaelsproul
Copy link
Member

Nice! Thanks for following that up!

@pawanjay176 pawanjay176 added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Dec 14, 2024
@michaelsproul
Copy link
Member

Some of the tests seem to be failing due to builder stuff. Did you mean to include mock-builder changes in this PR?

@pawanjay176
Copy link
Member Author

Ahh I didn't realise I pushed the mock builder changes to this PR. I'll revert them and fix the tests.
Will make a separate PR for the mock builder changes

@michaelsproul
Copy link
Member

I think I've fixed another consensus bug in this commit:

The spec iterates over post.validators, but we were iterating over a clone of validators taken prior to modifying post.validators in the pre_activation loop. So if there are any validators that are pre-activation with compounding withdrawal credentials, we would double credit them by pushing a PendingDeposit in the pre_activation loop here:

post.pending_deposits_mut()?
.push(PendingDeposit {
pubkey,
withdrawal_credentials,
amount: balance_copy,
signature: Signature::infinity()?.into(),
slot: spec.genesis_slot,
})
.map_err(Error::MilhouseError)?;

And then another deposit if they meet the conditions has_compounding_withdrawal_credential (true) and balance > spec.min_activation_balance (true):

for (index, validator) in validators.iter().enumerate() {
if validator.has_compounding_withdrawal_credential(spec) {
post.queue_excess_active_balance(index, spec)?;
}
}

pub fn queue_excess_active_balance(
&mut self,
validator_index: usize,
spec: &ChainSpec,
) -> Result<(), Error> {
let balance = self
.balances_mut()
.get_mut(validator_index)
.ok_or(Error::UnknownValidator(validator_index))?;
if *balance > spec.min_activation_balance {
let excess_balance = balance.safe_sub(spec.min_activation_balance)?;
*balance = spec.min_activation_balance;
let validator = self.get_validator(validator_index)?.clone();
self.pending_deposits_mut()?.push(PendingDeposit {
pubkey: validator.pubkey,
withdrawal_credentials: validator.withdrawal_credentials,
amount: excess_balance,
signature: Signature::infinity()?.into(),
slot: spec.genesis_slot,
})?;
}
Ok(())
}

Additionally, in this case, the balance of the validator would be set to spec.min_activation_balance rather than 0 (the correct value). So their total balance including deposits would end up being balance (first deposit) + excess_balance (second deposit) + min_activation_balance (state) = 2 * balance.

@michaelsproul
Copy link
Member

I also simplified some sorting in this commit (non-semantic change):

Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

Looks good. Let's merge this so we can get other Electra PRs into unstable on top

@pawanjay176
Copy link
Member Author

Great find with the other accounting bug as well! 🙏 I looked through it and also agree with your solution.

@michaelsproul michaelsproul added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Dec 17, 2024
@michaelsproul
Copy link
Member

@mergify queue

Copy link

mergify bot commented Dec 17, 2024

queue

🛑 The pull request has been removed from the queue default

The merge conditions cannot be satisfied due to failing checks.

You can take a look at Queue: Embarked in merge queue check runs for more details.

In case of a failure due to a flaky test, you should first retrigger the CI.
Then, re-embark the pull request into the merge queue by posting the comment
@mergifyio refresh on the pull request.

Copy link

mergify bot commented Dec 17, 2024

This pull request has been removed from the queue for the following reason: checks failed.

The merge conditions cannot be satisfied due to failing checks:

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@michaelsproul
Copy link
Member

@mergify requeue

Copy link

mergify bot commented Dec 17, 2024

requeue

✅ This pull request will be re-embarked automatically

The followup queue command will be automatically executed to re-embark the pull request

Copy link

mergify bot commented Dec 17, 2024

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at d74b2d9

@mergify mergify bot merged commit d74b2d9 into sigp:unstable Dec 17, 2024
29 checks passed
@michaelsproul
Copy link
Member

Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
electra Required for the Electra/Prague fork ready-for-merge This PR is ready to merge. v6.1.0 New release c. Q1 2025
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants