@@ -60,11 +60,11 @@ impl<
6060 /// Handle incoming network messages during monitoring.
6161 pub async fn handle_network_message (
6262 & mut self ,
63- message : dashcore:: network:: message:: NetworkMessage ,
63+ message : & dashcore:: network:: message:: NetworkMessage ,
6464 ) -> Result < ( ) > {
6565 use dashcore:: network:: message:: NetworkMessage ;
6666
67- tracing:: debug!( "Client handling network message: {:?}" , std:: mem:: discriminant( & message) ) ;
67+ tracing:: debug!( "Client handling network message: {:?}" , std:: mem:: discriminant( message) ) ;
6868
6969 // First check if this is a message that ONLY the sync manager handles
7070 // These messages can be moved to the sync manager without cloning
@@ -147,17 +147,11 @@ impl<
147147 SpvError :: Sync ( e)
148148 } ) ;
149149 }
150- _ => { }
151- }
152-
153- // Handle messages that may need sync manager processing
154- // We optimize to avoid cloning expensive messages like blocks
155- match & message {
156150 NetworkMessage :: Headers ( _) | NetworkMessage :: CFilter ( _) => {
157151 // Headers and CFilters are relatively small, cloning is acceptable
158152 if let Err ( e) = self
159153 . sync_manager
160- . handle_message ( message. clone ( ) , & mut * self . network , & mut * self . storage )
154+ . handle_message ( message, & mut * self . network , & mut * self . storage )
161155 . await
162156 {
163157 tracing:: error!( "Sequential sync manager error handling message: {}" , e) ;
@@ -183,13 +177,10 @@ impl<
183177 }
184178 }
185179 NetworkMessage :: Block ( _) => {
186- // Blocks can be large - avoid cloning unless necessary
187- // Check if sync manager actually needs to process this block
188180 if self . sync_manager . is_in_downloading_blocks_phase ( ) {
189- // Only clone if we're in the downloading blocks phase
190181 if let Err ( e) = self
191182 . sync_manager
192- . handle_message ( message. clone ( ) , & mut * self . network , & mut * self . storage )
183+ . handle_message ( message, & mut * self . network , & mut * self . storage )
193184 . await
194185 {
195186 tracing:: error!(
@@ -241,7 +232,7 @@ impl<
241232 let headers_msg = NetworkMessage :: Headers ( vec ! [ block. header] ) ;
242233 if let Err ( e) = self
243234 . sync_manager
244- . handle_message ( headers_msg, & mut * self . network , & mut * self . storage )
235+ . handle_message ( & headers_msg, & mut * self . network , & mut * self . storage )
245236 . await
246237 {
247238 tracing:: error!(
@@ -261,7 +252,7 @@ impl<
261252 NetworkMessage :: Inv ( inv) => {
262253 tracing:: debug!( "Received inventory message with {} items" , inv. len( ) ) ;
263254 // Handle inventory messages (new blocks, transactions, etc.)
264- self . handle_inventory ( inv) . await ?;
255+ self . handle_inventory ( inv. clone ( ) ) . await ?;
265256 }
266257 NetworkMessage :: Tx ( tx) => {
267258 tracing:: info!( "📨 Received transaction: {}" , tx. txid( ) ) ;
@@ -293,7 +284,7 @@ impl<
293284 // Emit event
294285 let event = SpvEvent :: MempoolTransactionAdded {
295286 txid,
296- transaction : Box :: new ( tx) ,
287+ transaction : Box :: new ( tx. clone ( ) ) ,
297288 amount,
298289 addresses,
299290 is_instant_send,
@@ -339,7 +330,7 @@ impl<
339330 NetworkMessage :: SendDsq ( wants_dsq) => {
340331 tracing:: info!( "Received SendDsq message - peer wants DSQ messages: {}" , wants_dsq) ;
341332 // Store peer's DSQ preference
342- if let Err ( e) = self . network . update_peer_dsq_preference ( wants_dsq) . await {
333+ if let Err ( e) = self . network . update_peer_dsq_preference ( * wants_dsq) . await {
343334 tracing:: error!( "Failed to update peer DSQ preference: {}" , e) ;
344335 }
345336
@@ -351,7 +342,7 @@ impl<
351342 }
352343 _ => {
353344 // Ignore other message types for now
354- tracing:: debug!( "Received network message: {:?}" , std:: mem:: discriminant( & message) ) ;
345+ tracing:: debug!( "Received network message: {:?}" , std:: mem:: discriminant( message) ) ;
355346 }
356347 }
357348
@@ -468,7 +459,7 @@ impl<
468459 // We just need to send them through the unified message interface
469460 let headers_msg = dashcore:: network:: message:: NetworkMessage :: Headers ( headers) ;
470461 self . sync_manager
471- . handle_message ( headers_msg, & mut * self . network , & mut * self . storage )
462+ . handle_message ( & headers_msg, & mut * self . network , & mut * self . storage )
472463 . await
473464 . map_err ( SpvError :: Sync ) ?;
474465
@@ -506,7 +497,7 @@ impl<
506497 // For sequential sync, route through the message handler
507498 let cfheaders_msg = dashcore:: network:: message:: NetworkMessage :: CFHeaders ( cfheaders) ;
508499 self . sync_manager
509- . handle_message ( cfheaders_msg, & mut * self . network , & mut * self . storage )
500+ . handle_message ( & cfheaders_msg, & mut * self . network , & mut * self . storage )
510501 . await
511502 . map_err ( SpvError :: Sync ) ?;
512503
@@ -520,15 +511,15 @@ impl<
520511 }
521512
522513 /// Process a new block.
523- pub async fn process_new_block ( & mut self , block : dashcore:: Block ) -> Result < ( ) > {
514+ pub async fn process_new_block ( & mut self , block : & dashcore:: Block ) -> Result < ( ) > {
524515 let block_hash = block. block_hash ( ) ;
525516
526517 tracing:: info!( "📦 Routing block {} to async block processor" , block_hash) ;
527518
528519 // Send block to the background processor without waiting for completion
529520 let ( response_tx, _response_rx) = tokio:: sync:: oneshot:: channel ( ) ;
530521 let task = crate :: client:: BlockProcessingTask :: ProcessBlock {
531- block : Box :: new ( block) ,
522+ block : Box :: new ( block. clone ( ) ) ,
532523 response_tx,
533524 } ;
534525
@@ -564,7 +555,7 @@ impl<
564555 // The sequential sync manager's handle_new_headers method will automatically
565556 // request filter headers and filters as needed
566557 self . sync_manager
567- . handle_new_headers ( headers. to_vec ( ) , & mut * self . network , & mut * self . storage )
558+ . handle_new_headers ( headers, & mut * self . network , & mut * self . storage )
568559 . await
569560 . map_err ( SpvError :: Sync ) ?;
570561
0 commit comments