Skip to content

Conversation

t-bast
Copy link
Member

@t-bast t-bast commented Jul 21, 2020

With this PR, it's possible to activate anchor outputs and have fully operating channels that use the anchor commitment format.
Interop testing has been done with lnd, and there is only one pending issue during mutual close, where they incorrectly compute the closing amounts (we are discussing this on the spec PR, it should be resolved soon).

However, for the sake of simplicity, this PR doesn't handle unilateral close scenario. This will be done in another, separate PR.
We don't do any kind of automatic fee bumping either; this will be done later, once we have PSBT support and once bitcoind offers the psbtbumpfee RPC (see bitcoin/bitcoin#18654).

@t-bast t-bast requested review from pm47 and sstone July 21, 2020 07:06
* @return a signature generated with a private key generated from the input keys's matching
* private key and the remote point.
*/
def sign(tx: TransactionWithInputInfo, publicKey: ExtendedPublicKey, remotePoint: PublicKey, sighashType: Int): ByteVector64
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not a huge fan of directly exposing the sighash here, I would have liked a slightly higher-level abstraction.
If you have a suggestion, I'd love to hear it! The gist of it is that we need to distinguish signing local vs remote txs: when signing local txs we will always use SIGHASH_ALL, but when signing remote txs we may use less restrictive sighash flags (in anchor outputs, we use SIGHASH_SINGLE | SIGHASH_ANYONECANPAY for htlc txs.

Copy link
Member Author

@t-bast t-bast Jul 21, 2020

Choose a reason for hiding this comment

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

I'd like the sighash flag to be somehow encapsulated in the TransactionWithInputInfo.
One thing I can try, is to enrich TransactionWithInputInfo with either Local or Remote -> this way our type system will let us know whether this is a local tx or a remote tx, which could be useful.
Then TransactionWithInputInfo can expose a method that returns the sighash that should be used depending on the commitment format. I'll experiment with that and will see if it's better.

2873839 does a better job at defining the sighash closer to the transactions and signing operations.

Copy link
Member

Choose a reason for hiding this comment

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

The sighash handling feels a bit clunky, but it's not too bad either and I don't have a better proposition.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think we can't fully hide it as the signing interface should allow setting it explicitly (it's part of a signature's "settings").
For now it's not used that much since only anchor output HTLCs use something different than sighash_all, but if a later commitment format makes more extensive use of different flags we may want to revisit that to ensure the code stays simple

@t-bast t-bast force-pushed the anchor-output-channels branch from 1794df1 to 3b76820 Compare July 21, 2020 09:37
t-bast added 3 commits July 22, 2020 17:21
Pick channel version based on local/remote feature support.
At this point all normal channel operations work (open, exchange htlcs,
mutual close, etc). However force-closing isn't handled, so nodes should
*not* activate the feature yet.
We add the concept of a TxOwner and encapsulate the choice of sighash
flags to use when signing thanks for that abstraction.
@t-bast t-bast force-pushed the anchor-output-channels branch from 8e460c2 to 2873839 Compare July 22, 2020 15:21
* @return a signature generated with the private key that matches the input
* extended public key
*/
def sign(tx: TransactionWithInputInfo, publicKey: ExtendedPublicKey, txOwner: TxOwner, commitmentFormat: CommitmentFormat): ByteVector64
Copy link
Member

Choose a reason for hiding this comment

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

Wonder what @sstone thinks of the change in the interface.

* @return a signature generated with a private key generated from the input keys's matching
* private key and the remote point.
*/
def sign(tx: TransactionWithInputInfo, publicKey: ExtendedPublicKey, remotePoint: PublicKey, sighashType: Int): ByteVector64
Copy link
Member

Choose a reason for hiding this comment

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

The sighash handling feels a bit clunky, but it's not too bad either and I don't have a better proposition.

Copy link
Member

@pm47 pm47 left a comment

Choose a reason for hiding this comment

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

Feels pretty neat, just minor questions.

@t-bast t-bast merged commit 3d4e00f into master Jul 27, 2020
@t-bast t-bast deleted the anchor-output-channels branch July 27, 2020 18:01
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.

2 participants