Skip to content

Commit 0dda609

Browse files
committed
Fix indentation spaces.
1 parent a4e108b commit 0dda609

File tree

2 files changed

+617
-617
lines changed

2 files changed

+617
-617
lines changed

lightning-graph-sync/src/lib.rs

+107-107
Original file line numberDiff line numberDiff line change
@@ -53,125 +53,125 @@ pub mod processing;
5353
/// `sync_path`: Path to the file where the gossip update data is located
5454
///
5555
pub fn sync_network_graph_with_file_path(
56-
network_graph: &network_graph::NetworkGraph,
57-
sync_path: &str,
56+
network_graph: &network_graph::NetworkGraph,
57+
sync_path: &str,
5858
) -> Result<(), GraphSyncError> {
59-
let mut file = File::open(sync_path)?;
60-
processing::update_network_graph_from_byte_stream(&network_graph, &mut file)
59+
let mut file = File::open(sync_path)?;
60+
processing::update_network_graph_from_byte_stream(&network_graph, &mut file)
6161
}
6262

6363
#[cfg(test)]
6464
mod tests {
65-
use std::fs;
66-
67-
use bitcoin::blockdata::constants::genesis_block;
68-
use bitcoin::Network;
69-
70-
use lightning::routing::network_graph::NetworkGraph;
71-
72-
use crate::sync_network_graph_with_file_path;
73-
74-
#[test]
75-
fn test_sync_from_file() {
76-
// same as incremental_only_update_fails_without_prior_same_direction_updates
77-
let valid_response = vec![
78-
76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,
79-
79, 147, 30, 131, 101, 225, 90, 8, 156, 104, 214, 25, 0, 0, 0, 0, 0, 97, 227, 98, 218,
80-
0, 0, 0, 4, 2, 22, 7, 207, 206, 25, 164, 197, 231, 230, 231, 56, 102, 61, 250, 251,
81-
187, 172, 38, 46, 79, 247, 108, 44, 155, 48, 219, 238, 252, 53, 192, 6, 67, 2, 36, 125,
82-
157, 176, 223, 175, 234, 116, 94, 248, 201, 225, 97, 235, 50, 47, 115, 172, 63, 136,
83-
88, 216, 115, 11, 111, 217, 114, 84, 116, 124, 231, 107, 2, 158, 1, 242, 121, 152, 106,
84-
204, 131, 186, 35, 93, 70, 216, 10, 237, 224, 183, 89, 95, 65, 3, 83, 185, 58, 138,
85-
181, 64, 187, 103, 127, 68, 50, 2, 201, 19, 17, 138, 136, 149, 185, 226, 156, 137, 175,
86-
110, 32, 237, 0, 217, 90, 31, 100, 228, 149, 46, 219, 175, 168, 77, 4, 143, 38, 128,
87-
76, 97, 0, 0, 0, 2, 0, 0, 255, 8, 153, 192, 0, 2, 27, 0, 0, 0, 1, 0, 0, 255, 2, 68,
88-
226, 0, 6, 11, 0, 1, 2, 3, 0, 0, 0, 2, 0, 40, 0, 0, 0, 0, 0, 0, 3, 232, 0, 0, 3, 232,
89-
0, 0, 0, 1, 0, 0, 0, 0, 58, 85, 116, 216, 255, 8, 153, 192, 0, 2, 27, 0, 0, 25, 0, 0,
90-
0, 1, 0, 0, 0, 125, 255, 2, 68, 226, 0, 6, 11, 0, 1, 5, 0, 0, 0, 0, 29, 129, 25, 192,
91-
];
92-
93-
let tmp_directory = "./tmp";
94-
let graph_sync_test_directory = tmp_directory.to_owned() + "/graph-sync-tests";
95-
let graph_sync_test_file = graph_sync_test_directory.to_owned() + "/test_data.lngossip";
96-
fs::create_dir_all(graph_sync_test_directory).unwrap();
97-
fs::write(&graph_sync_test_file, valid_response).unwrap();
98-
99-
let block_hash = genesis_block(Network::Bitcoin).block_hash();
100-
let network_graph = NetworkGraph::new(block_hash);
101-
102-
let before = network_graph.to_string();
103-
assert_eq!(before.len(), 31);
104-
105-
let sync_result = sync_network_graph_with_file_path(&network_graph, &graph_sync_test_file);
106-
fs::remove_dir_all(tmp_directory).unwrap();
107-
108-
if sync_result.is_err() {
109-
panic!("Unexpected sync result: {:?}", sync_result)
110-
}
111-
112-
let after = network_graph.to_string();
113-
assert_eq!(after.len(), 1727);
114-
assert!(
115-
after.contains("021607cfce19a4c5e7e6e738663dfafbbbac262e4ff76c2c9b30dbeefc35c00643:")
116-
);
117-
assert!(
118-
after.contains("02247d9db0dfafea745ef8c9e161eb322f73ac3f8858d8730b6fd97254747ce76b:")
119-
);
120-
assert!(
121-
after.contains("029e01f279986acc83ba235d46d80aede0b7595f410353b93a8ab540bb677f4432:")
122-
);
123-
assert!(
124-
after.contains("02c913118a8895b9e29c89af6e20ed00d95a1f64e4952edbafa84d048f26804c61:")
125-
);
126-
assert!(after.contains("channels: [619737530008010752]"));
127-
assert!(after.contains("channels: [783241506229452801]"));
128-
}
129-
130-
#[ignore]
131-
#[test]
132-
fn measure_native_read_from_file() {
133-
let block_hash = genesis_block(Network::Bitcoin).block_hash();
134-
let network_graph = NetworkGraph::new(block_hash);
135-
136-
let before = network_graph.to_string();
137-
assert_eq!(before.len(), 31);
138-
139-
let start = std::time::Instant::now();
140-
let sync_result =
141-
sync_network_graph_with_file_path(&network_graph, "./res/full_graph.lngossip");
142-
if let Err(crate::error::GraphSyncError::IOError(io_error)) = &sync_result {
143-
let error_string = io_error.to_string();
144-
if error_string
145-
.to_lowercase()
146-
.contains("no such file or directory")
147-
{
148-
panic!("Input file lightning-graph-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-bc08df7542-2022-05-05.bin")
149-
}
150-
}
151-
let elapsed = start.elapsed();
152-
println!("initialization duration: {:?}", elapsed);
153-
if sync_result.is_err() {
154-
panic!("Unexpected sync result: {:?}", sync_result)
155-
}
156-
}
65+
use std::fs;
66+
67+
use bitcoin::blockdata::constants::genesis_block;
68+
use bitcoin::Network;
69+
70+
use lightning::routing::network_graph::NetworkGraph;
71+
72+
use crate::sync_network_graph_with_file_path;
73+
74+
#[test]
75+
fn test_sync_from_file() {
76+
// same as incremental_only_update_fails_without_prior_same_direction_updates
77+
let valid_response = vec![
78+
76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,
79+
79, 147, 30, 131, 101, 225, 90, 8, 156, 104, 214, 25, 0, 0, 0, 0, 0, 97, 227, 98, 218,
80+
0, 0, 0, 4, 2, 22, 7, 207, 206, 25, 164, 197, 231, 230, 231, 56, 102, 61, 250, 251,
81+
187, 172, 38, 46, 79, 247, 108, 44, 155, 48, 219, 238, 252, 53, 192, 6, 67, 2, 36, 125,
82+
157, 176, 223, 175, 234, 116, 94, 248, 201, 225, 97, 235, 50, 47, 115, 172, 63, 136,
83+
88, 216, 115, 11, 111, 217, 114, 84, 116, 124, 231, 107, 2, 158, 1, 242, 121, 152, 106,
84+
204, 131, 186, 35, 93, 70, 216, 10, 237, 224, 183, 89, 95, 65, 3, 83, 185, 58, 138,
85+
181, 64, 187, 103, 127, 68, 50, 2, 201, 19, 17, 138, 136, 149, 185, 226, 156, 137, 175,
86+
110, 32, 237, 0, 217, 90, 31, 100, 228, 149, 46, 219, 175, 168, 77, 4, 143, 38, 128,
87+
76, 97, 0, 0, 0, 2, 0, 0, 255, 8, 153, 192, 0, 2, 27, 0, 0, 0, 1, 0, 0, 255, 2, 68,
88+
226, 0, 6, 11, 0, 1, 2, 3, 0, 0, 0, 2, 0, 40, 0, 0, 0, 0, 0, 0, 3, 232, 0, 0, 3, 232,
89+
0, 0, 0, 1, 0, 0, 0, 0, 58, 85, 116, 216, 255, 8, 153, 192, 0, 2, 27, 0, 0, 25, 0, 0,
90+
0, 1, 0, 0, 0, 125, 255, 2, 68, 226, 0, 6, 11, 0, 1, 5, 0, 0, 0, 0, 29, 129, 25, 192,
91+
];
92+
93+
let tmp_directory = "./tmp";
94+
let graph_sync_test_directory = tmp_directory.to_owned() + "/graph-sync-tests";
95+
let graph_sync_test_file = graph_sync_test_directory.to_owned() + "/test_data.lngossip";
96+
fs::create_dir_all(graph_sync_test_directory).unwrap();
97+
fs::write(&graph_sync_test_file, valid_response).unwrap();
98+
99+
let block_hash = genesis_block(Network::Bitcoin).block_hash();
100+
let network_graph = NetworkGraph::new(block_hash);
101+
102+
let before = network_graph.to_string();
103+
assert_eq!(before.len(), 31);
104+
105+
let sync_result = sync_network_graph_with_file_path(&network_graph, &graph_sync_test_file);
106+
fs::remove_dir_all(tmp_directory).unwrap();
107+
108+
if sync_result.is_err() {
109+
panic!("Unexpected sync result: {:?}", sync_result)
110+
}
111+
112+
let after = network_graph.to_string();
113+
assert_eq!(after.len(), 1727);
114+
assert!(
115+
after.contains("021607cfce19a4c5e7e6e738663dfafbbbac262e4ff76c2c9b30dbeefc35c00643:")
116+
);
117+
assert!(
118+
after.contains("02247d9db0dfafea745ef8c9e161eb322f73ac3f8858d8730b6fd97254747ce76b:")
119+
);
120+
assert!(
121+
after.contains("029e01f279986acc83ba235d46d80aede0b7595f410353b93a8ab540bb677f4432:")
122+
);
123+
assert!(
124+
after.contains("02c913118a8895b9e29c89af6e20ed00d95a1f64e4952edbafa84d048f26804c61:")
125+
);
126+
assert!(after.contains("channels: [619737530008010752]"));
127+
assert!(after.contains("channels: [783241506229452801]"));
128+
}
129+
130+
#[ignore]
131+
#[test]
132+
fn measure_native_read_from_file() {
133+
let block_hash = genesis_block(Network::Bitcoin).block_hash();
134+
let network_graph = NetworkGraph::new(block_hash);
135+
136+
let before = network_graph.to_string();
137+
assert_eq!(before.len(), 31);
138+
139+
let start = std::time::Instant::now();
140+
let sync_result =
141+
sync_network_graph_with_file_path(&network_graph, "./res/full_graph.lngossip");
142+
if let Err(crate::error::GraphSyncError::IOError(io_error)) = &sync_result {
143+
let error_string = io_error.to_string();
144+
if error_string
145+
.to_lowercase()
146+
.contains("no such file or directory")
147+
{
148+
panic!("Input file lightning-graph-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-bc08df7542-2022-05-05.bin")
149+
}
150+
}
151+
let elapsed = start.elapsed();
152+
println!("initialization duration: {:?}", elapsed);
153+
if sync_result.is_err() {
154+
panic!("Unexpected sync result: {:?}", sync_result)
155+
}
156+
}
157157
}
158158

