Skip to content

Commit 1d5db19

Browse files
committed
Send warning messages when appropriate in gossip handling pipeline
1 parent ffcb1a7 commit 1d5db19

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, CMH: Deref> P
877877
msgs::DecodeError::Io(_) => return Err(PeerHandleError { no_connection_possible: false }),
878878
msgs::DecodeError::UnsupportedCompression => {
879879
log_trace!(self.logger, "We don't support zlib-compressed message fields, ignoring message");
880+
self.enqueue_message(peer, &msgs::WarningMessage { channel_id: [0; 32], data: "We don't support zlib-compressed message fields".to_owned() });
880881
continue;
881882
}
882883
}

lightning/src/routing/network_graph.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,21 @@ where C::Target: chain::Access, L::Target: Logger
216216
}
217217

218218
macro_rules! secp_verify_sig {
219-
( $secp_ctx: expr, $msg: expr, $sig: expr, $pubkey: expr ) => {
219+
( $secp_ctx: expr, $msg: expr, $sig: expr, $pubkey: expr, $msg_type: expr ) => {
220220
match $secp_ctx.verify($msg, $sig, $pubkey) {
221221
Ok(_) => {},
222-
Err(_) => return Err(LightningError{err: "Invalid signature from remote node".to_owned(), action: ErrorAction::IgnoreError}),
222+
Err(_) => {
223+
return Err(LightningError {
224+
err: format!("Invalid signature on {} message", $msg_type),
225+
action: ErrorAction::SendWarningMessage {
226+
msg: msgs::WarningMessage {
227+
channel_id: [0; 32],
228+
data: format!("Invalid signature on {} message", $msg_type),
229+
},
230+
log_level: Level::Trace,
231+
},
232+
});
233+
},
223234
}
224235
};
225236
}
@@ -767,7 +778,7 @@ impl NetworkGraph {
767778
/// routing messages from a source using a protocol other than the lightning P2P protocol.
768779
pub fn update_node_from_announcement<T: secp256k1::Verification>(&self, msg: &msgs::NodeAnnouncement, secp_ctx: &Secp256k1<T>) -> Result<(), LightningError> {
769780
let msg_hash = hash_to_message!(&Sha256dHash::hash(&msg.contents.encode()[..])[..]);
770-
secp_verify_sig!(secp_ctx, &msg_hash, &msg.signature, &msg.contents.node_id);
781+
secp_verify_sig!(secp_ctx, &msg_hash, &msg.signature, &msg.contents.node_id, "node_announcement");
771782
self.update_node_from_announcement_intern(&msg.contents, Some(&msg))
772783
}
773784

@@ -785,7 +796,7 @@ impl NetworkGraph {
785796
Some(node) => {
786797
if let Some(node_info) = node.announcement_info.as_ref() {
787798
if node_info.last_update >= msg.timestamp {
788-
return Err(LightningError{err: "Update older than last processed update".to_owned(), action: ErrorAction::IgnoreAndLog(Level::Trace)});
799+
return Err(LightningError {err: "Update older than last processed update".to_owned(), action: ErrorAction::IgnoreAndLog(Level::Trace)});
789800
}
790801
}
791802

@@ -822,10 +833,10 @@ impl NetworkGraph {
822833
C::Target: chain::Access,
823834
{
824835
let msg_hash = hash_to_message!(&Sha256dHash::hash(&msg.contents.encode()[..])[..]);
825-
secp_verify_sig!(secp_ctx, &msg_hash, &msg.node_signature_1, &msg.contents.node_id_1);
826-
secp_verify_sig!(secp_ctx, &msg_hash, &msg.node_signature_2, &msg.contents.node_id_2);
827-
secp_verify_sig!(secp_ctx, &msg_hash, &msg.bitcoin_signature_1, &msg.contents.bitcoin_key_1);
828-
secp_verify_sig!(secp_ctx, &msg_hash, &msg.bitcoin_signature_2, &msg.contents.bitcoin_key_2);
836+
secp_verify_sig!(secp_ctx, &msg_hash, &msg.node_signature_1, &msg.contents.node_id_1, "channel_announcement");
837+
secp_verify_sig!(secp_ctx, &msg_hash, &msg.node_signature_2, &msg.contents.node_id_2, "channel_announcement");
838+
secp_verify_sig!(secp_ctx, &msg_hash, &msg.bitcoin_signature_1, &msg.contents.bitcoin_key_1, "channel_announcement");
839+
secp_verify_sig!(secp_ctx, &msg_hash, &msg.bitcoin_signature_2, &msg.contents.bitcoin_key_2, "channel_announcement");
829840
self.update_channel_from_unsigned_announcement_intern(&msg.contents, Some(msg), chain_access)
830841
}
831842

@@ -1050,13 +1061,13 @@ impl NetworkGraph {
10501061
if msg.flags & 1 == 1 {
10511062
dest_node_id = channel.node_one.clone();
10521063
if let Some((sig, ctx)) = sig_info {
1053-
secp_verify_sig!(ctx, &msg_hash, &sig, &channel.node_two);
1064+
secp_verify_sig!(ctx, &msg_hash, &sig, &channel.node_two, "channel_update");
10541065
}
10551066
maybe_update_channel_info!(channel.two_to_one, channel.node_two);
10561067
} else {
10571068
dest_node_id = channel.node_two.clone();
10581069
if let Some((sig, ctx)) = sig_info {
1059-
secp_verify_sig!(ctx, &msg_hash, &sig, &channel.node_one);
1070+
secp_verify_sig!(ctx, &msg_hash, &sig, &channel.node_one, "channel_update");
10601071
}
10611072
maybe_update_channel_info!(channel.one_to_two, channel.node_one);
10621073
}
@@ -1282,7 +1293,7 @@ mod tests {
12821293
contents: unsigned_announcement.clone()
12831294
}) {
12841295
Ok(_) => panic!(),
1285-
Err(e) => assert_eq!(e.err, "Invalid signature from remote node")
1296+
Err(e) => assert_eq!(e.err, "Invalid signature on node_announcement message")
12861297
};
12871298

12881299
unsigned_announcement.timestamp += 1000;
@@ -1480,7 +1491,7 @@ mod tests {
14801491
};
14811492
match net_graph_msg_handler.handle_channel_announcement(&invalid_sig_announcement) {
14821493
Ok(_) => panic!(),
1483-
Err(e) => assert_eq!(e.err, "Invalid signature from remote node")
1494+
Err(e) => assert_eq!(e.err, "Invalid signature on channel_announcement message")
14841495
};
14851496

14861497
unsigned_announcement.node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_2_privkey);
@@ -1662,7 +1673,7 @@ mod tests {
16621673

16631674
match net_graph_msg_handler.handle_channel_update(&invalid_sig_channel_update) {
16641675
Ok(_) => panic!(),
1665-
Err(e) => assert_eq!(e.err, "Invalid signature from remote node")
1676+
Err(e) => assert_eq!(e.err, "Invalid signature on channel_update message")
16661677
};
16671678

16681679
}

0 commit comments

Comments
 (0)