11use std:: time:: { SystemTime , UNIX_EPOCH } ;
22
3- use libp2p:: gossipsub:: { Message , MessageAcceptance } ;
3+ use libp2p:: gossipsub:: Message ;
44use ream_chain_beacon:: beacon_chain:: BeaconChain ;
55use ream_consensus_beacon:: {
66 blob_sidecar:: BlobIdentifier ,
@@ -168,21 +168,13 @@ fn forward_gossip_message(message: &Message, p2p_sender: &P2PSender, data: Vec<u
168168 } ) ;
169169}
170170
171- fn message_acceptance ( validation_result : & ValidationResult ) -> MessageAcceptance {
172- match validation_result {
173- ValidationResult :: Accept => MessageAcceptance :: Accept ,
174- ValidationResult :: Reject ( _) => MessageAcceptance :: Reject ,
175- ValidationResult :: Ignore ( _) => MessageAcceptance :: Ignore ,
176- }
177- }
178-
179171/// Dispatches a gossipsub message to its appropriate handler.
180172pub async fn handle_gossipsub_message (
181173 message : Message ,
182174 beacon_chain : & BeaconChain ,
183175 cached_db : & BeaconCacheDB ,
184176 p2p_sender : & P2PSender ,
185- ) -> MessageAcceptance {
177+ ) {
186178 match GossipsubMessage :: decode ( & message. topic , & message. data ) {
187179 Ok ( gossip_message) => match gossip_message {
188180 GossipsubMessage :: BeaconBlock ( signed_block) => {
@@ -200,7 +192,7 @@ pub async fn handle_gossipsub_message(
200192 } ;
201193 if let Err ( err) = beacon_chain. process_tick ( tick_time) . await {
202194 warn ! ( "Failed to process gossipsub tick before block validation: {err}" ) ;
203- return MessageAcceptance :: Ignore ;
195+ return ;
204196 }
205197
206198 let validation_result = match validate_gossip_beacon_block (
@@ -213,11 +205,10 @@ pub async fn handle_gossipsub_message(
213205 Ok ( result) => result,
214206 Err ( err) => {
215207 warn ! ( "Failed to validate gossipsub beacon block: {err}" ) ;
216- return MessageAcceptance :: Ignore ;
208+ return ;
217209 }
218210 } ;
219211
220- let acceptance = message_acceptance ( & validation_result) ;
221212 match validation_result {
222213 ValidationResult :: Accept => {
223214 let signed_block_bytes = signed_block. as_ssz_bytes ( ) ;
@@ -233,51 +224,45 @@ pub async fn handle_gossipsub_message(
233224 warn ! ( "Rejecting gossipsub beacon block: {reason}" ) ;
234225 }
235226 }
236- acceptance
237227 }
238228 GossipsubMessage :: BeaconAttestation ( ( single_attestation, subnet_id) ) => {
239229 trace ! (
240230 "Beacon Attestation received over gossipsub: root: {}" ,
241231 single_attestation. tree_hash_root( )
242232 ) ;
243233
244- let validation_result = match validate_beacon_attestation (
234+ match validate_beacon_attestation (
245235 & single_attestation,
246236 beacon_chain,
247237 subnet_id,
248238 cached_db,
249239 )
250240 . await
251241 {
252- Ok ( validation_result) => validation_result,
242+ Ok ( validation_result) => match validation_result {
243+ ValidationResult :: Accept => {
244+ if let Err ( err) =
245+ import_gossip_attestation ( beacon_chain, & single_attestation) . await
246+ {
247+ warn ! ( "Failed to import gossipsub beacon attestation: {err}" ) ;
248+ }
249+ forward_gossip_message (
250+ & message,
251+ p2p_sender,
252+ single_attestation. as_ssz_bytes ( ) ,
253+ ) ;
254+ }
255+ ValidationResult :: Reject ( reason) => {
256+ info ! ( "Attestation rejected: {reason}" ) ;
257+ }
258+ ValidationResult :: Ignore ( reason) => {
259+ info ! ( "Attestation ignored: {reason}" ) ;
260+ }
261+ } ,
253262 Err ( err) => {
254263 trace ! ( "Could not validate attestation: {err}" ) ;
255- return MessageAcceptance :: Ignore ;
256- }
257- } ;
258-
259- let acceptance = message_acceptance ( & validation_result) ;
260- match validation_result {
261- ValidationResult :: Accept => {
262- if let Err ( err) =
263- import_gossip_attestation ( beacon_chain, & single_attestation) . await
264- {
265- warn ! ( "Failed to import gossipsub beacon attestation: {err}" ) ;
266- }
267- forward_gossip_message (
268- & message,
269- p2p_sender,
270- single_attestation. as_ssz_bytes ( ) ,
271- ) ;
272- }
273- ValidationResult :: Reject ( reason) => {
274- info ! ( "Attestation rejected: {reason}" ) ;
275- }
276- ValidationResult :: Ignore ( reason) => {
277- info ! ( "Attestation ignored: {reason}" ) ;
278264 }
279265 }
280- acceptance
281266 }
282267 GossipsubMessage :: BlsToExecutionChange ( signed_bls_to_execution_change) => {
283268 info ! (
@@ -311,7 +296,6 @@ pub async fn handle_gossipsub_message(
311296 error ! ( "Could not validate BLS to Execution Change: {err}" ) ;
312297 }
313298 }
314- MessageAcceptance :: Ignore
315299 }
316300 GossipsubMessage :: AggregateAndProof ( aggregate_and_proof) => {
317301 info ! (
@@ -341,7 +325,6 @@ pub async fn handle_gossipsub_message(
341325 error ! ( "Could not validate aggregate and proof: {err}" ) ;
342326 }
343327 }
344- MessageAcceptance :: Ignore
345328 }
346329 GossipsubMessage :: SyncCommittee ( ( sync_committee, subnet_id) ) => {
347330 trace ! (
@@ -371,7 +354,6 @@ pub async fn handle_gossipsub_message(
371354 error ! ( "Could not validate sync committee message: {err}" ) ;
372355 }
373356 }
374- MessageAcceptance :: Ignore
375357 }
376358 GossipsubMessage :: SyncCommitteeContributionAndProof ( signed_contribution_and_proof) => {
377359 info ! (
@@ -406,7 +388,6 @@ pub async fn handle_gossipsub_message(
406388 error ! ( "Could not validate sync committee contribution and proof: {err}" ) ;
407389 }
408390 }
409- MessageAcceptance :: Ignore
410391 }
411392 GossipsubMessage :: AttesterSlashing ( attester_slashing) => {
412393 info ! (
@@ -438,7 +419,6 @@ pub async fn handle_gossipsub_message(
438419 error ! ( "Could not validate attester slashing: {err}" ) ;
439420 }
440421 }
441- MessageAcceptance :: Ignore
442422 }
443423 GossipsubMessage :: ProposerSlashing ( proposer_slashing) => {
444424 info ! (
@@ -467,7 +447,6 @@ pub async fn handle_gossipsub_message(
467447 error ! ( "Could not validate proposer slashing: {err}" ) ;
468448 }
469449 }
470- MessageAcceptance :: Ignore
471450 }
472451 GossipsubMessage :: BlobSidecar ( blob_sidecar) => {
473452 info ! (
@@ -518,7 +497,6 @@ pub async fn handle_gossipsub_message(
518497 error ! ( "Could not validate blob_sidecar: {err}" ) ;
519498 }
520499 }
521- MessageAcceptance :: Ignore
522500 }
523501 GossipsubMessage :: DataColumnSidecar ( data_column_sidecar) => {
524502 info ! (
@@ -536,12 +514,12 @@ pub async fn handle_gossipsub_message(
536514 GossipTopicKind :: DataColumnSidecar ( id) => id,
537515 _ => {
538516 error ! ( "Unexpected topic kind for data column sidecar" ) ;
539- return MessageAcceptance :: Ignore ;
517+ return ;
540518 }
541519 } ,
542520 Err ( err) => {
543521 error ! ( "Failed to parse topic for data column sidecar: {err}" ) ;
544- return MessageAcceptance :: Ignore ;
522+ return ;
545523 }
546524 } ;
547525
@@ -556,7 +534,7 @@ pub async fn handle_gossipsub_message(
556534 Ok ( validation_result) => validation_result,
557535 Err ( err) => {
558536 error ! ( "Could not validate data_column_sidecar: {err}" ) ;
559- return MessageAcceptance :: Ignore ;
537+ return ;
560538 }
561539 } ;
562540
@@ -592,7 +570,6 @@ pub async fn handle_gossipsub_message(
592570 info ! ( "Data column sidecar ignored: {reason}" ) ;
593571 }
594572 }
595- MessageAcceptance :: Ignore
596573 }
597574 GossipsubMessage :: LightClientFinalityUpdate ( light_client_finality_update) => {
598575 info ! (
@@ -625,7 +602,6 @@ pub async fn handle_gossipsub_message(
625602 error ! ( "Could not validate light client finality update: {err}" ) ;
626603 }
627604 }
628- MessageAcceptance :: Ignore
629605 }
630606 GossipsubMessage :: LightClientOptimisticUpdate ( light_client_optimistic_update) => {
631607 info ! (
@@ -662,7 +638,6 @@ pub async fn handle_gossipsub_message(
662638 error ! ( "Could not validate light client optimistic update: {err}" ) ;
663639 }
664640 }
665- MessageAcceptance :: Ignore
666641 }
667642 GossipsubMessage :: VoluntaryExit ( voluntary_exit) => {
668643 info ! (
@@ -690,12 +665,10 @@ pub async fn handle_gossipsub_message(
690665 error ! ( "Could not validate voluntary_exit: {err}" ) ;
691666 }
692667 }
693- MessageAcceptance :: Ignore
694668 }
695669 } ,
696670 Err ( err) => {
697671 trace ! ( "Failed to decode gossip message: {err:?}" ) ;
698- MessageAcceptance :: Reject
699672 }
700- }
673+ } ;
701674}
0 commit comments