Skip to content

Conversation

@shamardy
Copy link
Contributor

This PR allows the user to track inbound channels closures by user_channel_id if user_channel_id is added when processing an OpenChannelRequest event.

@codecov-commenter
Copy link

codecov-commenter commented Mar 24, 2022

Codecov Report

Merging #1381 (14eb2d7) into main (f6fa8e9) will decrease coverage by 0.01%.
The diff coverage is 91.66%.

❗ Current head 14eb2d7 differs from pull request most recent head c156eea. Consider uploading reports for the commit c156eea to get more accurate results

@@            Coverage Diff             @@
##             main    #1381      +/-   ##
==========================================
- Coverage   90.81%   90.79%   -0.02%     
==========================================
  Files          73       73              
  Lines       41209    41211       +2     
  Branches    41209    41211       +2     
==========================================
- Hits        37424    37419       -5     
- Misses       3785     3792       +7     
Impacted Files Coverage Δ
lightning/src/ln/channel.rs 89.18% <80.00%> (-0.03%) ⬇️
lightning/src/ln/channelmanager.rs 84.85% <100.00%> (ø)
lightning/src/ln/functional_tests.rs 97.06% <100.00%> (-0.10%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f6fa8e9...c156eea. Read the comment docs.

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be trivial to add a test for this?

LGTM though after squash.

@shamardy shamardy force-pushed the 2022-03-set-inbound-user-chan-id branch from c156eea to a385b67 Compare March 24, 2022 22:49
@shamardy
Copy link
Contributor Author

Would it be trivial to add a test for this?

It's not needed in my opinion but can add a test if you think otherwise. user_channel_id: None case is already covered.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

///
/// [`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: Option<u64>) -> Result<(), APIError> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason to set this to an Option, the alternative is user_id is always 0 so there's no difference between None and 0.

/// 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
/// with which `accept_inbound_channel` call.
///
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: here and in events.rs you have EOL whitespace. git show locally should highlight them for you so its easy to remove them.

match events[0] {
Event::OpenChannelRequest { temporary_channel_id, .. } => {
nodes[1].node.accept_inbound_channel(&temporary_channel_id).unwrap();
nodes[1].node.accept_inbound_channel(&temporary_channel_id, None).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be trivial to just set a value here and test that you get it back if the channel is closed, no? Given its trivial might as well add a test to ensure we don't regress...you never know :p

fix docs

edit user_channel_id docs for Event::ChannelClosed

review fixes
@shamardy shamardy force-pushed the 2022-03-set-inbound-user-chan-id branch from a385b67 to edd4bab Compare March 25, 2022 03:40
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

channel_state.pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
node_id: counterparty_node_id.clone(),
msg: channel.accept_inbound_channel(),
msg: channel.accept_inbound_channel(0),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this now overwrites the user id for outbound channels - can either make the channel.rs function an Option again or re-set it by fetching the channel's ID here.

Copy link
Contributor Author

@shamardy shamardy Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me how this can happen since accept_inbound_channel doesn't allow outbound channels modifications

pub fn accept_inbound_channel(&mut self, user_id: u64) -> msgs::AcceptChannel {
if self.is_outbound() {
panic!("Tried to send accept_channel for an outbound channel?");
}

But I guess it's better to use get_user_id anyways.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I'm sorry, yes. So this comment is in internal_open_channel, not accept_inbound_channel, but I clearly wasn't thinking, that is also for inbound channels so no problem.

@valentinewallace valentinewallace merged commit eb50201 into lightningdevkit:main Mar 25, 2022
@shamardy shamardy deleted the 2022-03-set-inbound-user-chan-id branch March 25, 2022 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants