Pass `counterparty_node_id` to `accept_inbound_channel`
[rust-lightning] / lightning / src / ln / channelmanager.rs
index d40c3bb4c1d960190053347692967e2de6873842..8e39e87185b8101fcf0d15da688b0381faf14959 100644 (file)
@@ -4112,7 +4112,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
        /// Called to accept a request to open a channel after [`Event::OpenChannelRequest`] has been
        /// triggered.
        ///
-       /// The `temporary_channel_id` parameter indicates which inbound channel should be accepted.
+       /// The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
+       /// and the `counterparty_node_id` parameter is the id of the peer which has requested to open
+       /// the channel.
        ///
        /// For inbound channels, the `user_channel_id` parameter will be provided back in
        /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
@@ -4120,7 +4122,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
        ///
        /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
        /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
-       pub fn accept_inbound_channel(&self, temporary_channel_id: &[u8; 32], user_channel_id: u64) -> Result<(), APIError> {
+       pub fn accept_inbound_channel(&self, temporary_channel_id: &[u8; 32], counterparty_node_id: &PublicKey, user_channel_id: u64) -> Result<(), APIError> {
                let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
 
                let mut channel_state_lock = self.channel_state.lock().unwrap();
@@ -4130,6 +4132,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                                if !channel.get().inbound_is_awaiting_accept() {
                                        return Err(APIError::APIMisuseError { err: "The channel isn't currently awaiting to be accepted.".to_owned() });
                                }
+                               if *counterparty_node_id != channel.get().get_counterparty_node_id() {
+                                       return Err(APIError::APIMisuseError { err: "The passed counterparty_node_id doesn't match the channel's counterparty node_id".to_owned() });
+                               }
                                channel_state.pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
                                        node_id: channel.get().get_counterparty_node_id(),
                                        msg: channel.get_mut().accept_inbound_channel(user_channel_id),