Skip to content

Commit b4f5f9b

Browse files
committed
Add some basic logging to Rapid Gossip Sync processing
1 parent f7d880a commit b4f5f9b

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

fuzz/src/process_network_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
99
let block_hash = bitcoin::BlockHash::all_zeros();
1010
let logger = test_logger::TestLogger::new("".to_owned(), out);
1111
let network_graph = lightning::routing::gossip::NetworkGraph::new(block_hash, &logger);
12-
let rapid_sync = RapidGossipSync::new(&network_graph);
12+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
1313
let _ = rapid_sync.update_network_graph(data);
1414
}
1515

lightning-background-processor/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ mod tests {
954954
let params = ChainParameters { network, best_block };
955955
let manager = Arc::new(ChannelManager::new(fee_estimator.clone(), chain_monitor.clone(), tx_broadcaster.clone(), router.clone(), logger.clone(), keys_manager.clone(), keys_manager.clone(), keys_manager.clone(), UserConfig::default(), params));
956956
let p2p_gossip_sync = Arc::new(P2PGossipSync::new(network_graph.clone(), Some(chain_source.clone()), logger.clone()));
957-
let rapid_gossip_sync = Arc::new(RapidGossipSync::new(network_graph.clone()));
957+
let rapid_gossip_sync = Arc::new(RapidGossipSync::new(network_graph.clone(), logger.clone()));
958958
let msg_handler = MessageHandler { chan_handler: Arc::new(test_utils::TestChannelMessageHandler::new()), route_handler: Arc::new(test_utils::TestRoutingMessageHandler::new()), onion_message_handler: IgnoringMessageHandler{}};
959959
let peer_manager = Arc::new(PeerManager::new(msg_handler, 0, &seed, logger.clone(), IgnoringMessageHandler{}, keys_manager.clone()));
960960
let node = Node { node: manager, p2p_gossip_sync, rapid_gossip_sync, peer_manager, chain_monitor, persister, tx_broadcaster, network_graph, logger, best_block, scorer };

lightning-rapid-gossip-sync/src/lib.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
//!
5656
//! let block_hash = genesis_block(Network::Bitcoin).header.block_hash();
5757
//! let network_graph = NetworkGraph::new(block_hash, &logger);
58-
//! let rapid_sync = RapidGossipSync::new(&network_graph);
58+
//! let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
5959
//! let snapshot_contents: &[u8] = &[0; 0];
6060
//! let new_last_sync_timestamp_result = rapid_sync.update_network_graph(snapshot_contents);
6161
//! ```
@@ -95,14 +95,16 @@ mod processing;
9595
pub struct RapidGossipSync<NG: Deref<Target=NetworkGraph<L>>, L: Deref>
9696
where L::Target: Logger {
9797
network_graph: NG,
98+
logger: L,
9899
is_initial_sync_complete: AtomicBool
99100
}
100101

101102
impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L::Target: Logger {
102103
/// Instantiate a new [`RapidGossipSync`] instance.
103-
pub fn new(network_graph: NG) -> Self {
104+
pub fn new(network_graph: NG, logger: L) -> Self {
104105
Self {
105106
network_graph,
107+
logger,
106108
is_initial_sync_complete: AtomicBool::new(false)
107109
}
108110
}
@@ -231,7 +233,7 @@ mod tests {
231233

232234
assert_eq!(network_graph.read_only().channels().len(), 0);
233235

234-
let rapid_sync = RapidGossipSync::new(&network_graph);
236+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
235237
let sync_result = rapid_sync.sync_network_graph_with_file_path(&graph_sync_test_file);
236238

237239
if sync_result.is_err() {
@@ -264,7 +266,7 @@ mod tests {
264266

265267
assert_eq!(network_graph.read_only().channels().len(), 0);
266268

267-
let rapid_sync = RapidGossipSync::new(&network_graph);
269+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
268270
let start = std::time::Instant::now();
269271
let sync_result = rapid_sync
270272
.sync_network_graph_with_file_path("./res/full_graph.lngossip");
@@ -305,7 +307,7 @@ pub mod bench {
305307
let logger = TestLogger::new();
306308
b.iter(|| {
307309
let network_graph = NetworkGraph::new(block_hash, &logger);
308-
let rapid_sync = RapidGossipSync::new(&network_graph);
310+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
309311
let sync_result = rapid_sync.sync_network_graph_with_file_path("./res/full_graph.lngossip");
310312
if let Err(crate::error::GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {
311313
let error_string = format!("Input file lightning-rapid-gossip-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-bc08df7542-2022-05-05.bin\n\n{:?}", io_error);

lightning-rapid-gossip-sync/src/processing.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use lightning::ln::msgs::{
1010
};
1111
use lightning::routing::gossip::NetworkGraph;
1212
use lightning::util::logger::Logger;
13+
use lightning::{log_warn, log_trace, log_given_level};
1314
use lightning::util::ser::{BigSize, Readable};
1415
use lightning::io;
1516

@@ -120,6 +121,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
120121
if let ErrorAction::IgnoreDuplicateGossip = lightning_error.action {
121122
// everything is fine, just a duplicate channel announcement
122123
} else {
124+
log_warn!(self.logger, "Failed to process channel announcement: {:?}", lightning_error);
123125
return Err(lightning_error.into());
124126
}
125127
}
@@ -179,6 +181,9 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
179181
synthetic_update.fee_base_msat = directional_info.fees.base_msat;
180182
synthetic_update.fee_proportional_millionths = directional_info.fees.proportional_millionths;
181183
} else {
184+
log_trace!(self.logger,
185+
"Skipping application of channel update for chan {} with flags {} as original data is missing.",
186+
short_channel_id, channel_flags);
182187
skip_update_for_unknown_channel = true;
183188
}
184189
};
@@ -215,7 +220,9 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
215220
match network_graph.update_channel_unsigned(&synthetic_update) {
216221
Ok(_) => {},
217222
Err(LightningError { action: ErrorAction::IgnoreDuplicateGossip, .. }) => {},
218-
Err(LightningError { action: ErrorAction::IgnoreAndLog(_), .. }) => {},
223+
Err(LightningError { action: ErrorAction::IgnoreAndLog(level), err }) => {
224+
log_given_level!(self.logger, level, "Failed to apply channel update: {:?}", err);
225+
},
219226
Err(LightningError { action: ErrorAction::IgnoreError, .. }) => {},
220227
Err(e) => return Err(e.into()),
221228
}
@@ -281,7 +288,7 @@ mod tests {
281288
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 58, 85, 116, 216, 255, 2, 68, 226, 0, 6, 11, 0, 1, 24, 0,
282289
0, 3, 232, 0, 0, 0,
283290
];
284-
let rapid_sync = RapidGossipSync::new(&network_graph);
291+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
285292
let update_result = rapid_sync.update_network_graph(&example_input[..]);
286293
assert!(update_result.is_err());
287294
if let Err(GraphSyncError::DecodeError(DecodeError::ShortRead)) = update_result {
@@ -307,7 +314,7 @@ mod tests {
307314

308315
assert_eq!(network_graph.read_only().channels().len(), 0);
309316

310-
let rapid_sync = RapidGossipSync::new(&network_graph);
317+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
311318
let update_result = rapid_sync.update_network_graph(&incremental_update_input[..]);
312319
assert!(update_result.is_ok());
313320
}
@@ -336,7 +343,7 @@ mod tests {
336343

337344
assert_eq!(network_graph.read_only().channels().len(), 0);
338345

339-
let rapid_sync = RapidGossipSync::new(&network_graph);
346+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
340347
rapid_sync.update_network_graph(&announced_update_input[..]).unwrap();
341348
}
342349

@@ -364,7 +371,7 @@ mod tests {
364371

365372
assert_eq!(network_graph.read_only().channels().len(), 0);
366373

367-
let rapid_sync = RapidGossipSync::new(&network_graph);
374+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
368375
let initialization_result = rapid_sync.update_network_graph(&initialization_input[..]);
369376
if initialization_result.is_err() {
370377
panic!(
@@ -422,7 +429,7 @@ mod tests {
422429

423430
assert_eq!(network_graph.read_only().channels().len(), 0);
424431

425-
let rapid_sync = RapidGossipSync::new(&network_graph);
432+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
426433
let initialization_result = rapid_sync.update_network_graph(&initialization_input[..]);
427434
assert!(initialization_result.is_ok());
428435

@@ -482,7 +489,7 @@ mod tests {
482489

483490
assert_eq!(network_graph.read_only().channels().len(), 0);
484491

485-
let rapid_sync = RapidGossipSync::new(&network_graph);
492+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
486493
let initialization_result = rapid_sync.update_network_graph(&initialization_input[..]);
487494
assert!(initialization_result.is_ok());
488495

@@ -508,7 +515,7 @@ mod tests {
508515

509516
assert_eq!(network_graph.read_only().channels().len(), 0);
510517

511-
let rapid_sync = RapidGossipSync::new(&network_graph);
518+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
512519
let update_result = rapid_sync.update_network_graph(&VALID_RGS_BINARY);
513520
if update_result.is_err() {
514521
panic!("Unexpected update result: {:?}", update_result)
@@ -540,7 +547,7 @@ mod tests {
540547

541548
assert_eq!(network_graph.read_only().channels().len(), 0);
542549

543-
let rapid_sync = RapidGossipSync::new(&network_graph);
550+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
544551
// this is mostly for checking uint underflow issues before the fuzzer does
545552
let update_result = rapid_sync.update_network_graph_no_std(&VALID_RGS_BINARY, Some(0));
546553
assert!(update_result.is_ok());
@@ -560,7 +567,7 @@ mod tests {
560567
let network_graph = NetworkGraph::new(block_hash, &logger);
561568
assert_eq!(network_graph.read_only().channels().len(), 0);
562569

563-
let rapid_sync = RapidGossipSync::new(&network_graph);
570+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
564571
let update_result = rapid_sync.update_network_graph_no_std(&VALID_RGS_BINARY, Some(latest_succeeding_time));
565572
assert!(update_result.is_ok());
566573
assert_eq!(network_graph.read_only().channels().len(), 2);
@@ -570,7 +577,7 @@ mod tests {
570577
let network_graph = NetworkGraph::new(block_hash, &logger);
571578
assert_eq!(network_graph.read_only().channels().len(), 0);
572579

573-
let rapid_sync = RapidGossipSync::new(&network_graph);
580+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
574581
let update_result = rapid_sync.update_network_graph_no_std(&VALID_RGS_BINARY, Some(earliest_failing_time));
575582
assert!(update_result.is_err());
576583
if let Err(GraphSyncError::LightningError(lightning_error)) = update_result {
@@ -607,7 +614,7 @@ mod tests {
607614
let block_hash = genesis_block(Network::Bitcoin).block_hash();
608615
let logger = TestLogger::new();
609616
let network_graph = NetworkGraph::new(block_hash, &logger);
610-
let rapid_sync = RapidGossipSync::new(&network_graph);
617+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
611618
let update_result = rapid_sync.update_network_graph(&unknown_version_input[..]);
612619

613620
assert!(update_result.is_err());

0 commit comments

Comments
 (0)