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