Skip to content

Commit 6c13169

Browse files
committed
f set proper error code in HTLC timeouts from channel
1 parent cec27ca commit 6c13169

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lightning/src/ln/channel.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,13 +3139,16 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
31393139
/// In case of Err, the channel may have been closed, at which point the standard requirements
31403140
/// apply - no calls may be made except those explicitly stated to be allowed post-shutdown.
31413141
/// Only returns an ErrorAction of DisconnectPeer, if Err.
3142-
pub fn block_connected(&mut self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]) -> Result<(Option<msgs::FundingLocked>, Vec<(HTLCSource, PaymentHash, u64)>), msgs::ErrorMessage> {
3142+
///
3143+
/// May return some HTLCs (and their payment_hash) which have timed out and should be failed
3144+
/// back.
3145+
pub fn block_connected(&mut self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]) -> Result<(Option<msgs::FundingLocked>, Vec<(HTLCSource, PaymentHash)>), msgs::ErrorMessage> {
31433146
let mut timed_out_htlcs = Vec::new();
31443147
self.holding_cell_htlc_updates.retain(|htlc_update| {
31453148
match htlc_update {
3146-
&HTLCUpdateAwaitingACK::AddHTLC { ref payment_hash, ref source, ref cltv_expiry, ref amount_msat, .. } => {
3149+
&HTLCUpdateAwaitingACK::AddHTLC { ref payment_hash, ref source, ref cltv_expiry, .. } => {
31473150
if cltv_expiry - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS <= height {
3148-
timed_out_htlcs.push((source.clone(), payment_hash.clone(), *amount_msat));
3151+
timed_out_htlcs.push((source.clone(), payment_hash.clone()));
31493152
false
31503153
} else { true }
31513154
},

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2991,7 +2991,13 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
29912991
channel_state.by_id.retain(|_, channel| {
29922992
let res = channel.block_connected(header, height, txn_matched, indexes_of_txn_matched);
29932993
if let Ok((chan_res, mut timed_out_pending_htlcs)) = res {
2994-
timed_out_htlcs.append(&mut timed_out_pending_htlcs);
2994+
for (source, payment_hash) in timed_out_pending_htlcs.drain(..) {
2995+
let chan_update = self.get_channel_update(&channel).map(|u| u.encode_with_len()).unwrap(); // Cannot add/recv HTLCs before we have a short_id so unwrap is safe
2996+
timed_out_htlcs.push((source, payment_hash, HTLCFailReason::Reason {
2997+
failure_code: 0x1000 | 14, // expiry_too_soon, or at least it is now
2998+
data: chan_update,
2999+
}));
3000+
}
29953001
if let Some(funding_locked) = chan_res {
29963002
pending_msg_events.push(events::MessageSendEvent::SendFundingLocked {
29973003
node_id: channel.get_their_node_id(),

0 commit comments

Comments
 (0)