Skip to content

Commit 8321438

Browse files
committed
f make sure chan updates are atomic
1 parent 9431916 commit 8321438

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
@@ -3541,6 +3541,13 @@ where
35413541
.ok_or_else(|| APIError::ChannelUnavailable { err: format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id) })?;
35423542
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
35433543
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+
}
35443551
for channel_id in channel_ids {
35453552
if let Some(channel) = peer_state.channel_by_id.get_mut(channel_id) {
35463553
let mut config = channel.context.config();
@@ -10071,6 +10078,25 @@ mod tests {
1007110078
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
1007210079
_ => panic!("expected BroadcastChannelUpdate event"),
1007310080
}
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);
1007410100
}
1007510101
}
1007610102

0 commit comments

Comments
 (0)