mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-29 10:54:24 +00:00
Dedup Attestation constructor code
This commit is contained in:
@@ -122,7 +122,6 @@ use store::{
|
||||
use task_executor::{ShutdownReason, TaskExecutor};
|
||||
use tokio_stream::Stream;
|
||||
use tree_hash::TreeHash;
|
||||
use types::attestation::AttestationBase;
|
||||
use types::blob_sidecar::FixedBlobSidecarList;
|
||||
use types::payload::BlockProductionVersion;
|
||||
use types::*;
|
||||
@@ -1994,40 +1993,15 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
};
|
||||
drop(cache_timer);
|
||||
|
||||
if self
|
||||
.spec
|
||||
.fork_name_at_slot::<T::EthSpec>(request_slot)
|
||||
.electra_enabled()
|
||||
{
|
||||
let mut committee_bits = BitVector::default();
|
||||
if committee_len > 0 {
|
||||
committee_bits.set(request_index as usize, true)?;
|
||||
}
|
||||
Ok(Attestation::Electra(AttestationElectra {
|
||||
aggregation_bits: BitList::with_capacity(committee_len)?,
|
||||
data: AttestationData {
|
||||
slot: request_slot,
|
||||
index: 0u64,
|
||||
beacon_block_root,
|
||||
source: justified_checkpoint,
|
||||
target,
|
||||
},
|
||||
committee_bits,
|
||||
signature: AggregateSignature::empty(),
|
||||
}))
|
||||
} else {
|
||||
Ok(Attestation::Base(AttestationBase {
|
||||
aggregation_bits: BitList::with_capacity(committee_len)?,
|
||||
data: AttestationData {
|
||||
slot: request_slot,
|
||||
index: request_index,
|
||||
beacon_block_root,
|
||||
source: justified_checkpoint,
|
||||
target,
|
||||
},
|
||||
signature: AggregateSignature::empty(),
|
||||
}))
|
||||
}
|
||||
Ok(Attestation::<T::EthSpec>::empty_for_signing(
|
||||
request_index,
|
||||
committee_len,
|
||||
request_slot,
|
||||
beacon_block_root,
|
||||
justified_checkpoint,
|
||||
target,
|
||||
&self.spec,
|
||||
)?)
|
||||
}
|
||||
|
||||
/// Performs the same validation as `Self::verify_unaggregated_attestation_for_gossip`, but for
|
||||
|
||||
@@ -58,7 +58,6 @@ use store::{config::StoreConfig, HotColdDB, ItemStore, LevelDB, MemoryStore};
|
||||
use task_executor::TaskExecutor;
|
||||
use task_executor::{test_utils::TestRuntime, ShutdownReason};
|
||||
use tree_hash::TreeHash;
|
||||
use types::attestation::AttestationBase;
|
||||
use types::indexed_attestation::IndexedAttestationBase;
|
||||
use types::payload::BlockProductionVersion;
|
||||
pub use types::test_utils::generate_deterministic_keypairs;
|
||||
@@ -1033,40 +1032,18 @@ where
|
||||
*state.get_block_root(target_slot)?
|
||||
};
|
||||
|
||||
if self.spec.fork_name_at_slot::<E>(slot).electra_enabled() {
|
||||
let mut committee_bits = BitVector::default();
|
||||
committee_bits.set(index as usize, true)?;
|
||||
Ok(Attestation::Electra(AttestationElectra {
|
||||
aggregation_bits: BitList::with_capacity(committee_len)?,
|
||||
committee_bits,
|
||||
data: AttestationData {
|
||||
slot,
|
||||
index: 0u64,
|
||||
beacon_block_root,
|
||||
source: state.current_justified_checkpoint(),
|
||||
target: Checkpoint {
|
||||
epoch,
|
||||
root: target_root,
|
||||
},
|
||||
},
|
||||
signature: AggregateSignature::empty(),
|
||||
}))
|
||||
} else {
|
||||
Ok(Attestation::Base(AttestationBase {
|
||||
aggregation_bits: BitList::with_capacity(committee_len)?,
|
||||
data: AttestationData {
|
||||
slot,
|
||||
index,
|
||||
beacon_block_root,
|
||||
source: state.current_justified_checkpoint(),
|
||||
target: Checkpoint {
|
||||
epoch,
|
||||
root: target_root,
|
||||
},
|
||||
},
|
||||
signature: AggregateSignature::empty(),
|
||||
}))
|
||||
}
|
||||
Ok(Attestation::empty_for_signing(
|
||||
index,
|
||||
committee_len,
|
||||
slot,
|
||||
beacon_block_root,
|
||||
state.current_justified_checkpoint(),
|
||||
Checkpoint {
|
||||
epoch,
|
||||
root: target_root,
|
||||
},
|
||||
&self.spec,
|
||||
)?)
|
||||
}
|
||||
|
||||
/// A list of attestations for each committee for the given slot.
|
||||
|
||||
@@ -89,6 +89,7 @@ impl<E: EthSpec> Hash for Attestation<E> {
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Attestation<E> {
|
||||
/// Produces an attestation with empty signature.
|
||||
pub fn empty_for_signing(
|
||||
committee_index: u64,
|
||||
committee_length: usize,
|
||||
|
||||
Reference in New Issue
Block a user