-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Follow-ups to #2688 #2791
Follow-ups to #2688 #2791
Changes from all commits
2917666
d0d1634
5c880a0
04e70ba
95b3ef4
c1fbb90
3ec4d52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4344,7 +4344,7 @@ where | |
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); | ||
for forward_info in pending_forwards.drain(..) { | ||
match forward_info { | ||
let queue_fail_htlc_res = match forward_info { | ||
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo { | ||
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id, | ||
forward_info: PendingHTLCInfo { | ||
|
@@ -4390,40 +4390,35 @@ where | |
)); | ||
continue; | ||
} | ||
None | ||
}, | ||
HTLCForwardInfo::AddHTLC { .. } => { | ||
panic!("short_channel_id != 0 should imply any pending_forward entries are of type Forward"); | ||
}, | ||
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); | ||
if let Err(e) = chan.queue_fail_htlc( | ||
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; | ||
} | ||
Some((chan.queue_fail_htlc(htlc_id, err_packet, &&logger), htlc_id)) | ||
}, | ||
HTLCForwardInfo::FailMalformedHTLC { htlc_id, failure_code, sha256_of_onion } => { | ||
log_trace!(self.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, &self.logger) { | ||
if let ChannelError::Ignore(msg) = e { | ||
log_trace!(self.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; | ||
} | ||
log_trace!(logger, "Failing malformed HTLC back to channel with short id {} (backward HTLC ID {}) after delay", short_chan_id, htlc_id); | ||
let res = chan.queue_fail_malformed_htlc( | ||
htlc_id, failure_code, sha256_of_onion, &&logger | ||
); | ||
Some((res, htlc_id)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason for storing the result of the function call in a variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I thought it was more readable this way since it wouldn't all fit in one line like with L4400 |
||
}, | ||
}; | ||
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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are achieving a DRY code here, and that's great! But we are also combining the panic messages that can be generated from two different sources here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point (interpreting this as "our stack trace from the panic message won't be quite as useful as we won't be able to differentiate between the two cases"), however in this case I'm not sure we care too much about being able to differentiate, so the DRYing is likely worth more. Further, we should generally be able to differentiate the cases anyway, as logs should show different messages being received. |
||
} | ||
// 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 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should revert this change.
In the reading and writing of tlvs,
sha256_of_onion
is followed byfailure_code
.And if we want to prevent tuple destructing, I think we should follow tlvs order in the rest of the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in principle I agree with you, we should have gone with (failure_code, sha256) rather than the opposite, but sadly we can't (easily) change the
InboundHTLCRemovalReason
serialization at this point, and IMO we should prefer to match our existing order everywhere rather than have a different order here. Its not all that critical in any direction, of course, though, we're talking about moving around 32+2 bytes.