@@ -30,7 +30,6 @@ mod validator;
3030mod validator_inclusion;
3131mod validators;
3232mod version;
33-
3433use crate :: light_client:: { get_light_client_bootstrap, get_light_client_updates} ;
3534use crate :: produce_block:: { produce_blinded_block_v2, produce_block_v2, produce_block_v3} ;
3635use crate :: version:: fork_versioned_response;
@@ -63,6 +62,7 @@ pub use publish_blocks::{
6362 publish_blinded_block, publish_block, reconstruct_block, ProvenancedBlock ,
6463} ;
6564use serde:: { Deserialize , Serialize } ;
65+ use serde_json:: Value ;
6666use slog:: { crit, debug, error, info, warn, Logger } ;
6767use slot_clock:: SlotClock ;
6868use ssz:: Encode ;
@@ -83,14 +83,13 @@ use tokio_stream::{
8383 wrappers:: { errors:: BroadcastStreamRecvError , BroadcastStream } ,
8484 StreamExt ,
8585} ;
86- use types:: ChainSpec ;
8786use types:: {
8887 fork_versioned_response:: EmptyMetadata , Attestation , AttestationData , AttestationShufflingId ,
89- AttesterSlashing , BeaconStateError , CommitteeCache , ConfigAndPreset , Epoch , EthSpec , ForkName ,
90- ForkVersionedResponse , Hash256 , ProposerPreparationData , ProposerSlashing , RelativeEpoch ,
91- SignedAggregateAndProof , SignedBlindedBeaconBlock , SignedBlsToExecutionChange ,
92- SignedContributionAndProof , SignedValidatorRegistrationData , SignedVoluntaryExit ,
93- SingleAttestation , Slot , SyncCommitteeMessage , SyncContributionData ,
88+ AttesterSlashing , BeaconStateError , ChainSpec , CommitteeCache , ConfigAndPreset , Epoch , EthSpec ,
89+ ForkName , ForkVersionedResponse , Hash256 , ProposerPreparationData , ProposerSlashing ,
90+ RelativeEpoch , SignedAggregateAndProof , SignedBlindedBeaconBlock , SignedBlsToExecutionChange ,
91+ SignedContributionAndProof , SignedValidatorRegistrationData , SignedVoluntaryExit , Slot ,
92+ SyncCommitteeMessage , SyncContributionData ,
9493} ;
9594use validator:: pubkey_to_validator_index;
9695use version:: {
@@ -1279,6 +1278,9 @@ pub fn serve<T: BeaconChainTypes>(
12791278 let consensus_version_header_filter =
12801279 warp:: header:: header :: < ForkName > ( CONSENSUS_VERSION_HEADER ) ;
12811280
1281+ let optional_consensus_version_header_filter =
1282+ warp:: header:: optional :: < ForkName > ( CONSENSUS_VERSION_HEADER ) ;
1283+
12821284 // POST beacon/blocks
12831285 let post_beacon_blocks = eth_v1
12841286 . and ( warp:: path ( "beacon" ) )
@@ -1829,20 +1831,19 @@ pub fn serve<T: BeaconChainTypes>(
18291831 . and ( task_spawner_filter. clone ( ) )
18301832 . and ( chain_filter. clone ( ) ) ;
18311833
1832- let beacon_pool_path_any = any_version
1834+ let beacon_pool_path_v2 = eth_v2
18331835 . and ( warp:: path ( "beacon" ) )
18341836 . and ( warp:: path ( "pool" ) )
18351837 . and ( task_spawner_filter. clone ( ) )
18361838 . and ( chain_filter. clone ( ) ) ;
18371839
1838- let beacon_pool_path_v2 = eth_v2
1840+ let beacon_pool_path_any = any_version
18391841 . and ( warp:: path ( "beacon" ) )
18401842 . and ( warp:: path ( "pool" ) )
18411843 . and ( task_spawner_filter. clone ( ) )
18421844 . and ( chain_filter. clone ( ) ) ;
18431845
1844- // POST beacon/pool/attestations
1845- let post_beacon_pool_attestations = beacon_pool_path
1846+ let post_beacon_pool_attestations_v1 = beacon_pool_path
18461847 . clone ( )
18471848 . and ( warp:: path ( "attestations" ) )
18481849 . and ( warp:: path:: end ( ) )
@@ -1851,9 +1852,6 @@ pub fn serve<T: BeaconChainTypes>(
18511852 . and ( reprocess_send_filter. clone ( ) )
18521853 . and ( log_filter. clone ( ) )
18531854 . then (
1854- // V1 and V2 are identical except V2 has a consensus version header in the request.
1855- // We only require this header for SSZ deserialization, which isn't supported for
1856- // this endpoint presently.
18571855 |task_spawner : TaskSpawner < T :: EthSpec > ,
18581856 chain : Arc < BeaconChain < T > > ,
18591857 attestations : Vec < Attestation < T :: EthSpec > > ,
@@ -1879,18 +1877,40 @@ pub fn serve<T: BeaconChainTypes>(
18791877 . clone ( )
18801878 . and ( warp:: path ( "attestations" ) )
18811879 . and ( warp:: path:: end ( ) )
1882- . and ( warp_utils:: json:: json ( ) )
1880+ . and ( warp_utils:: json:: json :: < Value > ( ) )
1881+ . and ( optional_consensus_version_header_filter)
18831882 . and ( network_tx_filter. clone ( ) )
1884- . and ( reprocess_send_filter)
1883+ . and ( reprocess_send_filter. clone ( ) )
18851884 . and ( log_filter. clone ( ) )
18861885 . then (
18871886 |task_spawner : TaskSpawner < T :: EthSpec > ,
18881887 chain : Arc < BeaconChain < T > > ,
1889- attestations : Vec < SingleAttestation > ,
1888+ payload : Value ,
1889+ fork_name : Option < ForkName > ,
18901890 network_tx : UnboundedSender < NetworkMessage < T :: EthSpec > > ,
18911891 reprocess_tx : Option < Sender < ReprocessQueueMessage > > ,
18921892 log : Logger | async move {
1893- let attestations = attestations. into_iter ( ) . map ( Either :: Right ) . collect ( ) ;
1893+ let attestations =
1894+ match crate :: publish_attestations:: deserialize_attestation_payload :: < T > (
1895+ payload, fork_name, & log,
1896+ ) {
1897+ Ok ( attestations) => attestations,
1898+ Err ( err) => {
1899+ warn ! (
1900+ log,
1901+ "Unable to deserialize attestation POST request" ;
1902+ "error" => ?err
1903+ ) ;
1904+ return warp:: reply:: with_status (
1905+ warp:: reply:: json (
1906+ & "Unable to deserialize request body" . to_string ( ) ,
1907+ ) ,
1908+ eth2:: StatusCode :: BAD_REQUEST ,
1909+ )
1910+ . into_response ( ) ;
1911+ }
1912+ } ;
1913+
18941914 let result = crate :: publish_attestations:: publish_attestations (
18951915 task_spawner,
18961916 chain,
@@ -4765,7 +4785,7 @@ pub fn serve<T: BeaconChainTypes>(
47654785 . uor ( post_beacon_blinded_blocks)
47664786 . uor ( post_beacon_blocks_v2)
47674787 . uor ( post_beacon_blinded_blocks_v2)
4768- . uor ( post_beacon_pool_attestations )
4788+ . uor ( post_beacon_pool_attestations_v1 )
47694789 . uor ( post_beacon_pool_attestations_v2)
47704790 . uor ( post_beacon_pool_attester_slashings)
47714791 . uor ( post_beacon_pool_proposer_slashings)
0 commit comments