Skip to content

Commit 2ecec2e

Browse files
authored
Merge pull request #478 from arik-so/remove_decodeerror_macro
remove decode_error macro only used once
2 parents 2ec7c77 + 360ed11 commit 2ecec2e

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -517,37 +517,6 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
517517
}
518518
}
519519

520-
macro_rules! try_potential_decodeerror {
521-
($thing: expr) => {
522-
match $thing {
523-
Ok(x) => x,
524-
Err(e) => {
525-
match e {
526-
msgs::DecodeError::UnknownVersion => return Err(PeerHandleError{ no_connection_possible: false }),
527-
msgs::DecodeError::UnknownRequiredFeature => {
528-
log_debug!(self, "Got a channel/node announcement with an known required feature flag, you may want to update!");
529-
continue;
530-
},
531-
msgs::DecodeError::InvalidValue => {
532-
log_debug!(self, "Got an invalid value while deserializing message");
533-
return Err(PeerHandleError{ no_connection_possible: false });
534-
},
535-
msgs::DecodeError::ShortRead => {
536-
log_debug!(self, "Deserialization failed due to shortness of message");
537-
return Err(PeerHandleError{ no_connection_possible: false });
538-
},
539-
msgs::DecodeError::ExtraAddressesPerType => {
540-
log_debug!(self, "Error decoding message, ignoring due to lnd spec incompatibility. See https://github.com/lightningnetwork/lnd/issues/1407");
541-
continue;
542-
},
543-
msgs::DecodeError::BadLengthDescriptor => return Err(PeerHandleError{ no_connection_possible: false }),
544-
msgs::DecodeError::Io(_) => return Err(PeerHandleError{ no_connection_possible: false }),
545-
}
546-
}
547-
};
548-
}
549-
}
550-
551520
macro_rules! insert_node_id {
552521
() => {
553522
match peers.node_id_to_descriptor.entry(peer.their_node_id.unwrap()) {
@@ -613,7 +582,34 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
613582
peer.pending_read_is_header = true;
614583

615584
let mut reader = ::std::io::Cursor::new(&msg_data[..]);
616-
let message = try_potential_decodeerror!(wire::read(&mut reader));
585+
let message_result = wire::read(&mut reader);
586+
let message = match message_result {
587+
Ok(x) => x,
588+
Err(e) => {
589+
match e {
590+
msgs::DecodeError::UnknownVersion => return Err(PeerHandleError { no_connection_possible: false }),
591+
msgs::DecodeError::UnknownRequiredFeature => {
592+
log_debug!(self, "Got a channel/node announcement with an known required feature flag, you may want to update!");
593+
continue;
594+
}
595+
msgs::DecodeError::InvalidValue => {
596+
log_debug!(self, "Got an invalid value while deserializing message");
597+
return Err(PeerHandleError { no_connection_possible: false });
598+
}
599+
msgs::DecodeError::ShortRead => {
600+
log_debug!(self, "Deserialization failed due to shortness of message");
601+
return Err(PeerHandleError { no_connection_possible: false });
602+
}
603+
msgs::DecodeError::ExtraAddressesPerType => {
604+
log_debug!(self, "Error decoding message, ignoring due to lnd spec incompatibility. See https://github.com/lightningnetwork/lnd/issues/1407");
605+
continue;
606+
}
607+
msgs::DecodeError::BadLengthDescriptor => return Err(PeerHandleError { no_connection_possible: false }),
608+
msgs::DecodeError::Io(_) => return Err(PeerHandleError { no_connection_possible: false }),
609+
}
610+
}
611+
};
612+
617613
log_trace!(self, "Received message of type {} from {}", message.type_id(), log_pubkey!(peer.their_node_id.unwrap()));
618614

619615
// Need an Init as first message

0 commit comments

Comments
 (0)