@@ -29,7 +29,7 @@ use crate::ln::msgs::{QueryChannelRange, ReplyChannelRange, QueryShortChannelIds
29
29
use crate :: ln:: msgs;
30
30
use crate :: util:: ser:: { Readable , ReadableArgs , Writeable , Writer , MaybeReadable } ;
31
31
use crate :: util:: logger:: { Logger , Level } ;
32
- use crate :: util:: events:: { Event , EventHandler , MessageSendEvent , MessageSendEventsProvider } ;
32
+ use crate :: util:: events:: { MessageSendEvent , MessageSendEventsProvider } ;
33
33
use crate :: util:: scid_utils:: { block_from_scid, scid_from_parts, MAX_SCID_BLOCK } ;
34
34
use crate :: util:: string:: PrintableString ;
35
35
@@ -213,9 +213,6 @@ impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate,
213
213
/// This network graph is then used for routing payments.
214
214
/// Provides interface to help with initial routing sync by
215
215
/// serving historical announcements.
216
- ///
217
- /// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
218
- /// [`NetworkGraph`].
219
216
pub struct P2PGossipSync < G : Deref < Target =NetworkGraph < L > > , C : Deref , L : Deref >
220
217
where C :: Target : chain:: Access , L :: Target : Logger
221
218
{
@@ -275,32 +272,31 @@ where C::Target: chain::Access, L::Target: Logger
275
272
}
276
273
}
277
274
278
- impl < L : Deref > EventHandler for NetworkGraph < L > where L :: Target : Logger {
279
- fn handle_event ( & self , event : & Event ) {
280
- if let Event :: PaymentPathFailed { network_update, .. } = event {
281
- if let Some ( network_update) = network_update {
282
- match * network_update {
283
- NetworkUpdate :: ChannelUpdateMessage { ref msg } => {
284
- let short_channel_id = msg. contents . short_channel_id ;
285
- let is_enabled = msg. contents . flags & ( 1 << 1 ) != ( 1 << 1 ) ;
286
- let status = if is_enabled { "enabled" } else { "disabled" } ;
287
- log_debug ! ( self . logger, "Updating channel with channel_update from a payment failure. Channel {} is {}." , short_channel_id, status) ;
288
- let _ = self . update_channel ( msg) ;
289
- } ,
290
- NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent } => {
291
- let action = if is_permanent { "Removing" } else { "Disabling" } ;
292
- log_debug ! ( self . logger, "{} channel graph entry for {} due to a payment failure." , action, short_channel_id) ;
293
- self . channel_failed ( short_channel_id, is_permanent) ;
294
- } ,
295
- NetworkUpdate :: NodeFailure { ref node_id, is_permanent } => {
296
- if is_permanent {
297
- log_debug ! ( self . logger,
298
- "Removed node graph entry for {} due to a payment failure." , log_pubkey!( node_id) ) ;
299
- self . node_failed_permanent ( node_id) ;
300
- } ;
301
- } ,
302
- }
303
- }
275
+ impl < L : Deref > NetworkGraph < L > where L :: Target : Logger {
276
+ /// Handles any network updates originating from [`Event`]s.
277
+ ///
278
+ /// [`Event`]: crate::util::events::Event
279
+ pub fn handle_network_update ( & self , network_update : & NetworkUpdate ) {
280
+ match * network_update {
281
+ NetworkUpdate :: ChannelUpdateMessage { ref msg } => {
282
+ let short_channel_id = msg. contents . short_channel_id ;
283
+ let is_enabled = msg. contents . flags & ( 1 << 1 ) != ( 1 << 1 ) ;
284
+ let status = if is_enabled { "enabled" } else { "disabled" } ;
285
+ log_debug ! ( self . logger, "Updating channel with channel_update from a payment failure. Channel {} is {}." , short_channel_id, status) ;
286
+ let _ = self . update_channel ( msg) ;
287
+ } ,
288
+ NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent } => {
289
+ let action = if is_permanent { "Removing" } else { "Disabling" } ;
290
+ log_debug ! ( self . logger, "{} channel graph entry for {} due to a payment failure." , action, short_channel_id) ;
291
+ self . channel_failed ( short_channel_id, is_permanent) ;
292
+ } ,
293
+ NetworkUpdate :: NodeFailure { ref node_id, is_permanent } => {
294
+ if is_permanent {
295
+ log_debug ! ( self . logger,
296
+ "Removed node graph entry for {} due to a payment failure." , log_pubkey!( node_id) ) ;
297
+ self . node_failed_permanent ( node_id) ;
298
+ } ;
299
+ } ,
304
300
}
305
301
}
306
302
}
@@ -1931,15 +1927,14 @@ mod tests {
1931
1927
use crate :: chain;
1932
1928
use crate :: ln:: channelmanager;
1933
1929
use crate :: ln:: chan_utils:: make_funding_redeemscript;
1934
- use crate :: ln:: PaymentHash ;
1935
1930
use crate :: ln:: features:: InitFeatures ;
1936
1931
use crate :: routing:: gossip:: { P2PGossipSync , NetworkGraph , NetworkUpdate , NodeAlias , MAX_EXCESS_BYTES_FOR_RELAY , NodeId , RoutingFees , ChannelUpdateInfo , ChannelInfo , NodeAnnouncementInfo , NodeInfo } ;
1937
1932
use crate :: ln:: msgs:: { RoutingMessageHandler , UnsignedNodeAnnouncement , NodeAnnouncement ,
1938
1933
UnsignedChannelAnnouncement , ChannelAnnouncement , UnsignedChannelUpdate , ChannelUpdate ,
1939
1934
ReplyChannelRange , QueryChannelRange , QueryShortChannelIds , MAX_VALUE_MSAT } ;
1940
1935
use crate :: util:: test_utils;
1941
1936
use crate :: util:: ser:: { ReadableArgs , Writeable } ;
1942
- use crate :: util:: events:: { Event , EventHandler , MessageSendEvent , MessageSendEventsProvider } ;
1937
+ use crate :: util:: events:: { MessageSendEvent , MessageSendEventsProvider } ;
1943
1938
use crate :: util:: scid_utils:: scid_from_parts;
1944
1939
1945
1940
use crate :: routing:: gossip:: REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS ;
@@ -2383,19 +2378,8 @@ mod tests {
2383
2378
let valid_channel_update = get_signed_channel_update ( |_| { } , node_1_privkey, & secp_ctx) ;
2384
2379
assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_none( ) ) ;
2385
2380
2386
- network_graph. handle_event ( & Event :: PaymentPathFailed {
2387
- payment_id : None ,
2388
- payment_hash : PaymentHash ( [ 0 ; 32 ] ) ,
2389
- payment_failed_permanently : false ,
2390
- all_paths_failed : true ,
2391
- path : vec ! [ ] ,
2392
- network_update : Some ( NetworkUpdate :: ChannelUpdateMessage {
2393
- msg : valid_channel_update,
2394
- } ) ,
2395
- short_channel_id : None ,
2396
- retry : None ,
2397
- error_code : None ,
2398
- error_data : None ,
2381
+ network_graph. handle_network_update ( & NetworkUpdate :: ChannelUpdateMessage {
2382
+ msg : valid_channel_update,
2399
2383
} ) ;
2400
2384
2401
2385
assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_some( ) ) ;
@@ -2410,20 +2394,9 @@ mod tests {
2410
2394
}
2411
2395
} ;
2412
2396
2413
- network_graph. handle_event ( & Event :: PaymentPathFailed {
2414
- payment_id : None ,
2415
- payment_hash : PaymentHash ( [ 0 ; 32 ] ) ,
2416
- payment_failed_permanently : false ,
2417
- all_paths_failed : true ,
2418
- path : vec ! [ ] ,
2419
- network_update : Some ( NetworkUpdate :: ChannelFailure {
2420
- short_channel_id,
2421
- is_permanent : false ,
2422
- } ) ,
2423
- short_channel_id : None ,
2424
- retry : None ,
2425
- error_code : None ,
2426
- error_data : None ,
2397
+ network_graph. handle_network_update ( & NetworkUpdate :: ChannelFailure {
2398
+ short_channel_id,
2399
+ is_permanent : false ,
2427
2400
} ) ;
2428
2401
2429
2402
match network_graph. read_only ( ) . channels ( ) . get ( & short_channel_id) {
@@ -2435,20 +2408,9 @@ mod tests {
2435
2408
}
2436
2409
2437
2410
// Permanent closing deletes a channel
2438
- network_graph. handle_event ( & Event :: PaymentPathFailed {
2439
- payment_id : None ,
2440
- payment_hash : PaymentHash ( [ 0 ; 32 ] ) ,
2441
- payment_failed_permanently : false ,
2442
- all_paths_failed : true ,
2443
- path : vec ! [ ] ,
2444
- network_update : Some ( NetworkUpdate :: ChannelFailure {
2445
- short_channel_id,
2446
- is_permanent : true ,
2447
- } ) ,
2448
- short_channel_id : None ,
2449
- retry : None ,
2450
- error_code : None ,
2451
- error_data : None ,
2411
+ network_graph. handle_network_update ( & NetworkUpdate :: ChannelFailure {
2412
+ short_channel_id,
2413
+ is_permanent : true ,
2452
2414
} ) ;
2453
2415
2454
2416
assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
@@ -2467,40 +2429,18 @@ mod tests {
2467
2429
assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . is_some( ) ) ;
2468
2430
2469
2431
// Non-permanent node failure does not delete any nodes or channels
2470
- network_graph. handle_event ( & Event :: PaymentPathFailed {
2471
- payment_id : None ,
2472
- payment_hash : PaymentHash ( [ 0 ; 32 ] ) ,
2473
- payment_failed_permanently : false ,
2474
- all_paths_failed : true ,
2475
- path : vec ! [ ] ,
2476
- network_update : Some ( NetworkUpdate :: NodeFailure {
2477
- node_id : node_2_id,
2478
- is_permanent : false ,
2479
- } ) ,
2480
- short_channel_id : None ,
2481
- retry : None ,
2482
- error_code : None ,
2483
- error_data : None ,
2432
+ network_graph. handle_network_update ( & NetworkUpdate :: NodeFailure {
2433
+ node_id : node_2_id,
2434
+ is_permanent : false ,
2484
2435
} ) ;
2485
2436
2486
2437
assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . is_some( ) ) ;
2487
2438
assert ! ( network_graph. read_only( ) . nodes( ) . get( & NodeId :: from_pubkey( & node_2_id) ) . is_some( ) ) ;
2488
2439
2489
2440
// Permanent node failure deletes node and its channels
2490
- network_graph. handle_event ( & Event :: PaymentPathFailed {
2491
- payment_id : None ,
2492
- payment_hash : PaymentHash ( [ 0 ; 32 ] ) ,
2493
- payment_failed_permanently : false ,
2494
- all_paths_failed : true ,
2495
- path : vec ! [ ] ,
2496
- network_update : Some ( NetworkUpdate :: NodeFailure {
2497
- node_id : node_2_id,
2498
- is_permanent : true ,
2499
- } ) ,
2500
- short_channel_id : None ,
2501
- retry : None ,
2502
- error_code : None ,
2503
- error_data : None ,
2441
+ network_graph. handle_network_update ( & NetworkUpdate :: NodeFailure {
2442
+ node_id : node_2_id,
2443
+ is_permanent : true ,
2504
2444
} ) ;
2505
2445
2506
2446
assert_eq ! ( network_graph. read_only( ) . nodes( ) . len( ) , 0 ) ;
0 commit comments