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) = context.inbound_handshake_limits_override { limits } else { default_limits };
1125
+
1126
+
// Check sanity of message fields:
1127
+
if context.channel_state != ChannelState::OurInitSent as u32 {
1128
+
return Err(ChannelError::Close("Got an accept_channel message at a strange time".to_owned()));
1129
+
}
1130
+
if msg_dust_limit_satoshis > 21000000 * 100000000 {
1131
+
return Err(ChannelError::Close(format!("Peer never wants payout outputs? dust_limit_satoshis was {}", msg_dust_limit_satoshis)));
1132
+
}
1133
+
if msg_channel_reserve_satoshis > context.channel_value_satoshis {
1134
+
return Err(ChannelError::Close(format!("Bogus channel_reserve_satoshis ({}). Must not be greater than ({})", msg_channel_reserve_satoshis, context.channel_value_satoshis)));
1135
+
}
1136
+
if msg_dust_limit_satoshis > context.holder_selected_channel_reserve_satoshis {
1137
+
return Err(ChannelError::Close(format!("Dust limit ({}) is bigger than our channel reserve ({})", msg_dust_limit_satoshis, context.holder_selected_channel_reserve_satoshis)));
1138
+
}
1139
+
if msg_channel_reserve_satoshis > context.channel_value_satoshis - context.holder_selected_channel_reserve_satoshis {
1140
+
return Err(ChannelError::Close(format!("Bogus channel_reserve_satoshis ({}). Must not be greater than channel value minus our reserve ({})",
let full_channel_value_msat = (context.channel_value_satoshis - msg_channel_reserve_satoshis) * 1000;
1144
+
if msg_htlc_minimum_msat >= full_channel_value_msat {
1145
+
return Err(ChannelError::Close(format!("Minimum htlc value ({}) is full channel value ({})", msg_htlc_minimum_msat, full_channel_value_msat)));
1146
+
}
1147
+
let max_delay_acceptable = u16::min(peer_limits.their_to_self_delay, MAX_LOCAL_BREAKDOWN_TIMEOUT);
1148
+
if msg_to_self_delay > max_delay_acceptable {
1149
+
return Err(ChannelError::Close(format!("They wanted our payments to be delayed by a needlessly long period. Upper limit: {}. Actual: {}", max_delay_acceptable, msg_to_self_delay)));
1150
+
}
1151
+
if msg_max_accepted_htlcs < 1 {
1152
+
return Err(ChannelError::Close("0 max_accepted_htlcs makes for a useless channel".to_owned()));
1153
+
}
1154
+
if msg_max_accepted_htlcs > MAX_HTLCS {
1155
+
return Err(ChannelError::Close(format!("max_accepted_htlcs was {}. It must not be larger than {}", msg_max_accepted_htlcs, MAX_HTLCS)));
1156
+
}
1157
+
1158
+
// Now check against optional parameters as set by config...
1159
+
if msg_htlc_minimum_msat > peer_limits.max_htlc_minimum_msat {
1160
+
return Err(ChannelError::Close(format!("htlc_minimum_msat ({}) is higher than the user specified limit ({})", msg_htlc_minimum_msat, peer_limits.max_htlc_minimum_msat)));
1161
+
}
1162
+
if msg_max_htlc_value_in_flight_msat < peer_limits.min_max_htlc_value_in_flight_msat {
1163
+
return Err(ChannelError::Close(format!("max_htlc_value_in_flight_msat ({}) is less than the user specified limit ({})", msg_max_htlc_value_in_flight_msat, peer_limits.min_max_htlc_value_in_flight_msat)));
1164
+
}
1165
+
if msg_channel_reserve_satoshis > peer_limits.max_channel_reserve_satoshis {
1166
+
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)));
1167
+
}
1168
+
if msg_max_accepted_htlcs < peer_limits.min_max_accepted_htlcs {
1169
+
return Err(ChannelError::Close(format!("max_accepted_htlcs ({}) is less than the user specified limit ({})", msg_max_accepted_htlcs, peer_limits.min_max_accepted_htlcs)));
1170
+
}
1171
+
if msg_dust_limit_satoshis < MIN_CHAN_DUST_LIMIT_SATOSHIS {
1172
+
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is less than the implementation limit ({})", msg_dust_limit_satoshis, MIN_CHAN_DUST_LIMIT_SATOSHIS)));
1173
+
}
1174
+
if msg_dust_limit_satoshis > MAX_CHAN_DUST_LIMIT_SATOSHIS {
1175
+
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is greater than the implementation limit ({})", msg_dust_limit_satoshis, MAX_CHAN_DUST_LIMIT_SATOSHIS)));
1176
+
}
1177
+
if msg_minimum_depth > peer_limits.max_minimum_depth {
1178
+
return Err(ChannelError::Close(format!("We consider the minimum depth to be unreasonably large. Expected minimum: ({}). Actual: ({})", peer_limits.max_minimum_depth, msg_minimum_depth)));
1179
+
}
1180
+
1181
+
if let Some(ty) = &msg_channel_type {
1182
+
if *ty != context.channel_type {
1183
+
return Err(ChannelError::Close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
1184
+
}
1185
+
} else if their_features.supports_channel_type() {
1186
+
// Assume they've accepted the channel type as they said they understand it.
1187
+
} else {
1188
+
let channel_type = ChannelTypeFeatures::from_init(&their_features);
1189
+
if channel_type != ChannelTypeFeatures::only_static_remote_key() {
1190
+
return Err(ChannelError::Close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
1191
+
}
1192
+
context.channel_type = channel_type;
1193
+
}
1194
+
1195
+
let counterparty_shutdown_scriptpubkey = if their_features.supports_upfront_shutdown_script() {
1196
+
match &msg_shutdown_scriptpubkey {
1197
+
&Some(ref script) => {
1198
+
// Peer is signaling upfront_shutdown and has opt-out with a 0-length script. We don't enforce anything
1199
+
if script.len() == 0 {
1200
+
None
1201
+
} else {
1202
+
if !script::is_bolt2_compliant(&script, their_features) {
1203
+
return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: {}", script)));
1204
+
}
1205
+
Some(script.clone())
1206
+
}
1207
+
},
1208
+
// Peer is signaling upfront shutdown but don't opt-out with correct mechanism (a.k.a 0-length script). Peer looks buggy, we fail the channel
1209
+
&None => {
1210
+
return Err(ChannelError::Close("Peer is signaling upfront_shutdown but we don't get any script. Use 0-length script to opt-out".to_owned()));
let peer_limits = if let Some(ref limits) = self.context.inbound_handshake_limits_override { limits } else { default_limits };
5812
-
5813
-
// Check sanity of message fields:
5814
-
if !self.is_outbound() {
5815
-
return Err(ChannelError::Close("Got an accept_channel message from an inbound peer".to_owned()));
5816
-
}
5817
-
if self.context.channel_state != ChannelState::OurInitSent as u32 {
5818
-
return Err(ChannelError::Close("Got an accept_channel message at a strange time".to_owned()));
5819
-
}
5820
-
if msg.dust_limit_satoshis > 21000000 * 100000000 {
5821
-
return Err(ChannelError::Close(format!("Peer never wants payout outputs? dust_limit_satoshis was {}", msg.dust_limit_satoshis)));
5822
-
}
5823
-
if msg.channel_reserve_satoshis > self.context.channel_value_satoshis {
5824
-
return Err(ChannelError::Close(format!("Bogus channel_reserve_satoshis ({}). Must not be greater than ({})", msg.channel_reserve_satoshis, self.context.channel_value_satoshis)));
5825
-
}
5826
-
if msg.dust_limit_satoshis > self.context.holder_selected_channel_reserve_satoshis {
5827
-
return Err(ChannelError::Close(format!("Dust limit ({}) is bigger than our channel reserve ({})", msg.dust_limit_satoshis, self.context.holder_selected_channel_reserve_satoshis)));
5828
-
}
5829
-
if msg.channel_reserve_satoshis > self.context.channel_value_satoshis - self.context.holder_selected_channel_reserve_satoshis {
5830
-
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;
5834
-
if msg.htlc_minimum_msat >= full_channel_value_msat {
5835
-
return Err(ChannelError::Close(format!("Minimum htlc value ({}) is full channel value ({})", msg.htlc_minimum_msat, full_channel_value_msat)));
5836
-
}
5837
-
let max_delay_acceptable = u16::min(peer_limits.their_to_self_delay, MAX_LOCAL_BREAKDOWN_TIMEOUT);
5838
-
if msg.to_self_delay > max_delay_acceptable {
5839
-
return Err(ChannelError::Close(format!("They wanted our payments to be delayed by a needlessly long period. Upper limit: {}. Actual: {}", max_delay_acceptable, msg.to_self_delay)));
5840
-
}
5841
-
if msg.max_accepted_htlcs < 1 {
5842
-
return Err(ChannelError::Close("0 max_accepted_htlcs makes for a useless channel".to_owned()));
5843
-
}
5844
-
if msg.max_accepted_htlcs > MAX_HTLCS {
5845
-
return Err(ChannelError::Close(format!("max_accepted_htlcs was {}. It must not be larger than {}", msg.max_accepted_htlcs, MAX_HTLCS)));
5846
-
}
5847
-
5848
-
// Now check against optional parameters as set by config...
5849
-
if msg.htlc_minimum_msat > peer_limits.max_htlc_minimum_msat {
5850
-
return Err(ChannelError::Close(format!("htlc_minimum_msat ({}) is higher than the user specified limit ({})", msg.htlc_minimum_msat, peer_limits.max_htlc_minimum_msat)));
5851
-
}
5852
-
if msg.max_htlc_value_in_flight_msat < peer_limits.min_max_htlc_value_in_flight_msat {
5853
-
return Err(ChannelError::Close(format!("max_htlc_value_in_flight_msat ({}) is less than the user specified limit ({})", msg.max_htlc_value_in_flight_msat, peer_limits.min_max_htlc_value_in_flight_msat)));
5854
-
}
5855
-
if msg.channel_reserve_satoshis > peer_limits.max_channel_reserve_satoshis {
5856
-
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)));
5857
-
}
5858
-
if msg.max_accepted_htlcs < peer_limits.min_max_accepted_htlcs {
5859
-
return Err(ChannelError::Close(format!("max_accepted_htlcs ({}) is less than the user specified limit ({})", msg.max_accepted_htlcs, peer_limits.min_max_accepted_htlcs)));
5860
-
}
5861
-
if msg.dust_limit_satoshis < MIN_CHAN_DUST_LIMIT_SATOSHIS {
5862
-
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is less than the implementation limit ({})", msg.dust_limit_satoshis, MIN_CHAN_DUST_LIMIT_SATOSHIS)));
5863
-
}
5864
-
if msg.dust_limit_satoshis > MAX_CHAN_DUST_LIMIT_SATOSHIS {
5865
-
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is greater than the implementation limit ({})", msg.dust_limit_satoshis, MAX_CHAN_DUST_LIMIT_SATOSHIS)));
5866
-
}
5867
-
if msg.minimum_depth > peer_limits.max_minimum_depth {
5868
-
return Err(ChannelError::Close(format!("We consider the minimum depth to be unreasonably large. Expected minimum: ({}). Actual: ({})", peer_limits.max_minimum_depth, msg.minimum_depth)));
5869
-
}
5870
-
5871
-
if let Some(ty) = &msg.channel_type {
5872
-
if *ty != self.context.channel_type {
5873
-
return Err(ChannelError::Close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
5874
-
}
5875
-
} else if their_features.supports_channel_type() {
5876
-
// Assume they've accepted the channel type as they said they understand it.
5877
-
} else {
5878
-
let channel_type = ChannelTypeFeatures::from_init(&their_features);
5879
-
if channel_type != ChannelTypeFeatures::only_static_remote_key() {
5880
-
return Err(ChannelError::Close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
5881
-
}
5882
-
self.context.channel_type = channel_type;
5883
-
}
5884
-
5885
-
let counterparty_shutdown_scriptpubkey = if their_features.supports_upfront_shutdown_script() {
5886
-
match &msg.shutdown_scriptpubkey {
5887
-
&Some(ref script) => {
5888
-
// Peer is signaling upfront_shutdown and has opt-out with a 0-length script. We don't enforce anything
5889
-
if script.len() == 0 {
5890
-
None
5891
-
} else {
5892
-
if !script::is_bolt2_compliant(&script, their_features) {
5893
-
return Err(ChannelError::Close(format!("Peer is signaling upfront_shutdown but has provided an unacceptable scriptpubkey format: {}", script)));
5894
-
}
5895
-
Some(script.clone())
5896
-
}
5897
-
},
5898
-
// Peer is signaling upfront shutdown but don't opt-out with correct mechanism (a.k.a 0-length script). Peer looks buggy, we fail the channel
5899
-
&None => {
5900
-
return Err(ChannelError::Close("Peer is signaling upfront_shutdown but we don't get any script. Use 0-length script to opt-out".to_owned()));
0 commit comments