Skip to content

Commit

Permalink
Add aggregates POST method
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Sep 9, 2020
1 parent 71cd921 commit 1c788af
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
5 changes: 5 additions & 0 deletions beacon_node/beacon_chain/src/attestation_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ impl<T: BeaconChainTypes> VerifiedAggregatedAttestation<T> {
pub fn attestation(&self) -> &Attestation<T::EthSpec> {
&self.signed_aggregate.message.aggregate
}

/// Returns the underlying `signed_aggregate`.
pub fn aggregate(&self) -> &SignedAggregateAndProof<T::EthSpec> {
&self.signed_aggregate
}
}

impl<T: BeaconChainTypes> VerifiedUnaggregatedAttestation<T> {
Expand Down
57 changes: 54 additions & 3 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::sync::Arc;
use tokio::sync::mpsc::UnboundedSender;
use types::{
Attestation, AttesterSlashing, CommitteeCache, Epoch, EthSpec, ProposerSlashing, RelativeEpoch,
SignedBeaconBlock, SignedVoluntaryExit, Slot, YamlConfig,
SignedAggregateAndProof, SignedBeaconBlock, SignedVoluntaryExit, Slot, YamlConfig,
};
use warp::Filter;

Expand Down Expand Up @@ -760,7 +760,7 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path("voluntary_exits"))
.and(warp::path::end())
.and(warp::body::json())
.and(network_tx_filter)
.and(network_tx_filter.clone())
.and_then(
|chain: Arc<BeaconChain<T>>,
exit: SignedVoluntaryExit,
Expand Down Expand Up @@ -1037,7 +1037,7 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path("aggregate_attestation"))
.and(warp::path::end())
.and(warp::query::<api_types::ValidatorAggregateAttestationQuery>())
.and(chain_filter)
.and(chain_filter.clone())
.and_then(
|query: api_types::ValidatorAggregateAttestationQuery, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
Expand All @@ -1051,6 +1051,56 @@ pub fn serve<T: BeaconChainTypes>(
},
);

// POST validator/aggregate_and_proofs
let post_validator_aggregate_and_proofs = eth1_v1
.and(warp::path("validator"))
.and(warp::path("aggregate_and_proofs"))
.and(warp::path::end())
.and(chain_filter)
.and(warp::body::json())
.and(network_tx_filter.clone())
.and_then(
|chain: Arc<BeaconChain<T>>,
aggregate: SignedAggregateAndProof<T::EthSpec>,
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>| {
blocking_json_task(move || {
let aggregate = chain
.verify_aggregated_attestation_for_gossip(aggregate.clone())
.map_err(|e| {
crate::reject::object_invalid(format!(
"gossip verification failed: {:?}",
e
))
})?;

publish_network_message(
&network_tx,
PubsubMessage::AggregateAndProofAttestation(Box::new(
aggregate.aggregate().clone(),
)),
)?;

chain
.apply_attestation_to_fork_choice(&aggregate)
.map_err(|e| {
crate::reject::broadcast_without_import(format!(
"not applied to fork choice: {:?}",
e
))
})?;

chain.add_to_block_inclusion_pool(aggregate).map_err(|e| {
crate::reject::broadcast_without_import(format!(
"not applied to block inclusion pool: {:?}",
e
))
})?;

Ok(())
})
},
);

let routes = warp::get()
.and(
get_beacon_genesis
Expand Down Expand Up @@ -1087,6 +1137,7 @@ pub fn serve<T: BeaconChainTypes>(
.or(post_beacon_pool_attester_slashings.boxed())
.or(post_beacon_pool_proposer_slashings.boxed())
.or(post_beacon_pool_voluntary_exits.boxed())
.or(post_validator_aggregate_and_proofs.boxed())
.boxed(),
))
.recover(crate::reject::handle_rejection);
Expand Down

0 comments on commit 1c788af

Please sign in to comment.