mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 15:20:24 +01:00
DRY malformed HTLC handling during htlc batch processing.
This commit is contained in:
parent
5c880a0549
commit
04e70bad0a
1 changed files with 20 additions and 25 deletions
|
@ -4344,7 +4344,7 @@ where
|
||||||
if let Some(ChannelPhase::Funded(ref mut chan)) = peer_state.channel_by_id.get_mut(&forward_chan_id) {
|
if let Some(ChannelPhase::Funded(ref mut chan)) = peer_state.channel_by_id.get_mut(&forward_chan_id) {
|
||||||
let logger = WithChannelContext::from(&self.logger, &chan.context);
|
let logger = WithChannelContext::from(&self.logger, &chan.context);
|
||||||
for forward_info in pending_forwards.drain(..) {
|
for forward_info in pending_forwards.drain(..) {
|
||||||
match forward_info {
|
let queue_fail_htlc_res = match forward_info {
|
||||||
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
|
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
|
||||||
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
|
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
|
||||||
forward_info: PendingHTLCInfo {
|
forward_info: PendingHTLCInfo {
|
||||||
|
@ -4390,40 +4390,35 @@ where
|
||||||
));
|
));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
None
|
||||||
},
|
},
|
||||||
HTLCForwardInfo::AddHTLC { .. } => {
|
HTLCForwardInfo::AddHTLC { .. } => {
|
||||||
panic!("short_channel_id != 0 should imply any pending_forward entries are of type Forward");
|
panic!("short_channel_id != 0 should imply any pending_forward entries are of type Forward");
|
||||||
},
|
},
|
||||||
HTLCForwardInfo::FailHTLC { htlc_id, err_packet } => {
|
HTLCForwardInfo::FailHTLC { htlc_id, err_packet } => {
|
||||||
log_trace!(logger, "Failing HTLC back to channel with short id {} (backward HTLC ID {}) after delay", short_chan_id, htlc_id);
|
log_trace!(logger, "Failing HTLC back to channel with short id {} (backward HTLC ID {}) after delay", short_chan_id, htlc_id);
|
||||||
if let Err(e) = chan.queue_fail_htlc(
|
Some((chan.queue_fail_htlc(htlc_id, err_packet, &&logger), htlc_id))
|
||||||
htlc_id, err_packet, &&logger
|
|
||||||
) {
|
|
||||||
if let ChannelError::Ignore(msg) = e {
|
|
||||||
log_trace!(logger, "Failed to fail HTLC with ID {} backwards to short_id {}: {}", htlc_id, short_chan_id, msg);
|
|
||||||
} else {
|
|
||||||
panic!("Stated return value requirements in queue_fail_htlc() were not met");
|
|
||||||
}
|
|
||||||
// fail-backs are best-effort, we probably already have one
|
|
||||||
// pending, and if not that's OK, if not, the channel is on
|
|
||||||
// the chain and sending the HTLC-Timeout is their problem.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
HTLCForwardInfo::FailMalformedHTLC { htlc_id, failure_code, sha256_of_onion } => {
|
HTLCForwardInfo::FailMalformedHTLC { htlc_id, failure_code, sha256_of_onion } => {
|
||||||
log_trace!(logger, "Failing malformed HTLC back to channel with short id {} (backward HTLC ID {}) after delay", short_chan_id, htlc_id);
|
log_trace!(logger, "Failing malformed HTLC back to channel with short id {} (backward HTLC ID {}) after delay", short_chan_id, htlc_id);
|
||||||
if let Err(e) = chan.queue_fail_malformed_htlc(htlc_id, failure_code, sha256_of_onion, &&logger) {
|
let res = chan.queue_fail_malformed_htlc(
|
||||||
if let ChannelError::Ignore(msg) = e {
|
htlc_id, failure_code, sha256_of_onion, &&logger
|
||||||
log_trace!(logger, "Failed to fail HTLC with ID {} backwards to short_id {}: {}", htlc_id, short_chan_id, msg);
|
);
|
||||||
} else {
|
Some((res, htlc_id))
|
||||||
panic!("Stated return value requirements in queue_fail_malformed_htlc() were not met");
|
|
||||||
}
|
|
||||||
// fail-backs are best-effort, we probably already have one
|
|
||||||
// pending, and if not that's OK, if not, the channel is on
|
|
||||||
// the chain and sending the HTLC-Timeout is their problem.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
};
|
||||||
|
if let Some((queue_fail_htlc_res, htlc_id)) = queue_fail_htlc_res {
|
||||||
|
if let Err(e) = queue_fail_htlc_res {
|
||||||
|
if let ChannelError::Ignore(msg) = e {
|
||||||
|
log_trace!(logger, "Failed to fail HTLC with ID {} backwards to short_id {}: {}", htlc_id, short_chan_id, msg);
|
||||||
|
} else {
|
||||||
|
panic!("Stated return value requirements in queue_fail_{{malformed_}}htlc() were not met");
|
||||||
|
}
|
||||||
|
// fail-backs are best-effort, we probably already have one
|
||||||
|
// pending, and if not that's OK, if not, the channel is on
|
||||||
|
// the chain and sending the HTLC-Timeout is their problem.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue