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