Skip to content

Commit 0938c50

Browse files
committed
Drop now-unused ClaimFundsFromHop enum and replace with an Err
1 parent 3bec7cf commit 0938c50

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
@@ -4336,30 +4328,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
43364328
if valid_mpp {
43374329
for htlc in sources.drain(..) {
43384330
if channel_state.is_none() { channel_state = Some(self.channel_state.lock().unwrap()); }
4339-
match self.claim_funds_from_hop(channel_state.take().unwrap(), htlc.prev_hop,
4331+
if let Err((pk, err)) = self.claim_funds_from_hop(channel_state.take().unwrap(), htlc.prev_hop,
43404332
payment_preimage,
43414333
|_| Some(MonitorUpdateCompletionAction::PaymentClaimed { payment_hash }))
43424334
{
4343-
ClaimFundsFromHop::MonitorUpdateFail(pk, err, _) => {
4344-
if let msgs::ErrorAction::IgnoreError = err.err.action {
4345-
// We got a temporary failure updating monitor, but will claim the
4346-
// HTLC when the monitor updating is restored (or on chain).
4347-
log_error!(self.logger, "Temporary failure claiming HTLC, treating as success: {}", err.err.err);
4348-
} else { errs.push((pk, err)); }
4349-
},
4350-
ClaimFundsFromHop::PrevHopForceClosed => {
4351-
// This should be incredibly rare - we checked that all the channels were
4352-
// open above, though as we release the lock at each loop iteration it's
4353-
// still possible. We should still claim the HTLC on-chain through the
4354-
// closed-channel-update generated in claim_funds_from_hop.
4355-
},
4356-
ClaimFundsFromHop::DuplicateClaim => {
4357-
// While we should never get here in most cases, if we do, it likely
4358-
// indicates that the HTLC was timed out some time ago and is no longer
4359-
// available to be claimed. Thus, it does not make sense to set
4360-
// `claimed_any_htlcs`.
4361-
},
4362-
ClaimFundsFromHop::Success(_) => {},
4335+
if let msgs::ErrorAction::IgnoreError = err.err.action {
4336+
// We got a temporary failure updating monitor, but will claim the
4337+
// HTLC when the monitor updating is restored (or on chain).
4338+
log_error!(self.logger, "Temporary failure claiming HTLC, treating as success: {}", err.err.err);
4339+
} else { errs.push((pk, err)); }
43634340
}
43644341
}
43654342
}
@@ -4386,7 +4363,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
43864363
fn claim_funds_from_hop<ComplFunc: FnOnce(Option<u64>) -> Option<MonitorUpdateCompletionAction>>(&self,
43874364
mut channel_state_lock: MutexGuard<ChannelHolder<<K::Target as KeysInterface>::Signer>>,
43884365
prev_hop: HTLCPreviousHopData, payment_preimage: PaymentPreimage, completion_action: ComplFunc)
4389-
-> ClaimFundsFromHop {
4366+
-> Result<(), (PublicKey, MsgHandleErrInternal)> {
43904367
//TODO: Delay the claimed_funds relaying just like we do outbound relay!
43914368

43924369
let chan_id = prev_hop.outpoint.to_channel_id();
@@ -4402,11 +4379,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44024379
"Failed to update channel monitor with preimage {:?}: {:?}",
44034380
payment_preimage, e);
44044381
self.handle_monitor_update_completion_actions(completion_action(Some(htlc_value_msat)));
4405-
return ClaimFundsFromHop::MonitorUpdateFail(
4382+
return Err((
44064383
chan.get().get_counterparty_node_id(),
44074384
handle_monitor_update_res!(self, e, chan, RAACommitmentOrder::CommitmentFirst, false, msgs.is_some()).unwrap_err(),
4408-
Some(htlc_value_msat)
4409-
);
4385+
));
44104386
}
44114387
}
44124388
if let Some((msg, commitment_signed)) = msgs {
@@ -4425,9 +4401,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44254401
});
44264402
}
44274403
self.handle_monitor_update_completion_actions(completion_action(Some(htlc_value_msat)));
4428-
return ClaimFundsFromHop::Success(htlc_value_msat);
4404+
Ok(())
44294405
} else {
4430-
return ClaimFundsFromHop::DuplicateClaim;
4406+
Ok(())
44314407
}
44324408
},
44334409
Err((e, monitor_update)) => {
@@ -4445,7 +4421,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44454421
chan.remove_entry();
44464422
}
44474423
self.handle_monitor_update_completion_actions(completion_action(None));
4448-
return ClaimFundsFromHop::MonitorUpdateFail(counterparty_node_id, res, None);
4424+
Err((counterparty_node_id, res))
44494425
},
44504426
}
44514427
} else {
@@ -4473,7 +4449,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44734449
// generally always allowed to be duplicative (and it's specifically noted in
44744450
// `PaymentForwarded`)..
44754451
self.handle_monitor_update_completion_actions(completion_action(None));
4476-
return ClaimFundsFromHop::PrevHopForceClosed
4452+
Ok(())
44774453
}
44784454
}
44794455

@@ -4565,7 +4541,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
45654541
}})
45664542
} else { None }
45674543
});
4568-
if let ClaimFundsFromHop::MonitorUpdateFail(pk, err, _) = res {
4544+
if let Err((pk, err)) = res {
45694545
let result: Result<(), _> = Err(err);
45704546
let _ = handle_error!(self, result, pk);
45714547
}

0 commit comments

Comments
 (0)