Skip to content

Commit c1c368f

Browse files
DRY malformed HTLC handling during htlc batch processing.
1 parent 8aba23c commit c1c368f

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4344,7 +4344,7 @@ where
43444344
if let Some(ChannelPhase::Funded(ref mut chan)) = peer_state.channel_by_id.get_mut(&forward_chan_id) {
43454345
let logger = WithChannelContext::from(&self.logger, &chan.context);
43464346
for forward_info in pending_forwards.drain(..) {
4347-
match forward_info {
4347+
let queue_fail_htlc_res = match forward_info {
43484348
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
43494349
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
43504350
forward_info: PendingHTLCInfo {
@@ -4390,40 +4390,35 @@ where
43904390
));
43914391
continue;
43924392
}
4393+
None
43934394
},
43944395
HTLCForwardInfo::AddHTLC { .. } => {
43954396
panic!("short_channel_id != 0 should imply any pending_forward entries are of type Forward");
43964397
},
43974398
HTLCForwardInfo::FailHTLC { htlc_id, err_packet } => {
43984399
log_trace!(logger, "Failing HTLC back to channel with short id {} (backward HTLC ID {}) after delay", short_chan_id, htlc_id);
4399-
if let Err(e) = chan.queue_fail_htlc(
4400-
htlc_id, err_packet, &&logger
4401-
) {
4402-
if let ChannelError::Ignore(msg) = e {
4403-
log_trace!(logger, "Failed to fail HTLC with ID {} backwards to short_id {}: {}", htlc_id, short_chan_id, msg);
4404-
} else {
4405-
panic!("Stated return value requirements in queue_fail_htlc() were not met");
4406-
}
4407-
// fail-backs are best-effort, we probably already have one
4408-
// pending, and if not that's OK, if not, the channel is on
4409-
// the chain and sending the HTLC-Timeout is their problem.
4410-
continue;
4411-
}
4400+
Some((chan.queue_fail_htlc(htlc_id, err_packet, &&logger), htlc_id))
44124401
},
44134402
HTLCForwardInfo::FailMalformedHTLC { htlc_id, failure_code, sha256_of_onion } => {
44144403
log_trace!(logger, "Failing malformed HTLC back to channel with short id {} (backward HTLC ID {}) after delay", short_chan_id, htlc_id);
4415-
if let Err(e) = chan.queue_fail_malformed_htlc(htlc_id, failure_code, sha256_of_onion, &&logger) {
4416-
if let ChannelError::Ignore(msg) = e {
4417-
log_trace!(logger, "Failed to fail HTLC with ID {} backwards to short_id {}: {}", htlc_id, short_chan_id, msg);
4418-
} else {
4419-
panic!("Stated return value requirements in queue_fail_malformed_htlc() were not met");
4420-
}
4421-
// fail-backs are best-effort, we probably already have one
4422-
// pending, and if not that's OK, if not, the channel is on
4423-
// the chain and sending the HTLC-Timeout is their problem.
4424-
continue;
4425-
}
4404+
let res = chan.queue_fail_malformed_htlc(
4405+
htlc_id, failure_code, sha256_of_onion, &&logger
4406+
);
4407+
Some((res, htlc_id))
44264408
},
4409+
};
4410+
if let Some((queue_fail_htlc_res, htlc_id)) = queue_fail_htlc_res {
4411+
if let Err(e) = queue_fail_htlc_res {
4412+
if let ChannelError::Ignore(msg) = e {
4413+
log_trace!(logger, "Failed to fail HTLC with ID {} backwards to short_id {}: {}", htlc_id, short_chan_id, msg);
4414+
} else {
4415+
panic!("Stated return value requirements in queue_fail_{{malformed_}}htlc() were not met");
4416+
}
4417+
// fail-backs are best-effort, we probably already have one
4418+
// pending, and if not that's OK, if not, the channel is on
4419+
// the chain and sending the HTLC-Timeout is their problem.
4420+
continue;
4421+
}
44274422
}
44284423
}
44294424
} else {

0 commit comments

Comments
 (0)