mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 18:21:45 +00:00
Added more test coverage, simplified Attestation conversion, and other minor refactors
This commit is contained in:
@@ -81,12 +81,13 @@ use tokio_stream::{
|
||||
StreamExt,
|
||||
};
|
||||
use types::{
|
||||
fork_versioned_response::EmptyMetadata, Attestation, AttestationData, AttestationShufflingId,
|
||||
AttesterSlashing, BeaconStateError, CommitteeCache, ConfigAndPreset, Epoch, EthSpec, ForkName,
|
||||
ForkVersionedResponse, Hash256, ProposerPreparationData, ProposerSlashing, RelativeEpoch,
|
||||
SignedAggregateAndProof, SignedBlindedBeaconBlock, SignedBlsToExecutionChange,
|
||||
SignedContributionAndProof, SignedValidatorRegistrationData, SignedVoluntaryExit, Slot,
|
||||
SyncCommitteeMessage, SyncContributionData, attestation::SingleAttestation
|
||||
attestation::SingleAttestation, fork_versioned_response::EmptyMetadata, Attestation,
|
||||
AttestationData, AttestationShufflingId, AttesterSlashing, BeaconStateError, CommitteeCache,
|
||||
ConfigAndPreset, Epoch, EthSpec, ForkName, ForkVersionedResponse, Hash256,
|
||||
ProposerPreparationData, ProposerSlashing, RelativeEpoch, SignedAggregateAndProof,
|
||||
SignedBlindedBeaconBlock, SignedBlsToExecutionChange, SignedContributionAndProof,
|
||||
SignedValidatorRegistrationData, SignedVoluntaryExit, Slot, SyncCommitteeMessage,
|
||||
SyncContributionData,
|
||||
};
|
||||
use validator::pubkey_to_validator_index;
|
||||
use version::{
|
||||
@@ -1879,9 +1880,6 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.and(reprocess_send_filter)
|
||||
.and(log_filter.clone())
|
||||
.then(
|
||||
// V1 and V2 are identical except V2 has a consensus version header in the request.
|
||||
// We only require this header for SSZ deserialization, which isn't supported for
|
||||
// this endpoint presently.
|
||||
|task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
attestations: Vec<SingleAttestation>,
|
||||
|
||||
@@ -100,10 +100,14 @@ fn verify_and_publish_attestation<T: BeaconChainTypes>(
|
||||
attn.data.target.root,
|
||||
attn.data.slot.epoch(T::EthSpec::slots_per_epoch()),
|
||||
|committee_cache, _| {
|
||||
let committees =
|
||||
committee_cache.get_beacon_committees_at_slot(attn.data.slot)?;
|
||||
let committee_index = attn
|
||||
.committee_index()
|
||||
.ok_or(BeaconChainError::AttestationCommitteeIndexNotSet)?;
|
||||
|
||||
let single_attestation = attn.to_single_attestation(&committees)?;
|
||||
let committee =
|
||||
committee_cache.get_beacon_committee(attn.data.slot, committee_index);
|
||||
|
||||
let single_attestation = attn.to_single_attestation(committee)?;
|
||||
|
||||
network_tx
|
||||
.send(NetworkMessage::Publish {
|
||||
@@ -166,6 +170,7 @@ pub async fn publish_single_attestations<T: BeaconChainTypes>(
|
||||
log: Logger,
|
||||
) -> Result<(), warp::Rejection> {
|
||||
let mut attestations = vec![];
|
||||
|
||||
for single_attestation in single_attestations {
|
||||
let attestation = chain.with_committee_cache(
|
||||
single_attestation.data.target.root,
|
||||
@@ -174,10 +179,12 @@ pub async fn publish_single_attestations<T: BeaconChainTypes>(
|
||||
.slot
|
||||
.epoch(T::EthSpec::slots_per_epoch()),
|
||||
|committee_cache, _| {
|
||||
let committees =
|
||||
committee_cache.get_beacon_committees_at_slot(single_attestation.data.slot)?;
|
||||
let committee = committee_cache.get_beacon_committee(
|
||||
single_attestation.data.slot,
|
||||
single_attestation.committee_index as u64,
|
||||
);
|
||||
|
||||
let attestation = single_attestation.to_attestation::<T::EthSpec>(&committees)?;
|
||||
let attestation = single_attestation.to_attestation::<T::EthSpec>(committee)?;
|
||||
|
||||
Ok(attestation)
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user