@@ -3541,6 +3541,13 @@ where
3541
3541
. ok_or_else ( || APIError :: ChannelUnavailable { err : format ! ( "Can't find a peer matching the passed counterparty node_id {}" , counterparty_node_id) } ) ?;
3542
3542
let mut peer_state_lock = peer_state_mutex. lock ( ) . unwrap ( ) ;
3543
3543
let peer_state = & mut * peer_state_lock;
3544
+ for channel_id in channel_ids {
3545
+ if !peer_state. has_channel ( channel_id) {
3546
+ return Err ( APIError :: ChannelUnavailable {
3547
+ err : format ! ( "Channel with ID {} was not found for the passed counterparty_node_id {}" , log_bytes!( * channel_id) , counterparty_node_id) ,
3548
+ } ) ;
3549
+ } ;
3550
+ }
3544
3551
for channel_id in channel_ids {
3545
3552
if let Some ( channel) = peer_state. channel_by_id . get_mut ( channel_id) {
3546
3553
let mut config = channel. context . config ( ) ;
@@ -10071,6 +10078,25 @@ mod tests {
10071
10078
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
10072
10079
_ => panic ! ( "expected BroadcastChannelUpdate event" ) ,
10073
10080
}
10081
+
10082
+ // If we provide a channel_id not associated with the peer, we should get an error and no updates
10083
+ // should be applied to ensure update atomicity as specified in the API docs.
10084
+ let bad_channel_id = [ 10 ; 32 ] ;
10085
+ let current_fee = nodes[ 0 ] . node . list_channels ( ) [ 0 ] . config . unwrap ( ) . forwarding_fee_proportional_millionths ;
10086
+ let new_fee = current_fee + 100 ;
10087
+ assert ! (
10088
+ matches!(
10089
+ nodes[ 0 ] . node. update_partial_channel_config( & channel. counterparty. node_id, & [ channel. channel_id, bad_channel_id] , & ChannelConfigUpdate {
10090
+ forwarding_fee_proportional_millionths: Some ( new_fee) ,
10091
+ ..Default :: default ( )
10092
+ } ) ,
10093
+ Err ( APIError :: ChannelUnavailable { err: _ } ) ,
10094
+ )
10095
+ ) ;
10096
+ // Check that the fee hasn't changed for the channel that exists.
10097
+ assert_eq ! ( nodes[ 0 ] . node. list_channels( ) [ 0 ] . config. unwrap( ) . forwarding_fee_proportional_millionths, current_fee) ;
10098
+ let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
10099
+ assert_eq ! ( events. len( ) , 0 ) ;
10074
10100
}
10075
10101
}
10076
10102
0 commit comments