Skip to content

Commit b264801

Browse files
Support failing blinded non-intro HTLCs after RAA processing.
If an HTLC fails after its RAA is processed, it is failed back with ChannelManager::fail_htlc_backwards_internal. This method will now correctly inform the channel that this HTLC is blinded and to construct an update_malformed message accordingly.
1 parent 4198eda commit b264801

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

lightning/src/ln/channel.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,6 +2881,17 @@ impl<SP: Deref> Channel<SP> where
28812881
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
28822882
}
28832883

2884+
/// Used for failing back with [`msgs::UpdateFailMalformedHTLC`]. For now, this is used when we
2885+
/// want to fail blinded HTLCs where we are not the intro node.
2886+
///
2887+
/// See [`Self::queue_fail_htlc`] for more info.
2888+
pub fn queue_fail_malformed_htlc<L: Deref>(
2889+
&mut self, htlc_id_arg: u64, failure_code: u16, sha256_of_onion: [u8; 32], logger: &L
2890+
) -> Result<(), ChannelError> where L::Target: Logger {
2891+
self.fail_htlc(htlc_id_arg, (failure_code, sha256_of_onion), true, logger)
2892+
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
2893+
}
2894+
28842895
/// We can only have one resolution per HTLC. In some cases around reconnect, we may fulfill
28852896
/// an HTLC more than once or fulfill once and then attempt to fail after reconnect. We cannot,
28862897
/// however, fail more than once as we wait for an upstream failure to be irrevocably committed

lightning/src/ln/channelmanager.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4387,8 +4387,19 @@ where
43874387
continue;
43884388
}
43894389
},
4390-
HTLCForwardInfo::FailMalformedHTLC { .. } => {
4391-
todo!()
4390+
HTLCForwardInfo::FailMalformedHTLC { htlc_id, failure_code, sha256_of_onion } => {
4391+
log_trace!(self.logger, "Failing malformed HTLC back to channel with short id {} (backward HTLC ID {}) after delay", short_chan_id, htlc_id);
4392+
if let Err(e) = chan.queue_fail_malformed_htlc(htlc_id, failure_code, sha256_of_onion, &self.logger) {
4393+
if let ChannelError::Ignore(msg) = e {
4394+
log_trace!(self.logger, "Failed to fail HTLC with ID {} backwards to short_id {}: {}", htlc_id, short_chan_id, msg);
4395+
} else {
4396+
panic!("Stated return value requirements in queue_fail_malformed_htlc() were not met");
4397+
}
4398+
// fail-backs are best-effort, we probably already have one
4399+
// pending, and if not that's OK, if not, the channel is on
4400+
// the chain and sending the HTLC-Timeout is their problem.
4401+
continue;
4402+
}
43924403
},
43934404
}
43944405
}
@@ -5257,7 +5268,13 @@ where
52575268
);
52585269
HTLCForwardInfo::FailHTLC { htlc_id: *htlc_id, err_packet }
52595270
},
5260-
Some(BlindedFailure::FromBlindedNode) => todo!(),
5271+
Some(BlindedFailure::FromBlindedNode) => {
5272+
HTLCForwardInfo::FailMalformedHTLC {
5273+
htlc_id: *htlc_id,
5274+
failure_code: INVALID_ONION_BLINDING,
5275+
sha256_of_onion: [0; 32]
5276+
}
5277+
},
52615278
None => {
52625279
let err_packet = onion_error.get_encrypted_failure_packet(
52635280
incoming_packet_shared_secret, phantom_shared_secret

0 commit comments

Comments
 (0)