You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let peer_limits = if let Some(ref limits) = self.inbound_handshake_limits_override { limits } else { default_limits };
2156
+
2157
+
// Check sanity of message fields:
2158
+
if !self.is_outbound() {
2159
+
return Err(ChannelError::close("Got an accept_channel message from an inbound peer".to_owned()));
2160
+
}
2161
+
if !matches!(self.channel_state, ChannelState::NegotiatingFunding(flags) if flags == NegotiatingFundingFlags::OUR_INIT_SENT) {
2162
+
return Err(ChannelError::close("Got an accept_channel message at a strange time".to_owned()));
2163
+
}
2164
+
if common_fields.dust_limit_satoshis > 21000000 * 100000000 {
2165
+
return Err(ChannelError::close(format!("Peer never wants payout outputs? dust_limit_satoshis was {}", common_fields.dust_limit_satoshis)));
2166
+
}
2167
+
if channel_reserve_satoshis > self.channel_value_satoshis {
2168
+
return Err(ChannelError::close(format!("Bogus channel_reserve_satoshis ({}). Must not be greater than ({})", channel_reserve_satoshis, self.channel_value_satoshis)));
2169
+
}
2170
+
if common_fields.dust_limit_satoshis > self.holder_selected_channel_reserve_satoshis {
2171
+
return Err(ChannelError::close(format!("Dust limit ({}) is bigger than our channel reserve ({})", common_fields.dust_limit_satoshis, self.holder_selected_channel_reserve_satoshis)));
2172
+
}
2173
+
if channel_reserve_satoshis > self.channel_value_satoshis - self.holder_selected_channel_reserve_satoshis {
2174
+
return Err(ChannelError::close(format!("Bogus channel_reserve_satoshis ({}). Must not be greater than channel value minus our reserve ({})",
let full_channel_value_msat = (self.channel_value_satoshis - channel_reserve_satoshis) * 1000;
2178
+
if common_fields.htlc_minimum_msat >= full_channel_value_msat {
2179
+
return Err(ChannelError::close(format!("Minimum htlc value ({}) is full channel value ({})", common_fields.htlc_minimum_msat, full_channel_value_msat)));
2180
+
}
2181
+
let max_delay_acceptable = u16::min(peer_limits.their_to_self_delay, MAX_LOCAL_BREAKDOWN_TIMEOUT);
2182
+
if common_fields.to_self_delay > max_delay_acceptable {
2183
+
return Err(ChannelError::close(format!("They wanted our payments to be delayed by a needlessly long period. Upper limit: {}. Actual: {}", max_delay_acceptable, common_fields.to_self_delay)));
2184
+
}
2185
+
if common_fields.max_accepted_htlcs < 1 {
2186
+
return Err(ChannelError::close("0 max_accepted_htlcs makes for a useless channel".to_owned()));
2187
+
}
2188
+
if common_fields.max_accepted_htlcs > MAX_HTLCS {
2189
+
return Err(ChannelError::close(format!("max_accepted_htlcs was {}. It must not be larger than {}", common_fields.max_accepted_htlcs, MAX_HTLCS)));
2190
+
}
2191
+
2192
+
// Now check against optional parameters as set by config...
2193
+
if common_fields.htlc_minimum_msat > peer_limits.max_htlc_minimum_msat {
2194
+
return Err(ChannelError::close(format!("htlc_minimum_msat ({}) is higher than the user specified limit ({})", common_fields.htlc_minimum_msat, peer_limits.max_htlc_minimum_msat)));
2195
+
}
2196
+
if common_fields.max_htlc_value_in_flight_msat < peer_limits.min_max_htlc_value_in_flight_msat {
2197
+
return Err(ChannelError::close(format!("max_htlc_value_in_flight_msat ({}) is less than the user specified limit ({})", common_fields.max_htlc_value_in_flight_msat, peer_limits.min_max_htlc_value_in_flight_msat)));
2198
+
}
2199
+
if channel_reserve_satoshis > peer_limits.max_channel_reserve_satoshis {
2200
+
return Err(ChannelError::close(format!("channel_reserve_satoshis ({}) is higher than the user specified limit ({})", channel_reserve_satoshis, peer_limits.max_channel_reserve_satoshis)));
2201
+
}
2202
+
if common_fields.max_accepted_htlcs < peer_limits.min_max_accepted_htlcs {
2203
+
return Err(ChannelError::close(format!("max_accepted_htlcs ({}) is less than the user specified limit ({})", common_fields.max_accepted_htlcs, peer_limits.min_max_accepted_htlcs)));
2204
+
}
2205
+
if common_fields.dust_limit_satoshis < MIN_CHAN_DUST_LIMIT_SATOSHIS {
2206
+
return Err(ChannelError::close(format!("dust_limit_satoshis ({}) is less than the implementation limit ({})", common_fields.dust_limit_satoshis, MIN_CHAN_DUST_LIMIT_SATOSHIS)));
2207
+
}
2208
+
if common_fields.dust_limit_satoshis > MAX_CHAN_DUST_LIMIT_SATOSHIS {
2209
+
return Err(ChannelError::close(format!("dust_limit_satoshis ({}) is greater than the implementation limit ({})", common_fields.dust_limit_satoshis, MAX_CHAN_DUST_LIMIT_SATOSHIS)));
2210
+
}
2211
+
if common_fields.minimum_depth > peer_limits.max_minimum_depth {
2212
+
return Err(ChannelError::close(format!("We consider the minimum depth to be unreasonably large. Expected minimum: ({}). Actual: ({})", peer_limits.max_minimum_depth, common_fields.minimum_depth)));
2213
+
}
2214
+
2215
+
if let Some(ty) = &common_fields.channel_type {
2216
+
if *ty != self.channel_type {
2217
+
return Err(ChannelError::close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
2218
+
}
2219
+
} else if their_features.supports_channel_type() {
2220
+
// Assume they've accepted the channel type as they said they understand it.
2221
+
} else {
2222
+
let channel_type = ChannelTypeFeatures::from_init(&their_features);
2223
+
if channel_type != ChannelTypeFeatures::only_static_remote_key() {
2224
+
return Err(ChannelError::close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
let peer_limits = if let Some(ref limits) = self.context.inbound_handshake_limits_override { limits } else { default_limits };
7502
-
7503
-
// Check sanity of message fields:
7504
-
if !self.context.is_outbound() {
7505
-
return Err(ChannelError::close("Got an accept_channel message from an inbound peer".to_owned()));
7506
-
}
7507
-
if !matches!(self.context.channel_state, ChannelState::NegotiatingFunding(flags) if flags == NegotiatingFundingFlags::OUR_INIT_SENT) {
7508
-
return Err(ChannelError::close("Got an accept_channel message at a strange time".to_owned()));
7509
-
}
7510
-
if msg.common_fields.dust_limit_satoshis > 21000000 * 100000000 {
7511
-
return Err(ChannelError::close(format!("Peer never wants payout outputs? dust_limit_satoshis was {}", msg.common_fields.dust_limit_satoshis)));
7512
-
}
7513
-
if msg.channel_reserve_satoshis > self.context.channel_value_satoshis {
7514
-
return Err(ChannelError::close(format!("Bogus channel_reserve_satoshis ({}). Must not be greater than ({})", msg.channel_reserve_satoshis, self.context.channel_value_satoshis)));
7515
-
}
7516
-
if msg.common_fields.dust_limit_satoshis > self.context.holder_selected_channel_reserve_satoshis {
7517
-
return Err(ChannelError::close(format!("Dust limit ({}) is bigger than our channel reserve ({})", msg.common_fields.dust_limit_satoshis, self.context.holder_selected_channel_reserve_satoshis)));
7518
-
}
7519
-
if msg.channel_reserve_satoshis > self.context.channel_value_satoshis - self.context.holder_selected_channel_reserve_satoshis {
7520
-
return Err(ChannelError::close(format!("Bogus channel_reserve_satoshis ({}). Must not be greater than channel value minus our reserve ({})",
let full_channel_value_msat = (self.context.channel_value_satoshis - msg.channel_reserve_satoshis) * 1000;
7524
-
if msg.common_fields.htlc_minimum_msat >= full_channel_value_msat {
7525
-
return Err(ChannelError::close(format!("Minimum htlc value ({}) is full channel value ({})", msg.common_fields.htlc_minimum_msat, full_channel_value_msat)));
7526
-
}
7527
-
let max_delay_acceptable = u16::min(peer_limits.their_to_self_delay, MAX_LOCAL_BREAKDOWN_TIMEOUT);
7528
-
if msg.common_fields.to_self_delay > max_delay_acceptable {
7529
-
return Err(ChannelError::close(format!("They wanted our payments to be delayed by a needlessly long period. Upper limit: {}. Actual: {}", max_delay_acceptable, msg.common_fields.to_self_delay)));
7530
-
}
7531
-
if msg.common_fields.max_accepted_htlcs < 1 {
7532
-
return Err(ChannelError::close("0 max_accepted_htlcs makes for a useless channel".to_owned()));
7533
-
}
7534
-
if msg.common_fields.max_accepted_htlcs > MAX_HTLCS {
7535
-
return Err(ChannelError::close(format!("max_accepted_htlcs was {}. It must not be larger than {}", msg.common_fields.max_accepted_htlcs, MAX_HTLCS)));
7536
-
}
7537
-
7538
-
// Now check against optional parameters as set by config...
7539
-
if msg.common_fields.htlc_minimum_msat > peer_limits.max_htlc_minimum_msat {
7540
-
return Err(ChannelError::close(format!("htlc_minimum_msat ({}) is higher than the user specified limit ({})", msg.common_fields.htlc_minimum_msat, peer_limits.max_htlc_minimum_msat)));
7541
-
}
7542
-
if msg.common_fields.max_htlc_value_in_flight_msat < peer_limits.min_max_htlc_value_in_flight_msat {
7543
-
return Err(ChannelError::close(format!("max_htlc_value_in_flight_msat ({}) is less than the user specified limit ({})", msg.common_fields.max_htlc_value_in_flight_msat, peer_limits.min_max_htlc_value_in_flight_msat)));
7544
-
}
7545
-
if msg.channel_reserve_satoshis > peer_limits.max_channel_reserve_satoshis {
7546
-
return Err(ChannelError::close(format!("channel_reserve_satoshis ({}) is higher than the user specified limit ({})", msg.channel_reserve_satoshis, peer_limits.max_channel_reserve_satoshis)));
7547
-
}
7548
-
if msg.common_fields.max_accepted_htlcs < peer_limits.min_max_accepted_htlcs {
7549
-
return Err(ChannelError::close(format!("max_accepted_htlcs ({}) is less than the user specified limit ({})", msg.common_fields.max_accepted_htlcs, peer_limits.min_max_accepted_htlcs)));
7550
-
}
7551
-
if msg.common_fields.dust_limit_satoshis < MIN_CHAN_DUST_LIMIT_SATOSHIS {
7552
-
return Err(ChannelError::close(format!("dust_limit_satoshis ({}) is less than the implementation limit ({})", msg.common_fields.dust_limit_satoshis, MIN_CHAN_DUST_LIMIT_SATOSHIS)));
7553
-
}
7554
-
if msg.common_fields.dust_limit_satoshis > MAX_CHAN_DUST_LIMIT_SATOSHIS {
7555
-
return Err(ChannelError::close(format!("dust_limit_satoshis ({}) is greater than the implementation limit ({})", msg.common_fields.dust_limit_satoshis, MAX_CHAN_DUST_LIMIT_SATOSHIS)));
7556
-
}
7557
-
if msg.common_fields.minimum_depth > peer_limits.max_minimum_depth {
7558
-
return Err(ChannelError::close(format!("We consider the minimum depth to be unreasonably large. Expected minimum: ({}). Actual: ({})", peer_limits.max_minimum_depth, msg.common_fields.minimum_depth)));
7559
-
}
7560
-
7561
-
if let Some(ty) = &msg.common_fields.channel_type {
7562
-
if *ty != self.context.channel_type {
7563
-
return Err(ChannelError::close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
7564
-
}
7565
-
} else if their_features.supports_channel_type() {
7566
-
// Assume they've accepted the channel type as they said they understand it.
7567
-
} else {
7568
-
let channel_type = ChannelTypeFeatures::from_init(&their_features);
7569
-
if channel_type != ChannelTypeFeatures::only_static_remote_key() {
7570
-
return Err(ChannelError::close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
0 commit comments