Skip to content

Commit 55fff0a

Browse files
committed
Add some basic logging to Rapid Gossip Sync processing
1 parent cf3b64d commit 55fff0a

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
@@ -7,7 +7,7 @@ use crate::utils::test_logger;
77
fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
88
let logger = test_logger::TestLogger::new("".to_owned(), out);
99
let network_graph = lightning::routing::gossip::NetworkGraph::new(bitcoin::Network::Bitcoin, &logger);
10-
let rapid_sync = RapidGossipSync::new(&network_graph);
10+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
1111
let _ = rapid_sync.update_network_graph(data);
1212
}
1313

lightning-background-processor/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ mod tests {
953953
let params = ChainParameters { network, best_block };
954954
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));
955955
let p2p_gossip_sync = Arc::new(P2PGossipSync::new(network_graph.clone(), Some(chain_source.clone()), logger.clone()));
956-
let rapid_gossip_sync = Arc::new(RapidGossipSync::new(network_graph.clone()));
956+
let rapid_gossip_sync = Arc::new(RapidGossipSync::new(network_graph.clone(), logger.clone()));
957957
let msg_handler = MessageHandler { chan_handler: Arc::new(test_utils::TestChannelMessageHandler::new()), route_handler: Arc::new(test_utils::TestRoutingMessageHandler::new()), onion_message_handler: IgnoringMessageHandler{}};
958958
let peer_manager = Arc::new(PeerManager::new(msg_handler, 0, &seed, logger.clone(), IgnoringMessageHandler{}, keys_manager.clone()));
959959
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
@@ -54,7 +54,7 @@
5454
//! # let logger = FakeLogger {};
5555
//!
5656
//! let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
57-
//! let rapid_sync = RapidGossipSync::new(&network_graph);
57+
//! let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
5858
//! let snapshot_contents: &[u8] = &[0; 0];
5959
//! let new_last_sync_timestamp_result = rapid_sync.update_network_graph(snapshot_contents);
6060
//! ```
@@ -94,14 +94,16 @@ mod processing;
9494
pub struct RapidGossipSync<NG: Deref<Target=NetworkGraph<L>>, L: Deref>
9595
where L::Target: Logger {
9696
network_graph: NG,
97+
logger: L,
9798
is_initial_sync_complete: AtomicBool
9899
}
99100

100101
impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L::Target: Logger {
101102
/// Instantiate a new [`RapidGossipSync`] instance.
102-
pub fn new(network_graph: NG) -> Self {
103+
pub fn new(network_graph: NG, logger: L) -> Self {
103104
Self {
104105
network_graph,
106+
logger,
105107
is_initial_sync_complete: AtomicBool::new(false)
106108
}
107109
}
@@ -228,7 +230,7 @@ mod tests {
228230

229231
assert_eq!(network_graph.read_only().channels().len(), 0);
230232

231-
let rapid_sync = RapidGossipSync::new(&network_graph);
233+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
232234
let sync_result = rapid_sync.sync_network_graph_with_file_path(&graph_sync_test_file);
233235

234236
if sync_result.is_err() {
@@ -260,7 +262,7 @@ mod tests {
260262

261263
assert_eq!(network_graph.read_only().channels().len(), 0);
262264

263-
let rapid_sync = RapidGossipSync::new(&network_graph);
265+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
264266
let start = std::time::Instant::now();
265267
let sync_result = rapid_sync
266268
.sync_network_graph_with_file_path("./res/full_graph.lngossip");
@@ -299,7 +301,7 @@ pub mod bench {
299301
let logger = TestLogger::new();
300302
b.iter(|| {
301303
let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
302-
let rapid_sync = RapidGossipSync::new(&network_graph);
304+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
303305
let sync_result = rapid_sync.sync_network_graph_with_file_path("./res/full_graph.lngossip");
304306
if let Err(crate::error::GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {
305307
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
}
@@ -279,7 +286,7 @@ mod tests {
279286
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,
280287
0, 3, 232, 0, 0, 0,
281288
];
282-
let rapid_sync = RapidGossipSync::new(&network_graph);
289+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
283290
let update_result = rapid_sync.update_network_graph(&example_input[..]);
284291
assert!(update_result.is_err());
285292
if let Err(GraphSyncError::DecodeError(DecodeError::ShortRead)) = update_result {
@@ -304,7 +311,7 @@ mod tests {
304311

305312
assert_eq!(network_graph.read_only().channels().len(), 0);
306313

307-
let rapid_sync = RapidGossipSync::new(&network_graph);
314+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
308315
let update_result = rapid_sync.update_network_graph(&incremental_update_input[..]);
309316
assert!(update_result.is_ok());
310317
}
@@ -332,7 +339,7 @@ mod tests {
332339

333340
assert_eq!(network_graph.read_only().channels().len(), 0);
334341

335-
let rapid_sync = RapidGossipSync::new(&network_graph);
342+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
336343
rapid_sync.update_network_graph(&announced_update_input[..]).unwrap();
337344
}
338345

@@ -359,7 +366,7 @@ mod tests {
359366

360367
assert_eq!(network_graph.read_only().channels().len(), 0);
361368

362-
let rapid_sync = RapidGossipSync::new(&network_graph);
369+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
363370
let initialization_result = rapid_sync.update_network_graph(&initialization_input[..]);
364371
if initialization_result.is_err() {
365372
panic!(
@@ -416,7 +423,7 @@ mod tests {
416423

417424
assert_eq!(network_graph.read_only().channels().len(), 0);
418425

419-
let rapid_sync = RapidGossipSync::new(&network_graph);
426+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
420427
let initialization_result = rapid_sync.update_network_graph(&initialization_input[..]);
421428
assert!(initialization_result.is_ok());
422429

@@ -475,7 +482,7 @@ mod tests {
475482

476483
assert_eq!(network_graph.read_only().channels().len(), 0);
477484

478-
let rapid_sync = RapidGossipSync::new(&network_graph);
485+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
479486
let initialization_result = rapid_sync.update_network_graph(&initialization_input[..]);
480487
assert!(initialization_result.is_ok());
481488

@@ -500,7 +507,7 @@ mod tests {
500507

501508
assert_eq!(network_graph.read_only().channels().len(), 0);
502509

503-
let rapid_sync = RapidGossipSync::new(&network_graph);
510+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
504511
let update_result = rapid_sync.update_network_graph(&VALID_RGS_BINARY);
505512
if update_result.is_err() {
506513
panic!("Unexpected update result: {:?}", update_result)
@@ -531,7 +538,7 @@ mod tests {
531538

532539
assert_eq!(network_graph.read_only().channels().len(), 0);
533540

534-
let rapid_sync = RapidGossipSync::new(&network_graph);
541+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
535542
// this is mostly for checking uint underflow issues before the fuzzer does
536543
let update_result = rapid_sync.update_network_graph_no_std(&VALID_RGS_BINARY, Some(0));
537544
assert!(update_result.is_ok());
@@ -550,7 +557,7 @@ mod tests {
550557
let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
551558
assert_eq!(network_graph.read_only().channels().len(), 0);
552559

553-
let rapid_sync = RapidGossipSync::new(&network_graph);
560+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
554561
let update_result = rapid_sync.update_network_graph_no_std(&VALID_RGS_BINARY, Some(latest_succeeding_time));
555562
assert!(update_result.is_ok());
556563
assert_eq!(network_graph.read_only().channels().len(), 2);
@@ -560,7 +567,7 @@ mod tests {
560567
let network_graph = NetworkGraph::new(Network::Bitcoin, &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(earliest_failing_time));
565572
assert!(update_result.is_err());
566573
if let Err(GraphSyncError::LightningError(lightning_error)) = update_result {
@@ -596,7 +603,7 @@ mod tests {
596603

597604
let logger = TestLogger::new();
598605
let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
599-
let rapid_sync = RapidGossipSync::new(&network_graph);
606+
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
600607
let update_result = rapid_sync.update_network_graph(&unknown_version_input[..]);
601608

602609
assert!(update_result.is_err());

0 commit comments

Comments
 (0)