Skip to content

Commit b5f4bfa

Browse files
committed
Drop now-unused ClaimFundsFromHop enum and replace with an Err
1 parent 5f794d3 commit b5f4bfa

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
@@ -275,14 +275,6 @@ struct ReceiveError {
275275
msg: &'static str,
276276
}
277277

278-
/// Return value for claim_funds_from_hop
279-
enum ClaimFundsFromHop {
280-
PrevHopForceClosed,
281-
MonitorUpdateFail(PublicKey, MsgHandleErrInternal, Option<u64>),
282-
Success(u64),
283-
DuplicateClaim,
284-
}
285-
286278
type ShutdownResult = (Option<(OutPoint, ChannelMonitorUpdate)>, Vec<(HTLCSource, PaymentHash, PublicKey, [u8; 32])>);
287279

288280
/// Error type returned across the channel_state mutex boundary. When an Err is generated for a
@@ -4196,30 +4188,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
41964188
if valid_mpp {
41974189
for htlc in sources.drain(..) {
41984190
if channel_state.is_none() { channel_state = Some(self.channel_state.lock().unwrap()); }
4199-
match self.claim_funds_from_hop(channel_state.take().unwrap(), htlc.prev_hop,
4191+
if let Err((pk, err)) = self.claim_funds_from_hop(channel_state.take().unwrap(), htlc.prev_hop,
42004192
payment_preimage,
42014193
|_| Some(MonitorUpdateCompletionAction::PaymentClaimed { payment_hash }))
42024194
{
4203-
ClaimFundsFromHop::MonitorUpdateFail(pk, err, _) => {
4204-
if let msgs::ErrorAction::IgnoreError = err.err.action {
4205-
// We got a temporary failure updating monitor, but will claim the
4206-
// HTLC when the monitor updating is restored (or on chain).
4207-
log_error!(self.logger, "Temporary failure claiming HTLC, treating as success: {}", err.err.err);
4208-
} else { errs.push((pk, err)); }
4209-
},
4210-
ClaimFundsFromHop::PrevHopForceClosed => {
4211-
// This should be incredibly rare - we checked that all the channels were
4212-
// open above, though as we release the lock at each loop iteration it's
4213-
// still possible. We should still claim the HTLC on-chain through the
4214-
// closed-channel-update generated in claim_funds_from_hop.
4215-
},
4216-
ClaimFundsFromHop::DuplicateClaim => {
4217-
// While we should never get here in most cases, if we do, it likely
4218-
// indicates that the HTLC was timed out some time ago and is no longer
4219-
// available to be claimed. Thus, it does not make sense to set
4220-
// `claimed_any_htlcs`.
4221-
},
4222-
ClaimFundsFromHop::Success(_) => {},
4195+
if let msgs::ErrorAction::IgnoreError = err.err.action {
4196+
// We got a temporary failure updating monitor, but will claim the
4197+
// HTLC when the monitor updating is restored (or on chain).
4198+
log_error!(self.logger, "Temporary failure claiming HTLC, treating as success: {}", err.err.err);
4199+
} else { errs.push((pk, err)); }
42234200
}
42244201
}
42254202
}
@@ -4246,7 +4223,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
42464223
fn claim_funds_from_hop<ComplFunc: FnOnce(Option<u64>) -> Option<MonitorUpdateCompletionAction>>(&self,
42474224
mut channel_state_lock: MutexGuard<ChannelHolder<<K::Target as KeysInterface>::Signer>>,
42484225
prev_hop: HTLCPreviousHopData, payment_preimage: PaymentPreimage, completion_action: ComplFunc)
4249-
-> ClaimFundsFromHop {
4226+
-> Result<(), (PublicKey, MsgHandleErrInternal)> {
42504227
//TODO: Delay the claimed_funds relaying just like we do outbound relay!
42514228

42524229
let chan_id = prev_hop.outpoint.to_channel_id();
@@ -4262,11 +4239,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
42624239
"Failed to update channel monitor with preimage {:?}: {:?}",
42634240
payment_preimage, e);
42644241
self.handle_monitor_update_completion_actions(completion_action(Some(htlc_value_msat)));
4265-
return ClaimFundsFromHop::MonitorUpdateFail(
4242+
return Err((
42664243
chan.get().get_counterparty_node_id(),
42674244
handle_monitor_update_res!(self, e, chan, RAACommitmentOrder::CommitmentFirst, false, msgs.is_some()).unwrap_err(),
4268-
Some(htlc_value_msat)
4269-
);
4245+
));
42704246
}
42714247
}
42724248
if let Some((msg, commitment_signed)) = msgs {
@@ -4285,9 +4261,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
42854261
});
42864262
}
42874263
self.handle_monitor_update_completion_actions(completion_action(Some(htlc_value_msat)));
4288-
return ClaimFundsFromHop::Success(htlc_value_msat);
4264+
Ok(())
42894265
} else {
4290-
return ClaimFundsFromHop::DuplicateClaim;
4266+
Ok(())
42914267
}
42924268
},
42934269
Err((e, monitor_update)) => {
@@ -4305,7 +4281,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
43054281
chan.remove_entry();
43064282
}
43074283
self.handle_monitor_update_completion_actions(completion_action(None));
4308-
return ClaimFundsFromHop::MonitorUpdateFail(counterparty_node_id, res, None);
4284+
Err((counterparty_node_id, res))
43094285
},
43104286
}
43114287
} else {
@@ -4333,7 +4309,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
43334309
// generally always allowed to be duplicative (and it's specifically noted in
43344310
// `PaymentForwarded`)..
43354311
self.handle_monitor_update_completion_actions(completion_action(None));
4336-
return ClaimFundsFromHop::PrevHopForceClosed
4312+
Ok(())
43374313
}
43384314
}
43394315

@@ -4425,7 +4401,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44254401
}})
44264402
} else { None }
44274403
});
4428-
if let ClaimFundsFromHop::MonitorUpdateFail(pk, err, _) = res {
4404+
if let Err((pk, err)) = res {
44294405
let result: Result<(), _> = Err(err);
44304406
let _ = handle_error!(self, result, pk);
44314407
}

0 commit comments

Comments
 (0)