@@ -326,6 +326,22 @@ macro_rules! secp_verify_sig {
326
326
} ;
327
327
}
328
328
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
+
329
345
impl < G : Deref < Target =NetworkGraph < L > > , C : Deref , L : Deref > RoutingMessageHandler for P2PGossipSync < G , C , L >
330
346
where C :: Target : chain:: Access , L :: Target : Logger
331
347
{
@@ -1330,10 +1346,10 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1330
1346
C :: Target : chain:: Access ,
1331
1347
{
1332
1348
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" ) ;
1337
1353
self . update_channel_from_unsigned_announcement_intern ( & msg. contents , Some ( msg) , chain_access)
1338
1354
}
1339
1355
@@ -1438,9 +1454,6 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1438
1454
return Err ( LightningError { err : "Channel announcement node had a channel with itself" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1439
1455
}
1440
1456
1441
- let node_one = NodeId :: from_pubkey ( & msg. node_id_1 ) ;
1442
- let node_two = NodeId :: from_pubkey ( & msg. node_id_2 ) ;
1443
-
1444
1457
{
1445
1458
let channels = self . channels . read ( ) . unwrap ( ) ;
1446
1459
@@ -1457,7 +1470,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1457
1470
// We use the Node IDs rather than the bitcoin_keys to check for "equivalence"
1458
1471
// as we didn't (necessarily) store the bitcoin keys, and we only really care
1459
1472
// 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 {
1461
1474
return Err ( LightningError {
1462
1475
err : "Already have chain-validated channel" . to_owned ( ) ,
1463
1476
action : ErrorAction :: IgnoreDuplicateGossip
@@ -1478,8 +1491,8 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1478
1491
let removed_channels = self . removed_channels . lock ( ) . unwrap ( ) ;
1479
1492
let removed_nodes = self . removed_nodes . lock ( ) . unwrap ( ) ;
1480
1493
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 ) {
1483
1496
return Err ( LightningError {
1484
1497
err : format ! ( "Channel with SCID {} or one of its nodes was removed from our network graph recently" , & msg. short_channel_id) ,
1485
1498
action : ErrorAction :: IgnoreAndLog ( Level :: Gossip ) } ) ;
@@ -1495,7 +1508,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1495
1508
match chain_access. get_utxo ( & msg. chain_hash , msg. short_channel_id ) {
1496
1509
Ok ( TxOut { value, script_pubkey } ) => {
1497
1510
let expected_script =
1498
- make_funding_redeemscript ( & msg. bitcoin_key_1 , & msg. bitcoin_key_2 ) . to_v0_p2wsh ( ) ;
1511
+ make_funding_redeemscript ( & get_pubkey_from_node_id ! ( msg. bitcoin_key_1, "channel_announcement" ) , & get_pubkey_from_node_id ! ( msg. bitcoin_key_2, "channel_announcement" ) ) . to_v0_p2wsh ( ) ;
1499
1512
if script_pubkey != expected_script {
1500
1513
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 } ) ;
1501
1514
}
@@ -1522,9 +1535,9 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1522
1535
1523
1536
let chan_info = ChannelInfo {
1524
1537
features : msg. features . clone ( ) ,
1525
- node_one,
1538
+ node_one : msg . node_id_1 ,
1526
1539
one_to_two : None ,
1527
- node_two,
1540
+ node_two : msg . node_id_2 ,
1528
1541
two_to_one : None ,
1529
1542
capacity_sats : utxo_value,
1530
1543
announcement_message : if msg. excess_data . len ( ) <= MAX_EXCESS_BYTES_FOR_RELAY
@@ -1987,10 +2000,10 @@ mod tests {
1987
2000
features : channelmanager:: provided_channel_features ( & UserConfig :: default ( ) ) ,
1988
2001
chain_hash : genesis_block ( Network :: Testnet ) . header . block_hash ( ) ,
1989
2002
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) ) ,
1994
2007
excess_data : Vec :: new ( ) ,
1995
2008
} ;
1996
2009
f ( & mut unsigned_announcement) ;
0 commit comments