From: Viktor Tigerström <11711198+ViktorTigerstrom@users.noreply.github.com> Date: Thu, 12 May 2022 22:13:39 +0000 (+0200) Subject: Pass `counterparty_node_id` to `accept_inbound_channel` X-Git-Tag: v0.0.107~27^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=70fa46592465e4bbdf1e2cb34346c36486baefbe;p=rust-lightning Pass `counterparty_node_id` to `accept_inbound_channel` --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index d40c3bb4c..8e39e8718 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -4112,7 +4112,9 @@ impl 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 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 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), diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index f25875d24..5f24314a2 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -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");