@@ -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 . handshake_complete ( ) { 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 . handshake_complete ( ) { 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 . handshake_complete ( )
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 . handshake_complete ( )
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 . handshake_complete ( )
499
502
&& self . msgs_sent_since_pong < BUFFER_DRAIN_MSGS_PER_TICK
500
503
}
501
504
@@ -777,8 +780,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
777
780
let peers = self . peers . read ( ) . unwrap ( ) ;
778
781
peers. values ( ) . filter_map ( |peer_mutex| {
779
782
let p = peer_mutex. lock ( ) . unwrap ( ) ;
780
- if !p. channel_encryptor . is_ready_for_encryption ( ) || p. their_features . is_none ( ) ||
781
- p. their_node_id . is_none ( ) {
783
+ if !p. handshake_complete ( ) {
782
784
return None ;
783
785
}
784
786
Some ( ( p. their_node_id . unwrap ( ) . 0 , p. their_net_address . clone ( ) ) )
@@ -1537,10 +1539,12 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1537
1539
1538
1540
for ( _, peer_mutex) in peers. iter ( ) {
1539
1541
let mut peer = peer_mutex. lock ( ) . unwrap ( ) ;
1540
- if !peer. channel_encryptor . is_ready_for_encryption ( ) || peer . their_features . is_none ( ) ||
1542
+ if !peer. handshake_complete ( ) ||
1541
1543
!peer. should_forward_channel_announcement ( msg. contents . short_channel_id ) {
1542
1544
continue
1543
1545
}
1546
+ debug_assert ! ( peer. their_node_id. is_some( ) ) ;
1547
+ debug_assert ! ( peer. channel_encryptor. is_ready_for_encryption( ) ) ;
1544
1548
if peer. buffer_full_drop_gossip_broadcast ( ) {
1545
1549
log_gossip ! ( self . logger, "Skipping broadcast message to {:?} as its outbound buffer is full" , peer. their_node_id) ;
1546
1550
continue ;
@@ -1562,10 +1566,12 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1562
1566
1563
1567
for ( _, peer_mutex) in peers. iter ( ) {
1564
1568
let mut peer = peer_mutex. lock ( ) . unwrap ( ) ;
1565
- if !peer. channel_encryptor . is_ready_for_encryption ( ) || peer . their_features . is_none ( ) ||
1569
+ if !peer. handshake_complete ( ) ||
1566
1570
!peer. should_forward_node_announcement ( msg. contents . node_id ) {
1567
1571
continue
1568
1572
}
1573
+ debug_assert ! ( peer. their_node_id. is_some( ) ) ;
1574
+ debug_assert ! ( peer. channel_encryptor. is_ready_for_encryption( ) ) ;
1569
1575
if peer. buffer_full_drop_gossip_broadcast ( ) {
1570
1576
log_gossip ! ( self . logger, "Skipping broadcast message to {:?} as its outbound buffer is full" , peer. their_node_id) ;
1571
1577
continue ;
@@ -1587,10 +1593,12 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1587
1593
1588
1594
for ( _, peer_mutex) in peers. iter ( ) {
1589
1595
let mut peer = peer_mutex. lock ( ) . unwrap ( ) ;
1590
- if !peer. channel_encryptor . is_ready_for_encryption ( ) || peer . their_features . is_none ( ) ||
1596
+ if !peer. handshake_complete ( ) ||
1591
1597
!peer. should_forward_channel_announcement ( msg. contents . short_channel_id ) {
1592
1598
continue
1593
1599
}
1600
+ debug_assert ! ( peer. their_node_id. is_some( ) ) ;
1601
+ debug_assert ! ( peer. channel_encryptor. is_ready_for_encryption( ) ) ;
1594
1602
if peer. buffer_full_drop_gossip_broadcast ( ) {
1595
1603
log_gossip ! ( self . logger, "Skipping broadcast message to {:?} as its outbound buffer is full" , peer. their_node_id) ;
1596
1604
continue ;
@@ -1670,7 +1678,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1670
1678
Some ( descriptor) => match peers. get( & descriptor) {
1671
1679
Some ( peer_mutex) => {
1672
1680
let peer_lock = peer_mutex. lock( ) . unwrap( ) ;
1673
- if peer_lock. their_features . is_none ( ) {
1681
+ if ! peer_lock. handshake_complete ( ) {
1674
1682
continue ;
1675
1683
}
1676
1684
peer_lock
@@ -2024,7 +2032,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
2024
2032
let mut peer = peer_mutex. lock ( ) . unwrap ( ) ;
2025
2033
if flush_read_disabled { peer. received_channel_announce_since_backlogged = false ; }
2026
2034
2027
- if !peer. channel_encryptor . is_ready_for_encryption ( ) || peer . their_node_id . is_none ( ) {
2035
+ if !peer. handshake_complete ( ) {
2028
2036
// The peer needs to complete its handshake before we can exchange messages. We
2029
2037
// give peers one timer tick to complete handshake, reusing
2030
2038
// `awaiting_pong_timer_tick_intervals` to track number of timer ticks taken
@@ -2036,6 +2044,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
2036
2044
}
2037
2045
continue ;
2038
2046
}
2047
+ debug_assert ! ( peer. channel_encryptor. is_ready_for_encryption( ) ) ;
2048
+ debug_assert ! ( peer. their_node_id. is_some( ) ) ;
2039
2049
2040
2050
loop { // Used as a `goto` to skip writing a Ping message.
2041
2051
if peer. awaiting_pong_timer_tick_intervals == -1 {
0 commit comments