@@ -163,6 +163,9 @@ impl P2pNetworkPubsubState {
163163 pubsub_state. reduce_incoming_message ( peer_id, message, seen_limit) ?;
164164
165165 let ( dispatcher, global_state) = state_context. into_dispatcher_and_state ( ) ;
166+
167+ dispatcher. push ( P2pNetworkPubsubAction :: IncomingMessageCleanup { peer_id } ) ;
168+
166169 let state: & Self = global_state. substate ( ) ?;
167170 let config: & P2pConfig = global_state. substate ( ) ?;
168171
@@ -206,6 +209,26 @@ impl P2pNetworkPubsubState {
206209 }
207210 Ok ( ( ) )
208211 }
212+ P2pNetworkPubsubAction :: IncomingMessageCleanup { peer_id } => {
213+ pubsub_state. incoming_transactions . clear ( ) ;
214+ pubsub_state. incoming_snarks . clear ( ) ;
215+
216+ pubsub_state. incoming_transactions . shrink_to ( 0x20 ) ;
217+ pubsub_state. incoming_snarks . shrink_to ( 0x20 ) ;
218+
219+ pubsub_state. incoming_block = None ;
220+
221+ let Some ( client_state) = pubsub_state. clients . get_mut ( & peer_id) else {
222+ bug_condition ! (
223+ "State not found for action P2pNetworkPubsubAction::IncomingMessageCleanup"
224+ ) ;
225+ return Ok ( ( ) ) ;
226+ } ;
227+ client_state. incoming_messages . clear ( ) ;
228+ client_state. incoming_messages . shrink_to ( 0x20 ) ;
229+
230+ Ok ( ( ) )
231+ }
209232 // we want to add peer to our mesh
210233 P2pNetworkPubsubAction :: Graft { peer_id, topic_id } => {
211234 let Some ( state) = pubsub_state
@@ -441,19 +464,6 @@ impl P2pNetworkPubsubState {
441464 message : Message ,
442465 seen_limit : usize ,
443466 ) -> Result < ( ) , String > {
444- self . incoming_transactions . clear ( ) ;
445- self . incoming_snarks . clear ( ) ;
446-
447- self . incoming_transactions . shrink_to ( 0x20 ) ;
448- self . incoming_snarks . shrink_to ( 0x20 ) ;
449-
450- let Some ( state) = self . clients . get_mut ( & peer_id) else {
451- bug_condition ! ( "State not found for action P2pNetworkPubsubAction::IncomingMessage" ) ;
452- return Ok ( ( ) ) ;
453- } ;
454- state. incoming_messages . clear ( ) ;
455- state. incoming_messages . shrink_to ( 0x20 ) ;
456-
457467 let topic = self . topics . entry ( message. topic . clone ( ) ) . or_default ( ) ;
458468
459469 if let Some ( signature) = & message. signature {
0 commit comments