@@ -926,13 +926,13 @@ pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
926
926
pub ( crate ) const IDEMPOTENCY_TIMEOUT_TICKS : u8 = 7 ;
927
927
928
928
/// The maximum number of unfunded channels we can have per-peer before we start rejecting new
929
- /// (inbound) ones. The number of peers without funded channels is limited separately in
930
- /// [`MAX_NO_CHANNEL_PEERS `].
929
+ /// (inbound) ones. The number of peers with unfunded channels is limited separately in
930
+ /// [`MAX_UNFUNDED_CHANNEL_PEERS `].
931
931
const MAX_UNFUNDED_CHANS_PER_PEER : usize = 4 ;
932
932
933
- /// The maximum number of peers which we do not have a (funded) channel with . Once we reach this
934
- /// many peers we reject new (inbound) connections .
935
- const MAX_NO_CHANNEL_PEERS : usize = 50 ;
933
+ /// The maximum number of peers from which we will allow pending unfunded channels . Once we reach
934
+ /// this many peers we reject new (inbound) channels .
935
+ const MAX_UNFUNDED_CHANNEL_PEERS : usize = 50 ;
936
936
937
937
/// Information needed for constructing an invoice route hint for this channel.
938
938
#[ derive( Clone , Debug , PartialEq ) ]
@@ -4251,15 +4251,14 @@ where
4251
4251
Ok ( ( ) )
4252
4252
}
4253
4253
4254
- /// Gets the number of peers which match the given filter which have unfunded inbound channels.
4254
+ /// Gets the number of peers which match the given filter which do not have any funded,
4255
+ /// outbound, or 0-conf channels.
4255
4256
///
4256
- /// The filter is called for each node and provided with the number of unfunded channels the
4257
- /// node has.
4258
- ///
4259
- /// If the peer in question has funded channels, however, zero will be returned.
4260
- fn peers_with_unfunded_channels < Filter > ( & self , mut filter : Filter ) -> usize
4257
+ /// The filter is called for each peer and provided with the number of unfunded, inbound, and
4258
+ /// non-0-conf channels we have with the peer.
4259
+ fn peers_without_funded_channels < Filter > ( & self , mut filter : Filter ) -> usize
4261
4260
where Filter : FnMut ( & PublicKey , & PeerState < <SP :: Target as SignerProvider >:: Signer > , usize ) -> bool {
4262
- let mut peers_with_unfunded_channels = 0 ;
4261
+ let mut peers_without_funded_channels = 0 ;
4263
4262
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
4264
4263
{
4265
4264
let peer_state_lock = self . per_peer_state . read ( ) . unwrap ( ) ;
@@ -4275,11 +4274,11 @@ where
4275
4274
}
4276
4275
if !filter ( node_id, & * peer, num_unfunded_channels) { continue ; }
4277
4276
if num_unfunded_channels == peer. channel_by_id . len ( ) {
4278
- peers_with_unfunded_channels += 1 ;
4277
+ peers_without_funded_channels += 1 ;
4279
4278
}
4280
4279
}
4281
4280
}
4282
- return peers_with_unfunded_channels ;
4281
+ return peers_without_funded_channels ;
4283
4282
}
4284
4283
4285
4284
fn internal_open_channel ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: OpenChannel ) -> Result < ( ) , MsgHandleErrInternal > {
@@ -4306,7 +4305,7 @@ where
4306
4305
// about peers that never open a channel, so we filter by peers that have at least one
4307
4306
// channel, and then limit the number of those with unfunded channels.
4308
4307
let mut this_node_unfunded_channels = 0 ;
4309
- let peers_with_unfunded_channels = self . peers_with_unfunded_channels (
4308
+ let peers_without_funded_channels = self . peers_without_funded_channels (
4310
4309
|node_id, node, unfunded_channels| {
4311
4310
if node_id == counterparty_node_id {
4312
4311
this_node_unfunded_channels = unfunded_channels;
@@ -4323,7 +4322,7 @@ where
4323
4322
// If this peer already has some channels, a new channel won't increase our number of peers
4324
4323
// with unfunded channels, so as long as we aren't over the maximum number of unfunded
4325
4324
// channels per-peer we can accept channels from a peer with existing ones.
4326
- if peer_state. channel_by_id . is_empty ( ) && peers_with_unfunded_channels >= MAX_NO_CHANNEL_PEERS {
4325
+ if peer_state. channel_by_id . is_empty ( ) && peers_without_funded_channels >= MAX_UNFUNDED_CHANNEL_PEERS {
4327
4326
return Err ( MsgHandleErrInternal :: send_err_msg_no_close (
4328
4327
"Have too many peers with unfunded channels, not accepting new ones" . to_owned ( ) ,
4329
4328
msg. temporary_channel_id . clone ( ) ) ) ;
@@ -6289,14 +6288,14 @@ where
6289
6288
// disconnected peers, we still let new peers connect, but we'll reject new channels from
6290
6289
// them.
6291
6290
let mut this_peer_has_funded_channels = false ;
6292
- let connected_peers_with_unfunded_channels = self . peers_with_unfunded_channels (
6291
+ let connected_peers_without_funded_channels = self . peers_without_funded_channels (
6293
6292
|node_id, node, num_unfunded_channels| {
6294
6293
if node_id == counterparty_node_id && num_unfunded_channels != node. channel_by_id . len ( ) {
6295
6294
this_peer_has_funded_channels = true ;
6296
6295
}
6297
6296
node. is_connected
6298
6297
} ) ;
6299
- if inbound && !this_peer_has_funded_channels && connected_peers_with_unfunded_channels >= MAX_NO_CHANNEL_PEERS {
6298
+ if inbound && !this_peer_has_funded_channels && connected_peers_without_funded_channels >= MAX_UNFUNDED_CHANNEL_PEERS {
6300
6299
return Err ( ( ) ) ;
6301
6300
}
6302
6301
0 commit comments