@@ -184,17 +184,6 @@ impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate,
184
184
} ,
185
185
) ;
186
186
187
- impl < G : Deref < Target =NetworkGraph < L > > , C : Deref , L : Deref > EventHandler for P2PGossipSync < G , C , L >
188
- where C :: Target : chain:: Access , L :: Target : Logger {
189
- fn handle_event ( & self , event : & Event ) {
190
- if let Event :: PaymentPathFailed { payment_hash : _, rejected_by_dest : _, network_update, .. } = event {
191
- if let Some ( network_update) = network_update {
192
- self . handle_network_update ( network_update) ;
193
- }
194
- }
195
- }
196
- }
197
-
198
187
/// Receives and validates network updates from peers,
199
188
/// stores authentic and relevant data as a network graph.
200
189
/// This network graph is then used for routing payments.
@@ -257,27 +246,34 @@ where C::Target: chain::Access, L::Target: Logger
257
246
false
258
247
}
259
248
}
249
+ }
260
250
261
- /// Applies changes to the [`NetworkGraph`] from the given update.
262
- fn handle_network_update ( & self , update : & NetworkUpdate ) {
263
- match * update {
264
- NetworkUpdate :: ChannelUpdateMessage { ref msg } => {
265
- let short_channel_id = msg. contents . short_channel_id ;
266
- let is_enabled = msg. contents . flags & ( 1 << 1 ) != ( 1 << 1 ) ;
267
- let status = if is_enabled { "enabled" } else { "disabled" } ;
268
- log_debug ! ( self . logger, "Updating channel with channel_update from a payment failure. Channel {} is {}." , short_channel_id, status) ;
269
- let _ = self . network_graph . update_channel ( msg) ;
270
- } ,
271
- NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent } => {
272
- let action = if is_permanent { "Removing" } else { "Disabling" } ;
273
- log_debug ! ( self . logger, "{} channel graph entry for {} due to a payment failure." , action, short_channel_id) ;
274
- self . network_graph . channel_failed ( short_channel_id, is_permanent) ;
275
- } ,
276
- NetworkUpdate :: NodeFailure { ref node_id, is_permanent } => {
277
- let action = if is_permanent { "Removing" } else { "Disabling" } ;
278
- log_debug ! ( self . logger, "{} node graph entry for {} due to a payment failure." , action, node_id) ;
279
- self . network_graph . node_failed ( node_id, is_permanent) ;
280
- } ,
251
+ impl < G : Deref < Target = NetworkGraph < L > > , L : Deref > EventHandler for ( & G , & L )
252
+ where L :: Target : Logger {
253
+ fn handle_event ( & self , event : & Event ) {
254
+ if let Event :: PaymentPathFailed { payment_hash : _, rejected_by_dest : _, network_update, .. } = event {
255
+ if let Some ( network_update) = network_update {
256
+ let ( network_graph, logger) = self ;
257
+ match * network_update {
258
+ NetworkUpdate :: ChannelUpdateMessage { ref msg } => {
259
+ let short_channel_id = msg. contents . short_channel_id ;
260
+ let is_enabled = msg. contents . flags & ( 1 << 1 ) != ( 1 << 1 ) ;
261
+ let status = if is_enabled { "enabled" } else { "disabled" } ;
262
+ log_debug ! ( logger, "Updating channel with channel_update from a payment failure. Channel {} is {}." , short_channel_id, status) ;
263
+ let _ = network_graph. update_channel ( msg) ;
264
+ } ,
265
+ NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent } => {
266
+ let action = if is_permanent { "Removing" } else { "Disabling" } ;
267
+ log_debug ! ( logger, "{} channel graph entry for {} due to a payment failure." , action, short_channel_id) ;
268
+ network_graph. channel_failed ( short_channel_id, is_permanent) ;
269
+ } ,
270
+ NetworkUpdate :: NodeFailure { ref node_id, is_permanent } => {
271
+ let action = if is_permanent { "Removing" } else { "Disabling" } ;
272
+ log_debug ! ( logger, "{} node graph entry for {} due to a payment failure." , action, node_id) ;
273
+ network_graph. node_failed ( node_id, is_permanent) ;
274
+ } ,
275
+ }
276
+ }
281
277
}
282
278
}
283
279
}
@@ -2055,11 +2051,10 @@ mod tests {
2055
2051
#[ test]
2056
2052
fn handling_network_update ( ) {
2057
2053
let logger = test_utils:: TestLogger :: new ( ) ;
2058
- let chain_source = Arc :: new ( test_utils:: TestChainSource :: new ( Network :: Testnet ) ) ;
2059
2054
let genesis_hash = genesis_block ( Network :: Testnet ) . header . block_hash ( ) ;
2060
2055
let network_graph = NetworkGraph :: new ( genesis_hash, & logger) ;
2061
- let gossip_sync = P2PGossipSync :: new ( & network_graph, Some ( chain_source. clone ( ) ) , & logger) ;
2062
2056
let secp_ctx = Secp256k1 :: new ( ) ;
2057
+ let event_handler = ( & & network_graph, & & logger) ;
2063
2058
2064
2059
let node_1_privkey = & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
2065
2060
let node_2_privkey = & SecretKey :: from_slice ( & [ 41 ; 32 ] ) . unwrap ( ) ;
@@ -2081,7 +2076,7 @@ mod tests {
2081
2076
let valid_channel_update = get_signed_channel_update ( |_| { } , node_1_privkey, & secp_ctx) ;
2082
2077
assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_none( ) ) ;
2083
2078
2084
- gossip_sync . handle_event ( & Event :: PaymentPathFailed {
2079
+ event_handler . handle_event ( & Event :: PaymentPathFailed {
2085
2080
payment_id : None ,
2086
2081
payment_hash : PaymentHash ( [ 0 ; 32 ] ) ,
2087
2082
rejected_by_dest : false ,
@@ -2108,7 +2103,7 @@ mod tests {
2108
2103
}
2109
2104
} ;
2110
2105
2111
- gossip_sync . handle_event ( & Event :: PaymentPathFailed {
2106
+ event_handler . handle_event ( & Event :: PaymentPathFailed {
2112
2107
payment_id : None ,
2113
2108
payment_hash : PaymentHash ( [ 0 ; 32 ] ) ,
2114
2109
rejected_by_dest : false ,
@@ -2133,7 +2128,7 @@ mod tests {
2133
2128
}
2134
2129
2135
2130
// Permanent closing deletes a channel
2136
- gossip_sync . handle_event ( & Event :: PaymentPathFailed {
2131
+ event_handler . handle_event ( & Event :: PaymentPathFailed {
2137
2132
payment_id : None ,
2138
2133
payment_hash : PaymentHash ( [ 0 ; 32 ] ) ,
2139
2134
rejected_by_dest : false ,
0 commit comments