@@ -35,23 +35,12 @@ pub struct NetGraphMsgHandler {
35
35
36
36
impl NetGraphMsgHandler {
37
37
/// Creates a new tracker of the actual state of the network of channels and nodes.
38
- pub fn new ( our_pubkey : PublicKey , chain_monitor : Arc < ChainWatchInterface > , logger : Arc < Logger > ) -> Self {
39
- let mut nodes = BTreeMap :: new ( ) ;
40
- nodes. insert ( our_pubkey. clone ( ) , NodeInfo {
41
- channels : Vec :: new ( ) ,
42
- lowest_inbound_channel_fees : None ,
43
- features : NodeFeatures :: empty ( ) ,
44
- last_update : None ,
45
- rgb : [ 0 ; 3 ] ,
46
- alias : [ 0 ; 32 ] ,
47
- addresses : Vec :: new ( ) ,
48
- announcement_message : None ,
49
- } ) ;
38
+ pub fn new ( chain_monitor : Arc < ChainWatchInterface > , logger : Arc < Logger > ) -> Self {
50
39
NetGraphMsgHandler {
51
40
secp_ctx : Secp256k1 :: verification_only ( ) ,
52
41
network_graph : RwLock :: new ( NetworkGraph {
53
42
channels : BTreeMap :: new ( ) ,
54
- nodes : nodes ,
43
+ nodes : BTreeMap :: new ( ) ,
55
44
} ) ,
56
45
full_syncs_requested : AtomicUsize :: new ( 0 ) ,
57
46
chain_monitor,
@@ -766,18 +755,17 @@ mod tests {
766
755
767
756
use std:: sync:: Arc ;
768
757
769
- fn create_net_graph_msg_handler ( ) -> ( Secp256k1 < All > , PublicKey , NetGraphMsgHandler ) {
758
+ fn create_net_graph_msg_handler ( ) -> ( Secp256k1 < All > , NetGraphMsgHandler ) {
770
759
let secp_ctx = Secp256k1 :: new ( ) ;
771
- let our_id = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & hex:: decode ( "0101010101010101010101010101010101010101010101010101010101010101" ) . unwrap ( ) [ ..] ) . unwrap ( ) ) ;
772
760
let logger: Arc < Logger > = Arc :: new ( test_utils:: TestLogger :: new ( ) ) ;
773
761
let chain_monitor = Arc :: new ( chaininterface:: ChainWatchInterfaceUtil :: new ( Network :: Testnet , Arc :: clone ( & logger) ) ) ;
774
- let net_graph_msg_handler = NetGraphMsgHandler :: new ( our_id , chain_monitor, Arc :: clone ( & logger) ) ;
775
- ( secp_ctx, our_id , net_graph_msg_handler)
762
+ let net_graph_msg_handler = NetGraphMsgHandler :: new ( chain_monitor, Arc :: clone ( & logger) ) ;
763
+ ( secp_ctx, net_graph_msg_handler)
776
764
}
777
765
778
766
#[ test]
779
767
fn request_full_sync_finite_times ( ) {
780
- let ( secp_ctx, _ , net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
768
+ let ( secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
781
769
let node_id = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & hex:: decode ( "0202020202020202020202020202020202020202020202020202020202020202" ) . unwrap ( ) [ ..] ) . unwrap ( ) ) ;
782
770
783
771
assert ! ( net_graph_msg_handler. should_request_full_sync( & node_id) ) ;
@@ -790,7 +778,7 @@ mod tests {
790
778
791
779
#[ test]
792
780
fn handling_node_announcements ( ) {
793
- let ( secp_ctx, _ , net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
781
+ let ( secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
794
782
795
783
let node_1_privkey = & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
796
784
let node_2_privkey = & SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ;
@@ -895,11 +883,9 @@ mod tests {
895
883
#[ test]
896
884
fn handling_channel_announcements ( ) {
897
885
let secp_ctx = Secp256k1 :: new ( ) ;
898
- let our_id = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice (
899
- & hex:: decode ( "0101010101010101010101010101010101010101010101010101010101010101" ) . unwrap ( ) [ ..] ) . unwrap ( ) ) ;
900
886
let logger: Arc < Logger > = Arc :: new ( test_utils:: TestLogger :: new ( ) ) ;
901
887
let chain_monitor = Arc :: new ( test_utils:: TestChainWatcher :: new ( ) ) ;
902
- let net_graph_msg_handler = NetGraphMsgHandler :: new ( our_id , chain_monitor. clone ( ) , Arc :: clone ( & logger) ) ;
888
+ let net_graph_msg_handler = NetGraphMsgHandler :: new ( chain_monitor. clone ( ) , Arc :: clone ( & logger) ) ;
903
889
904
890
905
891
let node_1_privkey = & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
@@ -1084,7 +1070,7 @@ mod tests {
1084
1070
1085
1071
#[ test]
1086
1072
fn handling_channel_update ( ) {
1087
- let ( secp_ctx, _ , net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
1073
+ let ( secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
1088
1074
let node_1_privkey = & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
1089
1075
let node_2_privkey = & SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ;
1090
1076
let node_id_1 = PublicKey :: from_secret_key ( & secp_ctx, node_1_privkey) ;
@@ -1213,7 +1199,7 @@ mod tests {
1213
1199
1214
1200
#[ test]
1215
1201
fn handling_htlc_fail_channel_update ( ) {
1216
- let ( secp_ctx, our_id , net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
1202
+ let ( secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
1217
1203
let node_1_privkey = & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
1218
1204
let node_2_privkey = & SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ;
1219
1205
let node_id_1 = PublicKey :: from_secret_key ( & secp_ctx, node_1_privkey) ;
@@ -1225,10 +1211,9 @@ mod tests {
1225
1211
let chain_hash = genesis_block ( Network :: Testnet ) . header . bitcoin_hash ( ) ;
1226
1212
1227
1213
{
1228
- // There is only local node in the table at the beginning.
1214
+ // There is no nodes in the table at the beginning.
1229
1215
let network = net_graph_msg_handler. network_graph . read ( ) . unwrap ( ) ;
1230
- assert_eq ! ( network. get_nodes( ) . len( ) , 1 ) ;
1231
- assert_eq ! ( network. get_nodes( ) . contains_key( & our_id) , true ) ;
1216
+ assert_eq ! ( network. get_nodes( ) . len( ) , 0 ) ;
1232
1217
}
1233
1218
1234
1219
{
@@ -1290,16 +1275,14 @@ mod tests {
1290
1275
let network = net_graph_msg_handler. network_graph . read ( ) . unwrap ( ) ;
1291
1276
assert_eq ! ( network. get_channels( ) . len( ) , 0 ) ;
1292
1277
// Nodes are also deleted because there are no associated channels anymore
1293
- // Only the local node remains in the table.
1294
- assert_eq ! ( network. get_nodes( ) . len( ) , 1 ) ;
1295
- assert_eq ! ( network. get_nodes( ) . contains_key( & our_id) , true ) ;
1278
+ assert_eq ! ( network. get_nodes( ) . len( ) , 0 ) ;
1296
1279
}
1297
1280
// TODO: Test HTLCFailChannelUpdate::NodeFailure, which is not implemented yet.
1298
1281
}
1299
1282
1300
1283
#[ test]
1301
1284
fn getting_next_channel_announcements ( ) {
1302
- let ( secp_ctx, _ , net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
1285
+ let ( secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
1303
1286
let node_1_privkey = & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
1304
1287
let node_2_privkey = & SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ;
1305
1288
let node_id_1 = PublicKey :: from_secret_key ( & secp_ctx, node_1_privkey) ;
@@ -1431,7 +1414,7 @@ mod tests {
1431
1414
1432
1415
#[ test]
1433
1416
fn getting_next_node_announcements ( ) {
1434
- let ( secp_ctx, _ , net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
1417
+ let ( secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
1435
1418
let node_1_privkey = & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
1436
1419
let node_2_privkey = & SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ;
1437
1420
let node_id_1 = PublicKey :: from_secret_key ( & secp_ctx, node_1_privkey) ;
@@ -1548,7 +1531,7 @@ mod tests {
1548
1531
1549
1532
#[ test]
1550
1533
fn network_graph_serialization ( ) {
1551
- let ( secp_ctx, _ , net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
1534
+ let ( secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
1552
1535
1553
1536
let node_1_privkey = & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
1554
1537
let node_2_privkey = & SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ;
0 commit comments