diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 3549740bfb5..066a6e6e657 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -909,7 +909,7 @@ impl P if peer.pending_read_is_header { let msg_len = try_potential_handleerror!(peer, peer.channel_encryptor.decrypt_length_header(&peer.pending_read_buffer[..])); - peer.pending_read_buffer = Vec::with_capacity(msg_len as usize + 16); + if peer.pending_read_buffer.capacity() > 8192 { peer.pending_read_buffer = Vec::new(); } peer.pending_read_buffer.resize(msg_len as usize + 16, 0); if msg_len < 2 { // Need at least the message type tag return Err(PeerHandleError{ no_connection_possible: false }); @@ -921,7 +921,8 @@ impl P assert!(msg_data.len() >= 2); // Reset read buffer - peer.pending_read_buffer = [0; 18].to_vec(); + if peer.pending_read_buffer.capacity() > 8192 { peer.pending_read_buffer = Vec::new(); } + peer.pending_read_buffer.resize(18, 0); peer.pending_read_is_header = true; let mut reader = io::Cursor::new(&msg_data[..]);