Skip to content

Commit f322b3a

Browse files
committed
f make sure chan updates are atomic
1 parent 910d148 commit f322b3a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,6 +3540,13 @@ where
35403540
.ok_or_else(|| APIError::ChannelUnavailable { err: format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id) })?;
35413541
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
35423542
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+
}
35433550
for channel_id in channel_ids {
35443551
if let Some(channel) = peer_state.channel_by_id.get_mut(channel_id) {
35453552
let mut config = channel.context.config();
@@ -10151,6 +10158,25 @@ mod tests {
1015110158
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
1015210159
_ => panic!("expected BroadcastChannelUpdate event"),
1015310160
}
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);
1015410180
}
1015510181
}
1015610182

0 commit comments

Comments
 (0)