Skip to content

Commit 88d931a

Browse files
committed
Drop now-unused ClaimFundsFromHop enum and replace with an Err
1 parent b78fa5a commit 88d931a

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
@@ -4343,30 +4335,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
43434335
if valid_mpp {
43444336
for htlc in sources.drain(..) {
43454337
if channel_state.is_none() { channel_state = Some(self.channel_state.lock().unwrap()); }
4346-
match self.claim_funds_from_hop(channel_state.take().unwrap(), htlc.prev_hop,
4338+
if let Err((pk, err)) = self.claim_funds_from_hop(channel_state.take().unwrap(), htlc.prev_hop,
43474339
payment_preimage,
43484340
|_| Some(MonitorUpdateCompletionAction::PaymentClaimed { payment_hash }))
43494341
{
4350-
ClaimFundsFromHop::MonitorUpdateFail(pk, err, _) => {
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)); }
4356-
},
4357-
ClaimFundsFromHop::PrevHopForceClosed => {
4358-
// This should be incredibly rare - we checked that all the channels were
4359-
// open above, though as we release the lock at each loop iteration it's
4360-
// still possible. We should still claim the HTLC on-chain through the
4361-
// closed-channel-update generated in claim_funds_from_hop.
4362-
},
4363-
ClaimFundsFromHop::DuplicateClaim => {
4364-
// While we should never get here in most cases, if we do, it likely
4365-
// indicates that the HTLC was timed out some time ago and is no longer
4366-
// available to be claimed. Thus, it does not make sense to set
4367-
// `claimed_any_htlcs`.
4368-
},
4369-
ClaimFundsFromHop::Success(_) => {},
4342+
if let msgs::ErrorAction::IgnoreError = err.err.action {
4343+
// We got a temporary failure updating monitor, but will claim the
4344+
// HTLC when the monitor updating is restored (or on chain).
4345+
log_error!(self.logger, "Temporary failure claiming HTLC, treating as success: {}", err.err.err);
4346+
} else { errs.push((pk, err)); }
43704347
}
43714348
}
43724349
}
@@ -4393,7 +4370,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
43934370
fn claim_funds_from_hop<ComplFunc: FnOnce(Option<u64>) -> Option<MonitorUpdateCompletionAction>>(&self,
43944371
mut channel_state_lock: MutexGuard<ChannelHolder<<K::Target as KeysInterface>::Signer>>,
43954372
prev_hop: HTLCPreviousHopData, payment_preimage: PaymentPreimage, completion_action: ComplFunc)
4396-
-> ClaimFundsFromHop {
4373+
-> Result<(), (PublicKey, MsgHandleErrInternal)> {
43974374
//TODO: Delay the claimed_funds relaying just like we do outbound relay!
43984375

43994376
let chan_id = prev_hop.outpoint.to_channel_id();
@@ -4409,11 +4386,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44094386
"Failed to update channel monitor with preimage {:?}: {:?}",
44104387
payment_preimage, e);
44114388
self.handle_monitor_update_completion_actions(completion_action(Some(htlc_value_msat)));
4412-
return ClaimFundsFromHop::MonitorUpdateFail(
4389+
return Err((
44134390
chan.get().get_counterparty_node_id(),
44144391
handle_monitor_update_res!(self, e, chan, RAACommitmentOrder::CommitmentFirst, false, msgs.is_some()).unwrap_err(),
4415-
Some(htlc_value_msat)
4416-
);
4392+
));
44174393
}
44184394
}
44194395
if let Some((msg, commitment_signed)) = msgs {
@@ -4432,9 +4408,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44324408
});
44334409
}
44344410
self.handle_monitor_update_completion_actions(completion_action(Some(htlc_value_msat)));
4435-
return ClaimFundsFromHop::Success(htlc_value_msat);
4411+
Ok(())
44364412
} else {
4437-
return ClaimFundsFromHop::DuplicateClaim;
4413+
Ok(())
44384414
}
44394415
},
44404416
Err((e, monitor_update)) => {
@@ -4452,7 +4428,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44524428
chan.remove_entry();
44534429
}
44544430
self.handle_monitor_update_completion_actions(completion_action(None));
4455-
return ClaimFundsFromHop::MonitorUpdateFail(counterparty_node_id, res, None);
4431+
Err((counterparty_node_id, res))
44564432
},
44574433
}
44584434
} else {
@@ -4480,7 +4456,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44804456
// generally always allowed to be duplicative (and it's specifically noted in
44814457
// `PaymentForwarded`)..
44824458
self.handle_monitor_update_completion_actions(completion_action(None));
4483-
return ClaimFundsFromHop::PrevHopForceClosed
4459+
Ok(())
44844460
}
44854461
}
44864462

@@ -4572,7 +4548,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
45724548
}})
45734549
} else { None }
45744550
});
4575-
if let ClaimFundsFromHop::MonitorUpdateFail(pk, err, _) = res {
4551+
if let Err((pk, err)) = res {
45764552
let result: Result<(), _> = Err(err);
45774553
let _ = handle_error!(self, result, pk);
45784554
}

0 commit comments

Comments
 (0)