Skip to content

Commit 4839ef7

Browse files
yuntaiTheBlueMatt
authored andcommitted
Include flags when sending channel_disabled onion errors
1 parent 7a8bec7 commit 4839ef7

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/ln/channelmanager.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,13 +1164,16 @@ impl ChannelManager {
11641164
}
11651165
{
11661166
let mut res = Vec::with_capacity(8 + 128);
1167-
if code == 0x1000 | 11 || code == 0x1000 | 12 {
1168-
res.extend_from_slice(&byte_utils::be64_to_array(msg.amount_msat));
1169-
}
1170-
else if code == 0x1000 | 13 {
1171-
res.extend_from_slice(&byte_utils::be32_to_array(msg.cltv_expiry));
1172-
}
11731167
if let Some(chan_update) = chan_update {
1168+
if code == 0x1000 | 11 || code == 0x1000 | 12 {
1169+
res.extend_from_slice(&byte_utils::be64_to_array(msg.amount_msat));
1170+
}
1171+
else if code == 0x1000 | 13 {
1172+
res.extend_from_slice(&byte_utils::be32_to_array(msg.cltv_expiry));
1173+
}
1174+
else if code == 0x1000 | 20 {
1175+
res.extend_from_slice(&byte_utils::be16_to_array(chan_update.contents.flags));
1176+
}
11741177
res.extend_from_slice(&chan_update.encode_with_len()[..]);
11751178
}
11761179
return_err!(err, code, &res[..]);
@@ -2084,7 +2087,12 @@ impl ChannelManager {
20842087
channel_id: msg.channel_id,
20852088
htlc_id: msg.htlc_id,
20862089
reason: if let Ok(update) = chan_update {
2087-
ChannelManager::build_first_hop_failure_packet(&incoming_shared_secret, 0x1000|20, &update.encode_with_len()[..])
2090+
ChannelManager::build_first_hop_failure_packet(&incoming_shared_secret, 0x1000|20, &{
2091+
let mut res = Vec::with_capacity(8 + 128);
2092+
res.extend_from_slice(&byte_utils::be16_to_array(update.contents.flags));
2093+
res.extend_from_slice(&update.encode_with_len()[..]);
2094+
res
2095+
}[..])
20882096
} else {
20892097
// This can only happen if the channel isn't in the fully-funded
20902098
// state yet, implying our counterparty is trying to route payments
@@ -5022,7 +5030,8 @@ mod tests {
50225030
_ => panic!("Unexpected event"),
50235031
};
50245032
match msg_events[1] {
5025-
MessageSendEvent::PaymentFailureNetworkUpdate { .. } => {
5033+
MessageSendEvent::PaymentFailureNetworkUpdate { update: msgs::HTLCFailChannelUpdate::ChannelUpdateMessage { ref msg }} => {
5034+
assert_eq!(msg.contents.short_channel_id, chan_1.0.contents.short_channel_id);
50265035
},
50275036
_ => panic!("Unexpected event"),
50285037
}
@@ -8135,7 +8144,7 @@ mod tests {
81358144
// Tests handling of a monitor update failure when processing an incoming RAA
81368145
let mut nodes = create_network(3);
81378146
create_announced_chan_between_nodes(&nodes, 0, 1);
8138-
create_announced_chan_between_nodes(&nodes, 1, 2);
8147+
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2);
81398148

81408149
// Rebalance a bit so that we can send backwards from 2 to 1.
81418150
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000);
@@ -8221,7 +8230,9 @@ mod tests {
82218230
let msg_events = nodes[0].node.get_and_clear_pending_msg_events();
82228231
assert_eq!(msg_events.len(), 1);
82238232
match msg_events[0] {
8224-
MessageSendEvent::PaymentFailureNetworkUpdate { .. } => {
8233+
MessageSendEvent::PaymentFailureNetworkUpdate { update: msgs::HTLCFailChannelUpdate::ChannelUpdateMessage { ref msg }} => {
8234+
assert_eq!(msg.contents.short_channel_id, chan_2.0.contents.short_channel_id);
8235+
assert_eq!(msg.contents.flags & 2, 2); // temp disabled
82258236
},
82268237
_ => panic!("Unexpected event"),
82278238
}

0 commit comments

Comments
 (0)