Skip to content
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

[anchor] Pluggable commitments #3829

Merged

Conversation

halseth
Copy link
Contributor

@halseth halseth commented Dec 12, 2019

This lays the groundwork for making it easy to introduce anchor commitments.

Replaces #3773

@halseth halseth requested a review from joostjager December 12, 2019 14:57
lnwallet/commitment.go Show resolved Hide resolved
lnwallet/commitment.go Show resolved Hide resolved
@halseth halseth force-pushed the pluggable-commitments-lnwallet branch from 7988c13 to 8997dbd Compare December 13, 2019 09:33
@halseth halseth marked this pull request as ready for review December 13, 2019 09:34
@halseth halseth added this to the 0.9.0 milestone Dec 13, 2019
@halseth halseth force-pushed the pluggable-commitments-lnwallet branch from 8997dbd to d312255 Compare December 13, 2019 10:06
@halseth halseth force-pushed the pluggable-commitments-lnwallet branch from d312255 to 59cfcd9 Compare December 13, 2019 10:35
@joostjager joostjager self-requested a review December 17, 2019 11:47
Copy link
Contributor

@joostjager joostjager left a comment

Choose a reason for hiding this comment

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

Great improvement in the structure of the code and separation of responsibilities. I definitely feel more comfortable building anchor outputs on top of this.

With regards to naming, it can get quite confusing here and there with the definition of local/remote. Maybe in some cases, our and their may be more clear.

And I keep thinking that it should be possible to also convert the remaining commitment.go funcs to methods, perhaps on a lighter struct. Just to prevent mistakes with passing in parameters. I don't know if it is worth the effort at this point though.

lnwallet/channel.go Outdated Show resolved Hide resolved
lnwallet/channel.go Outdated Show resolved Hide resolved
lnwallet/channel.go Show resolved Hide resolved
lnwallet/channel.go Outdated Show resolved Hide resolved
lnwallet/commitment.go Show resolved Hide resolved
lnwallet/channel.go Outdated Show resolved Hide resolved
lnwallet/commitment.go Show resolved Hide resolved
lnwallet/commitment.go Show resolved Hide resolved
lnwallet/channel.go Show resolved Hide resolved
lnwallet/commitment.go Show resolved Hide resolved
// CommitSpendNoDelayTweakless is similar to the CommitSpendNoDelay
// type, but it omits the tweak that randomizes the key we need to
// spend with a channel peer supplied set of randomness.
CommitSpendNoDelayTweakless StandardWitnessType = 12
Copy link
Contributor

Choose a reason for hiding this comment

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

idt we can actually remove this since these values are persisted. may need to keep this behavior, but funnel all new channels into the consolidated logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where are they persisted exactly?

What we can do is just define it there (or change the name here to indicate it should not be used anymore), and convert it to the common type when reading it from disk.

Copy link
Contributor

Choose a reason for hiding this comment

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

breacharbiter and nursery for sure, probably a few other places.

What we can do is just define it there (or change the name here to indicate it should not be used anymore), and convert it to the common type when reading it from disk.

would need to see in how many places the serialization logic lives, but that's definitely one path. or we just leave the switch statements in place. since the tweakless-ness is now signaled through the sign descriptor, it might not be so bad

Copy link
Member

Choose a reason for hiding this comment

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

Had the same thought when I saw this, IIRC they're also persisted in some tower logic as well. Even independent of that, it's a useful witness type, as I may want to pass the very same sign descriptor for the two commitment types, an example being in the future if we opt to allow existing channels to switch over to this new witness type.

lnwallet/commitment.go Outdated Show resolved Hide resolved
lnwallet/channel.go Outdated Show resolved Hide resolved
lnwallet/commitment.go Show resolved Hide resolved
@halseth halseth force-pushed the pluggable-commitments-lnwallet branch from 59cfcd9 to 80f4ece Compare December 19, 2019 09:35
@halseth
Copy link
Contributor Author

halseth commented Dec 19, 2019

With regards to naming, it can get quite confusing here and there with the definition of local/remote. Maybe in some cases, our and their may be more clear.

I did a sweep to find a few places where this could be made more clear. Opted for ours/theirs in cases of static perspective (where we are always handling keys, outputs, commitments from our local node perspective), and local/remote for the dynamic perspective (where we are sharing logic from both perspectives).

Obviously this naming is used interchangeably throughout the codebase, so it was an effort way to large for this PR to change it everywhere, but would be nice to decide on a naming scheme and stick to it going forward.

I did the change in the parts already touched by this PR and for the ChannelConfigs:
0785952
7f7449d
03a6d37
4f02cde
80f4ece

lmk what you think!

@halseth halseth force-pushed the pluggable-commitments-lnwallet branch 2 times, most recently from 2d5ef02 to e37e62f Compare December 19, 2019 14:14
@halseth
Copy link
Contributor Author

halseth commented Dec 19, 2019

With regards to naming, it can get quite confusing here and there with the definition of local/remote. Maybe in some cases, our and their may be more clear.

I did a sweep to find a few places where this could be made more clear. Opted for ours/theirs in cases of static perspective (where we are always handling keys, outputs, commitments from our local node perspective), and local/remote for the dynamic perspective (where we are sharing logic from both perspectives).

Obviously this naming is used interchangeably throughout the codebase, so it was an effort way to large for this PR to change it everywhere, but would be nice to decide on a naming scheme and stick to it going forward.

