@@ -436,6 +436,7 @@ impl Peer {
436
436
/// point and we shouldn't send it yet to avoid sending duplicate updates. If we've already
437
437
/// sent the old versions, we should send the update, and so return true here.
438
438
fn should_forward_channel_announcement ( & self , channel_id : u64 ) -> bool {
439
+ if self . their_features . is_none ( ) { return false ; }
439
440
if self . their_features . as_ref ( ) . unwrap ( ) . supports_gossip_queries ( ) &&
440
441
!self . sent_gossip_timestamp_filter {
441
442
return false ;
@@ -449,6 +450,7 @@ impl Peer {
449
450
450
451
/// Similar to the above, but for node announcements indexed by node_id.
451
452
fn should_forward_node_announcement ( & self , node_id : NodeId ) -> bool {
453
+ if self . their_features . is_none ( ) { return false ; }
452
454
if self . their_features . as_ref ( ) . unwrap ( ) . supports_gossip_queries ( ) &&
453
455
!self . sent_gossip_timestamp_filter {
454
456
return false ;
@@ -475,19 +477,20 @@ impl Peer {
475
477
fn should_buffer_gossip_backfill ( & self ) -> bool {
476
478
self . pending_outbound_buffer . is_empty ( ) && self . gossip_broadcast_buffer . is_empty ( )
477
479
&& self . msgs_sent_since_pong < BUFFER_DRAIN_MSGS_PER_TICK
480
+ && self . their_features . is_some ( )
478
481
}
479
482
480
483
/// Determines if we should push an onion message onto a peer's outbound buffer. This is checked
481
484
/// every time the peer's buffer may have been drained.
482
485
fn should_buffer_onion_message ( & self ) -> bool {
483
- self . pending_outbound_buffer . is_empty ( )
486
+ self . pending_outbound_buffer . is_empty ( ) && self . their_features . is_some ( )
484
487
&& self . msgs_sent_since_pong < BUFFER_DRAIN_MSGS_PER_TICK
485
488
}
486
489
487
490
/// Determines if we should push additional gossip broadcast messages onto a peer's outbound
488
491
/// buffer. This is checked every time the peer's buffer may have been drained.
489
492
fn should_buffer_gossip_broadcast ( & self ) -> bool {
490
- self . pending_outbound_buffer . is_empty ( )
493
+ self . pending_outbound_buffer . is_empty ( ) && self . their_features . is_some ( )
491
494
&& self . msgs_sent_since_pong < BUFFER_DRAIN_MSGS_PER_TICK
492
495
}
493
496
@@ -1529,10 +1532,12 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1529
1532
1530
1533
for ( _, peer_mutex) in peers. iter ( ) {
1531
1534
let mut peer = peer_mutex. lock ( ) . unwrap ( ) ;
1532
- if !peer . channel_encryptor . is_ready_for_encryption ( ) || peer. their_features . is_none ( ) ||
1535
+ if peer. their_features . is_none ( ) ||
1533
1536
!peer. should_forward_channel_announcement ( msg. contents . short_channel_id ) {
1534
1537
continue
1535
1538
}
1539
+ debug_assert ! ( peer. their_node_id. is_some( ) ) ;
1540
+ debug_assert ! ( peer. channel_encryptor. is_ready_for_encryption( ) ) ;
1536
1541
if peer. buffer_full_drop_gossip_broadcast ( ) {
1537
1542
log_gossip ! ( self . logger, "Skipping broadcast message to {:?} as its outbound buffer is full" , peer. their_node_id) ;
1538
1543
continue ;
@@ -1554,10 +1559,12 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1554
1559
1555
1560
for ( _, peer_mutex) in peers. iter ( ) {
1556
1561
let mut peer = peer_mutex. lock ( ) . unwrap ( ) ;
1557
- if !peer . channel_encryptor . is_ready_for_encryption ( ) || peer. their_features . is_none ( ) ||
1562
+ if peer. their_features . is_none ( ) ||
1558
1563
!peer. should_forward_node_announcement ( msg. contents . node_id ) {
1559
1564
continue
1560
1565
}
1566
+ debug_assert ! ( peer. their_node_id. is_some( ) ) ;
1567
+ debug_assert ! ( peer. channel_encryptor. is_ready_for_encryption( ) ) ;
1561
1568
if peer. buffer_full_drop_gossip_broadcast ( ) {
1562
1569
log_gossip ! ( self . logger, "Skipping broadcast message to {:?} as its outbound buffer is full" , peer. their_node_id) ;
1563
1570
continue ;
@@ -1579,10 +1586,12 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1579
1586
1580
1587
for ( _, peer_mutex) in peers. iter ( ) {
1581
1588
let mut peer = peer_mutex. lock ( ) . unwrap ( ) ;
1582
- if !peer . channel_encryptor . is_ready_for_encryption ( ) || peer. their_features . is_none ( ) ||
1589
+ if peer. their_features . is_none ( ) ||
1583
1590
!peer. should_forward_channel_announcement ( msg. contents . short_channel_id ) {
1584
1591
continue
1585
1592
}
1593
+ debug_assert ! ( peer. their_node_id. is_some( ) ) ;
1594
+ debug_assert ! ( peer. channel_encryptor. is_ready_for_encryption( ) ) ;
1586
1595
if peer. buffer_full_drop_gossip_broadcast ( ) {
1587
1596
log_gossip ! ( self . logger, "Skipping broadcast message to {:?} as its outbound buffer is full" , peer. their_node_id) ;
1588
1597
continue ;
@@ -2016,7 +2025,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
2016
2025
let mut peer = peer_mutex. lock ( ) . unwrap ( ) ;
2017
2026
if flush_read_disabled { peer. received_channel_announce_since_backlogged = false ; }
2018
2027
2019
- if ! peer. channel_encryptor . is_ready_for_encryption ( ) || peer . their_node_id . is_none ( ) {
2028
+ if peer. their_features . is_none ( ) {
2020
2029
// The peer needs to complete its handshake before we can exchange messages. We
2021
2030
// give peers one timer tick to complete handshake, reusing
2022
2031
// `awaiting_pong_timer_tick_intervals` to track number of timer ticks taken
@@ -2028,6 +2037,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
2028
2037
}
2029
2038
continue ;
2030
2039
}
2040
+ debug_assert ! ( peer. channel_encryptor. is_ready_for_encryption( ) ) ;
2041
+ debug_assert ! ( peer. their_node_id. is_some( ) ) ;
2031
2042
2032
2043
loop { // Used as a `goto` to skip writing a Ping message.
2033
2044
if peer. awaiting_pong_timer_tick_intervals == -1 {
0 commit comments