mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 10:52:43 +00:00
There are certain crates which we re-export within `types` which creates a fragmented DevEx, where there are various ways to import the same crates.
```rust
// consensus/types/src/lib.rs
pub use bls::{
AggregatePublicKey, AggregateSignature, Error as BlsError, Keypair, PUBLIC_KEY_BYTES_LEN,
PublicKey, PublicKeyBytes, SIGNATURE_BYTES_LEN, SecretKey, Signature, SignatureBytes,
get_withdrawal_credentials,
};
pub use context_deserialize::{ContextDeserialize, context_deserialize};
pub use fixed_bytes::FixedBytesExtended;
pub use milhouse::{self, List, Vector};
pub use ssz_types::{BitList, BitVector, FixedVector, VariableList, typenum, typenum::Unsigned};
pub use superstruct::superstruct;
```
This PR removes these re-exports and makes it explicit that these types are imported from a non-`consensus/types` crate.
Co-Authored-By: Mac L <mjladson@pm.me>
61 lines
2.1 KiB
Rust
61 lines
2.1 KiB
Rust
use crate::attestation_verification::Error;
|
|
use ssz_types::{BitList, BitVector};
|
|
use types::{
|
|
Attestation, AttestationBase, AttestationElectra, 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(),
|
|
}))
|
|
}
|
|
}
|