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

Taproot wallet support #6035

Merged

Conversation

instagibbs
Copy link
Collaborator

@instagibbs instagibbs commented Feb 24, 2023

This switches CLN to issuing p2tr addresses for deposits optionally, and also by default sending change to p2tr outputs.

Open questions:

  1. should we deprecate wrapped segwit first?
  2. I'm not happy with how many places in the code I have to check things like chainparams->is_elements(12 times looks like), bet it would be good to have some simpler way to not forget what version we're doing?

@instagibbs
Copy link
Collaborator Author

one more libwally update to go....

@instagibbs instagibbs changed the title WIP Taproot wallet support Taproot wallet support May 22, 2023
@instagibbs instagibbs marked this pull request as ready for review May 22, 2023 15:59
@instagibbs instagibbs requested a review from cdecker as a code owner May 22, 2023 15:59
wallet/walletrpc.c Outdated Show resolved Hide resolved
@@ -395,7 +404,7 @@ static struct command_result *finish_psbt(struct command *cmd,
excess = AMOUNT_SAT(0);
/* Add additional weight of output */
weight += bitcoin_tx_output_weight(
BITCOIN_SCRIPTPUBKEY_P2WPKH_LEN);
chainparams->is_elements ? BITCOIN_SCRIPTPUBKEY_P2WPKH_LEN : BITCOIN_SCRIPTPUBKEY_P2TR_LEN);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

since script is known b32script we could just tal_count it, but there are other cases where we don't have a script on hand already. would rather we sync up behavior

@instagibbs instagibbs force-pushed the taproot_wallet_support branch 3 times, most recently from 83e529b to 4ced65f Compare May 23, 2023 19:44
Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

One minor weird delete...

It's unfortunate that we can't simply reuse "bech32" as the JSON field name for these addresses: I guess some software won't be up-to-date.

However, I think it's naive to use "p2tr" as well, since we're hoping that THIS TIME FOR SURE we have a universal address format: next change it would be great not to have everyone have to parse a new field. So, do we optimistically go for "bech32m"?

I may remove p2sh as part of the deprecations PR, let's not get bogged down behind that!

bitcoin/script.h Outdated Show resolved Hide resolved
Comment on lines 18 to 21
ext->pub_key + 1, sizeof(ext->pub_key) - 1,
NULL, 0,
fingerprint, sizeof(fingerprint),
path, 1) != WALLY_OK)
Copy link
Contributor

Choose a reason for hiding this comment

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

Guessing your local tabs are 4 spaces? Because this is very indented!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok im in libwally mode; what's the expected indent level :)

plugins/spender/multifundchannel.c Outdated Show resolved Hide resolved
@instagibbs
Copy link
Collaborator Author

However, I think it's naive to use "p2tr" as well, since we're hoping that THIS TIME FOR SURE we have a universal address format: next change it would be great not to have everyone have to parse a new field. So, do we optimistically go for "bech32m"?

If someday there's witness output v2 that also uses bech32m, we'll have to un-camp it? p2tr just seems more explicit to me.

@instagibbs
Copy link
Collaborator Author

instagibbs commented May 25, 2023

last question I'd have: is it better to not switch to taproot change outputs, just to limit blast radius if something were to go wrong, at least for a release?

pushed a couple fixes to tests as well

edit: can't replicate tests/test_connection.py::test_feerate_stress failures locally

@rustyrussell
Copy link
Contributor

last question I'd have: is it better to not switch to taproot change outputs, just to limit blast radius if something were to go wrong, at least for a release?

Unfortunately, I don't think we'd find any bugs without this, and it adds another step change.

However, I do note that you need to add two Changelog-Added lines, and edit the newaddr man page (which doesn't mention p2tr as an option for addresstype:

Changelog-Added: JSON-RPC: newaddr: p2tr option to create taproot addresses.
Changelog-Changed: Wallet: we now use taproot change addresses.

pushed a couple fixes to tests as well

edit: can't replicate tests/test_connection.py::test_feerate_stress failures locally

That's a known flake, ignore...

@rustyrussell rustyrussell added this to the v23.08 milestone May 30, 2023
@rustyrussell
Copy link
Contributor

Also, please change all v23.05 to v23.08!

Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

See comments...

@instagibbs
Copy link
Collaborator Author

instagibbs commented May 30, 2023

Changelog-Added: JSON-RPC: newaddr: p2tr option to create taproot addresses.
Changelog-Changed: Wallet: we now use taproot change addresses.

Added

Also, please change all v23.05 to v23.08!

done!

also added description for arg in doc/lightning-newaddr.7.md

@instagibbs instagibbs force-pushed the taproot_wallet_support branch 4 times, most recently from 4bfd9be to e39f019 Compare May 30, 2023 14:55
@instagibbs
Copy link
Collaborator Author

now that dual funding is back in CI matrix.... time to fix tests :)

@instagibbs instagibbs force-pushed the taproot_wallet_support branch 2 times, most recently from 746c41c to cc3820e Compare May 31, 2023 20:32
@instagibbs
Copy link
Collaborator Author

I'm going to look into storing the feature bits shared by the peers to remove this race in tests that I've run into. We'd like to know that we've previously seen a peer share anysegwit, and assume this when proposing a close.

@instagibbs
Copy link
Collaborator Author

rebased on the now-ACK'd #6308

removed the random gating in tests, things should be passing now...

@instagibbs instagibbs force-pushed the taproot_wallet_support branch 2 times, most recently from a66e29c to 4a99000 Compare June 26, 2023 15:06
@instagibbs instagibbs marked this pull request as draft July 2, 2023 00:19
@instagibbs instagibbs marked this pull request as ready for review July 2, 2023 00:20
@rustyrussell
Copy link
Contributor

rustyrussell commented Jul 10, 2023

Rebased on master, and folded the fixups into a single commit. Also did some indent fixups.

Ack: 3d97754

instagibbs and others added 8 commits July 11, 2023 01:53
Changelog-Added: JSON-RPC: newaddr: p2tr option to create taproot addresses.
Changelog-Changed: Wallet: we now use taproot change addresses.
When modifying the schema, regenerating the file can be challenging.
This change sets the autogenerate file as the default target, m
aking the process more convenient and simplifying our workflow.

Fixes ElementsProject#6365
Report-by: Dusty Daemon
Changelog-None
Signed-off-by: Vincenzo Palazzo <[email protected]>
@rustyrussell
Copy link
Contributor

Trivial rebase for generated file clash.

Ack 2c1d579

@rustyrussell rustyrussell merged commit da91e70 into ElementsProject:master Jul 11, 2023
@niftynei
Copy link
Collaborator

niftynei commented Jul 11, 2023 via email

@harding
Copy link

harding commented Jul 16, 2023

Regarding field names, @sipa previously had this advice for me:

<sipa> harding: i think output types should be distinguished based on sender's abilities to
    pay them, as you may need to construct different addresses for older/new sender software
<sipa> and in that regard, i think legacy/p2sh/bech32, and unfortunately, bech32m are
   probably the right choices
[...]
<harding> sipa: you're saying that (in December 2021) if I run `getnewaddress bech32m` I
    should get a P2TR address, and (years from now) if I run `getnewaddress bech32m` I should
    get a P2FOO address because all I care about is whether or not the person who will be spending
    to me can support bech32m?
<sipa> yes

Source: https://www.erisian.com.au/bitcoin-core-dev/log-2021-06-28.html#l-89

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.

5 participants