@@ -1693,15 +1693,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1693
1693
/// [`msgs::RevokeAndACK`] message from the counterparty.
1694
1694
sent_message_awaiting_response: Option<usize>,
1695
1695
1696
- #[cfg(any(test, fuzzing))]
1697
- // When we receive an HTLC fulfill on an outbound path, we may immediately fulfill the
1698
- // corresponding HTLC on the inbound path. If, then, the outbound path channel is
1699
- // disconnected and reconnected (before we've exchange commitment_signed and revoke_and_ack
1700
- // messages), they may re-broadcast their update_fulfill_htlc, causing a duplicate claim. This
1701
- // is fine, but as a sanity check in our failure to generate the second claim, we check here
1702
- // that the original was a claim, and that we aren't now trying to fulfill a failed HTLC.
1703
- historical_inbound_htlc_fulfills: HashSet<u64>,
1704
-
1705
1696
/// This channel's type, as negotiated during channel open
1706
1697
channel_type: ChannelTypeFeatures,
1707
1698
@@ -2403,9 +2394,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2403
2394
funding_tx_broadcast_safe_event_emitted: false,
2404
2395
channel_ready_event_emitted: false,
2405
2396
2406
- #[cfg(any(test, fuzzing))]
2407
- historical_inbound_htlc_fulfills: new_hash_set(),
2408
-
2409
2397
channel_type,
2410
2398
channel_keys_id,
2411
2399
@@ -2636,9 +2624,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2636
2624
funding_tx_broadcast_safe_event_emitted: false,
2637
2625
channel_ready_event_emitted: false,
2638
2626
2639
- #[cfg(any(test, fuzzing))]
2640
- historical_inbound_htlc_fulfills: new_hash_set(),
2641
-
2642
2627
channel_type,
2643
2628
channel_keys_id,
2644
2629
@@ -4665,10 +4650,6 @@ impl<SP: Deref> FundedChannel<SP> where
4665
4650
}
4666
4651
}
4667
4652
if pending_idx == core::usize::MAX {
4668
- #[cfg(any(test, fuzzing))]
4669
- // If we failed to find an HTLC to fulfill, make sure it was previously fulfilled and
4670
- // this is simply a duplicate claim, not previously failed and we lost funds.
4671
- debug_assert!(self.context.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
4672
4653
return UpdateFulfillFetch::DuplicateClaim {};
4673
4654
}
4674
4655
@@ -4698,8 +4679,6 @@ impl<SP: Deref> FundedChannel<SP> where
4698
4679
if htlc_id_arg == htlc_id {
4699
4680
// Make sure we don't leave latest_monitor_update_id incremented here:
4700
4681
self.context.latest_monitor_update_id -= 1;
4701
- #[cfg(any(test, fuzzing))]
4702
- debug_assert!(self.context.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
4703
4682
return UpdateFulfillFetch::DuplicateClaim {};
4704
4683
}
4705
4684
},
@@ -4721,12 +4700,8 @@ impl<SP: Deref> FundedChannel<SP> where
4721
4700
self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
4722
4701
payment_preimage: payment_preimage_arg, htlc_id: htlc_id_arg,
4723
4702
});
4724
- #[cfg(any(test, fuzzing))]
4725
- self.context.historical_inbound_htlc_fulfills.insert(htlc_id_arg);
4726
4703
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: None };
4727
4704
}
4728
- #[cfg(any(test, fuzzing))]
4729
- self.context.historical_inbound_htlc_fulfills.insert(htlc_id_arg);
4730
4705
4731
4706
{
4732
4707
let htlc = &mut self.context.pending_inbound_htlcs[pending_idx];
@@ -4791,14 +4766,8 @@ impl<SP: Deref> FundedChannel<SP> where
4791
4766
}
4792
4767
}
4793
4768
4794
- /// We can only have one resolution per HTLC. In some cases around reconnect, we may fulfill
4795
- /// an HTLC more than once or fulfill once and then attempt to fail after reconnect. We cannot,
4796
- /// however, fail more than once as we wait for an upstream failure to be irrevocably committed
4797
- /// before we fail backwards.
4798
- ///
4799
- /// If we do fail twice, we `debug_assert!(false)` and return `Ok(None)`. Thus, this will always
4800
- /// return `Ok(_)` if preconditions are met. In any case, `Err`s will only be
4801
- /// [`ChannelError::Ignore`].
4769
+ /// Returns `Err` (always with [`ChannelError::Ignore`]) if the HTLC could not be failed (e.g.
4770
+ /// if it was already resolved). Otherwise returns `Ok`.
4802
4771
pub fn queue_fail_htlc<L: Deref>(&mut self, htlc_id_arg: u64, err_packet: msgs::OnionErrorPacket, logger: &L)
4803
4772
-> Result<(), ChannelError> where L::Target: Logger {
4804
4773
self.fail_htlc(htlc_id_arg, err_packet, true, logger)
@@ -4816,14 +4785,8 @@ impl<SP: Deref> FundedChannel<SP> where
4816
4785
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
4817
4786
}
4818
4787
4819
- /// We can only have one resolution per HTLC. In some cases around reconnect, we may fulfill
4820
- /// an HTLC more than once or fulfill once and then attempt to fail after reconnect. We cannot,
4821
- /// however, fail more than once as we wait for an upstream failure to be irrevocably committed
4822
- /// before we fail backwards.
4823
- ///
4824
- /// If we do fail twice, we `debug_assert!(false)` and return `Ok(None)`. Thus, this will always
4825
- /// return `Ok(_)` if preconditions are met. In any case, `Err`s will only be
4826
- /// [`ChannelError::Ignore`].
4788
+ /// Returns `Err` (always with [`ChannelError::Ignore`]) if the HTLC could not be failed (e.g.
4789
+ /// if it was already resolved). Otherwise returns `Ok`.
4827
4790
fn fail_htlc<L: Deref, E: FailHTLCContents + Clone>(
4828
4791
&mut self, htlc_id_arg: u64, err_contents: E, mut force_holding_cell: bool,
4829
4792
logger: &L
@@ -4841,12 +4804,8 @@ impl<SP: Deref> FundedChannel<SP> where
4841
4804
if htlc.htlc_id == htlc_id_arg {
4842
4805
match htlc.state {
4843
4806
InboundHTLCState::Committed => {},
4844
- InboundHTLCState::LocalRemoved(ref reason) => {
4845
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
4846
- } else {
4847
- debug_assert!(false, "Tried to fail an HTLC that was already failed");
4848
- }
4849
- return Ok(None);
4807
+ InboundHTLCState::LocalRemoved(_) => {
4808
+ return Err(ChannelError::Ignore(format!("HTLC {} was already resolved", htlc.htlc_id)));
4850
4809
},
4851
4810
_ => {
4852
4811
debug_assert!(false, "Have an inbound HTLC we tried to claim before it was fully committed to");
@@ -4857,11 +4816,7 @@ impl<SP: Deref> FundedChannel<SP> where
4857
4816
}
4858
4817
}
4859
4818
if pending_idx == core::usize::MAX {
4860
- #[cfg(any(test, fuzzing))]
4861
- // If we failed to find an HTLC to fail, make sure it was previously fulfilled and this
4862
- // is simply a duplicate fail, not previously failed and we failed-back too early.
4863
- debug_assert!(self.context.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
4864
- return Ok(None);
4819
+ return Err(ChannelError::Ignore(format!("Unable to find a pending HTLC which matched the given HTLC ID ({})", htlc_id_arg)));
4865
4820
}
4866
4821
4867
4822
if !self.context.channel_state.can_generate_new_commitment() {
@@ -4875,17 +4830,14 @@ impl<SP: Deref> FundedChannel<SP> where
4875
4830
match pending_update {
4876
4831
&HTLCUpdateAwaitingACK::ClaimHTLC { htlc_id, .. } => {
4877
4832
if htlc_id_arg == htlc_id {
4878
- #[cfg(any(test, fuzzing))]
4879
- debug_assert!(self.context.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
4880
- return Ok(None);
4833
+ return Err(ChannelError::Ignore(format!("HTLC {} was already claimed!", htlc_id)));
4881
4834
}
4882
4835
},
4883
4836
&HTLCUpdateAwaitingACK::FailHTLC { htlc_id, .. } |
4884
4837
&HTLCUpdateAwaitingACK::FailMalformedHTLC { htlc_id, .. } =>
4885
4838
{
4886
4839
if htlc_id_arg == htlc_id {
4887
- debug_assert!(false, "Tried to fail an HTLC that was already failed");
4888
- return Err(ChannelError::Ignore("Unable to find a pending HTLC which matched the given HTLC ID".to_owned()));
4840
+ return Err(ChannelError::Ignore(format!("HTLC {} was already pending failure", htlc_id)));
4889
4841
}
4890
4842
},
4891
4843
_ => {}
@@ -9718,13 +9670,6 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
9718
9670
9719
9671
self.context.channel_update_status.write(writer)?;
9720
9672
9721
- #[cfg(any(test, fuzzing))]
9722
- (self.context.historical_inbound_htlc_fulfills.len() as u64).write(writer)?;
9723
- #[cfg(any(test, fuzzing))]
9724
- for htlc in self.context.historical_inbound_htlc_fulfills.iter() {
9725
- htlc.write(writer)?;
9726
- }
9727
-
9728
9673
// If the channel type is something other than only-static-remote-key, then we need to have
9729
9674
// older clients fail to deserialize this channel at all. If the type is
9730
9675
// only-static-remote-key, we simply consider it "default" and don't write the channel type
@@ -10058,16 +10003,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10058
10003
10059
10004
let channel_update_status = Readable::read(reader)?;
10060
10005
10061
- #[cfg(any(test, fuzzing))]
10062
- let mut historical_inbound_htlc_fulfills = new_hash_set();
10063
- #[cfg(any(test, fuzzing))]
10064
- {
10065
- let htlc_fulfills_len: u64 = Readable::read(reader)?;
10066
- for _ in 0..htlc_fulfills_len {
10067
- assert!(historical_inbound_htlc_fulfills.insert(Readable::read(reader)?));
10068
- }
10069
- }
10070
-
10071
10006
let pending_update_fee = if let Some(feerate) = pending_update_fee_value {
10072
10007
Some((feerate, if channel_parameters.is_outbound_from_holder {
10073
10008
FeeUpdateState::Outbound
@@ -10408,9 +10343,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10408
10343
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
10409
10344
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
10410
10345
10411
- #[cfg(any(test, fuzzing))]
10412
- historical_inbound_htlc_fulfills,
10413
-
10414
10346
channel_type: channel_type.unwrap(),
10415
10347
channel_keys_id,
10416
10348
0 commit comments