@@ -3538,27 +3538,48 @@ where
3538
3538
let mut peer_state_lock = peer_state_mutex. lock ( ) . unwrap ( ) ;
3539
3539
let peer_state = & mut * peer_state_lock;
3540
3540
for channel_id in channel_ids {
3541
- if !peer_state. channel_by_id . contains_key ( channel_id) {
3541
+ if !peer_state. has_channel ( channel_id) {
3542
3542
return Err ( APIError :: ChannelUnavailable {
3543
3543
err : format ! ( "Channel with ID {} was not found for the passed counterparty_node_id {}" , log_bytes!( * channel_id) , counterparty_node_id) ,
3544
3544
} ) ;
3545
- }
3545
+ } ;
3546
3546
}
3547
3547
for channel_id in channel_ids {
3548
- let channel = peer_state. channel_by_id . get_mut ( channel_id) . unwrap ( ) ;
3549
- let mut config = channel. context . config ( ) ;
3550
- config. apply ( config_update) ;
3551
- if !channel. context . update_config ( & config) {
3548
+ if let Some ( channel) = peer_state. channel_by_id . get_mut ( channel_id) {
3549
+ let mut config = channel. context . config ( ) ;
3550
+ config. apply ( config_update) ;
3551
+ if !channel. context . update_config ( & config) {
3552
+ continue ;
3553
+ }
3554
+ if let Ok ( msg) = self . get_channel_update_for_broadcast ( channel) {
3555
+ peer_state. pending_msg_events . push ( events:: MessageSendEvent :: BroadcastChannelUpdate { msg } ) ;
3556
+ } else if let Ok ( msg) = self . get_channel_update_for_unicast ( channel) {
3557
+ peer_state. pending_msg_events . push ( events:: MessageSendEvent :: SendChannelUpdate {
3558
+ node_id : channel. context . get_counterparty_node_id ( ) ,
3559
+ msg,
3560
+ } ) ;
3561
+ }
3552
3562
continue ;
3553
3563
}
3554
- if let Ok ( msg) = self . get_channel_update_for_broadcast ( channel) {
3555
- peer_state. pending_msg_events . push ( events:: MessageSendEvent :: BroadcastChannelUpdate { msg } ) ;
3556
- } else if let Ok ( msg) = self . get_channel_update_for_unicast ( channel) {
3557
- peer_state. pending_msg_events . push ( events:: MessageSendEvent :: SendChannelUpdate {
3558
- node_id : channel. context . get_counterparty_node_id ( ) ,
3559
- msg,
3564
+
3565
+ let context = if let Some ( channel) = peer_state. inbound_v1_channel_by_id . get_mut ( channel_id) {
3566
+ & mut channel. context
3567
+ } else if let Some ( channel) = peer_state. outbound_v1_channel_by_id . get_mut ( channel_id) {
3568
+ & mut channel. context
3569
+ } else {
3570
+ // This should not be reachable as we've already checked for non-existence in the previous channel_id loop.
3571
+ debug_assert ! ( false ) ;
3572
+ return Err ( APIError :: ChannelUnavailable {
3573
+ err : format ! (
3574
+ "Channel with ID {} for passed counterparty_node_id {} disappeared after we confirmed its existence - this should not be reachable!" ,
3575
+ log_bytes!( * channel_id) , counterparty_node_id) ,
3560
3576
} ) ;
3561
- }
3577
+ } ;
3578
+ let mut config = context. config ( ) ;
3579
+ config. apply ( config_update) ;
3580
+ // We update the config, but we MUST NOT broadcast a `channel_update` before `channel_ready`
3581
+ // which would be the case for pending inbound/outbound channels.
3582
+ context. update_config ( & config) ;
3562
3583
}
3563
3584
Ok ( ( ) )
3564
3585
}
@@ -10184,6 +10205,25 @@ mod tests {
10184
10205
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
10185
10206
_ => panic ! ( "expected BroadcastChannelUpdate event" ) ,
10186
10207
}
10208
+
10209
+ // If we provide a channel_id not associated with the peer, we should get an error and no updates
10210
+ // should be applied to ensure update atomicity as specified in the API docs.
10211
+ let bad_channel_id = [ 10 ; 32 ] ;
10212
+ let current_fee = nodes[ 0 ] . node . list_channels ( ) [ 0 ] . config . unwrap ( ) . forwarding_fee_proportional_millionths ;
10213
+ let new_fee = current_fee + 100 ;
10214
+ assert ! (
10215
+ matches!(
10216
+ nodes[ 0 ] . node. update_partial_channel_config( & channel. counterparty. node_id, & [ channel. channel_id, bad_channel_id] , & ChannelConfigUpdate {
10217
+ forwarding_fee_proportional_millionths: Some ( new_fee) ,
10218
+ ..Default :: default ( )
10219
+ } ) ,
10220
+ Err ( APIError :: ChannelUnavailable { err: _ } ) ,
10221
+ )
10222
+ ) ;
10223
+ // Check that the fee hasn't changed for the channel that exists.
10224
+ assert_eq ! ( nodes[ 0 ] . node. list_channels( ) [ 0 ] . config. unwrap( ) . forwarding_fee_proportional_millionths, current_fee) ;
10225
+ let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
10226
+ assert_eq ! ( events. len( ) , 0 ) ;
10187
10227
}
10188
10228
}
10189
10229
0 commit comments