I did the change in the parts already touched by this PR and for the ChannelConfigs:
0785952
7f7449d
03a6d37
4f02cde
80f4ece

lmk what you think!

Ended up reverting most of these changes, since it made a large PR even larger. I think we should agree on a proper way of naming things, and do a PR that does only that change if wanted.

@halseth halseth force-pushed the pluggable-commitments-lnwallet branch from e37e62f to 2703a10 Compare December 19, 2019 14:35
Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

@halseth did another pass, overall pr looks pretty complete. only q rn is how to deal with existing CommitmentNoDelayTweakless witness types in the database

@@ -193,10 +191,6 @@ func genTaskTest(
}

witnessType := input.CommitmentNoDelay
if tweakless {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems we don't test tweakless at all now?

// CommitSpendNoDelayTweakless is similar to the CommitSpendNoDelay
// type, but it omits the tweak that randomizes the key we need to
// spend with a channel peer supplied set of randomness.
CommitSpendNoDelayTweakless StandardWitnessType = 12
Copy link
Contributor

Choose a reason for hiding this comment

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

breacharbiter and nursery for sure, probably a few other places.

What we can do is just define it there (or change the name here to indicate it should not be used anymore), and convert it to the common type when reading it from disk.

would need to see in how many places the serialization logic lives, but that's definitely one path. or we just leave the switch statements in place. since the tweakless-ness is now signaled through the sign descriptor, it might not be so bad

@halseth halseth force-pushed the pluggable-commitments-lnwallet branch from 2703a10 to d808d13 Compare December 20, 2019 08:29
@halseth halseth mentioned this pull request Dec 20, 2019
@halseth
Copy link
Contributor Author

halseth commented Dec 20, 2019

Removed the last commit, we can move that discussion to #3864, as it is not essential for anchor progress.

@halseth halseth force-pushed the pluggable-commitments-lnwallet branch from 0e58bf8 to 1281443 Compare January 3, 2020 11:40
Copy link
Contributor

@joostjager joostjager left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

did a final pass, only minor comments. otherwise LGTM! 👍

+1 for keeping local/remote instead of ours/theirs

lnwallet/channel.go Show resolved Hide resolved
lnwallet/channel.go Show resolved Hide resolved
lnwallet/commitment.go Outdated Show resolved Hide resolved
@@ -36,11 +39,14 @@ type CommitmentKeyRing struct {
// the local HTLC base point. This value is needed in order to
// derive the final key used within the HTLC scripts in the commitment
// transaction.
//
// NOTE: This will always refer to "our" local HTLC key, regardless of
Copy link
Contributor

Choose a reason for hiding this comment

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

this is indeed quite confusing that it doesn't switch perspectives like everything else, esp if isOurs is passed into the derivation. probably not worth fixing rn tho

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this led to some confusion during review.

I also tried switching the perspective always, but that turned out to be a large change since it will ripple through many parts of the codebase, so felt it was better to leave it as-is for now, with some clarifying commentary.

lnwallet/commitment.go Outdated Show resolved Hide resolved
lnwallet/commitment.go Show resolved Hide resolved
lnwallet/commitment.go Outdated Show resolved Hide resolved
input/signdescriptor.go Show resolved Hide resolved
@halseth halseth force-pushed the pluggable-commitments-lnwallet branch 2 times, most recently from 5914f8d to 3dfeeab Compare January 6, 2020 10:40
It was incorrectly stated that the commitment balance was before
subctracting the commit fee, which led to some confusion.
It has no dependency on LightningChannel
Instead of passing delays and dustlimits separately, we pass the correct
channel config to CreateCommitTx from the POV of the local party that
owns the commit tx.

To make it more clear which commitment we are actually creating, we
rename variables to denote local and remote, to prepare for the case
when both outputs might be delayed.
PURE CODE MOVE:
Moving createCommitmentTx, CreateCommitTx, createStateHintObfuscator,
CommitmentKeyRing, DeriveCommitmentKeys, addHTLC, genHtlcScripts

We move the methods and structs to a new file commitment.go in
preparation for defining all the logic that is dependent on the channel
type in this new file.
We define a new struct CommitmentBuilder that will be used to craft the
final commitment transaction based on the current active channel type.
@halseth halseth force-pushed the pluggable-commitments-lnwallet branch from 3dfeeab to a7dfc97 Compare January 6, 2020 10:42
createCommitmentTx would earlier mutate the passed commitment struct
after evaluating the htlc view and calculating the final balances, which
was confusing since the balances are supposed to only be *after*
subtracting fees.

Instead we take the needed parameters as arguments, and return the final
balances, tx and fee to populate the commitment struct in a proper way.
Since both parties are going to have their ouputs delayed, we move way
from the DelayKey naming, and instead use ToLocalKey and ToRemoteKey.
We abstract away how keys are generated for the different channel types
types (currently tweak(less)).

Intention is that more of the logic that is unique for each commitment
type lives in commitment.go, making the channel state machine oblivious
to the keys and outputs being created on the commitment tx for a given
channel state.
To make the channel state machine less concerned about the type of
commitment, we nil the local tweak when creating the keyring, depending
on the commitment type.
Also update the WitnessScript doc to note it should be set also for
p2wkh.
Based on the current channel type, we derive the script used for the
to_remote output. Currently only the unencumbered p2wkh type is used,
but that will change with upcoming channel types.
When creating the keyring, the tweak is already calculated in the remote
commitment case. We add the calculation also for our own commitment, so
we can use it in all cases without deriving the tweak.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants