Skip to content

Commit b1cd5a7

Browse files
authored
Merge pull request #1311 from TheBlueMatt/2022-02-0conf-part-1
Support for SCID Aliases
2 parents 756bcbc + e4486fe commit b1cd5a7

13 files changed

+671
-357
lines changed

fuzz/src/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
216216
},
217217
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
218218
short_channel_id: Some(scid),
219+
inbound_scid_alias: None,
219220
channel_value_satoshis: slice_to_be64(get_slice!(8)),
220221
user_channel_id: 0, inbound_capacity_msat: 0,
221222
unspendable_punishment_reserve: None,

lightning-invoice/src/utils.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn create_phantom_invoice<Signer: Sign, K: Deref>(
6868

6969
for hint in phantom_route_hints {
7070
for channel in &hint.channels {
71-
let short_channel_id = match channel.short_channel_id {
71+
let short_channel_id = match channel.get_inbound_payment_scid() {
7272
Some(id) => id,
7373
None => continue,
7474
};
@@ -165,7 +165,7 @@ where
165165
let our_channels = channelmanager.list_usable_channels();
166166
let mut route_hints = vec![];
167167
for channel in our_channels {
168-
let short_channel_id = match channel.short_channel_id {
168+
let short_channel_id = match channel.get_inbound_payment_scid() {
169169
Some(id) => id,
170170
None => continue,
171171
};
@@ -325,6 +325,13 @@ mod test {
325325
assert_eq!(invoice.min_final_cltv_expiry(), MIN_FINAL_CLTV_EXPIRY as u64);
326326
assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string())));
327327

328+
// Invoice SCIDs should always use inbound SCID aliases over the real channel ID, if one is
329+
// available.
330+
assert_eq!(invoice.route_hints().len(), 1);
331+
assert_eq!(invoice.route_hints()[0].0.len(), 1);
332+
assert_eq!(invoice.route_hints()[0].0[0].short_channel_id,
333+
nodes[1].node.list_usable_channels()[0].inbound_scid_alias.unwrap());
334+
328335
let payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key())
329336
.with_features(invoice.features().unwrap().clone())
330337
.with_route_hints(invoice.route_hints());

lightning/src/ln/channel.rs

Lines changed: 93 additions & 21 deletions
Large diffs are not rendered by default.

lightning/src/ln/channelmanager.rs

Lines changed: 188 additions & 75 deletions
Large diffs are not rendered by default.

lightning/src/ln/functional_test_utils.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,61 @@ pub fn create_announced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &'a
693693
(chan_announcement.1, chan_announcement.2, chan_announcement.3, chan_announcement.4)
694694
}
695695

696+
pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &'a Vec<Node<'b, 'c, 'd>>, a: usize, b: usize, channel_value: u64, push_msat: u64, a_flags: InitFeatures, b_flags: InitFeatures) -> (msgs::FundingLocked, Transaction) {
697+
let mut no_announce_cfg = test_default_channel_config();
698+
no_announce_cfg.channel_options.announced_channel = false;
699+
nodes[a].node.create_channel(nodes[b].node.get_our_node_id(), channel_value, push_msat, 42, Some(no_announce_cfg)).unwrap();
700+
let open_channel = get_event_msg!(nodes[a], MessageSendEvent::SendOpenChannel, nodes[b].node.get_our_node_id());
701+
nodes[b].node.handle_open_channel(&nodes[a].node.get_our_node_id(), a_flags, &open_channel);
702+
let accept_channel = get_event_msg!(nodes[b], MessageSendEvent::SendAcceptChannel, nodes[a].node.get_our_node_id());
703+
nodes[a].node.handle_accept_channel(&nodes[b].node.get_our_node_id(), b_flags, &accept_channel);
704+
705+
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[a], channel_value, 42);
706+
nodes[a].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
707+
nodes[b].node.handle_funding_created(&nodes[a].node.get_our_node_id(), &get_event_msg!(nodes[a], MessageSendEvent::SendFundingCreated, nodes[b].node.get_our_node_id()));
708+
check_added_monitors!(nodes[b], 1);
709+
710+
let cs_funding_signed = get_event_msg!(nodes[b], MessageSendEvent::SendFundingSigned, nodes[a].node.get_our_node_id());
711+
nodes[a].node.handle_funding_signed(&nodes[b].node.get_our_node_id(), &cs_funding_signed);
712+
check_added_monitors!(nodes[a], 1);
713+
714+
let conf_height = core::cmp::max(nodes[a].best_block_info().1 + 1, nodes[b].best_block_info().1 + 1);
715+
confirm_transaction_at(&nodes[a], &tx, conf_height);
716+
connect_blocks(&nodes[a], CHAN_CONFIRM_DEPTH - 1);
717+
confirm_transaction_at(&nodes[b], &tx, conf_height);
718+
connect_blocks(&nodes[b], CHAN_CONFIRM_DEPTH - 1);
719+
let as_funding_locked = get_event_msg!(nodes[a], MessageSendEvent::SendFundingLocked, nodes[b].node.get_our_node_id());
720+
nodes[a].node.handle_funding_locked(&nodes[b].node.get_our_node_id(), &get_event_msg!(nodes[b], MessageSendEvent::SendFundingLocked, nodes[a].node.get_our_node_id()));
721+
let as_update = get_event_msg!(nodes[a], MessageSendEvent::SendChannelUpdate, nodes[b].node.get_our_node_id());
722+
nodes[b].node.handle_funding_locked(&nodes[a].node.get_our_node_id(), &as_funding_locked);
723+
let bs_update = get_event_msg!(nodes[b], MessageSendEvent::SendChannelUpdate, nodes[a].node.get_our_node_id());
724+
725+
nodes[a].node.handle_channel_update(&nodes[b].node.get_our_node_id(), &bs_update);
726+
nodes[b].node.handle_channel_update(&nodes[a].node.get_our_node_id(), &as_update);
727+
728+
let mut found_a = false;
729+
for chan in nodes[a].node.list_usable_channels() {
730+
if chan.channel_id == as_funding_locked.channel_id {
731+
assert!(!found_a);
732+
found_a = true;
733+
assert!(!chan.is_public);
734+
}
735+
}
736+
assert!(found_a);
737+
738+
let mut found_b = false;
739+
for chan in nodes[b].node.list_usable_channels() {
740+
if chan.channel_id == as_funding_locked.channel_id {
741+
assert!(!found_b);
742+
found_b = true;
743+
assert!(!chan.is_public);
744+
}
745+
}
746+
assert!(found_b);
747+
748+
(as_funding_locked, tx)
749+
}
750+
696751
pub fn update_nodes_with_chan_announce<'a, 'b, 'c, 'd>(nodes: &'a Vec<Node<'b, 'c, 'd>>, a: usize, b: usize, ann: &msgs::ChannelAnnouncement, upd_1: &msgs::ChannelUpdate, upd_2: &msgs::ChannelUpdate) {
697752
nodes[a].node.broadcast_node_announcement([0, 0, 0], [0; 32], Vec::new());
698753
let a_events = nodes[a].node.get_and_clear_pending_msg_events();
@@ -748,6 +803,11 @@ pub fn update_nodes_with_chan_announce<'a, 'b, 'c, 'd>(nodes: &'a Vec<Node<'b, '
748803
node.net_graph_msg_handler.handle_channel_update(upd_2).unwrap();
749804
node.net_graph_msg_handler.handle_node_announcement(&a_node_announcement).unwrap();
750805
node.net_graph_msg_handler.handle_node_announcement(&b_node_announcement).unwrap();
806+
807+
// Note that channel_updates are also delivered to ChannelManagers to ensure we have
808+
// forwarding info for local channels even if its not accepted in the network graph.
809+
node.node.handle_channel_update(&nodes[a].node.get_our_node_id(), &upd_1);
810+
node.node.handle_channel_update(&nodes[b].node.get_our_node_id(), &upd_2);
751811
}
752812
}
753813

0 commit comments

Comments
 (0)