@@ -3,7 +3,7 @@ use std::{collections::btree_map::Entry, sync::Arc};
33use binprot:: BinProtRead ;
44use mina_p2p_messages:: { gossip, v2} ;
55use openmina_core:: { block:: BlockWithHash , bug_condition, fuzz_maybe, fuzzed_maybe, Substate } ;
6- use redux:: Dispatcher ;
6+ use redux:: { Dispatcher , Timestamp } ;
77
88use crate :: {
99 channels:: { snark:: P2pChannelsSnarkAction , transaction:: P2pChannelsTransactionAction } ,
@@ -28,7 +28,7 @@ impl P2pNetworkPubsubState {
2828 Action : crate :: P2pActionTrait < State > ,
2929 {
3030 let pubsub_state = state_context. get_substate_mut ( ) ?;
31- let ( action, _meta ) = action. split ( ) ;
31+ let ( action, meta ) = action. split ( ) ;
3232
3333 match action {
3434 P2pNetworkPubsubAction :: NewStream {
@@ -125,7 +125,7 @@ impl P2pNetworkPubsubState {
125125 seen_limit,
126126 ..
127127 } => {
128- pubsub_state. reduce_incoming_data ( & peer_id, data) ?;
128+ pubsub_state. reduce_incoming_data ( & peer_id, data, meta . time ( ) ) ?;
129129
130130 let dispatcher: & mut Dispatcher < Action , State > = state_context. into_dispatcher ( ) ;
131131 dispatcher. push ( P2pNetworkPubsubEffectfulAction :: IncomingData {
@@ -447,7 +447,12 @@ impl P2pNetworkPubsubState {
447447 Ok ( ( ) )
448448 }
449449
450- fn reduce_incoming_data ( & mut self , peer_id : & PeerId , data : Data ) -> Result < ( ) , String > {
450+ fn reduce_incoming_data (
451+ & mut self ,
452+ peer_id : & PeerId ,
453+ data : Data ,
454+ timestamp : Timestamp ,
455+ ) -> Result < ( ) , String > {
451456 let Some ( state) = self . clients . get_mut ( peer_id) else {
452457 // TODO: investigate, cannot reproduce this
453458 // bug_condition!("State not found for action: P2pNetworkPubsubAction::IncomingData");
@@ -529,14 +534,24 @@ impl P2pNetworkPubsubState {
529534 }
530535 }
531536
532- for ihave in & control. ihave {
533- let message_ids = ihave
534- . message_ids
535- . iter ( )
536- . filter ( |msg_id| !self . mcache . map . contains_key ( * msg_id) )
537- . cloned ( )
538- . collect ( ) ;
539- if let Some ( client) = self . clients . get_mut ( peer_id) {
537+ for ihave in control. ihave {
538+ if self . clients . contains_key ( peer_id) {
539+ let message_ids = ihave
540+ . message_ids
541+ . into_iter ( )
542+ . filter ( |msg_id| !self . mcache . map . contains_key ( msg_id) )
543+ . collect :: < Vec < _ > > ( ) ;
544+
545+ let message_ids = message_ids
546+ . into_iter ( )
547+ . filter ( |message_id| self . filter_iwant_message_ids ( message_id, timestamp) )
548+ . collect :: < Vec < _ > > ( ) ;
549+
550+ let Some ( client) = self . clients . get_mut ( peer_id) else {
551+ bug_condition ! ( "State not found for {}" , peer_id) ;
552+ return Ok ( ( ) ) ;
553+ } ;
554+
540555 let ctr = client. message . control . get_or_insert_with ( Default :: default) ;
541556 ctr. iwant . push ( pb:: ControlIWant { message_ids } )
542557 }
0 commit comments