mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
Fixes to make EF Capella tests pass (#3719)
* Fixes to make EF Capella tests pass * Clippy for state_processing
This commit is contained in:
@@ -1 +1,2 @@
|
||||
#[allow(clippy::module_inception)]
|
||||
pub mod eip4844;
|
||||
|
||||
@@ -6,8 +6,8 @@ use ssz::Decode;
|
||||
use ssz_types::VariableList;
|
||||
use types::consts::eip4844::{BLOB_TX_TYPE, VERSIONED_HASH_VERSION_KZG};
|
||||
use types::{
|
||||
AbstractExecPayload, BeaconBlockBodyRef, EthSpec, ExecPayload, FullPayload, FullPayloadRef,
|
||||
KzgCommitment, Transaction, Transactions, VersionedHash,
|
||||
AbstractExecPayload, BeaconBlockBodyRef, EthSpec, ExecPayload, KzgCommitment, Transaction,
|
||||
Transactions, VersionedHash,
|
||||
};
|
||||
|
||||
pub fn process_blob_kzg_commitments<T: EthSpec, Payload: AbstractExecPayload<T>>(
|
||||
@@ -34,7 +34,7 @@ pub fn verify_kzg_commitments_against_transactions<T: EthSpec>(
|
||||
let nested_iter = transactions
|
||||
.into_iter()
|
||||
.filter(|tx| {
|
||||
tx.get(0)
|
||||
tx.first()
|
||||
.map(|tx_type| *tx_type == BLOB_TX_TYPE)
|
||||
.unwrap_or(false)
|
||||
})
|
||||
|
||||
@@ -94,6 +94,7 @@ pub enum BlockProcessingError {
|
||||
index: usize,
|
||||
length: usize,
|
||||
},
|
||||
WithdrawalCredentialsInvalid,
|
||||
}
|
||||
|
||||
impl From<BeaconStateError> for BlockProcessingError {
|
||||
|
||||
@@ -33,8 +33,11 @@ pub fn process_operations<'a, T: EthSpec, Payload: AbstractExecPayload<T>>(
|
||||
process_attestations(state, block_body, verify_signatures, ctxt, spec)?;
|
||||
process_deposits(state, block_body.deposits(), spec)?;
|
||||
process_exits(state, block_body.voluntary_exits(), verify_signatures, spec)?;
|
||||
|
||||
#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))]
|
||||
process_bls_to_execution_changes(state, block_body, verify_signatures, spec)?;
|
||||
if let Ok(bls_to_execution_changes) = block_body.bls_to_execution_changes() {
|
||||
process_bls_to_execution_changes(state, bls_to_execution_changes, verify_signatures, spec)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -287,39 +290,25 @@ pub fn process_exits<T: EthSpec>(
|
||||
/// Returns `Ok(())` if the validation and state updates completed successfully. Otherwise returs
|
||||
/// an `Err` describing the invalid object or cause of failure.
|
||||
#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))]
|
||||
pub fn process_bls_to_execution_changes<'a, T: EthSpec, Payload: AbstractExecPayload<T>>(
|
||||
pub fn process_bls_to_execution_changes<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
block_body: BeaconBlockBodyRef<'a, T, Payload>,
|
||||
bls_to_execution_changes: &[SignedBlsToExecutionChange],
|
||||
verify_signatures: VerifySignatures,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), BlockProcessingError> {
|
||||
match block_body {
|
||||
BeaconBlockBodyRef::Base(_)
|
||||
| BeaconBlockBodyRef::Altair(_)
|
||||
| BeaconBlockBodyRef::Merge(_) => Ok(()),
|
||||
BeaconBlockBodyRef::Capella(_) | BeaconBlockBodyRef::Eip4844(_) => {
|
||||
for (i, signed_address_change) in
|
||||
block_body.bls_to_execution_changes()?.iter().enumerate()
|
||||
{
|
||||
verify_bls_to_execution_change(
|
||||
state,
|
||||
&signed_address_change,
|
||||
verify_signatures,
|
||||
spec,
|
||||
)
|
||||
.map_err(|e| e.into_with_index(i))?;
|
||||
for (i, signed_address_change) in bls_to_execution_changes.iter().enumerate() {
|
||||
verify_bls_to_execution_change(state, signed_address_change, verify_signatures, spec)
|
||||
.map_err(|e| e.into_with_index(i))?;
|
||||
|
||||
state
|
||||
.get_validator_mut(signed_address_change.message.validator_index as usize)?
|
||||
.change_withdrawal_credentials(
|
||||
&signed_address_change.message.to_execution_address,
|
||||
spec,
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
state
|
||||
.get_validator_mut(signed_address_change.message.validator_index as usize)?
|
||||
.change_withdrawal_credentials(
|
||||
&signed_address_change.message.to_execution_address,
|
||||
spec,
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Validates each `Deposit` and updates the state, short-circuiting on an invalid object.
|
||||
|
||||
@@ -42,13 +42,13 @@ pub fn verify_bls_to_execution_change<T: EthSpec>(
|
||||
// FIXME: Should this check be put inside the verify_signatures.is_true() condition?
|
||||
// I believe that's used for fuzzing so this is a Mehdi question..
|
||||
verify!(
|
||||
validator.withdrawal_credentials.as_bytes()[1..] == pubkey_hash[1..],
|
||||
validator.withdrawal_credentials.as_bytes().get(1..) == pubkey_hash.get(1..),
|
||||
Invalid::WithdrawalCredentialsMismatch
|
||||
);
|
||||
|
||||
if verify_signatures.is_true() {
|
||||
verify!(
|
||||
bls_execution_change_signature_set(state, signed_address_change, spec,)?.verify(),
|
||||
bls_execution_change_signature_set(state, signed_address_change, spec)?.verify(),
|
||||
Invalid::BadSignature
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user