mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-23 14:54:45 +00:00
convert op pool messages to electra in electra
This commit is contained in:
@@ -26,6 +26,12 @@ pub enum Error {
|
||||
InvalidCommitteeIndex,
|
||||
}
|
||||
|
||||
impl From<ssz_types::Error> for Error {
|
||||
fn from(e: ssz_types::Error) -> Self {
|
||||
Error::SszTypesError(e)
|
||||
}
|
||||
}
|
||||
|
||||
#[superstruct(
|
||||
variants(Base, Electra),
|
||||
variant_attributes(
|
||||
@@ -416,6 +422,35 @@ impl<E: EthSpec> AttestationBase<E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> TryFrom<AttestationBase<E>> for AttestationElectra<E> {
|
||||
type Error = Error;
|
||||
fn try_from(att: AttestationBase<E>) -> Result<Self, Self::Error> {
|
||||
// Extend the aggregation bits list.
|
||||
let aggregation_bits = att.extend_aggregation_bits()?;
|
||||
let AttestationBase {
|
||||
aggregation_bits: _,
|
||||
mut data,
|
||||
signature,
|
||||
} = att;
|
||||
|
||||
// Set the committee index based on the index field.
|
||||
let mut committee_bits: BitVector<E::MaxCommitteesPerSlot> = BitVector::default();
|
||||
committee_bits
|
||||
.set(data.index as usize, true)
|
||||
.map_err(|_| Error::InvalidCommitteeIndex)?;
|
||||
|
||||
// Set the attestation data's index to zero.
|
||||
data.index = 0;
|
||||
|
||||
Ok(Self {
|
||||
aggregation_bits,
|
||||
data,
|
||||
committee_bits,
|
||||
signature,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> SlotData for Attestation<E> {
|
||||
fn get_slot(&self) -> Slot {
|
||||
self.data().slot
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::indexed_attestation::{
|
||||
IndexedAttestationBase, IndexedAttestationElectra, IndexedAttestationRef,
|
||||
IndexedAttestation, IndexedAttestationBase, IndexedAttestationElectra, IndexedAttestationRef,
|
||||
};
|
||||
use crate::{test_utils::TestRandom, EthSpec};
|
||||
use derivative::Derivative;
|
||||
@@ -161,6 +161,19 @@ impl<E: EthSpec> AttesterSlashing<E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<AttesterSlashingBase<E>> for AttesterSlashingElectra<E> {
|
||||
fn from(attester_slashing: AttesterSlashingBase<E>) -> Self {
|
||||
let AttesterSlashingBase {
|
||||
attestation_1,
|
||||
attestation_2,
|
||||
} = attester_slashing;
|
||||
AttesterSlashingElectra {
|
||||
attestation_1: IndexedAttestation::Base(attestation_1).to_electra(),
|
||||
attestation_2: IndexedAttestation::Base(attestation_2).to_electra(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> TestRandom for AttesterSlashing<E> {
|
||||
fn random_for_test(rng: &mut impl RngCore) -> Self {
|
||||
if rng.gen_bool(0.5) {
|
||||
|
||||
Reference in New Issue
Block a user