@@ -1790,15 +1790,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1790
1790
/// [`msgs::RevokeAndACK`] message from the counterparty.
1791
1791
sent_message_awaiting_response: Option<usize>,
1792
1792
1793
- #[cfg(any(test, fuzzing))]
1794
- // When we receive an HTLC fulfill on an outbound path, we may immediately fulfill the
1795
- // corresponding HTLC on the inbound path. If, then, the outbound path channel is
1796
- // disconnected and reconnected (before we've exchange commitment_signed and revoke_and_ack
1797
- // messages), they may re-broadcast their update_fulfill_htlc, causing a duplicate claim. This
1798
- // is fine, but as a sanity check in our failure to generate the second claim, we check here
1799
- // that the original was a claim, and that we aren't now trying to fulfill a failed HTLC.
1800
- historical_inbound_htlc_fulfills: HashSet<u64>,
1801
-
1802
1793
/// This channel's type, as negotiated during channel open
1803
1794
channel_type: ChannelTypeFeatures,
1804
1795
@@ -2518,9 +2509,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2518
2509
funding_tx_broadcast_safe_event_emitted: false,
2519
2510
channel_ready_event_emitted: false,
2520
2511
2521
- #[cfg(any(test, fuzzing))]
2522
- historical_inbound_htlc_fulfills: new_hash_set(),
2523
-
2524
2512
channel_type,
2525
2513
channel_keys_id,
2526
2514
@@ -2751,9 +2739,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2751
2739
funding_tx_broadcast_safe_event_emitted: false,
2752
2740
channel_ready_event_emitted: false,
2753
2741
2754
- #[cfg(any(test, fuzzing))]
2755
- historical_inbound_htlc_fulfills: new_hash_set(),
2756
-
2757
2742
channel_type,
2758
2743
channel_keys_id,
2759
2744
@@ -4784,10 +4769,6 @@ impl<SP: Deref> FundedChannel<SP> where
4784
4769
}
4785
4770
}
4786
4771
if pending_idx == core::usize::MAX {
4787
- #[cfg(any(test, fuzzing))]
4788
- // If we failed to find an HTLC to fulfill, make sure it was previously fulfilled and
4789
- // this is simply a duplicate claim, not previously failed and we lost funds.
4790
- debug_assert!(self.context.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
4791
4772
return UpdateFulfillFetch::DuplicateClaim {};
4792
4773
}
4793
4774
@@ -4817,8 +4798,6 @@ impl<SP: Deref> FundedChannel<SP> where
4817
4798
if htlc_id_arg == htlc_id {
4818
4799
// Make sure we don't leave latest_monitor_update_id incremented here:
4819
4800
self.context.latest_monitor_update_id -= 1;
4820
- #[cfg(any(test, fuzzing))]
4821
- debug_assert!(self.context.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
4822
4801
return UpdateFulfillFetch::DuplicateClaim {};
4823
4802
}
4824
4803
},
@@ -4840,12 +4819,8 @@ impl<SP: Deref> FundedChannel<SP> where
4840
4819
self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
4841
4820
payment_preimage: payment_preimage_arg, htlc_id: htlc_id_arg,
4842
4821
});
4843
- #[cfg(any(test, fuzzing))]
4844
- self.context.historical_inbound_htlc_fulfills.insert(htlc_id_arg);
4845
4822
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: None };
4846
4823
}
4847
- #[cfg(any(test, fuzzing))]
4848
- self.context.historical_inbound_htlc_fulfills.insert(htlc_id_arg);
4849
4824
4850
4825
{
4851
4826
let htlc = &mut self.context.pending_inbound_htlcs[pending_idx];
@@ -4910,14 +4885,8 @@ impl<SP: Deref> FundedChannel<SP> where
4910
4885
}
4911
4886
}
4912
4887
4913
- /// We can only have one resolution per HTLC. In some cases around reconnect, we may fulfill
4914
- /// an HTLC more than once or fulfill once and then attempt to fail after reconnect. We cannot,
4915
- /// however, fail more than once as we wait for an upstream failure to be irrevocably committed
4916
- /// before we fail backwards.
4917
- ///
4918
- /// If we do fail twice, we `debug_assert!(false)` and return `Ok(None)`. Thus, this will always
4919
- /// return `Ok(_)` if preconditions are met. In any case, `Err`s will only be
4920
- /// [`ChannelError::Ignore`].
4888
+ /// Returns `Err` (always with [`ChannelError::Ignore`]) if the HTLC could not be failed (e.g.
4889
+ /// if it was already resolved). Otherwise returns `Ok`.
4921
4890
pub fn queue_fail_htlc<L: Deref>(&mut self, htlc_id_arg: u64, err_packet: msgs::OnionErrorPacket, logger: &L)
4922
4891
-> Result<(), ChannelError> where L::Target: Logger {
4923
4892
self.fail_htlc(htlc_id_arg, err_packet, true, logger)
@@ -4935,14 +4904,8 @@ impl<SP: Deref> FundedChannel<SP> where
4935
4904
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
4936
4905
}
4937
4906
4938
- /// We can only have one resolution per HTLC. In some cases around reconnect, we may fulfill
4939
- /// an HTLC more than once or fulfill once and then attempt to fail after reconnect. We cannot,
4940
- /// however, fail more than once as we wait for an upstream failure to be irrevocably committed
4941
- /// before we fail backwards.
4942
- ///
4943
- /// If we do fail twice, we `debug_assert!(false)` and return `Ok(None)`. Thus, this will always
4944
- /// return `Ok(_)` if preconditions are met. In any case, `Err`s will only be
4945
- /// [`ChannelError::Ignore`].
4907
+ /// Returns `Err` (always with [`ChannelError::Ignore`]) if the HTLC could not be failed (e.g.
4908
+ /// if it was already resolved). Otherwise returns `Ok`.
4946
4909
fn fail_htlc<L: Deref, E: FailHTLCContents + Clone>(
4947
4910
&mut self, htlc_id_arg: u64, err_contents: E, mut force_holding_cell: bool,
4948
4911
logger: &L
@@ -4960,12 +4923,8 @@ impl<SP: Deref> FundedChannel<SP> where
4960
4923
if htlc.htlc_id == htlc_id_arg {
4961
4924
match htlc.state {
4962
4925
InboundHTLCState::Committed => {},
4963
- InboundHTLCState::LocalRemoved(ref reason) => {
4964
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
4965
- } else {
4966
- debug_assert!(false, "Tried to fail an HTLC that was already failed");
4967
- }
4968
- return Ok(None);
4926
+ InboundHTLCState::LocalRemoved(_) => {
4927
+ return Err(ChannelError::Ignore(format!("HTLC {} was already resolved", htlc.htlc_id)));
4969
4928
},
4970
4929
_ => {
4971
4930
debug_assert!(false, "Have an inbound HTLC we tried to claim before it was fully committed to");
@@ -4976,11 +4935,7 @@ impl<SP: Deref> FundedChannel<SP> where
4976
4935
}
4977
4936
}
4978
4937
if pending_idx == core::usize::MAX {
4979
- #[cfg(any(test, fuzzing))]
4980
- // If we failed to find an HTLC to fail, make sure it was previously fulfilled and this
4981
- // is simply a duplicate fail, not previously failed and we failed-back too early.
4982
- debug_assert!(self.context.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
4983
- return Ok(None);
4938
+ return Err(ChannelError::Ignore(format!("Unable to find a pending HTLC which matched the given HTLC ID ({})", htlc_id_arg)));
4984
4939
}
4985
4940
4986
4941
if !self.context.channel_state.can_generate_new_commitment() {
@@ -4994,17 +4949,14 @@ impl<SP: Deref> FundedChannel<SP> where
4994
4949
match pending_update {
4995
4950
&HTLCUpdateAwaitingACK::ClaimHTLC { htlc_id, .. } => {
4996
4951
if htlc_id_arg == htlc_id {
4997
- #[cfg(any(test, fuzzing))]
4998
- debug_assert!(self.context.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
4999
- return Ok(None);
4952
+ return Err(ChannelError::Ignore(format!("HTLC {} was already claimed!", htlc_id)));
5000
4953
}
5001
4954
},
5002
4955
&HTLCUpdateAwaitingACK::FailHTLC { htlc_id, .. } |
5003
4956
&HTLCUpdateAwaitingACK::FailMalformedHTLC { htlc_id, .. } =>
5004
4957
{
5005
4958
if htlc_id_arg == htlc_id {
5006
- debug_assert!(false, "Tried to fail an HTLC that was already failed");
5007
- return Err(ChannelError::Ignore("Unable to find a pending HTLC which matched the given HTLC ID".to_owned()));
4959
+ return Err(ChannelError::Ignore(format!("HTLC {} was already pending failure", htlc_id)));
5008
4960
}
5009
4961
},
5010
4962
_ => {}
@@ -9795,13 +9747,6 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
9795
9747
9796
9748
self.context.channel_update_status.write(writer)?;
9797
9749
9798
- #[cfg(any(test, fuzzing))]
9799
- (self.context.historical_inbound_htlc_fulfills.len() as u64).write(writer)?;
9800
- #[cfg(any(test, fuzzing))]
9801
- for htlc in self.context.historical_inbound_htlc_fulfills.iter() {
9802
- htlc.write(writer)?;
9803
- }
9804
-
9805
9750
// If the channel type is something other than only-static-remote-key, then we need to have
9806
9751
// older clients fail to deserialize this channel at all. If the type is
9807
9752
// only-static-remote-key, we simply consider it "default" and don't write the channel type
@@ -10135,16 +10080,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10135
10080
10136
10081
let channel_update_status = Readable::read(reader)?;
10137
10082
10138
- #[cfg(any(test, fuzzing))]
10139
- let mut historical_inbound_htlc_fulfills = new_hash_set();
10140
- #[cfg(any(test, fuzzing))]
10141
- {
10142
- let htlc_fulfills_len: u64 = Readable::read(reader)?;
10143
- for _ in 0..htlc_fulfills_len {
10144
- assert!(historical_inbound_htlc_fulfills.insert(Readable::read(reader)?));
10145
- }
10146
- }
10147
-
10148
10083
let pending_update_fee = if let Some(feerate) = pending_update_fee_value {
10149
10084
Some((feerate, if channel_parameters.is_outbound_from_holder {
10150
10085
FeeUpdateState::Outbound
@@ -10485,9 +10420,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10485
10420
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
10486
10421
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
10487
10422
10488
- #[cfg(any(test, fuzzing))]
10489
- historical_inbound_htlc_fulfills,
10490
-
10491
10423
channel_type: channel_type.unwrap(),
10492
10424
channel_keys_id,
10493
10425
0 commit comments