Pass `counterparty_node_id` to `accept_inbound_channel`
authorViktor Tigerström <11711198+ViktorTigerstrom@users.noreply.github.com>
Thu, 12 May 2022 22:13:39 +0000 (00:13 +0200)
committerViktor Tigerström <11711198+ViktorTigerstrom@users.noreply.github.com>
Sat, 14 May 2022 18:32:44 +0000 (20:32 +0200)
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_tests.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),
index f25875d2432dcb27881df4f378ec6910cf6e8d70..5f24314a29f320f507084b51d22130f9c08b3b01 100644 (file)
@@ -8283,7 +8283,7 @@ fn test_manually_accept_inbound_channel_request() {
        let events = nodes[1].node.get_and_clear_pending_events();
        match events[0] {
                Event::OpenChannelRequest { temporary_channel_id, .. } => {
-                       nodes[1].node.accept_inbound_channel(&temporary_channel_id, 23).unwrap();
+                       nodes[1].node.accept_inbound_channel(&temporary_channel_id, &nodes[0].node.get_our_node_id(), 23).unwrap();
                }
                _ => panic!("Unexpected event"),
        }
@@ -8433,8 +8433,8 @@ fn test_can_not_accept_inbound_channel_twice() {
        let events = nodes[1].node.get_and_clear_pending_events();
        match events[0] {
                Event::OpenChannelRequest { temporary_channel_id, .. } => {
-                       nodes[1].node.accept_inbound_channel(&temporary_channel_id, 0).unwrap();
-                       let api_res = nodes[1].node.accept_inbound_channel(&temporary_channel_id, 0);
+                       nodes[1].node.accept_inbound_channel(&temporary_channel_id, &nodes[0].node.get_our_node_id(), 0).unwrap();
+                       let api_res = nodes[1].node.accept_inbound_channel(&temporary_channel_id, &nodes[0].node.get_our_node_id(), 0);
                        match api_res {
                                Err(APIError::APIMisuseError { err }) => {
                                        assert_eq!(err, "The channel isn't currently awaiting to be accepted.");
@@ -8460,13 +8460,13 @@ fn test_can_not_accept_inbound_channel_twice() {
 
 #[test]
 fn test_can_not_accept_unknown_inbound_channel() {
-       let chanmon_cfg = create_chanmon_cfgs(1);
-       let node_cfg = create_node_cfgs(1, &chanmon_cfg);
-       let node_chanmgr = create_node_chanmgrs(1, &node_cfg, &[None]);
-       let node = create_network(1, &node_cfg, &node_chanmgr)[0].node;
+       let chanmon_cfg = create_chanmon_cfgs(2);
+       let node_cfg = create_node_cfgs(2, &chanmon_cfg);
+       let node_chanmgr = create_node_chanmgrs(2, &node_cfg, &[None, None]);
+       let nodes = create_network(2, &node_cfg, &node_chanmgr);
 
        let unknown_channel_id = [0; 32];
-       let api_res = node.accept_inbound_channel(&unknown_channel_id, 0);
+       let api_res = nodes[0].node.accept_inbound_channel(&unknown_channel_id, &nodes[1].node.get_our_node_id(), 0);
        match api_res {
                Err(APIError::ChannelUnavailable { err }) => {
                        assert_eq!(err, "Can't accept a channel that doesn't exist");