Skip to content

Improve documentation for InboundHTLCState enum states. #634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

valentinewallace
Copy link
Contributor

@jkczyz related to a previous discussion on Slack -- would appreciate your input on whether this is clarifying (though another reviewer will probably have to confirm that everything's correct here, first).

@codecov
Copy link

codecov bot commented May 31, 2020

Codecov Report

Merging #634 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #634   +/-   ##
=======================================
  Coverage   91.26%   91.26%           
=======================================
  Files          35       35           
  Lines       20918    20918           
=======================================
  Hits        19090    19090           
  Misses       1828     1828           
Impacted Files Coverage Δ
lightning/src/ln/channel.rs 86.62% <ø> (ø)

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 f08d610...96daffa. Read the comment docs.

@jkczyz
Copy link
Contributor

jkczyz commented Jun 1, 2020

Yes, definitely much clearer! Especially with the example.

I think a further improvement could be to rename the enum variants. When I was struggling to understand these states, the following questions came to mind:

  • What is being announced? Is it different for each place "announce" is used? Seems like a source of ambiguity.
  • Is "remote" redundant in the "awaiting" states? IMHO, it makes the identifiers a bit of a mouthful.

By answering the first point, I think we can come up with some more intuitive names.

@valentinewallace
Copy link
Contributor Author

valentinewallace commented Jun 1, 2020

Yes, I'd agree with those assessments --

Do you think this would be clearer, for the first 3?

Offered(PendingHTLCStatus)
AwaitingPrevStateRAAToAccept(PendingHTLCStatus)
AwaitingFinalRAA(PendingHTLCStatus)

I prefer the terms "offered" and "accepted", since they align with the spec better.

If the first Q was not rhetorical, it seems to me like there are 3 different definitions of "announced" here. In RemoteAnnounced, Announced == offered. In AwaitingRemoteRevokeToAnnounce, Announce = accept. In AwaitingAnnouncedRemoteRevoke, Announced = "sent"(?). Though @TheBlueMatt would have to confirm these guesses...

@jkczyz
Copy link
Contributor

jkczyz commented Jun 1, 2020

I like Offered. And I'd like to make sure "accepted" has a clear definition.

For the Awaiting states, given there are comments that each implies AwaitingRemoteRevoke, one possibility is to not encode that information in the name at all. Rather, name states in a logically consistent manner with respect to the HTLC itself and define what those names mean in terms of messages that have been passed within the documentation.

One idea:

enum InboundHTLCState {
	Offered(PendingHTLCStatus),
	Pending(PendingHTLCStatus),
	Accepted(PendingHTLCStatus),
	Committed,
	Removed(InboundHTLCRemovalReason),
}

I'm not sure if there are better names for Pending and Accepted, so let me know if something better comes to mind. I would want to make sure we aren't overloading the term "pending" elsewhere for instance. And even better if we are consistent with terminology used elsewhere. So maybe "Held" or something similar would be more appropriate.

Thoughts?

@valentinewallace
Copy link
Contributor Author

valentinewallace commented Jun 1, 2020

Agree pending is a bit overloaded, but I like the direction of those names. I slightly preferred LocalRemoved since the remote has not removed the HTLC, so it's not fully removed per se.

My definition of "accepted" means the HTLC is definitely in our commitment tx and we've sent commitment sigs for it. I can explicitly define it the comments. But, the spec doesn't explicitly define it.

edit: removed my suggestion for the Pending replacement, wasn't a fan actually

@jkczyz
Copy link
Contributor

jkczyz commented Jun 1, 2020

FYI, my argument for using Held instead of Pending would be if it corresponded to HTLCs in the holding cell, which I'm not certain about.

Don't have a strong opinion yet on LocalRemoved. One argument for leaving the prefix out -- or keeping it in for that matter -- is that each state could possibly be similarly prefixed by either "Local" or "Remote" if there is some ambiguity. Though I hope that with whatever naming we decide on, the "inbound" context makes it clear which. The same goes for renaming the states within OutboundHTLCState. So trying a similar renaming there may help determine what sort of prefixing, if any, works best.

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.

Nice! Thanks.

/// Included in a received commitment_signed message (implying we've revoke_and_ack'd it), but
/// the remote hasn't yet revoked their previous state (see the example below). We have not yet
/// included this HTLC in a commitment_signed message because we are waiting on the remote's
/// aforementioned state revocation. The reason we need this remote RAA (revoke_and_ack) is
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel a bit awkward calling this the reason - is true, it is a reason, but the other reason is because RAA "commits" a state, but doesn't specify which state, leaving an implication of it ACK'ing the latest state (commitent_signed that we sent).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if the new version is good. I added the second reason as the last sentence of the paragraph

@valentinewallace valentinewallace force-pushed the improve-inbound-htlc-docs branch 2 times, most recently from a6d1b81 to 20e1b78 Compare June 8, 2020 21:37
@valentinewallace
Copy link
Contributor Author

valentinewallace commented Jun 8, 2020

I like Offered. And I'd like to make sure "accepted" has a clear definition.

For the Awaiting states, given there are comments that each implies AwaitingRemoteRevoke, one possibility is to not encode that information in the name at all. Rather, name states in a logically consistent manner with respect to the HTLC itself and define what those names mean in terms of messages that have been passed within the documentation.

One idea:

enum InboundHTLCState {
	Offered(PendingHTLCStatus),
	Pending(PendingHTLCStatus),
	Accepted(PendingHTLCStatus),
	Committed,
	Removed(InboundHTLCRemovalReason),
}

I'm not sure if there are better names for Pending and Accepted, so let me know if something better comes to mind. I would want to make sure we aren't overloading the term "pending" elsewhere for instance. And even better if we are consistent with terminology used elsewhere. So maybe "Held" or something similar would be more appropriate.

Thoughts?

@jkczyz Upon further reflection, I'm in favor of all these names, except Pending, which I'm in favor of switching to Blocked. Sorta captures that the HTLC's progress is blocked on an RAA. And I'd probably like to do a separate PR, since this one seems pretty close to mergable + self-contained. Would agree that it'd be best to change the names of the Inbound and Outbound HTLC states in the same PR, though, to make sure they align well.

@valentinewallace
Copy link
Contributor Author

FYI, my argument for using Held instead of Pending would be if it corresponded to HTLCs in the holding cell, which I'm not certain about.

Don't have a strong opinion yet on LocalRemoved. One argument for leaving the prefix out -- or keeping it in for that matter -- is that each state could possibly be similarly prefixed by either "Local" or "Remote" if there is some ambiguity. Though I hope that with whatever naming we decide on, the "inbound" context makes it clear which. The same goes for renaming the states within OutboundHTLCState. So trying a similar renaming there may help determine what sort of prefixing, if any, works best.

IMO "Held" could be a tad misleading since these HTLCs are a subset of all HTLCs in the holding cell, afaict from the holding cell code?

@jkczyz
Copy link
Contributor

jkczyz commented Jun 8, 2020

@jkczyz Upon further reflection, I'm in favor of all these names, except Pending, which I'm in favor of switching to Blocked. Sorta captures that the HTLC's progress is blocked on an RAA. And I'd probably like to do a separate PR, since this one seems pretty close to mergable + self-contained. Would agree that it'd be best to change the names of the Inbound and Outbound HTLC states in the same PR, though, to make sure they align well.

SGTM. Yes, Blocked is much better!

IMO "Held" could be a tad misleading since these HTLCs are a subset of all HTLCs in the holding cell, afaict from the holding cell code?

Good point -- I think you're right.

@valentinewallace valentinewallace force-pushed the improve-inbound-htlc-docs branch from 20e1b78 to 96daffa Compare June 11, 2020 18:40
@TheBlueMatt TheBlueMatt merged commit 9be497c into lightningdevkit:master Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants