Skip to content

watchtower: conditionally reconstruct justice txns for anchor channels - #4576

Merged
Roasbeef merged 8 commits into
lightningnetwork:masterfrom
cfromknecht:anchor-justice-txn
Sep 23, 2020
Merged

Roasbeef merged 8 commits into
lightningnetwork:masterfrom
cfromknecht:anchor-justice-txn

Conversation

@cfromknecht

Copy link
Copy Markdown
Contributor

This PR is the first in a series that will enable watchtower support for anchor channels in 0.12.
We start by adding a new blob.FlagAnchorChannel indicating whether an encrypted blob is
supposed to spend an anchor channel. Upon successful decryption, this bit is used to signal
that the tower needs to craft the justice txn such that properly spends a to_remote_confirmed
p2wsh input rather than the legacy to_remote p2wkh input.

The good news is that these changes require no modification of the encrypted payload format.
The anchor payloads are equal size and contain exactly the same witness info as the legacy
payloads, only requiring light modifications to the reconstruction logic.

Comment thread watchtower/blob/type.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why no TypeRewardAnchorCommit? Also why didn't we need to change these once we added support for static remote key?

Comment thread watchtower/blob/justice_kit.go Outdated
Comment thread watchtower/blob/justice_kit.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't we also need to update the encode/decode methods? As looks like they'll fail with an unknown blob type as is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nope, the encode/decode logic is gate on FlagCommitOutputs which is also set in TypeAltruistAnchorCommit. the payload format doesn't change at all between the legacy and anchor channel blobs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW, when in the non nested-p2wsh land I usually like to refer to this as the "witness script" to distinguish things a bit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmm, technically this is referred to as the witness program in BIP 143. IMO the term witness script is ambiguous because we use it interchangeably as as you said for witness program, but also for redeem script.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, from my PoV (non-blocking here):

  • witness program -> the pkScript iself
    • this is also used as the redeem script for nested p2wsh
  • witness script -> the top element in the witness stack for p2wsh sends
    • this is typically what's signed, but there's a quirk where Script "injects" an "unrolled p2wkh" script

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Heh yeh this can be super confusing for those that haven't read BIP 141 closely and/or implemented the verification on the script level....

@cfromknecht cfromknecht Sep 9, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the confusing part is the sign descriptor accepts a WitnessScript, which can be either a redeem script or a witness program. just noting that our API could be improved.

@wpaulino wpaulino left a comment

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.

Not my area of expertise, but the changes read well to me.

Comment thread watchtower/blob/type.go Outdated

@Roasbeef Roasbeef left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 🕶

This is also a prepatory step to making
TestJusticeKitRemoteWitnessConstruction parameteried by the blob type so
we can test both anchor and legacy witness construction.
This is preparation for later commits where the values returned by
member methods will need to be conditioned on the blob type used during
decryption.
This commit modifies the ToRemoteWitnessScript function to be
conditioned on the blob type, and return either the legacy or anchor
to-remote script. The same witness satisfies either script, so no
changes are necessary to ToRemoteWitnessStack.
This commit modifies the JusticeDescriptor to support creation of
justice transactions spending from anchor commitments. Rather than the
unencumbered p2wkh scripts from before, the tower will now use the
to-remote-confirmed that includes the additional CSV delay of 1. This
also requires setting the sequence number appropriately on the to-remote
input.
This commit fixes the to-local-witness estimate to use the correct
witness size estimate for anchor channels. We retain the off-by-one bug
from the original constant otherwise.
@cfromknecht

Copy link
Copy Markdown
Contributor Author

@wpaulino @Roasbeef comments addressed, also tacked on a new commit to ensure that anchor channels use the correct to-local-penalty witness size constant, rather than keeping the existing off-by-one. PTAL

// avoid invalidating signatures by older clients. For anchor channels
// we correct this and use the correct witness size.
if p.JusticeKit.BlobType.IsAnchorChannel() {
weightEstimate.AddWitnessInput(input.ToLocalPenaltyWitnessSize)

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.

👍

@Roasbeef Roasbeef left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 💎

@Roasbeef
Roasbeef merged commit 50976e5 into lightningnetwork:master Sep 23, 2020
@cfromknecht
cfromknecht deleted the anchor-justice-txn branch September 23, 2020 23:14
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.

3 participants