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