Pass counterparty_node_id to accept_inbound_channel

This commit is contained in:
Viktor Tigerström 2022-05-13 00:13:39 +02:00
parent c581bab8be
commit 70fa465924
2 changed files with 15 additions and 10 deletions

View 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 /// Called to accept a request to open a channel after [`Event::OpenChannelRequest`] has been
/// triggered. /// 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 /// 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 /// [`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::OpenChannelRequest`]: events::Event::OpenChannelRequest
/// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id /// [`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 _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
let mut channel_state_lock = self.channel_state.lock().unwrap(); 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() { if !channel.get().inbound_is_awaiting_accept() {
return Err(APIError::APIMisuseError { err: "The channel isn't currently awaiting to be accepted.".to_owned() }); 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 { channel_state.pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
node_id: channel.get().get_counterparty_node_id(), node_id: channel.get().get_counterparty_node_id(),
msg: channel.get_mut().accept_inbound_channel(user_channel_id), msg: channel.get_mut().accept_inbound_channel(user_channel_id),

View file

@ -8283,7 +8283,7 @@ fn test_manually_accept_inbound_channel_request() {
let events = nodes[1].node.get_and_clear_pending_events(); let events = nodes[1].node.get_and_clear_pending_events();
match events[0] { match events[0] {
Event::OpenChannelRequest { temporary_channel_id, .. } => { 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"), _ => 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(); let events = nodes[1].node.get_and_clear_pending_events();
match events[0] { match events[0] {
Event::OpenChannelRequest { temporary_channel_id, .. } => { Event::OpenChannelRequest { temporary_channel_id, .. } => {
nodes[1].node.accept_inbound_channel(&temporary_channel_id, 0).unwrap(); 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, 0); let api_res = nodes[1].node.accept_inbound_channel(&temporary_channel_id, &nodes[0].node.get_our_node_id(), 0);
match api_res { match api_res {
Err(APIError::APIMisuseError { err }) => { Err(APIError::APIMisuseError { err }) => {
assert_eq!(err, "The channel isn't currently awaiting to be accepted."); 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] #[test]
fn test_can_not_accept_unknown_inbound_channel() { fn test_can_not_accept_unknown_inbound_channel() {
let chanmon_cfg = create_chanmon_cfgs(1); let chanmon_cfg = create_chanmon_cfgs(2);
let node_cfg = create_node_cfgs(1, &chanmon_cfg); let node_cfg = create_node_cfgs(2, &chanmon_cfg);
let node_chanmgr = create_node_chanmgrs(1, &node_cfg, &[None]); let node_chanmgr = create_node_chanmgrs(2, &node_cfg, &[None, None]);
let node = create_network(1, &node_cfg, &node_chanmgr)[0].node; let nodes = create_network(2, &node_cfg, &node_chanmgr);
let unknown_channel_id = [0; 32]; 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 { match api_res {
Err(APIError::ChannelUnavailable { err }) => { Err(APIError::ChannelUnavailable { err }) => {
assert_eq!(err, "Can't accept a channel that doesn't exist"); assert_eq!(err, "Can't accept a channel that doesn't exist");