@@ -1453,15 +1453,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1453
1453
/// [`msgs::RevokeAndACK`] message from the counterparty.
1454
1454
sent_message_awaiting_response: Option<usize>,
1455
1455
1456
- #[cfg(any(test, fuzzing))]
1457
- // When we receive an HTLC fulfill on an outbound path, we may immediately fulfill the
1458
- // corresponding HTLC on the inbound path. If, then, the outbound path channel is
1459
- // disconnected and reconnected (before we've exchange commitment_signed and revoke_and_ack
1460
- // messages), they may re-broadcast their update_fulfill_htlc, causing a duplicate claim. This
1461
- // is fine, but as a sanity check in our failure to generate the second claim, we check here
1462
- // that the original was a claim, and that we aren't now trying to fulfill a failed HTLC.
1463
- historical_inbound_htlc_fulfills: HashSet<u64>,
1464
-
1465
1456
/// This channel's type, as negotiated during channel open
1466
1457
channel_type: ChannelTypeFeatures,
1467
1458
@@ -2210,9 +2201,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2210
2201
funding_tx_broadcast_safe_event_emitted: false,
2211
2202
channel_ready_event_emitted: false,
2212
2203
2213
- #[cfg(any(test, fuzzing))]
2214
- historical_inbound_htlc_fulfills: new_hash_set(),
2215
-
2216
2204
channel_type,
2217
2205
channel_keys_id,
2218
2206
@@ -2443,9 +2431,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2443
2431
funding_tx_broadcast_safe_event_emitted: false,
2444
2432
channel_ready_event_emitted: false,
2445
2433
2446
- #[cfg(any(test, fuzzing))]
2447
- historical_inbound_htlc_fulfills: new_hash_set(),
2448
-
2449
2434
channel_type,
2450
2435
channel_keys_id,
2451
2436
@@ -4472,10 +4457,6 @@ impl<SP: Deref> Channel<SP> where
4472
4457
}
4473
4458
}
4474
4459
if pending_idx == core::usize::MAX {
4475
- #[cfg(any(test, fuzzing))]
4476
- // If we failed to find an HTLC to fulfill, make sure it was previously fulfilled and
4477
- // this is simply a duplicate claim, not previously failed and we lost funds.
4478
- debug_assert!(self.context.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
4479
4460
return UpdateFulfillFetch::DuplicateClaim {};
4480
4461
}
4481
4462
@@ -4505,8 +4486,6 @@ impl<SP: Deref> Channel<SP> where
4505
4486
if htlc_id_arg == htlc_id {
4506
4487
// Make sure we don't leave latest_monitor_update_id incremented here:
4507
4488
self.context.latest_monitor_update_id -= 1;
4508
- #[cfg(any(test, fuzzing))]
4509
- debug_assert!(self.context.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
4510
4489
return UpdateFulfillFetch::DuplicateClaim {};
4511
4490
}
4512
4491
},
@@ -4528,12 +4507,8 @@ impl<SP: Deref> Channel<SP> where
4528
4507
self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
4529
4508
payment_preimage: payment_preimage_arg, htlc_id: htlc_id_arg,
4530
4509
});
4531
- #[cfg(any(test, fuzzing))]
4532
- self.context.historical_inbound_htlc_fulfills.insert(htlc_id_arg);
4533
4510
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: None };
4534
4511
}
4535
- #[cfg(any(test, fuzzing))]
4536
- self.context.historical_inbound_htlc_fulfills.insert(htlc_id_arg);
4537
4512
4538
4513
{
4539
4514
let htlc = &mut self.context.pending_inbound_htlcs[pending_idx];
@@ -4598,14 +4573,8 @@ impl<SP: Deref> Channel<SP> where
4598
4573
}
4599
4574
}
4600
4575
4601
- /// We can only have one resolution per HTLC. In some cases around reconnect, we may fulfill
4602
- /// an HTLC more than once or fulfill once and then attempt to fail after reconnect. We cannot,
4603
- /// however, fail more than once as we wait for an upstream failure to be irrevocably committed
4604
- /// before we fail backwards.
4605
- ///
4606
- /// If we do fail twice, we `debug_assert!(false)` and return `Ok(None)`. Thus, this will always
4607
- /// return `Ok(_)` if preconditions are met. In any case, `Err`s will only be
4608
- /// [`ChannelError::Ignore`].
4576
+ /// Returns `Err` (always with [`ChannelError::Ignore`]) if the HTLC could not be failed (e.g.
4577
+ /// if it was already resolved). Otherwise returns `Ok`.
4609
4578
pub fn queue_fail_htlc<L: Deref>(&mut self, htlc_id_arg: u64, err_packet: msgs::OnionErrorPacket, logger: &L)
4610
4579
-> Result<(), ChannelError> where L::Target: Logger {
4611
4580
self.fail_htlc(htlc_id_arg, err_packet, true, logger)
@@ -4623,14 +4592,8 @@ impl<SP: Deref> Channel<SP> where
4623
4592
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
4624
4593
}
4625
4594
4626
- /// We can only have one resolution per HTLC. In some cases around reconnect, we may fulfill
4627
- /// an HTLC more than once or fulfill once and then attempt to fail after reconnect. We cannot,
4628
- /// however, fail more than once as we wait for an upstream failure to be irrevocably committed
4629
- /// before we fail backwards.
4630
- ///
4631
- /// If we do fail twice, we `debug_assert!(false)` and return `Ok(None)`. Thus, this will always
4632
- /// return `Ok(_)` if preconditions are met. In any case, `Err`s will only be
4633
- /// [`ChannelError::Ignore`].
4595
+ /// Returns `Err` (always with [`ChannelError::Ignore`]) if the HTLC could not be failed (e.g.
4596
+ /// if it was already resolved). Otherwise returns `Ok`.
4634
4597
fn fail_htlc<L: Deref, E: FailHTLCContents + Clone>(
4635
4598
&mut self, htlc_id_arg: u64, err_contents: E, mut force_holding_cell: bool,
4636
4599
logger: &L
@@ -4648,12 +4611,8 @@ impl<SP: Deref> Channel<SP> where
4648
4611
if htlc.htlc_id == htlc_id_arg {
4649
4612
match htlc.state {
4650
4613
InboundHTLCState::Committed => {},
4651
- InboundHTLCState::LocalRemoved(ref reason) => {
4652
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
4653
- } else {
4654
- debug_assert!(false, "Tried to fail an HTLC that was already failed");
4655
- }
4656
- return Ok(None);
4614
+ InboundHTLCState::LocalRemoved(_) => {
4615
+ return Err(ChannelError::Ignore(format!("HTLC {} was already resolved", htlc.htlc_id)));
4657
4616
},
4658
4617
_ => {
4659
4618
debug_assert!(false, "Have an inbound HTLC we tried to claim before it was fully committed to");
@@ -4664,11 +4623,7 @@ impl<SP: Deref> Channel<SP> where
4664
4623
}
4665
4624
}
4666
4625
if pending_idx == core::usize::MAX {
4667
- #[cfg(any(test, fuzzing))]
4668
- // If we failed to find an HTLC to fail, make sure it was previously fulfilled and this
4669
- // is simply a duplicate fail, not previously failed and we failed-back too early.
4670
- debug_assert!(self.context.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
4671
- return Ok(None);
4626
+ return Err(ChannelError::Ignore(format!("Unable to find a pending HTLC which matched the given HTLC ID ({})", htlc_id_arg)));
4672
4627
}
4673
4628
4674
4629
if !self.context.channel_state.can_generate_new_commitment() {
@@ -4682,17 +4637,14 @@ impl<SP: Deref> Channel<SP> where
4682
4637
match pending_update {
4683
4638
&HTLCUpdateAwaitingACK::ClaimHTLC { htlc_id, .. } => {
4684
4639
if htlc_id_arg == htlc_id {
4685
- #[cfg(any(test, fuzzing))]
4686
- debug_assert!(self.context.historical_inbound_htlc_fulfills.contains(&htlc_id_arg));
4687
- return Ok(None);
4640
+ return Err(ChannelError::Ignore(format!("HTLC {} was already claimed!", htlc_id)));
4688
4641
}
4689
4642
},
4690
4643
&HTLCUpdateAwaitingACK::FailHTLC { htlc_id, .. } |
4691
4644
&HTLCUpdateAwaitingACK::FailMalformedHTLC { htlc_id, .. } =>
4692
4645
{
4693
4646
if htlc_id_arg == htlc_id {
4694
- debug_assert!(false, "Tried to fail an HTLC that was already failed");
4695
- return Err(ChannelError::Ignore("Unable to find a pending HTLC which matched the given HTLC ID".to_owned()));
4647
+ return Err(ChannelError::Ignore(format!("HTLC {} was already pending failure", htlc_id)));
4696
4648
}
4697
4649
},
4698
4650
_ => {}
@@ -9543,13 +9495,6 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
9543
9495
9544
9496
self.context.channel_update_status.write(writer)?;
9545
9497
9546
- #[cfg(any(test, fuzzing))]
9547
- (self.context.historical_inbound_htlc_fulfills.len() as u64).write(writer)?;
9548
- #[cfg(any(test, fuzzing))]
9549
- for htlc in self.context.historical_inbound_htlc_fulfills.iter() {
9550
- htlc.write(writer)?;
9551
- }
9552
-
9553
9498
// If the channel type is something other than only-static-remote-key, then we need to have
9554
9499
// older clients fail to deserialize this channel at all. If the type is
9555
9500
// only-static-remote-key, we simply consider it "default" and don't write the channel type
@@ -9883,16 +9828,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9883
9828
9884
9829
let channel_update_status = Readable::read(reader)?;
9885
9830
9886
- #[cfg(any(test, fuzzing))]
9887
- let mut historical_inbound_htlc_fulfills = new_hash_set();
9888
- #[cfg(any(test, fuzzing))]
9889
- {
9890
- let htlc_fulfills_len: u64 = Readable::read(reader)?;
9891
- for _ in 0..htlc_fulfills_len {
9892
- assert!(historical_inbound_htlc_fulfills.insert(Readable::read(reader)?));
9893
- }
9894
- }
9895
-
9896
9831
let pending_update_fee = if let Some(feerate) = pending_update_fee_value {
9897
9832
Some((feerate, if channel_parameters.is_outbound_from_holder {
9898
9833
FeeUpdateState::Outbound
@@ -10233,9 +10168,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10233
10168
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
10234
10169
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
10235
10170
10236
- #[cfg(any(test, fuzzing))]
10237
- historical_inbound_htlc_fulfills,
10238
-
10239
10171
channel_type: channel_type.unwrap(),
10240
10172
channel_keys_id,
10241
10173
0 commit comments