@@ -21,7 +21,7 @@ use bitcoin::hash_types::BlockHash;
2121
2222use crate :: chain;
2323use crate :: chain:: Access ;
24- use crate :: ln:: chan_utils:: make_funding_redeemscript ;
24+ use crate :: ln:: chan_utils:: make_funding_redeemscript_from_slices ;
2525use crate :: ln:: features:: { ChannelFeatures , NodeFeatures , InitFeatures } ;
2626use crate :: ln:: msgs:: { DecodeError , ErrorAction , Init , LightningError , RoutingMessageHandler , NetAddress , MAX_VALUE_MSAT } ;
2727use crate :: ln:: msgs:: { ChannelAnnouncement , ChannelUpdate , NodeAnnouncement , GossipTimestampFilter } ;
@@ -326,6 +326,22 @@ macro_rules! secp_verify_sig {
326326 } ;
327327}
328328
329+ macro_rules! get_pubkey_from_node_id {
330+ ( $node_id: expr, $msg_type: expr ) => {
331+ PublicKey :: from_slice( $node_id. as_slice( ) )
332+ . map_err( |_| LightningError {
333+ err: format!( "Invalid public key on {} message" , $msg_type) ,
334+ action: ErrorAction :: SendWarningMessage {
335+ msg: msgs:: WarningMessage {
336+ channel_id: [ 0 ; 32 ] ,
337+ data: format!( "Invalid public key on {} message" , $msg_type) ,
338+ } ,
339+ log_level: Level :: Trace
340+ }
341+ } ) ?
342+ }
343+ }
344+
329345impl < G : Deref < Target =NetworkGraph < L > > , C : Deref , L : Deref > RoutingMessageHandler for P2PGossipSync < G , C , L >
330346where C :: Target : chain:: Access , L :: Target : Logger
331347{
@@ -1330,10 +1346,10 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
13301346 C :: Target : chain:: Access ,
13311347 {
13321348 let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. contents. encode( ) [ ..] ) [ ..] ) ;
1333- secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. node_signature_1, & msg. contents. node_id_1, "channel_announcement" ) ;
1334- secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. node_signature_2, & msg. contents. node_id_2, "channel_announcement" ) ;
1335- secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. bitcoin_signature_1, & msg. contents. bitcoin_key_1, "channel_announcement" ) ;
1336- secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. bitcoin_signature_2, & msg. contents. bitcoin_key_2, "channel_announcement" ) ;
1349+ secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. node_signature_1, & get_pubkey_from_node_id! ( msg. contents. node_id_1, "channel_announcement" ) , "channel_announcement" ) ;
1350+ secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. node_signature_2, & get_pubkey_from_node_id! ( msg. contents. node_id_2, "channel_announcement" ) , "channel_announcement" ) ;
1351+ secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. bitcoin_signature_1, & get_pubkey_from_node_id! ( msg. contents. bitcoin_key_1, "channel_announcement" ) , "channel_announcement" ) ;
1352+ secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. bitcoin_signature_2, & get_pubkey_from_node_id! ( msg. contents. bitcoin_key_2, "channel_announcement" ) , "channel_announcement" ) ;
13371353 self . update_channel_from_unsigned_announcement_intern ( & msg. contents , Some ( msg) , chain_access)
13381354 }
13391355
@@ -1438,9 +1454,6 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
14381454 return Err ( LightningError { err : "Channel announcement node had a channel with itself" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
14391455 }
14401456
1441- let node_one = NodeId :: from_pubkey ( & msg. node_id_1 ) ;
1442- let node_two = NodeId :: from_pubkey ( & msg. node_id_2 ) ;
1443-
14441457 {
14451458 let channels = self . channels . read ( ) . unwrap ( ) ;
14461459
@@ -1457,7 +1470,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
14571470 // We use the Node IDs rather than the bitcoin_keys to check for "equivalence"
14581471 // as we didn't (necessarily) store the bitcoin keys, and we only really care
14591472 // if the peers on the channel changed anyway.
1460- if node_one == chan. node_one && node_two == chan. node_two {
1473+ if msg . node_id_1 == chan. node_one && msg . node_id_2 == chan. node_two {
14611474 return Err ( LightningError {
14621475 err : "Already have chain-validated channel" . to_owned ( ) ,
14631476 action : ErrorAction :: IgnoreDuplicateGossip
@@ -1478,8 +1491,8 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
14781491 let removed_channels = self . removed_channels . lock ( ) . unwrap ( ) ;
14791492 let removed_nodes = self . removed_nodes . lock ( ) . unwrap ( ) ;
14801493 if removed_channels. contains_key ( & msg. short_channel_id ) ||
1481- removed_nodes. contains_key ( & node_one ) ||
1482- removed_nodes. contains_key ( & node_two ) {
1494+ removed_nodes. contains_key ( & msg . node_id_1 ) ||
1495+ removed_nodes. contains_key ( & msg . node_id_2 ) {
14831496 return Err ( LightningError {
14841497 err : format ! ( "Channel with SCID {} or one of its nodes was removed from our network graph recently" , & msg. short_channel_id) ,
14851498 action : ErrorAction :: IgnoreAndLog ( Level :: Gossip ) } ) ;
@@ -1495,7 +1508,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
14951508 match chain_access. get_utxo ( & msg. chain_hash , msg. short_channel_id ) {
14961509 Ok ( TxOut { value, script_pubkey } ) => {
14971510 let expected_script =
1498- make_funding_redeemscript ( & msg. bitcoin_key_1 , & msg. bitcoin_key_2 ) . to_v0_p2wsh ( ) ;
1511+ make_funding_redeemscript_from_slices ( msg. bitcoin_key_1 . as_slice ( ) , msg. bitcoin_key_2 . as_slice ( ) ) . to_v0_p2wsh ( ) ;
14991512 if script_pubkey != expected_script {
15001513 return Err ( LightningError { err : format ! ( "Channel announcement key ({}) didn't match on-chain script ({})" , expected_script. to_hex( ) , script_pubkey. to_hex( ) ) , action : ErrorAction :: IgnoreError } ) ;
15011514 }
@@ -1522,9 +1535,9 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
15221535
15231536 let chan_info = ChannelInfo {
15241537 features : msg. features . clone ( ) ,
1525- node_one,
1538+ node_one : msg . node_id_1 ,
15261539 one_to_two : None ,
1527- node_two,
1540+ node_two : msg . node_id_2 ,
15281541 two_to_one : None ,
15291542 capacity_sats : utxo_value,
15301543 announcement_message : if msg. excess_data . len ( ) <= MAX_EXCESS_BYTES_FOR_RELAY
@@ -1987,10 +2000,10 @@ mod tests {
19872000 features : channelmanager:: provided_channel_features ( & UserConfig :: default ( ) ) ,
19882001 chain_hash : genesis_block ( Network :: Testnet ) . header . block_hash ( ) ,
19892002 short_channel_id : 0 ,
1990- node_id_1,
1991- node_id_2,
1992- bitcoin_key_1 : PublicKey :: from_secret_key ( & secp_ctx, node_1_btckey) ,
1993- bitcoin_key_2 : PublicKey :: from_secret_key ( & secp_ctx, node_2_btckey) ,
2003+ node_id_1 : NodeId :: from_pubkey ( & node_id_1 ) ,
2004+ node_id_2 : NodeId :: from_pubkey ( & node_id_2 ) ,
2005+ bitcoin_key_1 : NodeId :: from_pubkey ( & PublicKey :: from_secret_key ( & secp_ctx, node_1_btckey) ) ,
2006+ bitcoin_key_2 : NodeId :: from_pubkey ( & PublicKey :: from_secret_key ( & secp_ctx, node_2_btckey) ) ,
19942007 excess_data : Vec :: new ( ) ,
19952008 } ;
19962009 f ( & mut unsigned_announcement) ;
0 commit comments