@@ -511,34 +511,14 @@ pub fn verify_channel_announcement<C: Verification>(
511
511
msg : & ChannelAnnouncement , secp_ctx : & Secp256k1 < C > ,
512
512
) -> Result < ( ) , LightningError > {
513
513
let msg_hash = hash_to_message ! ( & message_sha256d_hash( & msg. contents) [ ..] ) ;
514
- secp_verify_sig ! (
515
- secp_ctx,
516
- & msg_hash,
517
- & msg. node_signature_1,
518
- & get_pubkey_from_node_id!( msg. contents. node_id_1, "channel_announcement" ) ,
519
- "channel_announcement"
520
- ) ;
521
- secp_verify_sig ! (
522
- secp_ctx,
523
- & msg_hash,
524
- & msg. node_signature_2,
525
- & get_pubkey_from_node_id!( msg. contents. node_id_2, "channel_announcement" ) ,
526
- "channel_announcement"
527
- ) ;
528
- secp_verify_sig ! (
529
- secp_ctx,
530
- & msg_hash,
531
- & msg. bitcoin_signature_1,
532
- & get_pubkey_from_node_id!( msg. contents. bitcoin_key_1, "channel_announcement" ) ,
533
- "channel_announcement"
534
- ) ;
535
- secp_verify_sig ! (
536
- secp_ctx,
537
- & msg_hash,
538
- & msg. bitcoin_signature_2,
539
- & get_pubkey_from_node_id!( msg. contents. bitcoin_key_2, "channel_announcement" ) ,
540
- "channel_announcement"
541
- ) ;
514
+ let node_a = get_pubkey_from_node_id ! ( msg. contents. node_id_1, "channel_announcement" ) ;
515
+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. node_signature_1, & node_a, "channel_announcement" ) ;
516
+ let node_b = get_pubkey_from_node_id ! ( msg. contents. node_id_2, "channel_announcement" ) ;
517
+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. node_signature_2, & node_b, "channel_announcement" ) ;
518
+ let btc_a = get_pubkey_from_node_id ! ( msg. contents. bitcoin_key_1, "channel_announcement" ) ;
519
+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. bitcoin_signature_1, & btc_a, "channel_announcement" ) ;
520
+ let btc_b = get_pubkey_from_node_id ! ( msg. contents. bitcoin_key_2, "channel_announcement" ) ;
521
+ secp_verify_sig ! ( secp_ctx, & msg_hash, & msg. bitcoin_signature_2, & btc_b, "channel_announcement" ) ;
542
522
543
523
Ok ( ( ) )
544
524
}
@@ -2962,16 +2942,11 @@ pub(crate) mod tests {
2962
2942
_ => panic ! ( ) ,
2963
2943
} ;
2964
2944
2965
- {
2966
- match network_graph
2967
- . read_only ( )
2968
- . channels ( )
2969
- . get ( & valid_announcement. contents . short_channel_id )
2970
- {
2971
- None => panic ! ( ) ,
2972
- Some ( _) => ( ) ,
2973
- } ;
2974
- }
2945
+ let scid = valid_announcement. contents . short_channel_id ;
2946
+ match network_graph. read_only ( ) . channels ( ) . get ( & scid) {
2947
+ None => panic ! ( ) ,
2948
+ Some ( _) => ( ) ,
2949
+ } ;
2975
2950
2976
2951
// If we receive announcement for the same channel (with UTXO lookups disabled),
2977
2952
// drop new one on the floor, since we can't see any changes.
@@ -3015,16 +2990,11 @@ pub(crate) mod tests {
3015
2990
_ => panic ! ( ) ,
3016
2991
} ;
3017
2992
3018
- {
3019
- match network_graph
3020
- . read_only ( )
3021
- . channels ( )
3022
- . get ( & valid_announcement. contents . short_channel_id )
3023
- {
3024
- None => panic ! ( ) ,
3025
- Some ( _) => ( ) ,
3026
- } ;
3027
- }
2993
+ let scid = valid_announcement. contents . short_channel_id ;
2994
+ match network_graph. read_only ( ) . channels ( ) . get ( & scid) {
2995
+ None => panic ! ( ) ,
2996
+ Some ( _) => ( ) ,
2997
+ } ;
3028
2998
3029
2999
// If we receive announcement for the same channel, once we've validated it against the
3030
3000
// chain, we simply ignore all new (duplicate) announcements.
@@ -3044,9 +3014,8 @@ pub(crate) mod tests {
3044
3014
. expect ( "Time must be > 1970" )
3045
3015
. as_secs ( ) ;
3046
3016
// Mark a node as permanently failed so it's tracked as removed.
3047
- gossip_sync
3048
- . network_graph ( )
3049
- . node_failed_permanent ( & PublicKey :: from_secret_key ( & secp_ctx, node_1_privkey) ) ;
3017
+ let node_1_pubkey = PublicKey :: from_secret_key ( & secp_ctx, node_1_privkey) ;
3018
+ gossip_sync. network_graph ( ) . node_failed_permanent ( & node_1_pubkey) ;
3050
3019
3051
3020
// Return error and ignore valid channel announcement if one of the nodes has been tracked as removed.
3052
3021
let valid_announcement = get_signed_channel_announcement (
@@ -3291,59 +3260,48 @@ pub(crate) mod tests {
3291
3260
3292
3261
let node_1_privkey = & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
3293
3262
let node_2_privkey = & SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ;
3294
- let node_2_id = PublicKey :: from_secret_key ( & secp_ctx, node_2_privkey) ;
3263
+ let node_2_pk = PublicKey :: from_secret_key ( & secp_ctx, node_2_privkey) ;
3264
+ let node_2_id = NodeId :: from_pubkey ( & node_2_pk) ;
3295
3265
3296
3266
{
3297
3267
// There is no nodes in the table at the beginning.
3298
3268
assert_eq ! ( network_graph. read_only( ) . nodes( ) . len( ) , 0 ) ;
3299
3269
}
3300
3270
3301
- let short_channel_id ;
3271
+ let scid ;
3302
3272
{
3303
3273
// Check that we can manually apply a channel update.
3304
3274
let valid_channel_announcement =
3305
3275
get_signed_channel_announcement ( |_| { } , node_1_privkey, node_2_privkey, & secp_ctx) ;
3306
- short_channel_id = valid_channel_announcement. contents . short_channel_id ;
3276
+ scid = valid_channel_announcement. contents . short_channel_id ;
3307
3277
let chain_source: Option < & test_utils:: TestChainSource > = None ;
3308
3278
assert ! ( network_graph
3309
3279
. update_channel_from_announcement( & valid_channel_announcement, & chain_source)
3310
3280
. is_ok( ) ) ;
3311
- assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id ) . is_some( ) ) ;
3281
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & scid ) . is_some( ) ) ;
3312
3282
3313
3283
let valid_channel_update = get_signed_channel_update ( |_| { } , node_1_privkey, & secp_ctx) ;
3314
3284
3315
- assert ! ( network_graph
3316
- . read_only( )
3317
- . channels( )
3318
- . get( & short_channel_id)
3319
- . unwrap( )
3320
- . one_to_two
3321
- . is_none( ) ) ;
3285
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & scid) . unwrap( ) . one_to_two. is_none( ) ) ;
3322
3286
network_graph. update_channel ( & valid_channel_update) . unwrap ( ) ;
3323
- assert ! ( network_graph
3324
- . read_only( )
3325
- . channels( )
3326
- . get( & short_channel_id)
3327
- . unwrap( )
3328
- . one_to_two
3329
- . is_some( ) ) ;
3287
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & scid) . unwrap( ) . one_to_two. is_some( ) ) ;
3330
3288
}
3331
3289
3332
3290
// Non-permanent failure doesn't touch the channel at all
3333
3291
{
3334
- match network_graph. read_only ( ) . channels ( ) . get ( & short_channel_id ) {
3292
+ match network_graph. read_only ( ) . channels ( ) . get ( & scid ) {
3335
3293
None => panic ! ( ) ,
3336
3294
Some ( channel_info) => {
3337
3295
assert ! ( channel_info. one_to_two. as_ref( ) . unwrap( ) . enabled) ;
3338
3296
} ,
3339
3297
} ;
3340
3298
3341
3299
network_graph. handle_network_update ( & NetworkUpdate :: ChannelFailure {
3342
- short_channel_id,
3300
+ short_channel_id : scid ,
3343
3301
is_permanent : false ,
3344
3302
} ) ;
3345
3303
3346
- match network_graph. read_only ( ) . channels ( ) . get ( & short_channel_id ) {
3304
+ match network_graph. read_only ( ) . channels ( ) . get ( & scid ) {
3347
3305
None => panic ! ( ) ,
3348
3306
Some ( channel_info) => {
3349
3307
assert ! ( channel_info. one_to_two. as_ref( ) . unwrap( ) . enabled) ;
@@ -3353,7 +3311,7 @@ pub(crate) mod tests {
3353
3311
3354
3312
// Permanent closing deletes a channel
3355
3313
network_graph. handle_network_update ( & NetworkUpdate :: ChannelFailure {
3356
- short_channel_id,
3314
+ short_channel_id : scid ,
3357
3315
is_permanent : true ,
3358
3316
} ) ;
3359
3317
@@ -3377,20 +3335,16 @@ pub(crate) mod tests {
3377
3335
3378
3336
// Non-permanent node failure does not delete any nodes or channels
3379
3337
network_graph. handle_network_update ( & NetworkUpdate :: NodeFailure {
3380
- node_id : node_2_id ,
3338
+ node_id : node_2_pk ,
3381
3339
is_permanent : false ,
3382
3340
} ) ;
3383
3341
3384
3342
assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . is_some( ) ) ;
3385
- assert ! ( network_graph
3386
- . read_only( )
3387
- . nodes( )
3388
- . get( & NodeId :: from_pubkey( & node_2_id) )
3389
- . is_some( ) ) ;
3343
+ assert ! ( network_graph. read_only( ) . nodes( ) . get( & node_2_id) . is_some( ) ) ;
3390
3344
3391
3345
// Permanent node failure deletes node and its channels
3392
3346
network_graph. handle_network_update ( & NetworkUpdate :: NodeFailure {
3393
- node_id : node_2_id ,
3347
+ node_id : node_2_pk ,
3394
3348
is_permanent : true ,
3395
3349
} ) ;
3396
3350
@@ -3415,25 +3369,19 @@ pub(crate) mod tests {
3415
3369
3416
3370
let valid_channel_announcement =
3417
3371
get_signed_channel_announcement ( |_| { } , node_1_privkey, node_2_privkey, & secp_ctx) ;
3418
- let short_channel_id = valid_channel_announcement. contents . short_channel_id ;
3372
+ let scid = valid_channel_announcement. contents . short_channel_id ;
3419
3373
let chain_source: Option < & test_utils:: TestChainSource > = None ;
3420
3374
assert ! ( network_graph
3421
3375
. update_channel_from_announcement( & valid_channel_announcement, & chain_source)
3422
3376
. is_ok( ) ) ;
3423
- assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id ) . is_some( ) ) ;
3377
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & scid ) . is_some( ) ) ;
3424
3378
3425
3379
// Submit two channel updates for each channel direction (update.flags bit).
3426
3380
let valid_channel_update = get_signed_channel_update ( |_| { } , node_1_privkey, & secp_ctx) ;
3427
3381
assert ! ( gossip_sync
3428
3382
. handle_channel_update( Some ( node_1_pubkey) , & valid_channel_update)
3429
3383
. is_ok( ) ) ;
3430
- assert ! ( network_graph
3431
- . read_only( )
3432
- . channels( )
3433
- . get( & short_channel_id)
3434
- . unwrap( )
3435
- . one_to_two
3436
- . is_some( ) ) ;
3384
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & scid) . unwrap( ) . one_to_two. is_some( ) ) ;
3437
3385
3438
3386
let valid_channel_update_2 = get_signed_channel_update (
3439
3387
|update| {
@@ -3443,13 +3391,7 @@ pub(crate) mod tests {
3443
3391
& secp_ctx,
3444
3392
) ;
3445
3393
gossip_sync. handle_channel_update ( Some ( node_1_pubkey) , & valid_channel_update_2) . unwrap ( ) ;
3446
- assert ! ( network_graph
3447
- . read_only( )
3448
- . channels( )
3449
- . get( & short_channel_id)
3450
- . unwrap( )
3451
- . two_to_one
3452
- . is_some( ) ) ;
3394
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & scid) . unwrap( ) . two_to_one. is_some( ) ) ;
3453
3395
3454
3396
network_graph. remove_stale_channels_and_tracking_with_time (
3455
3397
100 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS ,
@@ -3480,13 +3422,7 @@ pub(crate) mod tests {
3480
3422
// Note that the directional channel information will have been removed already..
3481
3423
// We want to check that this will work even if *one* of the channel updates is recent,
3482
3424
// so we should add it with a recent timestamp.
3483
- assert ! ( network_graph
3484
- . read_only( )
3485
- . channels( )
3486
- . get( & short_channel_id)
3487
- . unwrap( )
3488
- . one_to_two
3489
- . is_none( ) ) ;
3425
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & scid) . unwrap( ) . one_to_two. is_none( ) ) ;
3490
3426
use std:: time:: { SystemTime , UNIX_EPOCH } ;
3491
3427
let announcement_time = SystemTime :: now ( )
3492
3428
. duration_since ( UNIX_EPOCH )
@@ -3503,13 +3439,7 @@ pub(crate) mod tests {
3503
3439
assert ! ( gossip_sync
3504
3440
. handle_channel_update( Some ( node_1_pubkey) , & valid_channel_update)
3505
3441
. is_ok( ) ) ;
3506
- assert ! ( network_graph
3507
- . read_only( )
3508
- . channels( )
3509
- . get( & short_channel_id)
3510
- . unwrap( )
3511
- . one_to_two
3512
- . is_some( ) ) ;
3442
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & scid) . unwrap( ) . one_to_two. is_some( ) ) ;
3513
3443
network_graph. remove_stale_channels_and_tracking_with_time (
3514
3444
announcement_time + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS ,
3515
3445
) ;
@@ -3548,7 +3478,7 @@ pub(crate) mod tests {
3548
3478
3549
3479
// Mark the channel as permanently failed. This will also remove the two nodes
3550
3480
// and all of the entries will be tracked as removed.
3551
- network_graph. channel_failed_permanent_with_time ( short_channel_id , Some ( tracking_time) ) ;
3481
+ network_graph. channel_failed_permanent_with_time ( scid , Some ( tracking_time) ) ;
3552
3482
3553
3483
// Should not remove from tracking if insufficient time has passed
3554
3484
network_graph. remove_stale_channels_and_tracking_with_time (
@@ -3597,7 +3527,7 @@ pub(crate) mod tests {
3597
3527
3598
3528
// Mark the channel as permanently failed. This will also remove the two nodes
3599
3529
// and all of the entries will be tracked as removed.
3600
- network_graph. channel_failed_permanent ( short_channel_id ) ;
3530
+ network_graph. channel_failed_permanent ( scid ) ;
3601
3531
3602
3532
// The first time we call the following, the channel will have a removal time assigned.
3603
3533
network_graph. remove_stale_channels_and_tracking_with_time ( removal_time) ;
0 commit comments