@@ -3540,6 +3540,13 @@ where
3540
3540
. ok_or_else ( || APIError :: ChannelUnavailable { err : format ! ( "Can't find a peer matching the passed counterparty node_id {}" , counterparty_node_id) } ) ?;
3541
3541
let mut peer_state_lock = peer_state_mutex. lock ( ) . unwrap ( ) ;
3542
3542
let peer_state = & mut * peer_state_lock;
3543
+ for channel_id in channel_ids {
3544
+ if !peer_state. has_channel ( channel_id) {
3545
+ return Err ( APIError :: ChannelUnavailable {
3546
+ err : format ! ( "Channel with ID {} was not found for the passed counterparty_node_id {}" , log_bytes!( * channel_id) , counterparty_node_id) ,
3547
+ } ) ;
3548
+ } ;
3549
+ }
3543
3550
for channel_id in channel_ids {
3544
3551
if let Some ( channel) = peer_state. channel_by_id . get_mut ( channel_id) {
3545
3552
let mut config = channel. context . config ( ) ;
@@ -10151,6 +10158,25 @@ mod tests {
10151
10158
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
10152
10159
_ => panic ! ( "expected BroadcastChannelUpdate event" ) ,
10153
10160
}
10161
+
10162
+ // If we provide a channel_id not associated with the peer, we should get an error and no updates
10163
+ // should be applied to ensure update atomicity as specified in the API docs.
10164
+ let bad_channel_id = [ 10 ; 32 ] ;
10165
+ let current_fee = nodes[ 0 ] . node . list_channels ( ) [ 0 ] . config . unwrap ( ) . forwarding_fee_proportional_millionths ;
10166
+ let new_fee = current_fee + 100 ;
10167
+ assert ! (
10168
+ matches!(
10169
+ nodes[ 0 ] . node. update_partial_channel_config( & channel. counterparty. node_id, & [ channel. channel_id, bad_channel_id] , & ChannelConfigUpdate {
10170
+ forwarding_fee_proportional_millionths: Some ( new_fee) ,
10171
+ ..Default :: default ( )
10172
+ } ) ,
10173
+ Err ( APIError :: ChannelUnavailable { err: _ } ) ,
10174
+ )
10175
+ ) ;
10176
+ // Check that the fee hasn't changed for the channel that exists.
10177
+ assert_eq ! ( nodes[ 0 ] . node. list_channels( ) [ 0 ] . config. unwrap( ) . forwarding_fee_proportional_millionths, current_fee) ;
10178
+ let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
10179
+ assert_eq ! ( events. len( ) , 0 ) ;
10154
10180
}
10155
10181
}
10156
10182
0 commit comments