mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
#6970 This allows for us to receive `SingleAttestation` over gossip and process it without converting. There is still a conversion to `Attestation` as a final step in the attestation verification process, but by then the `SingleAttestation` is fully verified. I've also fully removed the `submitPoolAttestationsV1` endpoint as its been deprecated I've also pre-emptively deprecated supporting `Attestation` in `submitPoolAttestationsV2` endpoint. See here for more info: https://github.com/ethereum/beacon-APIs/pull/531 I tried to the minimize the diff here by only making the "required" changes. There are some unnecessary complexities with the way we manage the different attestation verification wrapper types. We could probably consolidate this to one wrapper type and refactor this even further. We could leave that to a separate PR if we feel like cleaning things up in the future. Note that I've also updated the test harness to always submit `SingleAttestation` regardless of fork variant. I don't see a problem in that approach and it allows us to delete more code :)
61 lines
2.1 KiB
Rust
61 lines
2.1 KiB
Rust
use crate::attestation_verification::Error;
|
|
use types::{
|
|
Attestation, AttestationBase, AttestationElectra, BitList, BitVector, EthSpec, ForkName,
|
|
SingleAttestation,
|
|
};
|
|
|
|
pub fn single_attestation_to_attestation<E: EthSpec>(
|
|
single_attestation: &SingleAttestation,
|
|
committee: &[usize],
|
|
fork_name: ForkName,
|
|
) -> Result<Attestation<E>, Error> {
|
|
let attester_index = single_attestation.attester_index;
|
|
let committee_index = single_attestation.committee_index;
|
|
let slot = single_attestation.data.slot;
|
|
|
|
let aggregation_bit = committee
|
|
.iter()
|
|
.enumerate()
|
|
.find_map(|(i, &validator_index)| {
|
|
if attester_index as usize == validator_index {
|
|
return Some(i);
|
|
}
|
|
None
|
|
})
|
|
.ok_or(Error::AttesterNotInCommittee {
|
|
attester_index,
|
|
committee_index,
|
|
slot,
|
|
})?;
|
|
|
|
if fork_name.electra_enabled() {
|
|
let mut committee_bits: BitVector<E::MaxCommitteesPerSlot> = BitVector::default();
|
|
committee_bits
|
|
.set(committee_index as usize, true)
|
|
.map_err(|e| Error::Invalid(e.into()))?;
|
|
|
|
let mut aggregation_bits =
|
|
BitList::with_capacity(committee.len()).map_err(|e| Error::Invalid(e.into()))?;
|
|
aggregation_bits
|
|
.set(aggregation_bit, true)
|
|
.map_err(|e| Error::Invalid(e.into()))?;
|
|
Ok(Attestation::Electra(AttestationElectra {
|
|
aggregation_bits,
|
|
committee_bits,
|
|
data: single_attestation.data.clone(),
|
|
signature: single_attestation.signature.clone(),
|
|
}))
|
|
} else {
|
|
let mut aggregation_bits =
|
|
BitList::with_capacity(committee.len()).map_err(|e| Error::Invalid(e.into()))?;
|
|
aggregation_bits
|
|
.set(aggregation_bit, true)
|
|
.map_err(|e| Error::Invalid(e.into()))?;
|
|
Ok(Attestation::Base(AttestationBase {
|
|
aggregation_bits,
|
|
data: single_attestation.data.clone(),
|
|
signature: single_attestation.signature.clone(),
|
|
}))
|
|
}
|
|
}
|