Skip to content

Commit a40f05b

Browse files
committed
f Address rustfmt comments
1 parent 21afc58 commit a40f05b

1 file changed

Lines changed: 41 additions & 103 deletions

File tree

lightning/src/routing/utxo.rs

Lines changed: 41 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -655,30 +655,24 @@ mod tests {
655655
let node_a_announce = get_signed_node_announcement(|_| {}, node_1_privkey, &secp_ctx);
656656
let node_b_announce = get_signed_node_announcement(|_| {}, node_2_privkey, &secp_ctx);
657657

658-
// Note that we have to set the "direction" flag correctly on both messages
659-
let chan_update_a =
660-
get_signed_channel_update(|msg| msg.channel_flags = 0, node_1_privkey, &secp_ctx);
661-
let chan_update_b =
662-
get_signed_channel_update(|msg| msg.channel_flags = 1, node_2_privkey, &secp_ctx);
663-
let chan_update_c = get_signed_channel_update(
664-
|msg| {
665-
msg.channel_flags = 1;
666-
msg.timestamp += 1;
667-
},
668-
node_2_privkey,
669-
&secp_ctx,
670-
);
671-
672658
(
673659
valid_announcement,
674660
chain_source,
675661
network_graph,
676662
good_script,
677663
node_a_announce,
678664
node_b_announce,
679-
chan_update_a,
680-
chan_update_b,
681-
chan_update_c,
665+
get_signed_channel_update(|msg| msg.channel_flags = 0, node_1_privkey, &secp_ctx),
666+
get_signed_channel_update(|msg| msg.channel_flags = 1, node_2_privkey, &secp_ctx),
667+
// Note that we have to set the "direction" flag correctly on both messages
668+
get_signed_channel_update(
669+
|msg| {
670+
msg.channel_flags = 1;
671+
msg.timestamp += 1;
672+
},
673+
node_2_privkey,
674+
&secp_ctx,
675+
),
682676
)
683677
}
684678

