Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion consensus/types/src/attestation/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
IndexedAttestationElectra,
},
core::{ChainSpec, Domain, EthSpec, Hash256, SignedRoot, Slot, SlotData},
fork::{Fork, ForkName},
fork::{Fork, ForkName, ForkVersionDecode},
test_utils::TestRandom,
};

Expand Down Expand Up @@ -261,6 +261,17 @@ impl<E: EthSpec> Attestation<E> {
Self::Electra(attn) => attn.get_aggregation_bits(),
}
}

pub fn from_ssz_bytes_for_fork(
Copy link
Member

Choose a reason for hiding this comment

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

To fix the bug that was reported we probably also need to use this func in the network layer.

bytes: &[u8],
fork_name: ForkName,
) -> Result<Self, ssz::DecodeError> {
if fork_name.electra_enabled() {
ssz::Decode::from_ssz_bytes(bytes).map(Self::Electra)
} else {
ssz::Decode::from_ssz_bytes(bytes).map(Self::Base)
}
}
}

impl<E: EthSpec> AttestationRef<'_, E> {
Expand Down Expand Up @@ -582,6 +593,12 @@ impl<'de, E: EthSpec> ContextDeserialize<'de, ForkName> for Attestation<E> {
}
}

impl<E: EthSpec> ForkVersionDecode for Attestation<E> {
fn from_ssz_bytes_by_fork(bytes: &[u8], fork_name: ForkName) -> Result<Self, ssz::DecodeError> {
Self::from_ssz_bytes_for_fork(bytes, fork_name)
}
}

/*
impl<'de, E: EthSpec> ContextDeserialize<'de, ForkName> for Vec<Attestation<E>> {
Copy link
Member

Choose a reason for hiding this comment

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

This commented out code could be revived or deleted as part of this PR too.

fn context_deserialize<D>(
Expand Down