mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 18:32:42 +00:00
Dedup attestation constructor logic in attester cache
This commit is contained in:
@@ -15,6 +15,7 @@ use state_processing::state_advance::{partial_state_advance, Error as StateAdvan
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Range;
|
||||
use types::{
|
||||
attestation::Error as AttestationError,
|
||||
beacon_state::{
|
||||
compute_committee_index_in_epoch, compute_committee_range_in_epoch, epoch_committee_count,
|
||||
},
|
||||
@@ -59,6 +60,7 @@ pub enum Error {
|
||||
InverseRange {
|
||||
range: Range<usize>,
|
||||
},
|
||||
AttestationError(AttestationError),
|
||||
}
|
||||
|
||||
impl From<BeaconStateError> for Error {
|
||||
|
||||
@@ -6,7 +6,6 @@ use crate::{
|
||||
use parking_lot::RwLock;
|
||||
use proto_array::Block as ProtoBlock;
|
||||
use std::sync::Arc;
|
||||
use types::attestation::AttestationBase;
|
||||
use types::*;
|
||||
|
||||
pub struct CacheItem<E: EthSpec> {
|
||||
@@ -123,40 +122,16 @@ impl<E: EthSpec> EarlyAttesterCache<E> {
|
||||
item.committee_lengths
|
||||
.get_committee_length::<E>(request_slot, request_index, spec)?;
|
||||
|
||||
let attestation = if spec.fork_name_at_slot::<E>(request_slot).electra_enabled() {
|
||||
let mut committee_bits = BitVector::default();
|
||||
if committee_len > 0 {
|
||||
committee_bits
|
||||
.set(request_index as usize, true)
|
||||
.map_err(BeaconStateError::from)?;
|
||||
}
|
||||
Attestation::Electra(AttestationElectra {
|
||||
aggregation_bits: BitList::with_capacity(committee_len)
|
||||
.map_err(BeaconStateError::from)?,
|
||||
committee_bits,
|
||||
data: AttestationData {
|
||||
slot: request_slot,
|
||||
index: 0u64,
|
||||
beacon_block_root: item.beacon_block_root,
|
||||
source: item.source,
|
||||
target: item.target,
|
||||
},
|
||||
signature: AggregateSignature::empty(),
|
||||
})
|
||||
} else {
|
||||
Attestation::Base(AttestationBase {
|
||||
aggregation_bits: BitList::with_capacity(committee_len)
|
||||
.map_err(BeaconStateError::from)?,
|
||||
data: AttestationData {
|
||||
slot: request_slot,
|
||||
index: request_index,
|
||||
beacon_block_root: item.beacon_block_root,
|
||||
source: item.source,
|
||||
target: item.target,
|
||||
},
|
||||
signature: AggregateSignature::empty(),
|
||||
})
|
||||
};
|
||||
let attestation = Attestation::empty_for_signing(
|
||||
request_index,
|
||||
committee_len,
|
||||
request_slot,
|
||||
item.beacon_block_root,
|
||||
item.source,
|
||||
item.target,
|
||||
spec,
|
||||
)
|
||||
.map_err(Error::AttestationError)?;
|
||||
|
||||
metrics::inc_counter(&metrics::BEACON_EARLY_ATTESTER_CACHE_HITS);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user