@@ -687,6 +681,7 @@ mod tests {
687681
// Check that async lookups which resolve quicker than the future is returned to the
688682
// `get_utxo` call can read it still resolve properly.
689683
let (valid_announcement, chain_source, network_graph, good_script, ..) = get_test_objects();
684+
let scid = valid_announcement.contents.short_channel_id;
690685

691686
let notifier = Arc::new(Notifier::new());
692687
let future = UtxoFuture::new(Arc::clone(&notifier));
@@ -699,11 +694,7 @@ mod tests {
699694
network_graph
700695
.update_channel_from_announcement(&valid_announcement, &Some(&chain_source))
701696
.unwrap();
702-
assert!(network_graph
703-
.read_only()
704-
.channels()
705-
.get(&valid_announcement.contents.short_channel_id)
706-
.is_some());
697+
assert!(network_graph.read_only().channels().get(&scid).is_some());
707698
}
708699

709700
#[test]
@@ -718,6 +709,8 @@ mod tests {
718709
node_b_announce,
719710
..,
720711
) = get_test_objects();
712+
let scid = valid_announcement.contents.short_channel_id;
713+
let node_id_1 = valid_announcement.contents.node_id_1;
721714

722715
let notifier = Arc::new(Notifier::new());
723716
let future = UtxoFuture::new(Arc::clone(&notifier));
@@ -730,30 +723,18 @@ mod tests {
730723
.err,
731724
"Channel being checked async"
732725
);
733-
assert!(network_graph
734-
.read_only()
735-
.channels()
736-
.get(&valid_announcement.contents.short_channel_id)
737-
.is_none());
726+
assert!(network_graph.read_only().channels().get(&scid).is_none());
738727

739728
future.resolve(Ok(TxOut { value: Amount::ZERO, script_pubkey: good_script }));
740729
assert!(notifier.notify_pending());
741730
network_graph.pending_checks.check_resolved_futures(&network_graph);
742-
network_graph
743-
.read_only()
744-
.channels()
745-
.get(&valid_announcement.contents.short_channel_id)
746-
.unwrap();
747-
network_graph
748-
.read_only()
749-
.channels()
750-
.get(&valid_announcement.contents.short_channel_id)
751-
.unwrap();
731+
network_graph.read_only().channels().get(&scid).unwrap();
732+
network_graph.read_only().channels().get(&scid).unwrap();
752733

753734
assert!(network_graph
754735
.read_only()
755736
.nodes()
756-
.get(&valid_announcement.contents.node_id_1)
737+
.get(&node_id_1)
757738
.unwrap()
758739
.announcement_info
759740
.is_none());
@@ -764,7 +745,7 @@ mod tests {
764745
assert!(network_graph
765746
.read_only()
766747
.nodes()
767-
.get(&valid_announcement.contents.node_id_1)
748+
.get(&node_id_1)
768749
.unwrap()
769750
.announcement_info
770751
.is_some());
@@ -774,6 +755,7 @@ mod tests {
774755
fn test_invalid_async_lookup() {
775756
// Test an async lookup which returns an incorrect script
776757
let (valid_announcement, chain_source, network_graph, ..) = get_test_objects();
758+
let scid = valid_announcement.contents.short_channel_id;
777759

778760
let notifier = Arc::new(Notifier::new());
779761
let future = UtxoFuture::new(Arc::clone(&notifier));
@@ -786,27 +768,20 @@ mod tests {
786768
.err,
787769
"Channel being checked async"
788770
);
789-
assert!(network_graph
790-
.read_only()
791-
.channels()
792-
.get(&valid_announcement.contents.short_channel_id)
793-
.is_none());
771+
assert!(network_graph.read_only().channels().get(&scid).is_none());
794772

795773
let value = Amount::from_sat(1_000_000);
796774
future.resolve(Ok(TxOut { value, script_pubkey: bitcoin::ScriptBuf::new() }));
797775
assert!(notifier.notify_pending());
798776
network_graph.pending_checks.check_resolved_futures(&network_graph);
799-
assert!(network_graph
800-
.read_only()
801-
.channels()
802-
.get(&valid_announcement.contents.short_channel_id)
803-
.is_none());
777+
assert!(network_graph.read_only().channels().get(&scid).is_none());
804778
}
805779

806780
#[test]
807781
fn test_failing_async_lookup() {
808782
// Test an async lookup which returns an error
809783
let (valid_announcement, chain_source, network_graph, ..) = get_test_objects();
784+
let scid = valid_announcement.contents.short_channel_id;
810785

811786
let notifier = Arc::new(Notifier::new());
812787
let future = UtxoFuture::new(Arc::clone(&notifier));
@@ -819,20 +794,12 @@ mod tests {
819794
.err,
820795
"Channel being checked async"
821796
);
822-
assert!(network_graph
823-
.read_only()
824-
.channels()
825-
.get(&valid_announcement.contents.short_channel_id)
826-
.is_none());
797+
assert!(network_graph.read_only().channels().get(&scid).is_none());
827798

828799
future.resolve(Err(UtxoLookupError::UnknownTx));
829800
assert!(notifier.notify_pending());
830801
network_graph.pending_checks.check_resolved_futures(&network_graph);
831-
assert!(network_graph
832-
.read_only()
833-
.channels()
834-
.get(&valid_announcement.contents.short_channel_id)
835-
.is_none());
802+
assert!(network_graph.read_only().channels().get(&scid).is_none());
836803
}
837804

838805
#[test]
@@ -850,6 +817,7 @@ mod tests {
850817
chan_update_b,
851818
..,
852819
) = get_test_objects();
820+
let scid = valid_announcement.contents.short_channel_id;
853821

854822
let notifier = Arc::new(Notifier::new());
855823
let future = UtxoFuture::new(Arc::clone(&notifier));
@@ -862,11 +830,7 @@ mod tests {
862830
.err,
863831
"Channel being checked async"
864832
);
865-
assert!(network_graph
866-
.read_only()
867-
.channels()
868-
.get(&valid_announcement.contents.short_channel_id)
869-
.is_none());
833+
assert!(network_graph.read_only().channels().get(&scid).is_none());
870834

871835
assert_eq!(
872836
network_graph.update_node_from_announcement(&node_a_announce).unwrap_err().err,
@@ -892,20 +856,8 @@ mod tests {
892856
assert!(notifier.notify_pending());
893857
network_graph.pending_checks.check_resolved_futures(&network_graph);
894858

895-
assert!(network_graph
896-
.read_only()
897-
.channels()
898-
.get(&valid_announcement.contents.short_channel_id)
899-
.unwrap()
900-
.one_to_two
901-
.is_some());
902-
assert!(network_graph
903-
.read_only()
904-
.channels()
905-
.get(&valid_announcement.contents.short_channel_id)
906-
.unwrap()
907-
.two_to_one
908-
.is_some());
859+
assert!(network_graph.read_only().channels().get(&scid).unwrap().one_to_two.is_some());
860+
assert!(network_graph.read_only().channels().get(&scid).unwrap().two_to_one.is_some());
909861

910862
assert!(network_graph
911863
.read_only()
@@ -939,6 +891,7 @@ mod tests {
939891
chan_update_c,
940892
..,
941893
) = get_test_objects();
894+
let scid = valid_announcement.contents.short_channel_id;
942895

943896
let notifier = Arc::new(Notifier::new());
944897
let future = UtxoFuture::new(Arc::clone(&notifier));
@@ -951,11 +904,7 @@ mod tests {
951904
.err,
952905
"Channel being checked async"
953906
);
954-
assert!(network_graph
955-
.read_only()
956-
.channels()
957-
.get(&valid_announcement.contents.short_channel_id)
958-
.is_none());
907+
assert!(network_graph.read_only().channels().get(&scid).is_none());
959908

960909
assert_eq!(
961910
network_graph.update_channel(&chan_update_a).unwrap_err().err,
@@ -978,32 +927,21 @@ mod tests {
978927

979928
assert_eq!(chan_update_a.contents.timestamp, chan_update_b.contents.timestamp);
980929
let graph_lock = network_graph.read_only();
981-
assert!(
982-
graph_lock
983-
.channels()
984-
.get(&valid_announcement.contents.short_channel_id)
985-
.as_ref()
986-
.unwrap()
987-
.one_to_two
988-
.as_ref()
989-
.unwrap()
990-
.last_update != graph_lock
991-
.channels()
992-
.get(&valid_announcement.contents.short_channel_id)
993-
.as_ref()
994-
.unwrap()
995-
.two_to_one
996-
.as_ref()
997-
.unwrap()
998-
.last_update
999-
);
930+
#[rustfmt::skip]
931+
let one_to_two_update =
932+
graph_lock.channels().get(&scid).as_ref().unwrap().one_to_two.as_ref().unwrap().last_update;
933+
#[rustfmt::skip]
934+
let two_to_one_update =
935+
graph_lock.channels().get(&scid).as_ref().unwrap().two_to_one.as_ref().unwrap().last_update;
936+
assert!(one_to_two_update != two_to_one_update);
1000937
}
1001938

1002939
#[test]
1003940
fn test_no_double_lookups() {
1004941
// Test that a pending async lookup will prevent a second async lookup from flying, but
1005942
// only if the channel_announcement message is identical.
1006943
let (valid_announcement, chain_source, network_graph, good_script, ..) = get_test_objects();
944+
let scid = valid_announcement.contents.short_channel_id;
1007945

1008946
let notifier_a = Arc::new(Notifier::new());
1009947
let future = UtxoFuture::new(Arc::clone(&notifier_a));
@@ -1056,7 +994,7 @@ mod tests {
1056994
assert!(!network_graph
1057995
.read_only()
1058996
.channels()
1059-
.get(&valid_announcement.contents.short_channel_id)
997+
.get(&scid)
1060998
.unwrap()
1061999
.announcement_message
10621000
.as_ref()

0 commit comments

Comments
 (0)