Skip to content

Commit aa5d7a9

Browse files
committed
Add awaiting_downstream_confirmation flag on HTLCUpdate
1 parent 61d72f8 commit aa5d7a9

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,25 @@ impl_writeable_tlv_based_enum_upgradable!(MonitorEvent,
171171
);
172172

173173
/// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
174-
/// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
175-
/// preimage claim backward will lead to loss of funds.
174+
/// chain, or when we failing an HTLC awaiting downstream confirmation to prevent a
175+
/// backwards channel from going on-chain. Used to update the corresponding HTLC in the backward
176+
/// channel. Failing to pass the preimage claim backward will lead to loss of funds.
176177
#[derive(Clone, PartialEq, Eq)]
177178
pub struct HTLCUpdate {
178179
pub(crate) payment_hash: PaymentHash,
179180
pub(crate) payment_preimage: Option<PaymentPreimage>,
180181
pub(crate) source: HTLCSource,
181182
pub(crate) htlc_value_satoshis: Option<u64>,
183+
/// If this is an update to fail back the upstream HTLC, this signals whether we're failing
184+
/// back this HTLC because we saw a downstream claim on-chain, or if we're close to the
185+
/// upstream timeout and want to prevent the channel from going on-chain.
186+
pub(crate) awaiting_downstream_confirmation: bool,
182187
}
183188
impl_writeable_tlv_based!(HTLCUpdate, {
184189
(0, payment_hash, required),
185190
(1, htlc_value_satoshis, option),
186191
(2, source, required),
192+
(3, awaiting_downstream_confirmation, (default_value, false)),
187193
(4, payment_preimage, option),
188194
});
189195

@@ -3560,6 +3566,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
35603566
payment_preimage: None,
35613567
source: source.clone(),
35623568
htlc_value_satoshis,
3569+
awaiting_downstream_confirmation: false,
35633570
}));
35643571
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
35653572
commitment_tx_output_idx,
@@ -3937,6 +3944,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39373944
payment_preimage: Some(payment_preimage),
39383945
payment_hash,
39393946
htlc_value_satoshis: Some(amount_msat / 1000),
3947+
awaiting_downstream_confirmation: false,
39403948
}));
39413949
}
39423950
} else if offered_preimage_claim {
@@ -3960,6 +3968,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39603968
payment_preimage: Some(payment_preimage),
39613969
payment_hash,
39623970
htlc_value_satoshis: Some(amount_msat / 1000),
3971+
awaiting_downstream_confirmation: false,
39633972
}));
39643973
}
39653974
} else {

0 commit comments

Comments
 (0)