@@ -444,6 +444,7 @@ impl Peer {
444
444
/// point and we shouldn't send it yet to avoid sending duplicate updates. If we've already
445
445
/// sent the old versions, we should send the update, and so return true here.
446
446
fn should_forward_channel_announcement ( & self , channel_id : u64 ) -> bool {
447
+ if self . their_features . is_none ( ) { return false ; }
447
448
if self . their_features . as_ref ( ) . unwrap ( ) . supports_gossip_queries ( ) &&
448
449
!self . sent_gossip_timestamp_filter {
449
450
return false ;
@@ -457,6 +458,7 @@ impl Peer {
457
458
458
459
/// Similar to the above, but for node announcements indexed by node_id.
459
460
fn should_forward_node_announcement ( & self , node_id : NodeId ) -> bool {
461
+ if self . their_features . is_none ( ) { return false ; }
460
462
if self . their_features . as_ref ( ) . unwrap ( ) . supports_gossip_queries ( ) &&
461
463
!self . sent_gossip_timestamp_filter {
462
464
return false ;
@@ -483,19 +485,20 @@ impl Peer {
483
485
fn should_buffer_gossip_backfill ( & self ) -> bool {
484
486
self . pending_outbound_buffer . is_empty ( ) && self . gossip_broadcast_buffer . is_empty ( )
485
487
&& self . msgs_sent_since_pong < BUFFER_DRAIN_MSGS_PER_TICK
488
+ && self . their_features . is_some ( )
486
489
}
487
490
488
491
/// Determines if we should push an onion message onto a peer's outbound buffer. This is checked
489
492
/// every time the peer's buffer may have been drained.
490
493
fn should_buffer_onion_message ( & self ) -> bool {
491
- self . pending_outbound_buffer . is_empty ( )
494
+ self . pending_outbound_buffer . is_empty ( ) && self . their_features . is_some ( )
492
495
&& self . msgs_sent_since_pong < BUFFER_DRAIN_MSGS_PER_TICK
493
496
}
494
497
495
498
/// Determines if we should push additional gossip broadcast messages onto a peer's outbound
496
499
/// buffer. This is checked every time the peer's buffer may have been drained.
497
500
fn should_buffer_gossip_broadcast ( & self ) -> bool {
498
- self . pending_outbound_buffer . is_empty ( )
501
+ self . pending_outbound_buffer . is_empty ( ) && self . their_features . is_some ( )
499
502
&& self . msgs_sent_since_pong < BUFFER_DRAIN_MSGS_PER_TICK
500
503
}
501
504
@@ -1537,10 +1540,12 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1537
1540
1538
1541
for ( _, peer_mutex) in peers. iter ( ) {
1539
1542
let mut peer = peer_mutex. lock ( ) . unwrap ( ) ;
1540
- if !peer . channel_encryptor . is_ready_for_encryption ( ) || peer. their_features . is_none ( ) ||
1543
+ if peer. their_features . is_none ( ) ||
1541
1544
!peer. should_forward_channel_announcement ( msg. contents . short_channel_id ) {
1542
1545
continue
1543
1546
}
1547
+ debug_assert ! ( peer. their_node_id. is_some( ) ) ;
1548
+ debug_assert ! ( peer. channel_encryptor. is_ready_for_encryption( ) ) ;
1544
1549
if peer. buffer_full_drop_gossip_broadcast ( ) {
1545
1550
log_gossip ! ( self . logger, "Skipping broadcast message to {:?} as its outbound buffer is full" , peer. their_node_id) ;
1546
1551
continue ;
@@ -1562,10 +1567,12 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1562
1567
1563
1568
for ( _, peer_mutex) in peers. iter ( ) {
1564
1569
let mut peer = peer_mutex. lock ( ) . unwrap ( ) ;
1565
- if !peer . channel_encryptor . is_ready_for_encryption ( ) || peer. their_features . is_none ( ) ||
1570
+ if peer. their_features . is_none ( ) ||
1566
1571
!peer. should_forward_node_announcement ( msg. contents . node_id ) {
1567
1572
continue
1568
1573
}
1574
+ debug_assert ! ( peer. their_node_id. is_some( ) ) ;
1575
+ debug_assert ! ( peer. channel_encryptor. is_ready_for_encryption( ) ) ;
1569
1576
if peer. buffer_full_drop_gossip_broadcast ( ) {
1570
1577
log_gossip ! ( self . logger, "Skipping broadcast message to {:?} as its outbound buffer is full" , peer. their_node_id) ;
1571
1578
continue ;
@@ -1587,10 +1594,12 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1587
1594
1588
1595
for ( _, peer_mutex) in peers. iter ( ) {
1589
1596
let mut peer = peer_mutex. lock ( ) . unwrap ( ) ;
1590
- if !peer . channel_encryptor . is_ready_for_encryption ( ) || peer. their_features . is_none ( ) ||
1597
+ if peer. their_features . is_none ( ) ||
1591
1598
!peer. should_forward_channel_announcement ( msg. contents . short_channel_id ) {
1592
1599
continue
1593
1600
}
1601
+ debug_assert ! ( peer. their_node_id. is_some( ) ) ;
1602
+ debug_assert ! ( peer. channel_encryptor. is_ready_for_encryption( ) ) ;
1594
1603
if peer. buffer_full_drop_gossip_broadcast ( ) {
1595
1604
log_gossip ! ( self . logger, "Skipping broadcast message to {:?} as its outbound buffer is full" , peer. their_node_id) ;
1596
1605
continue ;
@@ -2024,7 +2033,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
2024
2033
let mut peer = peer_mutex. lock ( ) . unwrap ( ) ;
2025
2034
if flush_read_disabled { peer. received_channel_announce_since_backlogged = false ; }
2026
2035
2027
- if ! peer. channel_encryptor . is_ready_for_encryption ( ) || peer . their_node_id . is_none ( ) {
2036
+ if peer. their_features . is_none ( ) {
2028
2037
// The peer needs to complete its handshake before we can exchange messages. We
2029
2038
// give peers one timer tick to complete handshake, reusing
2030
2039
// `awaiting_pong_timer_tick_intervals` to track number of timer ticks taken
@@ -2036,6 +2045,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
2036
2045
}
2037
2046
continue ;
2038
2047
}
2048
+ debug_assert ! ( peer. channel_encryptor. is_ready_for_encryption( ) ) ;
2049
+ debug_assert ! ( peer. their_node_id. is_some( ) ) ;
2039
2050
2040
2051
loop { // Used as a `goto` to skip writing a Ping message.
2041
2052
if peer. awaiting_pong_timer_tick_intervals == -1 {
0 commit comments