Skip to content

Commit 2d39ef8

Browse files
committed
lightning/refactor: rename HTLCFailReason to HTLCFailurePayload
This struct doesn't just contain a failure reason, it has all the data that's used to construct our failure.
1 parent 0191890 commit 2d39ef8

File tree

5 files changed

+60
-59
lines changed

5 files changed

+60
-59
lines changed

Diff for: lightning/src/ln/channel.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use crate::ln::chan_utils::{
5050
#[cfg(splicing)]
5151
use crate::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
5252
use crate::ln::chan_utils;
53-
use crate::ln::onion_utils::{HTLCFailReason, LocalHTLCFailureReason, AttributionData};
53+
use crate::ln::onion_utils::{HTLCFailurePayload, LocalHTLCFailureReason, AttributionData};
5454
use crate::chain::BestBlock;
5555
use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, LowerBoundedFeeEstimator, fee_for_weight};
5656
use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, LATENCY_GRACE_PERIOD_BLOCKS};
@@ -380,11 +380,11 @@ enum OutboundHTLCOutcome {
380380
/// We started always filling in the preimages here in 0.0.105, and the requirement
381381
/// that the preimages always be filled in was added in 0.2.
382382
Success(PaymentPreimage),
383-
Failure(HTLCFailReason),
383+
Failure(HTLCFailurePayload),
384384
}
385385

386-
impl<'a> Into<Option<&'a HTLCFailReason>> for &'a OutboundHTLCOutcome {
387-
fn into(self) -> Option<&'a HTLCFailReason> {
386+
impl<'a> Into<Option<&'a HTLCFailurePayload>> for &'a OutboundHTLCOutcome {
387+
fn into(self) -> Option<&'a HTLCFailurePayload> {
388388
match self {
389389
OutboundHTLCOutcome::Success(_) => None,
390390
OutboundHTLCOutcome::Failure(ref r) => Some(r)
@@ -1042,7 +1042,7 @@ pub(super) struct MonitorRestoreUpdates {
10421042
pub commitment_update: Option<msgs::CommitmentUpdate>,
10431043
pub order: RAACommitmentOrder,
10441044
pub accepted_htlcs: Vec<(PendingHTLCInfo, u64)>,
1045-
pub failed_htlcs: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
1045+
pub failed_htlcs: Vec<(HTLCSource, PaymentHash, HTLCFailurePayload)>,
10461046
pub finalized_claimed_htlcs: Vec<HTLCSource>,
10471047
pub pending_update_adds: Vec<msgs::UpdateAddHTLC>,
10481048
pub funding_broadcastable: Option<Transaction>,
@@ -1971,7 +1971,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
19711971
// completed or not. We currently ignore these fields entirely when force-closing a channel,
19721972
// but need to handle this somehow or we run the risk of losing HTLCs!
19731973
monitor_pending_forwards: Vec<(PendingHTLCInfo, u64)>,
1974-
monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
1974+
monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailurePayload)>,
19751975
monitor_pending_finalized_fulfills: Vec<HTLCSource>,
19761976
monitor_pending_update_adds: Vec<msgs::UpdateAddHTLC>,
19771977
monitor_pending_tx_signatures: Option<msgs::TxSignatures>,
@@ -5828,7 +5828,7 @@ impl<SP: Deref> FundedChannel<SP> where
58285828
self.mark_outbound_htlc_removed(msg.htlc_id, OutboundHTLCOutcome::Success(msg.payment_preimage)).map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
58295829
}
58305830

5831-
pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailReason) -> Result<(), ChannelError> {
5831+
pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailurePayload) -> Result<(), ChannelError> {
58325832
if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
58335833
return Err(ChannelError::WarnAndDisconnect("Got fail HTLC message while quiescent".to_owned()));
58345834
}
@@ -5843,7 +5843,7 @@ impl<SP: Deref> FundedChannel<SP> where
58435843
Ok(())
58445844
}
58455845

5846-
pub fn update_fail_malformed_htlc(&mut self, msg: &msgs::UpdateFailMalformedHTLC, fail_reason: HTLCFailReason) -> Result<(), ChannelError> {
5846+
pub fn update_fail_malformed_htlc(&mut self, msg: &msgs::UpdateFailMalformedHTLC, fail_reason: HTLCFailurePayload) -> Result<(), ChannelError> {
58475847
if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
58485848
return Err(ChannelError::WarnAndDisconnect("Got fail malformed HTLC message while quiescent".to_owned()));
58495849
}
@@ -6000,7 +6000,7 @@ impl<SP: Deref> FundedChannel<SP> where
60006000
if let &mut OutboundHTLCState::RemoteRemoved(ref mut outcome) = &mut htlc.state {
60016001
log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToRemove due to commitment_signed in channel {}.",
60026002
&htlc.payment_hash, &self.context.channel_id);
6003-
// Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
6003+
// Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailurePayload)`
60046004
let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
60056005
mem::swap(outcome, &mut reason);
60066006
if let OutboundHTLCOutcome::Success(preimage) = reason {
@@ -6413,7 +6413,7 @@ impl<SP: Deref> FundedChannel<SP> where
64136413
}
64146414
if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
64156415
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
6416-
// Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
6416+
// Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailurePayload)`
64176417
let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
64186418
mem::swap(outcome, &mut reason);
64196419
htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
@@ -6768,7 +6768,7 @@ impl<SP: Deref> FundedChannel<SP> where
67686768
/// [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress
67696769
fn monitor_updating_paused(&mut self, resend_raa: bool, resend_commitment: bool,
67706770
resend_channel_ready: bool, mut pending_forwards: Vec<(PendingHTLCInfo, u64)>,
6771-
mut pending_fails: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
6771+
mut pending_fails: Vec<(HTLCSource, PaymentHash, HTLCFailurePayload)>,
67726772
mut pending_finalized_claimed_htlcs: Vec<HTLCSource>
67736773
) {
67746774
self.context.monitor_pending_revoke_and_ack |= resend_raa;
@@ -8987,7 +8987,7 @@ impl<SP: Deref> FundedChannel<SP> where
89878987
for htlc in self.context.pending_outbound_htlcs.iter_mut() {
89888988
if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
89898989
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
8990-
// Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
8990+
// Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailurePayload)`
89918991
let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
89928992
mem::swap(outcome, &mut reason);
89938993
htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
@@ -10644,15 +10644,15 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1064410644
if let OutboundHTLCOutcome::Success(preimage) = outcome {
1064510645
preimages.push(Some(preimage));
1064610646
}
10647-
let reason: Option<&HTLCFailReason> = outcome.into();
10647+
let reason: Option<&HTLCFailurePayload> = outcome.into();
1064810648
reason.write(writer)?;
1064910649
}
1065010650
&OutboundHTLCState::AwaitingRemovedRemoteRevoke(ref outcome) => {
1065110651
4u8.write(writer)?;
1065210652
if let OutboundHTLCOutcome::Success(preimage) = outcome {
1065310653
preimages.push(Some(preimage));
1065410654
}
10655-
let reason: Option<&HTLCFailReason> = outcome.into();
10655+
let reason: Option<&HTLCFailurePayload> = outcome.into();
1065610656
reason.write(writer)?;
1065710657
}
1065810658
}
@@ -10988,7 +10988,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1098810988
0 => OutboundHTLCState::LocalAnnounced(Box::new(Readable::read(reader)?)),
1098910989
1 => OutboundHTLCState::Committed,
1099010990
2 => {
10991-
let option: Option<HTLCFailReason> = Readable::read(reader)?;
10991+
let option: Option<HTLCFailurePayload> = Readable::read(reader)?;
1099210992
let outcome = match option {
1099310993
Some(r) => OutboundHTLCOutcome::Failure(r),
1099410994
// Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
@@ -10997,7 +10997,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1099710997
OutboundHTLCState::RemoteRemoved(outcome)
1099810998
},
1099910999
3 => {
11000-
let option: Option<HTLCFailReason> = Readable::read(reader)?;
11000+
let option: Option<HTLCFailurePayload> = Readable::read(reader)?;
1100111001
let outcome = match option {
1100211002
Some(r) => OutboundHTLCOutcome::Failure(r),
1100311003
// Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
@@ -11006,7 +11006,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1100611006
OutboundHTLCState::AwaitingRemoteRevokeToRemove(outcome)
1100711007
},
1100811008
4 => {
11009-
let option: Option<HTLCFailReason> = Readable::read(reader)?;
11009+
let option: Option<HTLCFailurePayload> = Readable::read(reader)?;
1101011010
let outcome = match option {
1101111011
Some(r) => OutboundHTLCOutcome::Failure(r),
1101211012
// Initialize this variant with a dummy preimage, the actual preimage will be filled in further down

0 commit comments

Comments
 (0)