Skip to content

Handle peer disconnect tracking/channel_reestablish - #178

Merged
TheBlueMatt merged 8 commits into
lightningdevkit:masterfrom
TheBlueMatt:2018-09-channel_reestablish
Sep 15, 2018
Merged

TheBlueMatt merged 8 commits into
lightningdevkit:masterfrom
TheBlueMatt:2018-09-channel_reestablish

Conversation

@TheBlueMatt

@TheBlueMatt TheBlueMatt commented Sep 13, 2018 •

Copy link
Copy Markdown
Collaborator

This is based on #177 just cause thats easier with my workflow, but mostly tracks peer/channel connectedness/disconnectedness status and handles generating/processing channel_reestablish messages. It still needs some tests before its mergeable but I figured I'd open it up in case anyone wanted to review.

This is most of #138!

@TheBlueMatt
TheBlueMatt force-pushed the 2018-09-channel_reestablish branch 2 times, most recently from f530de5 to b79886b Compare September 13, 2018 22:38
@TheBlueMatt
TheBlueMatt force-pushed the 2018-09-channel_reestablish branch from b79886b to d50101f Compare September 14, 2018 00:30
@TheBlueMatt

Copy link
Copy Markdown
Collaborator Author

Now based on #179.

Comment thread src/ln/channel.rs Outdated
self.channel_update_count += 1;
} else if self.channel_state & (ChannelState::ChannelFunded as u32) != 0 &&
self.cur_local_commitment_transaction_number == (1 << 48) - 2 &&
self.cur_remote_commitment_transaction_number == (1 << 48) - 2 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry didn't get the rationale for testing against these specific values, why decrease max commitment transaction number by 2 ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added a comment.

Comment thread src/ln/channel.rs Outdated
err = Some(e);
if let Some(msgs::ErrorAction::IgnoreError) = e.action {}
else {
panic!("Got a non-IgnoreError action trying to fulfill holding cell HTLC");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wouldn't be "trying to fail holding cell HTLC" here ?

@TheBlueMatt TheBlueMatt Sep 14, 2018 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, though note the comment was on the wrong line, this one is fulfilil, the fail one is the next hunk down.

Comment thread src/ln/channel.rs
}
}

self.holding_cell_htlc_updates.retain(|htlc_update| {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should be a good pattern to use drain_filter and avoid clone, sad it's still nightly-only..

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yea, sadly gonna be a while before we can upgrade to that :(

Comment thread src/ln/channel.rs Outdated
return Err(HandleError{err: "Peer sent a loose channel_reestablish not after reconnect", action: Some(msgs::ErrorAction::SendErrorMessage{msg: msgs::ErrorMessage{data: "Peer sent a loose channel_reestablish not after reconnect".to_string(), channel_id: msg.channel_id}})});
}

if msg.next_local_commitment_number == 0 || msg.next_local_commitment_number >= 0xffffffffffff ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is a const MAX_COMMITMENT_NUMBER could be more meaningful? (mostly to avoid confusion with 0xfffffffffffe on a quick skim)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added a constant (note that its INITIAL_COMMITMENT_NUMBER not MAX, see the comment in Channel above the commitment number fields for why).

Comment thread src/ln/channel.rs Outdated
self.channel_state &= !(ChannelState::PeerDisconnected as u32);

let mut required_revoke = None;
if msg.next_remote_commitment_number == 0xffffffffffff - self.cur_local_commitment_transaction_number {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

maybe add a comment there? "Remote and local nodes are up-to-date" if understand it well, void if clause is still confusing at first.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added more comment.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks ! Easier to understand it with this and constify of 2**48 -1 !

Comment thread src/ln/channel.rs Outdated
if (self.channel_state & (ChannelState::PeerDisconnected as u32)) == (ChannelState::PeerDisconnected as u32) {
// Note that this should never really happen, if we're !is_live() on receipt of an
// incoming HTLC for relay will result in us rejecting the HTLC and we won't allow
// the user to send directly into a !is_live() channel. However, if we we

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

duplicate *we

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Heh, fixed.

@TheBlueMatt
TheBlueMatt force-pushed the 2018-09-channel_reestablish branch 3 times, most recently from fd9673f to 4949470 Compare September 14, 2018 20:26
Comment thread src/ln/channel.rs Outdated
for (idx, htlc) in self.pending_inbound_htlcs.iter().enumerate() {
if htlc.htlc_id == htlc_id_arg {
if htlc.state != InboundHTLCState::Committed {
debug_assert!(false, "Have an inbound HTLC we tried to claim before it was fully committed to");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tried to fail.. ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oops, fixed.

@TheBlueMatt
TheBlueMatt force-pushed the 2018-09-channel_reestablish branch 2 times, most recently from 109f18c to 57c070c Compare September 14, 2018 21:39
@ariard

ariard commented Sep 15, 2018

Copy link
Copy Markdown

ACK, have reviewed the remaining part of ChannelManager and tests. Seems to me that channel_reestablish is compliant with Message Retransmission of BOLT 2, except of option_data_loss_protect optional part.

@TheBlueMatt
TheBlueMatt force-pushed the 2018-09-channel_reestablish branch from 57c070c to e606f13 Compare September 15, 2018 14:53
@TheBlueMatt
TheBlueMatt merged commit 97488ad into lightningdevkit:master Sep 15, 2018
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.

3 participants