Skip to content

Commit 7204fde

Browse files
committed
Get rid of legacy multi-chain methods
1 parent f665bb2 commit 7204fde

File tree

2 files changed

+42
-64
lines changed

2 files changed

+42
-64
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -516,18 +516,6 @@ impl NetworkGraph {
516516
self.nodes.insert(node_id, node_info);
517517
}
518518

519-
#[inline]
520-
/// Key used to link channel on the Bitcoin chain to other entities
521-
pub fn get_key(short_channel_id: u64, _: Sha256dHash) -> u64 {
522-
short_channel_id
523-
}
524-
525-
#[inline]
526-
/// Key used to link channel on the Bitcoin chain to other entities
527-
pub fn get_short_id(id: &u64) -> &u64 {
528-
id
529-
}
530-
531519
fn process_node_announcement(&mut self, msg: &msgs::NodeAnnouncement) -> Result<bool, LightningError> {
532520
match self.nodes.get_mut(&msg.contents.node_id) {
533521
None => Err(LightningError{err: "No existing channels for node_announcement", action: ErrorAction::IgnoreError}),
@@ -584,7 +572,7 @@ impl NetworkGraph {
584572
announcement_message: if should_relay { Some(msg.clone()) } else { None },
585573
};
586574

587-
match self.channels.entry(NetworkGraph::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)) {
575+
match self.channels.entry(msg.contents.short_channel_id) {
588576
BtreeEntry::Occupied(mut entry) => {
589577
//TODO: because asking the blockchain if short_channel_id is valid is only optional
590578
//in the blockchain API, we need to handle it smartly here, though it's unclear
@@ -613,11 +601,11 @@ impl NetworkGraph {
613601
( $node_id: expr ) => {
614602
match self.nodes.entry($node_id) {
615603
BtreeEntry::Occupied(node_entry) => {
616-
node_entry.into_mut().channels.push(NetworkGraph::get_key(msg.contents.short_channel_id, msg.contents.chain_hash));
604+
node_entry.into_mut().channels.push(msg.contents.short_channel_id);
617605
},
618606
BtreeEntry::Vacant(node_entry) => {
619607
node_entry.insert(NodeInfo {
620-
channels: vec!(NetworkGraph::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)),
608+
channels: vec!(msg.contents.short_channel_id),
621609
lowest_inbound_channel_fees: None,
622610
features: NodeFeatures::empty(),
623611
last_update: None,
@@ -663,7 +651,7 @@ impl NetworkGraph {
663651
let chan_enabled = msg.contents.flags & (1 << 1) != (1 << 1);
664652
let chan_was_enabled;
665653

666-
match self.channels.get_mut(&NetworkGraph::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)) {
654+
match self.channels.get_mut(&msg.contents.short_channel_id) {
667655
None => return Err(LightningError{err: "Couldn't find channel for update", action: ErrorAction::IgnoreError}),
668656
Some(channel) => {
669657
macro_rules! maybe_update_channel_info {
@@ -747,7 +735,7 @@ impl NetworkGraph {
747735
($node_id: expr) => {
748736
if let BtreeEntry::Occupied(mut entry) = nodes.entry($node_id) {
749737
entry.get_mut().channels.retain(|chan_id| {
750-
short_channel_id != *NetworkGraph::get_short_id(chan_id)
738+
short_channel_id != *chan_id
751739
});
752740
if entry.get().channels.is_empty() {
753741
entry.remove_entry();
@@ -953,9 +941,6 @@ mod tests {
953941
excess_data: Vec::new(),
954942
};
955943

956-
let channel_key = NetworkGraph::get_key(unsigned_announcement.short_channel_id,
957-
unsigned_announcement.chain_hash);
958-
959944
let mut msghash = hash_to_message!(&Sha256dHash::hash(&unsigned_announcement.encode()[..])[..]);
960945
let valid_announcement = ChannelAnnouncement {
961946
node_signature_1: secp_ctx.sign(&msghash, node_1_privkey),
@@ -974,7 +959,7 @@ mod tests {
974959
};
975960
{
976961
let network = net_graph_msg_handler.network_graph.write().unwrap();
977-
match network.channels.get(&channel_key) {
962+
match network.channels.get(&unsigned_announcement.short_channel_id) {
978963
None => panic!(),
979964
Some(_) => ()
980965
}
@@ -1010,8 +995,6 @@ mod tests {
1010995
// Now test if the transaction is found in the UTXO set and the script is correct.
1011996
unsigned_announcement.short_channel_id += 1;
1012997
*chain_monitor.utxo_ret.lock().unwrap() = Ok((good_script.clone(), 0));
1013-
let channel_key = NetworkGraph::get_key(unsigned_announcement.short_channel_id,
1014-
unsigned_announcement.chain_hash);
1015998

1016999
msghash = hash_to_message!(&Sha256dHash::hash(&unsigned_announcement.encode()[..])[..]);
10171000
let valid_announcement = ChannelAnnouncement {
@@ -1027,7 +1010,7 @@ mod tests {
10271010
};
10281011
{
10291012
let network = net_graph_msg_handler.network_graph.write().unwrap();
1030-
match network.channels.get(&channel_key) {
1013+
match network.channels.get(&unsigned_announcement.short_channel_id) {
10311014
None => panic!(),
10321015
Some(_) => ()
10331016
}
@@ -1058,7 +1041,7 @@ mod tests {
10581041
};
10591042
{
10601043
let mut network = net_graph_msg_handler.network_graph.write().unwrap();
1061-
match network.channels.entry(channel_key) {
1044+
match network.channels.entry(unsigned_announcement.short_channel_id) {
10621045
BtreeEntry::Occupied(channel_entry) => {
10631046
assert_eq!(channel_entry.get().features, ChannelFeatures::empty());
10641047
},
@@ -1123,9 +1106,6 @@ mod tests {
11231106
let zero_hash = Sha256dHash::hash(&[0; 32]);
11241107
let short_channel_id = 0;
11251108
let chain_hash = genesis_block(Network::Testnet).header.bitcoin_hash();
1126-
let channel_key = NetworkGraph::get_key(short_channel_id, chain_hash);
1127-
1128-
11291109
{
11301110
// Announce a channel we will update
11311111
let unsigned_announcement = UnsignedChannelAnnouncement {
@@ -1178,7 +1158,7 @@ mod tests {
11781158

11791159
{
11801160
let network = net_graph_msg_handler.network_graph.write().unwrap();
1181-
match network.channels.get(&channel_key) {
1161+
match network.channels.get(&short_channel_id) {
11821162
None => panic!(),
11831163
Some(channel_info) => {
11841164
assert_eq!(channel_info.one_to_two.cltv_expiry_delta, 144);
@@ -1254,7 +1234,6 @@ mod tests {
12541234

12551235
let short_channel_id = 0;
12561236
let chain_hash = genesis_block(Network::Testnet).header.bitcoin_hash();
1257-
let channel_key = NetworkGraph::get_key(short_channel_id, chain_hash);
12581237

12591238
{
12601239
// There is only local node in the table at the beginning.
@@ -1301,7 +1280,7 @@ mod tests {
13011280
{
13021281
// Non-permanent closing just disables a channel
13031282
let network = net_graph_msg_handler.network_graph.write().unwrap();
1304-
match network.channels.get(&channel_key) {
1283+
match network.channels.get(&short_channel_id) {
13051284
None => panic!(),
13061285
Some(channel_info) => {
13071286
assert!(!channel_info.one_to_two.enabled);
@@ -1342,7 +1321,6 @@ mod tests {
13421321

13431322
let short_channel_id = 1;
13441323
let chain_hash = genesis_block(Network::Testnet).header.bitcoin_hash();
1345-
let channel_key = NetworkGraph::get_key(short_channel_id, chain_hash);
13461324

13471325
// Channels were not announced yet.
13481326
let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(0, 1);
@@ -1376,7 +1354,7 @@ mod tests {
13761354
}
13771355

13781356
// Contains initial channel announcement now.
1379-
let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(channel_key, 1);
1357+
let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(short_channel_id, 1);
13801358
assert_eq!(channels_with_announcements.len(), 1);
13811359
if let Some(channel_announcements) = channels_with_announcements.first() {
13821360
let &(_, ref update_1, ref update_2) = channel_announcements;
@@ -1412,7 +1390,7 @@ mod tests {
14121390
}
14131391

14141392
// Now contains an initial announcement and an update.
1415-
let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(channel_key, 1);
1393+
let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(short_channel_id, 1);
14161394
assert_eq!(channels_with_announcements.len(), 1);
14171395
if let Some(channel_announcements) = channels_with_announcements.first() {
14181396
let &(_, ref update_1, ref update_2) = channel_announcements;
@@ -1448,7 +1426,7 @@ mod tests {
14481426
}
14491427

14501428
// Test that announcements with excess data won't be returned
1451-
let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(channel_key, 1);
1429+
let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(short_channel_id, 1);
14521430
assert_eq!(channels_with_announcements.len(), 1);
14531431
if let Some(channel_announcements) = channels_with_announcements.first() {
14541432
let &(_, ref update_1, ref update_2) = channel_announcements;
@@ -1459,7 +1437,7 @@ mod tests {
14591437
}
14601438

14611439
// Further starting point have no channels after it
1462-
let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(channel_key + 1000, 1);
1440+
let channels_with_announcements = net_graph_msg_handler.get_next_channel_announcements(short_channel_id + 1000, 1);
14631441
assert_eq!(channels_with_announcements.len(), 0);
14641442
}
14651443

@@ -1595,7 +1573,7 @@ mod tests {
15951573
proportional_millionths: 0,
15961574
};
15971575
network.add_node(node1.clone(), NodeInfo {
1598-
channels: vec!(NetworkGraph::get_key(1, zero_hash.clone()), NetworkGraph::get_key(3, zero_hash.clone())),
1576+
channels: vec!(1, 3),
15991577
lowest_inbound_channel_fees: Some(node_routing_fees),
16001578
features: NodeFeatures::supported(),
16011579
last_update: Some(1),
@@ -1604,7 +1582,7 @@ mod tests {
16041582
addresses: Vec::new(),
16051583
announcement_message: None,
16061584
});
1607-
network.add_channel(NetworkGraph::get_key(1, zero_hash.clone()), ChannelInfo {
1585+
network.add_channel(1, ChannelInfo {
16081586
features: ChannelFeatures::supported(),
16091587
one_to_two: DirectionalChannelInfo {
16101588
src_node_id: our_id.clone(),

lightning/src/routing/router.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ mod tests {
513513
proportional_millionths: 0
514514
};
515515
network.add_node(node1.clone(), NodeInfo {
516-
channels: vec!(NetworkGraph::get_key(1, zero_hash.clone()), NetworkGraph::get_key(3, zero_hash.clone())),
516+
channels: vec!(1, 3),
517517
lowest_inbound_channel_fees: Some(lowest_routing_fees),
518518
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(1)),
519519
last_update: Some(1),
@@ -522,7 +522,7 @@ mod tests {
522522
addresses: Vec::new(),
523523
announcement_message: None,
524524
});
525-
network.add_channel(NetworkGraph::get_key(1, zero_hash.clone()), ChannelInfo {
525+
network.add_channel(1, ChannelInfo {
526526
features: ChannelFeatures::from_le_bytes(id_to_feature_flags!(1)),
527527
one_to_two: DirectionalChannelInfo {
528528
src_node_id: our_id.clone(),
@@ -551,7 +551,7 @@ mod tests {
551551
proportional_millionths: 0
552552
};
553553
network.add_node(node2.clone(), NodeInfo {
554-
channels: vec!(NetworkGraph::get_key(2, zero_hash.clone()), NetworkGraph::get_key(4, zero_hash.clone())),
554+
channels: vec!(2, 4),
555555
lowest_inbound_channel_fees: Some(routing_fees.clone()),
556556
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(2)),
557557
last_update: Some(1),
@@ -560,7 +560,7 @@ mod tests {
560560
addresses: Vec::new(),
561561
announcement_message: None,
562562
});
563-
network.add_channel(NetworkGraph::get_key(2, zero_hash.clone()), ChannelInfo {
563+
network.add_channel(2, ChannelInfo {
564564
features: ChannelFeatures::from_le_bytes(id_to_feature_flags!(2)),
565565
one_to_two: DirectionalChannelInfo {
566566
src_node_id: our_id.clone(),
@@ -585,7 +585,7 @@ mod tests {
585585
announcement_message: None,
586586
});
587587
network.add_node(node8.clone(), NodeInfo {
588-
channels: vec!(NetworkGraph::get_key(12, zero_hash.clone()), NetworkGraph::get_key(13, zero_hash.clone())),
588+
channels: vec!(12, 13),
589589
lowest_inbound_channel_fees: Some(routing_fees.clone()),
590590
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(8)),
591591
last_update: Some(1),
@@ -594,7 +594,7 @@ mod tests {
594594
addresses: Vec::new(),
595595
announcement_message: None,
596596
});
597-
network.add_channel(NetworkGraph::get_key(12, zero_hash.clone()), ChannelInfo {
597+
network.add_channel(12, ChannelInfo {
598598
features: ChannelFeatures::from_le_bytes(id_to_feature_flags!(12)),
599599
one_to_two: DirectionalChannelInfo {
600600
src_node_id: our_id.clone(),
@@ -620,12 +620,12 @@ mod tests {
620620
});
621621
network.add_node(node3.clone(), NodeInfo {
622622
channels: vec!(
623-
NetworkGraph::get_key(3, zero_hash.clone()),
624-
NetworkGraph::get_key(4, zero_hash.clone()),
625-
NetworkGraph::get_key(13, zero_hash.clone()),
626-
NetworkGraph::get_key(5, zero_hash.clone()),
627-
NetworkGraph::get_key(6, zero_hash.clone()),
628-
NetworkGraph::get_key(7, zero_hash.clone())),
623+
3,
624+
4,
625+
13,
626+
5,
627+
6,
628+
7),
629629
lowest_inbound_channel_fees: Some(routing_fees.clone()),
630630
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(3)),
631631
last_update: Some(1),
@@ -634,7 +634,7 @@ mod tests {
634634
addresses: Vec::new(),
635635
announcement_message: None,
636636
});
637-
network.add_channel(NetworkGraph::get_key(3, zero_hash.clone()), ChannelInfo {
637+
network.add_channel(3, ChannelInfo {
638638
features: ChannelFeatures::from_le_bytes(id_to_feature_flags!(3)),
639639
one_to_two: DirectionalChannelInfo {
640640
src_node_id: node1.clone(),
@@ -658,7 +658,7 @@ mod tests {
658658
},
659659
announcement_message: None,
660660
});
661-
network.add_channel(NetworkGraph::get_key(4, zero_hash.clone()), ChannelInfo {
661+
network.add_channel(4, ChannelInfo {
662662
features: ChannelFeatures::from_le_bytes(id_to_feature_flags!(4)),
663663
one_to_two: DirectionalChannelInfo {
664664
src_node_id: node2.clone(),
@@ -682,7 +682,7 @@ mod tests {
682682
},
683683
announcement_message: None,
684684
});
685-
network.add_channel(NetworkGraph::get_key(13, zero_hash.clone()), ChannelInfo {
685+
network.add_channel(13, ChannelInfo {
686686
features: ChannelFeatures::from_le_bytes(id_to_feature_flags!(13)),
687687
one_to_two: DirectionalChannelInfo {
688688
src_node_id: node8.clone(),
@@ -707,7 +707,7 @@ mod tests {
707707
announcement_message: None,
708708
});
709709
network.add_node(node4.clone(), NodeInfo {
710-
channels: vec!(NetworkGraph::get_key(5, zero_hash.clone()), NetworkGraph::get_key(11, zero_hash.clone())),
710+
channels: vec!(5, 11),
711711
lowest_inbound_channel_fees: Some(routing_fees.clone()),
712712
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(4)),
713713
last_update: Some(1),
@@ -716,7 +716,7 @@ mod tests {
716716
addresses: Vec::new(),
717717
announcement_message: None,
718718
});
719-
network.add_channel(NetworkGraph::get_key(5, zero_hash.clone()), ChannelInfo {
719+
network.add_channel(5, ChannelInfo {
720720
features: ChannelFeatures::from_le_bytes(id_to_feature_flags!(5)),
721721
one_to_two: DirectionalChannelInfo {
722722
src_node_id: node3.clone(),
@@ -741,7 +741,7 @@ mod tests {
741741
announcement_message: None,
742742
});
743743
network.add_node(node5.clone(), NodeInfo {
744-
channels: vec!(NetworkGraph::get_key(6, zero_hash.clone()), NetworkGraph::get_key(11, zero_hash.clone())),
744+
channels: vec!(6, 11),
745745
lowest_inbound_channel_fees: Some(routing_fees.clone()),
746746
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(5)),
747747
last_update: Some(1),
@@ -750,7 +750,7 @@ mod tests {
750750
addresses: Vec::new(),
751751
announcement_message: None,
752752
});
753-
network.add_channel(NetworkGraph::get_key(6, zero_hash.clone()), ChannelInfo {
753+
network.add_channel(6, ChannelInfo {
754754
features: ChannelFeatures::from_le_bytes(id_to_feature_flags!(6)),
755755
one_to_two: DirectionalChannelInfo {
756756
src_node_id: node3.clone(),
@@ -771,7 +771,7 @@ mod tests {
771771
},
772772
announcement_message: None,
773773
});
774-
network.add_channel(NetworkGraph::get_key(11, zero_hash.clone()), ChannelInfo {
774+
network.add_channel(11, ChannelInfo {
775775
features: ChannelFeatures::from_le_bytes(id_to_feature_flags!(11)),
776776
one_to_two: DirectionalChannelInfo {
777777
src_node_id: node5.clone(),
@@ -793,7 +793,7 @@ mod tests {
793793
announcement_message: None,
794794
});
795795
network.add_node(node6.clone(), NodeInfo {
796-
channels: vec!(NetworkGraph::get_key(7, zero_hash.clone())),
796+
channels: vec!(7),
797797
lowest_inbound_channel_fees: Some(routing_fees.clone()),
798798
features: NodeFeatures::from_le_bytes(id_to_feature_flags!(6)),
799799
last_update: Some(1),
@@ -802,7 +802,7 @@ mod tests {
802802
addresses: Vec::new(),
803803
announcement_message: None,
804804
});
805-
network.add_channel(NetworkGraph::get_key(7, zero_hash.clone()), ChannelInfo {
805+
network.add_channel(7, ChannelInfo {
806806
features: ChannelFeatures::from_le_bytes(id_to_feature_flags!(7)),
807807
one_to_two: DirectionalChannelInfo {
808808
src_node_id: node3.clone(),
@@ -849,8 +849,8 @@ mod tests {
849849

850850
{ // Disable channels 4 and 12 by requiring unknown feature bits
851851
let mut network = net_graph_msg_handler.network_graph.write().unwrap();
852-
network.get_channel_mut(&NetworkGraph::get_key(4, zero_hash.clone())).unwrap().features.set_require_unknown_bits();
853-
network.get_channel_mut(&NetworkGraph::get_key(12, zero_hash.clone())).unwrap().features.set_require_unknown_bits();
852+
network.get_channel_mut(&4).unwrap().features.set_require_unknown_bits();
853+
network.get_channel_mut(&12).unwrap().features.set_require_unknown_bits();
854854
}
855855

856856
{ // If all the channels require some features we don't understand, route should fail
@@ -891,8 +891,8 @@ mod tests {
891891

892892
{ // Re-enable channels 4 and 12 by wiping the unknown feature bits
893893
let mut network = net_graph_msg_handler.network_graph.write().unwrap();
894-
network.get_channel_mut(&NetworkGraph::get_key(4, zero_hash.clone())).unwrap().features.clear_require_unknown_bits();
895-
network.get_channel_mut(&NetworkGraph::get_key(12, zero_hash.clone())).unwrap().features.clear_require_unknown_bits();
894+
network.get_channel_mut(&4).unwrap().features.clear_require_unknown_bits();
895+
network.get_channel_mut(&12).unwrap().features.clear_require_unknown_bits();
896896
}
897897

898898
{ // Disable nodes 1, 2, and 8 by requiring unknown feature bits

0 commit comments

Comments
 (0)