@@ -10,6 +10,7 @@ use lightning::ln::msgs::{
1010} ;
1111use lightning:: routing:: gossip:: NetworkGraph ;
1212use lightning:: util:: logger:: Logger ;
13+ use lightning:: { log_warn, log_trace, log_given_level} ;
1314use lightning:: util:: ser:: { BigSize , Readable } ;
1415use 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 }
@@ -169,24 +171,19 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
169171 if ( channel_flags & 0b_1000_0000 ) != 0 {
170172 // incremental update, field flags will indicate mutated values
171173 let read_only_network_graph = network_graph. read_only ( ) ;
172- if let Some ( channel) = read_only_network_graph
173- . channels ( )
174- . get ( & short_channel_id) {
175-
176- let directional_info = channel
177- . get_directional_info ( channel_flags)
178- . ok_or ( LightningError {
179- err : "Couldn't find previous directional data for update" . to_owned ( ) ,
180- action : ErrorAction :: IgnoreError ,
181- } ) ?;
182-
174+ if let Some ( directional_info) =
175+ read_only_network_graph. channels ( ) . get ( & short_channel_id)
176+ . and_then ( |channel| channel. get_directional_info ( channel_flags) )
177+ {
183178 synthetic_update. cltv_expiry_delta = directional_info. cltv_expiry_delta ;
184179 synthetic_update. htlc_minimum_msat = directional_info. htlc_minimum_msat ;
185180 synthetic_update. htlc_maximum_msat = directional_info. htlc_maximum_msat ;
186181 synthetic_update. fee_base_msat = directional_info. fees . base_msat ;
187182 synthetic_update. fee_proportional_millionths = directional_info. fees . proportional_millionths ;
188-
189183 } 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) ;
190187 skip_update_for_unknown_channel = true ;
191188 }
192189 } ;
@@ -223,7 +220,9 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
223220 match network_graph. update_channel_unsigned ( & synthetic_update) {
224221 Ok ( _) => { } ,
225222 Err ( LightningError { action : ErrorAction :: IgnoreDuplicateGossip , .. } ) => { } ,
226- 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+ } ,
227226 Err ( LightningError { action : ErrorAction :: IgnoreError , .. } ) => { } ,
228227 Err ( e) => return Err ( e. into ( ) ) ,
229228 }
@@ -287,7 +286,7 @@ mod tests {
287286 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 ,
288287 0 , 3 , 232 , 0 , 0 , 0 ,
289288 ] ;
290- let rapid_sync = RapidGossipSync :: new ( & network_graph) ;
289+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger ) ;
291290 let update_result = rapid_sync. update_network_graph ( & example_input[ ..] ) ;
292291 assert ! ( update_result. is_err( ) ) ;
293292 if let Err ( GraphSyncError :: DecodeError ( DecodeError :: ShortRead ) ) = update_result {
@@ -312,7 +311,7 @@ mod tests {
312311
313312 assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
314313
315- let rapid_sync = RapidGossipSync :: new ( & network_graph) ;
314+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger ) ;
316315 let update_result = rapid_sync. update_network_graph ( & incremental_update_input[ ..] ) ;
317316 assert ! ( update_result. is_ok( ) ) ;
318317 }
@@ -340,17 +339,8 @@ mod tests {
340339
341340 assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
342341
343- let rapid_sync = RapidGossipSync :: new ( & network_graph) ;
344- let update_result = rapid_sync. update_network_graph ( & announced_update_input[ ..] ) ;
345- assert ! ( update_result. is_err( ) ) ;
346- if let Err ( GraphSyncError :: LightningError ( lightning_error) ) = update_result {
347- assert_eq ! (
348- lightning_error. err,
349- "Couldn't find previous directional data for update"
350- ) ;
351- } else {
352- panic ! ( "Unexpected update result: {:?}" , update_result)
353- }
342+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger) ;
343+ rapid_sync. update_network_graph ( & announced_update_input[ ..] ) . unwrap ( ) ;
354344 }
355345
356346 #[ test]
@@ -376,7 +366,7 @@ mod tests {
376366
377367 assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
378368
379- let rapid_sync = RapidGossipSync :: new ( & network_graph) ;
369+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger ) ;
380370 let initialization_result = rapid_sync. update_network_graph ( & initialization_input[ ..] ) ;
381371 if initialization_result. is_err ( ) {
382372 panic ! (
@@ -405,16 +395,7 @@ mod tests {
405395 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255 , 8 , 153 , 192 , 0 , 2 , 27 , 0 , 0 , 136 , 0 , 0 , 0 , 221 , 255 , 2 ,
406396 68 , 226 , 0 , 6 , 11 , 0 , 1 , 128 ,
407397 ] ;
408- let update_result = rapid_sync. update_network_graph ( & opposite_direction_incremental_update_input[ ..] ) ;
409- assert ! ( update_result. is_err( ) ) ;
410- if let Err ( GraphSyncError :: LightningError ( lightning_error) ) = update_result {
411- assert_eq ! (
412- lightning_error. err,
413- "Couldn't find previous directional data for update"
414- ) ;
415- } else {
416- panic ! ( "Unexpected update result: {:?}" , update_result)
417- }
398+ rapid_sync. update_network_graph ( & opposite_direction_incremental_update_input[ ..] ) . unwrap ( ) ;
418399 }
419400
420401 #[ test]
@@ -442,7 +423,7 @@ mod tests {
442423
443424 assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
444425
445- let rapid_sync = RapidGossipSync :: new ( & network_graph) ;
426+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger ) ;
446427 let initialization_result = rapid_sync. update_network_graph ( & initialization_input[ ..] ) ;
447428 assert ! ( initialization_result. is_ok( ) ) ;
448429
@@ -501,7 +482,7 @@ mod tests {
501482
502483 assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
503484
504- let rapid_sync = RapidGossipSync :: new ( & network_graph) ;
485+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger ) ;
505486 let initialization_result = rapid_sync. update_network_graph ( & initialization_input[ ..] ) ;
506487 assert ! ( initialization_result. is_ok( ) ) ;
507488
@@ -526,7 +507,7 @@ mod tests {
526507
527508 assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
528509
529- let rapid_sync = RapidGossipSync :: new ( & network_graph) ;
510+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger ) ;
530511 let update_result = rapid_sync. update_network_graph ( & VALID_RGS_BINARY ) ;
531512 if update_result. is_err ( ) {
532513 panic ! ( "Unexpected update result: {:?}" , update_result)
@@ -557,7 +538,7 @@ mod tests {
557538
558539 assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
559540
560- let rapid_sync = RapidGossipSync :: new ( & network_graph) ;
541+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger ) ;
561542 // this is mostly for checking uint underflow issues before the fuzzer does
562543 let update_result = rapid_sync. update_network_graph_no_std ( & VALID_RGS_BINARY , Some ( 0 ) ) ;
563544 assert ! ( update_result. is_ok( ) ) ;
@@ -576,7 +557,7 @@ mod tests {
576557 let network_graph = NetworkGraph :: new ( Network :: Bitcoin , & logger) ;
577558 assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
578559
579- let rapid_sync = RapidGossipSync :: new ( & network_graph) ;
560+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger ) ;
580561 let update_result = rapid_sync. update_network_graph_no_std ( & VALID_RGS_BINARY , Some ( latest_succeeding_time) ) ;
581562 assert ! ( update_result. is_ok( ) ) ;
582563 assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 2 ) ;
@@ -586,7 +567,7 @@ mod tests {
586567 let network_graph = NetworkGraph :: new ( Network :: Bitcoin , & logger) ;
587568 assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
588569
589- let rapid_sync = RapidGossipSync :: new ( & network_graph) ;
570+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger ) ;
590571 let update_result = rapid_sync. update_network_graph_no_std ( & VALID_RGS_BINARY , Some ( earliest_failing_time) ) ;
591572 assert ! ( update_result. is_err( ) ) ;
592573 if let Err ( GraphSyncError :: LightningError ( lightning_error) ) = update_result {
@@ -622,7 +603,7 @@ mod tests {
622603
623604 let logger = TestLogger :: new ( ) ;
624605 let network_graph = NetworkGraph :: new ( Network :: Bitcoin , & logger) ;
625- let rapid_sync = RapidGossipSync :: new ( & network_graph) ;
606+ let rapid_sync = RapidGossipSync :: new ( & network_graph, & logger ) ;
626607 let update_result = rapid_sync. update_network_graph ( & unknown_version_input[ ..] ) ;
627608
628609 assert ! ( update_result. is_err( ) ) ;
0 commit comments