Electra updates for v1.5.0-alpha.6 (#6445)

* Update process_slashing

* Update test vectors version

* Delete Domain::Consolidation

* Rename to get_max_effective_balance

* Fix unused; lint

* Add the pre-electra slashing processing

* lint

* Change request json types

* Move requests from payload to beacon block body

* Refactor engine api

* Fix warnings

* Update engine api to latest

* engine api changed..again

* yet again

* Merge branch 'engine-requests' into electra-updates

* Fix tests

* Store reference instead of bytes in NewPayloadRequest

* Merge branch 'unstable' into electra-updates

* Update beacon_node/execution_layer/src/engine_api/json_structures.rs

Co-authored-by: Michael Sproul <micsproul@gmail.com>

* Update beacon_node/execution_layer/src/lib.rs

Co-authored-by: Michael Sproul <micsproul@gmail.com>

* Update beacon_node/execution_layer/src/test_utils/handle_rpc.rs

Co-authored-by: Michael Sproul <micsproul@gmail.com>
This commit is contained in:
Pawan Dhananjay
2024-10-15 10:38:43 -07:00
committed by GitHub
parent 2e440df4f1
commit 83d5c521d7
35 changed files with 445 additions and 913 deletions

View File

@@ -579,8 +579,7 @@ pub fn get_expected_withdrawals<E: EthSpec>(
.get_execution_withdrawal_address(spec)
.ok_or(BlockProcessingError::WithdrawalCredentialsInvalid)?,
amount: balance.safe_sub(
validator
.get_validator_max_effective_balance(spec, state.fork_name_unchecked()),
validator.get_max_effective_balance(spec, state.fork_name_unchecked()),
)?,
});
withdrawal_index.safe_add_assign(1)?;

View File

@@ -40,15 +40,13 @@ pub fn process_operations<E: EthSpec, Payload: AbstractExecPayload<E>>(
if state.fork_name_unchecked().electra_enabled() {
state.update_pubkey_cache()?;
if let Some(deposit_requests) = block_body.execution_payload()?.deposit_requests()? {
process_deposit_requests(state, &deposit_requests, spec)?;
}
if let Some(withdrawal_requests) = block_body.execution_payload()?.withdrawal_requests()? {
process_withdrawal_requests(state, &withdrawal_requests, spec)?;
}
if let Some(consolidations) = block_body.execution_payload()?.consolidation_requests()? {
process_consolidation_requests(state, &consolidations, spec)?;
}
process_deposit_requests(state, &block_body.execution_requests()?.deposits, spec)?;
process_withdrawal_requests(state, &block_body.execution_requests()?.withdrawals, spec)?;
process_consolidation_requests(
state,
&block_body.execution_requests()?.consolidations,
spec,
)?;
}
Ok(())

View File

@@ -82,6 +82,7 @@ struct RewardsAndPenaltiesContext {
struct SlashingsContext {
adjusted_total_slashing_balance: u64,
target_withdrawable_epoch: Epoch,
penalty_per_effective_balance_increment: u64,
}
struct PendingBalanceDepositsContext {
@@ -775,9 +776,16 @@ impl SlashingsContext {
.current_epoch
.safe_add(E::EpochsPerSlashingsVector::to_u64().safe_div(2)?)?;
let penalty_per_effective_balance_increment = adjusted_total_slashing_balance.safe_div(
state_ctxt
.total_active_balance
.safe_div(spec.effective_balance_increment)?,
)?;
Ok(Self {
adjusted_total_slashing_balance,
target_withdrawable_epoch,
penalty_per_effective_balance_increment,
})
}
}
@@ -792,14 +800,20 @@ fn process_single_slashing(
if validator.slashed && slashings_ctxt.target_withdrawable_epoch == validator.withdrawable_epoch
{
let increment = spec.effective_balance_increment;
let penalty_numerator = validator
.effective_balance
.safe_div(increment)?
.safe_mul(slashings_ctxt.adjusted_total_slashing_balance)?;
let penalty = penalty_numerator
.safe_div(state_ctxt.total_active_balance)?
.safe_mul(increment)?;
let penalty = if state_ctxt.fork_name.electra_enabled() {
let effective_balance_increments = validator.effective_balance.safe_div(increment)?;
slashings_ctxt
.penalty_per_effective_balance_increment
.safe_mul(effective_balance_increments)?
} else {
let penalty_numerator = validator
.effective_balance
.safe_div(increment)?
.safe_mul(slashings_ctxt.adjusted_total_slashing_balance)?;
penalty_numerator
.safe_div(state_ctxt.total_active_balance)?
.safe_mul(increment)?
};
*balance.make_mut()? = balance.saturating_sub(penalty);
}
Ok(())
@@ -1022,8 +1036,7 @@ fn process_single_effective_balance_update(
) -> Result<(), Error> {
// Use the higher effective balance limit if post-Electra and compounding withdrawal credentials
// are set.
let effective_balance_limit =
validator.get_validator_max_effective_balance(spec, state_ctxt.fork_name);
let effective_balance_limit = validator.get_max_effective_balance(spec, state_ctxt.fork_name);
let old_effective_balance = validator.effective_balance;
let new_effective_balance = if balance.safe_add(eb_ctxt.downward_threshold)?