@@ -3538,27 +3538,44 @@ 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
+ return Err ( APIError :: ChannelUnavailable {
3571
+ err : format ! ( "Channel with ID {} was not found for the passed counterparty_node_id {}" , log_bytes!( * channel_id) , counterparty_node_id) ,
3560
3572
} ) ;
3561
- }
3573
+ } ;
3574
+ let mut config = context. config ( ) ;
3575
+ config. apply ( config_update) ;
3576
+ // We update the config, but we MUST NOT broadcast a `channel_update` before `channel_ready`
3577
+ // which would be the case for pending inbound/outbound channels.
3578
+ context. update_config ( & config) ;
3562
3579
}
3563
3580
Ok ( ( ) )
3564
3581
}
@@ -10172,6 +10189,25 @@ mod tests {
10172
10189
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
10173
10190
_ => panic ! ( "expected BroadcastChannelUpdate event" ) ,
10174
10191
}
10192
+
10193
+ // If we provide a channel_id not associated with the peer, we should get an error and no updates
10194
+ // should be applied to ensure update atomicity as specified in the API docs.
10195
+ let bad_channel_id = [ 10 ; 32 ] ;
10196
+ let current_fee = nodes[ 0 ] . node . list_channels ( ) [ 0 ] . config . unwrap ( ) . forwarding_fee_proportional_millionths ;
10197
+ let new_fee = current_fee + 100 ;
10198
+ assert ! (
10199
+ matches!(
10200
+ nodes[ 0 ] . node. update_partial_channel_config( & channel. counterparty. node_id, & [ channel. channel_id, bad_channel_id] , & ChannelConfigUpdate {
10201
+ forwarding_fee_proportional_millionths: Some ( new_fee) ,
10202
+ ..Default :: default ( )
10203
+ } ) ,
10204
+ Err ( APIError :: ChannelUnavailable { err: _ } ) ,
10205
+ )
10206
+ ) ;
10207
+ // Check that the fee hasn't changed for the channel that exists.
10208
+ assert_eq ! ( nodes[ 0 ] . node. list_channels( ) [ 0 ] . config. unwrap( ) . forwarding_fee_proportional_millionths, current_fee) ;
10209
+ let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
10210
+ assert_eq ! ( events. len( ) , 0 ) ;
10175
10211
}
10176
10212
}
10177
10213
0 commit comments