Skip to content

Commit 8a61b10

Browse files
committed
Drop now-unused ClaimFundsFromHop enum and replace with an Err
1 parent 352ecdc commit 8a61b10

File tree

1 file changed

+14
-38
lines changed

1 file changed

+14
-38
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,6 @@ struct ReceiveError {
303303
msg: &'static str,
304304
}
305305

306-
/// Return value for claim_funds_from_hop
307-
enum ClaimFundsFromHop {
308-
PrevHopForceClosed,
309-
MonitorUpdateFail(PublicKey, MsgHandleErrInternal, Option<u64>),
310-
Success(u64),
311-
DuplicateClaim,
312-
}
313-
314306
type ShutdownResult = (Option<(OutPoint, ChannelMonitorUpdate)>, Vec<(HTLCSource, PaymentHash, PublicKey, [u8; 32])>);
315307

316308
/// Error type returned across the channel_state mutex boundary. When an Err is generated for a
@@ -4352,29 +4344,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
43524344
if valid_mpp {
43534345
for htlc in sources.drain(..) {
43544346
if channel_state.is_none() { channel_state = Some(self.channel_state.lock().unwrap()); }
4355-
match self.claim_funds_from_hop(channel_state.take().unwrap(), htlc.prev_hop, payment_preimage,
4347+
if let Err((pk, err)) = self.claim_funds_from_hop(channel_state.take().unwrap(), htlc.prev_hop,
4348+
payment_preimage,
43564349
|_| Some(MonitorUpdateCompletionAction::PaymentClaimed { payment_hash }))
43574350
{
4358-
ClaimFundsFromHop::MonitorUpdateFail(pk, err, _) => {
4359-
if let msgs::ErrorAction::IgnoreError = err.err.action {
4360-
// We got a temporary failure updating monitor, but will claim the
4361-
// HTLC when the monitor updating is restored (or on chain).
4362-
log_error!(self.logger, "Temporary failure claiming HTLC, treating as success: {}", err.err.err);
4363-
} else { errs.push((pk, err)); }
4364-
},
4365-
ClaimFundsFromHop::PrevHopForceClosed => {
4366-
// This should be incredibly rare - we checked that all the channels were
4367-
// open above, though as we release the lock at each loop iteration it's
4368-
// still possible. We should still claim the HTLC on-chain through the
4369-
// closed-channel-update generated in claim_funds_from_hop.
4370-
},
4371-
ClaimFundsFromHop::DuplicateClaim => {
4372-
// While we should never get here in most cases, if we do, it likely
4373-
// indicates that the HTLC was timed out some time ago and is no longer
4374-
// available to be claimed. Thus, it does not make sense to set
4375-
// `claimed_any_htlcs`.
4376-
},
4377-
ClaimFundsFromHop::Success(_) => {},
4351+
if let msgs::ErrorAction::IgnoreError = err.err.action {
4352+
// We got a temporary failure updating monitor, but will claim the
4353+
// HTLC when the monitor updating is restored (or on chain).
4354+
log_error!(self.logger, "Temporary failure claiming HTLC, treating as success: {}", err.err.err);
4355+
} else { errs.push((pk, err)); }
43784356
}
43794357
}
43804358
}
@@ -4401,7 +4379,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44014379
fn claim_funds_from_hop<ComplFunc: FnOnce(Option<u64>) -> Option<MonitorUpdateCompletionAction>>(&self,
44024380
mut channel_state_lock: MutexGuard<ChannelHolder<<K::Target as KeysInterface>::Signer>>,
44034381
prev_hop: HTLCPreviousHopData, payment_preimage: PaymentPreimage, completion_action: ComplFunc)
4404-
-> ClaimFundsFromHop {
4382+
-> Result<(), (PublicKey, MsgHandleErrInternal)> {
44054383
//TODO: Delay the claimed_funds relaying just like we do outbound relay!
44064384

44074385
let chan_id = prev_hop.outpoint.to_channel_id();
@@ -4420,9 +4398,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44204398
let err = handle_monitor_update_res!(self, e, chan, RAACommitmentOrder::CommitmentFirst, false, msgs.is_some()).unwrap_err();
44214399
mem::drop(channel_state_lock);
44224400
self.handle_monitor_update_completion_actions(completion_action(Some(htlc_value_msat)));
4423-
return ClaimFundsFromHop::MonitorUpdateFail(
4424-
counterparty_node_id, err, Some(htlc_value_msat)
4425-
);
4401+
return Err((counterparty_node_id, err));
44264402
}
44274403
}
44284404
if let Some((msg, commitment_signed)) = msgs {
@@ -4442,9 +4418,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44424418
}
44434419
mem::drop(channel_state_lock);
44444420
self.handle_monitor_update_completion_actions(completion_action(Some(htlc_value_msat)));
4445-
return ClaimFundsFromHop::Success(htlc_value_msat);
4421+
Ok(())
44464422
} else {
4447-
return ClaimFundsFromHop::DuplicateClaim;
4423+
Ok(())
44484424
}
44494425
},
44504426
Err((e, monitor_update)) => {
@@ -4462,7 +4438,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44624438
}
44634439
mem::drop(channel_state_lock);
44644440
self.handle_monitor_update_completion_actions(completion_action(None));
4465-
return ClaimFundsFromHop::MonitorUpdateFail(counterparty_node_id, res, None);
4441+
Err((counterparty_node_id, res))
44664442
},
44674443
}
44684444
} else {
@@ -4490,7 +4466,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44904466
// generally always allowed to be duplicative (and it's specifically noted in
44914467
// `PaymentForwarded`).
44924468
self.handle_monitor_update_completion_actions(completion_action(None));
4493-
return ClaimFundsFromHop::PrevHopForceClosed
4469+
Ok(())
44944470
}
44954471
}
44964472

@@ -4582,7 +4558,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
45824558
}})
45834559
} else { None }
45844560
});
4585-
if let ClaimFundsFromHop::MonitorUpdateFail(pk, err, _) = res {
4561+
if let Err((pk, err)) = res {
45864562
let result: Result<(), _> = Err(err);
45874563
let _ = handle_error!(self, result, pk);
45884564
}

0 commit comments

Comments
 (0)