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
Check pending funding when validating update_add_htlc
If there are any pending splices when an update_add_htlc message is
received, it must be validated against each pending FundingScope.
Otherwise, the HTLC could be invalid once the splice is locked.
if msg.amount_msat > funding.get_value_satoshis() * 1000 {
5769
5760
return Err(ChannelError::close("Remote side tried to send more than the total value of the channel".to_owned()));
5770
5761
}
5771
-
if msg.amount_msat == 0 {
5772
-
return Err(ChannelError::close("Remote side tried to send a 0-msat HTLC".to_owned()));
5773
-
}
5774
-
if msg.amount_msat < self.context.holder_htlc_minimum_msat {
5775
-
return Err(ChannelError::close(format!("Remote side tried to send less than our minimum HTLC value. Lower limit: ({}). Actual: ({})", self.context.holder_htlc_minimum_msat, msg.amount_msat)));
5776
-
}
5777
5762
5778
5763
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
5779
-
let htlc_stats = self.context.get_pending_htlc_stats(&self.funding, None, dust_exposure_limiting_feerate);
5764
+
let htlc_stats = self.context.get_pending_htlc_stats(funding, None, dust_exposure_limiting_feerate);
5780
5765
if htlc_stats.pending_inbound_htlcs + 1 > self.context.holder_max_accepted_htlcs as usize {
5781
5766
return Err(ChannelError::close(format!("Remote tried to push more than our max accepted HTLCs ({})", self.context.holder_max_accepted_htlcs)));
5782
5767
}
@@ -5806,53 +5791,83 @@ impl<SP: Deref> FundedChannel<SP> where
return Err(ChannelError::close("Remote HTLC add would overdraw remaining funds".to_owned()));
5814
5799
}
5815
5800
5816
5801
// Check that the remote can afford to pay for this HTLC on-chain at the current
5817
5802
// feerate_per_kw, while maintaining their channel reserve (as required by the spec).
5818
5803
{
5819
-
let remote_commit_tx_fee_msat = if self.funding.is_outbound() { 0 } else {
5804
+
let remote_commit_tx_fee_msat = if funding.is_outbound() { 0 } else {
5820
5805
let htlc_candidate = HTLCCandidate::new(msg.amount_msat, HTLCInitiator::RemoteOffered);
5821
-
self.context.next_remote_commit_tx_fee_msat(&self.funding, Some(htlc_candidate), None) // Don't include the extra fee spike buffer HTLC in calculations
5806
+
self.context.next_remote_commit_tx_fee_msat(funding, Some(htlc_candidate), None) // Don't include the extra fee spike buffer HTLC in calculations
5822
5807
};
5823
-
let anchor_outputs_value_msat = if !self.funding.is_outbound() && self.funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
5808
+
let anchor_outputs_value_msat = if !funding.is_outbound() && funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
5824
5809
ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000
5825
5810
} else {
5826
5811
0
5827
5812
};
5828
5813
if pending_remote_value_msat.saturating_sub(msg.amount_msat).saturating_sub(anchor_outputs_value_msat) < remote_commit_tx_fee_msat {
5829
5814
return Err(ChannelError::close("Remote HTLC add would not leave enough to pay for fees".to_owned()));
5830
5815
};
5831
-
if pending_remote_value_msat.saturating_sub(msg.amount_msat).saturating_sub(remote_commit_tx_fee_msat).saturating_sub(anchor_outputs_value_msat) < self.funding.holder_selected_channel_reserve_satoshis * 1000 {
5816
+
if pending_remote_value_msat.saturating_sub(msg.amount_msat).saturating_sub(remote_commit_tx_fee_msat).saturating_sub(anchor_outputs_value_msat) < funding.holder_selected_channel_reserve_satoshis * 1000 {
5832
5817
return Err(ChannelError::close("Remote HTLC add would put them under remote reserve value".to_owned()));
5833
5818
}
5834
5819
}
5835
5820
5836
-
let anchor_outputs_value_msat = if self.funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
5821
+
let anchor_outputs_value_msat = if funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
5837
5822
ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000
5838
5823
} else {
5839
5824
0
5840
5825
};
5841
-
if self.funding.is_outbound() {
5826
+
if funding.is_outbound() {
5842
5827
// Check that they won't violate our local required channel reserve by adding this HTLC.
5843
5828
let htlc_candidate = HTLCCandidate::new(msg.amount_msat, HTLCInitiator::RemoteOffered);
5844
-
let local_commit_tx_fee_msat = self.context.next_local_commit_tx_fee_msat(&self.funding, htlc_candidate, None);
) -> Result<(), ChannelError> where F::Target: FeeEstimator {
5841
+
if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
5842
+
return Err(ChannelError::WarnAndDisconnect("Got add HTLC message while quiescent".to_owned()));
5843
+
}
5844
+
if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
5845
+
return Err(ChannelError::close("Got add HTLC message when channel was not in an operational state".to_owned()));
5846
+
}
5847
+
// If the remote has sent a shutdown prior to adding this HTLC, then they are in violation of the spec.
5848
+
if self.context.channel_state.is_remote_shutdown_sent() {
5849
+
return Err(ChannelError::close("Got add HTLC message when channel was not in an operational state".to_owned()));
5850
+
}
5851
+
if self.context.channel_state.is_peer_disconnected() {
5852
+
return Err(ChannelError::close("Peer sent update_add_htlc when we needed a channel_reestablish".to_owned()));
5853
+
}
5854
+
if msg.amount_msat == 0 {
5855
+
return Err(ChannelError::close("Remote side tried to send a 0-msat HTLC".to_owned()));
5856
+
}
5857
+
if msg.amount_msat < self.context.holder_htlc_minimum_msat {
5858
+
return Err(ChannelError::close(format!("Remote side tried to send less than our minimum HTLC value. Lower limit: ({}). Actual: ({})", self.context.holder_htlc_minimum_msat, msg.amount_msat)));
5859
+
}
5849
5860
if self.context.next_counterparty_htlc_id != msg.htlc_id {
5850
5861
return Err(ChannelError::close(format!("Remote skipped HTLC ID (skipped ID: {})", self.context.next_counterparty_htlc_id)));
5851
5862
}
5852
5863
if msg.cltv_expiry >= 500000000 {
5853
5864
return Err(ChannelError::close("Remote provided CLTV expiry in seconds instead of block height".to_owned()));
0 commit comments