159159
#[cfg(all(test, feature = "_bench_unstable"))]
160160
pub mod bench {
161-
use bitcoin::blockdata::constants::genesis_block;
162-
use bitcoin::Network;
161+
use test::Bencher;
163162

164-
use lightning::routing::network_graph::NetworkGraph;
163+
use bitcoin::blockdata::constants::genesis_block;
164+
use bitcoin::Network;
165165

166-
use crate::sync_network_graph_with_file_path;
166+
use lightning::routing::network_graph::NetworkGraph;
167167

168-
use test::Bencher;
168+
use crate::sync_network_graph_with_file_path;
169169

170-
#[cfg(test)]
171-
#[bench]
172-
fn bench_reading_full_graph_from_file(b: &mut Bencher) {
173-
let block_hash = genesis_block(Network::Bitcoin).block_hash();
174-
b.iter(|| {
170+
#[cfg(test)]
171+
#[bench]
172+
fn bench_reading_full_graph_from_file(b: &mut Bencher) {
173+
let block_hash = genesis_block(Network::Bitcoin).block_hash();
174+
b.iter(|| {
175175
let network_graph = NetworkGraph::new(block_hash);
176176
let sync_result = sync_network_graph_with_file_path(
177177
&network_graph,
@@ -185,5 +185,5 @@ pub mod bench {
185185
}
186186
assert!(sync_result.is_ok())
187187
});
188-
}
188+
}
189189
}

0 commit comments

Comments
 (0)