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

test: MiniWallet: add P2TR support and use it per default #23371

Conversation

theStack
Copy link
Contributor

@theStack theStack commented Oct 27, 2021

Taproot activates in about 19 days (2716 blocks), and it'd be nice if we set a good example and also support it in our MiniWallet. This PR changes the default mode from P2WSH (segwit v0 output, bech32 address) to P2TR (segwit v1 output, bech32m address) transactions type with the anyone-can-spend policy, i.e. a witness script of OP_TRUE. The transition is actually quite painless, one only needs one extra piece in the form of a internal public key that is passed in the control block on the witness stack, in order to trigger script-path spending. To keep things simple, the lowest possible valid x-only-public key with the value of 1 was chosen as internal key.
Since many tests expect to find outputs for the default scriptPubKey of MiniWallet in the pre-mined chain of the test framework, the generation address is also changed from ADDRESS_BCRT1_P2WSH_OP_TRUE to create_deterministic_address_bcrt1_p2tr_op_true()[0] accordingly (see method BitcoinTestFramework._initialize_chain(...)). Note that the pre-mined chain is cached locally, so you probably have to delete the ./test/cache folder first for the tests to pass again.

In order to avoid unnecessary renames, the import of ADDRESS_BCRT1_P2WSH_OP_TRUE is eliminated in rpc_blockchain.py by generating blocks directly to the MiniWallet address by using the self.generate(self.wallet, ...) interface (see first commit).

@fanquake fanquake added the Tests label Oct 27, 2021
@theStack theStack force-pushed the 202110-test-MiniWallet-change_P2WSH_to_P2TR branch from 682005b to 27c3783 Compare October 27, 2021 10:39
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

nice

test/functional/feature_rbf.py Outdated Show resolved Hide resolved
test/functional/rpc_blockchain.py Outdated Show resolved Hide resolved
@theStack theStack force-pushed the 202110-test-MiniWallet-change_P2WSH_to_P2TR branch from 27c3783 to 047e185 Compare October 27, 2021 11:51
@theStack
Copy link
Contributor Author

Force-pushed with suggestions by MarcoFalke (#23371 (comment), #23371 (comment), #23371 (comment)) and also adapted the PR description accordingly.

@laanwj
Copy link
Member

laanwj commented Oct 27, 2021

Concept ACK, nice

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 27, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

@mjdietzx
Copy link
Contributor

mjdietzx commented Oct 27, 2021

Great idea, Concept and Approach ACK

@theStack
Copy link
Contributor Author

Force-pushed with a fix for the failing test mempool_compatibility.py. On the previous release node (v0.19.1), the transaction from the newer node can't be added to the mempool, as CheckInputs() fails with non-mandatory-script-verify-flag (Witness version reserved for soft-fork upgrades). This is due to the script verification flag SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM being set. I.e. for this test, we can't use the default MiniWallet mode (P2TR), so it is changed to the raw P2PK mode instead.

maflcko pushed a commit to bitcoin-core/gui that referenced this pull request Oct 29, 2021
…n selection for coinbase UTXOs (oldest first)

d2c4904 test: MiniWallet: more deterministic coin selection for coinbase UTXOs (oldest first) (Sebastian Falbesoner)

Pull request description:

  The coin selection strategy for MiniWallet is quite straight-forward: simply pick a single UTXO with the largest value:

  https://github.com/bitcoin/bitcoin/blob/ab25ef8c7f767258d5fe44f53b35ad8bd51ed5cd/test/functional/test_framework/wallet.py#L173-L174

  If there are several candidates with the same value, however, it is not clear which one is taken.  This can be particularly problematic for coinbase outputs with fixed block subsidy, since spending could lead to a `bad-txns-premature-spend-of-coinbase` reject if an UTXO from a too-recent block is picked.  Introduce block height as second criteria (saved in `self._utxos` in the methods `generate(...)` and `rescan_utxos(...)`), in order to avoid potential issues with coinbases that are not matured yet. If there is a tie between coinbase UTXOs and non-coinbase UTXOs (the latter are added via `scan_tx(...)`), prefer the non-coinbase UTXOs, since those don't need to mature.

  The issue came up while refactoring the test rpc_blockchain.py, see bitcoin/bitcoin#23371 (comment) (PR #23371).

ACKs for top commit:
  MarcoFalke:
    review ACK d2c4904
  shaavan:
    ACK d2c4904

Tree-SHA512: 15d67b42fb8b77fd53022ea2ab8a6ed2b615567f3ce73bab16c06bfcb687c1a04dcb0360d0c2287c526b604cd3ac5eef7b14ce46fc31e23047ce1a3290027306
@theStack theStack force-pushed the 202110-test-MiniWallet-change_P2WSH_to_P2TR branch from c026917 to 8dfe7d4 Compare October 29, 2021 12:08
@theStack
Copy link
Contributor Author

Rebased on master (after the merge of #23375, the call to rescan_utxos is not needed anymore in rpc_blockchain.py) and fixed the cause for the failing CI log due to node shutdown while generate (#23371 (comment)). All CI instances should (hopefully) pass now.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 29, 2021
…ion for coinbase UTXOs (oldest first)

d2c4904 test: MiniWallet: more deterministic coin selection for coinbase UTXOs (oldest first) (Sebastian Falbesoner)

Pull request description:

  The coin selection strategy for MiniWallet is quite straight-forward: simply pick a single UTXO with the largest value:

  https://github.com/bitcoin/bitcoin/blob/ab25ef8c7f767258d5fe44f53b35ad8bd51ed5cd/test/functional/test_framework/wallet.py#L173-L174

  If there are several candidates with the same value, however, it is not clear which one is taken.  This can be particularly problematic for coinbase outputs with fixed block subsidy, since spending could lead to a `bad-txns-premature-spend-of-coinbase` reject if an UTXO from a too-recent block is picked.  Introduce block height as second criteria (saved in `self._utxos` in the methods `generate(...)` and `rescan_utxos(...)`), in order to avoid potential issues with coinbases that are not matured yet. If there is a tie between coinbase UTXOs and non-coinbase UTXOs (the latter are added via `scan_tx(...)`), prefer the non-coinbase UTXOs, since those don't need to mature.

  The issue came up while refactoring the test rpc_blockchain.py, see bitcoin#23371 (comment) (PR bitcoin#23371).

ACKs for top commit:
  MarcoFalke:
    review ACK d2c4904
  shaavan:
    ACK d2c4904

Tree-SHA512: 15d67b42fb8b77fd53022ea2ab8a6ed2b615567f3ce73bab16c06bfcb687c1a04dcb0360d0c2287c526b604cd3ac5eef7b14ce46fc31e23047ce1a3290027306
@theStack theStack force-pushed the 202110-test-MiniWallet-change_P2WSH_to_P2TR branch from 8dfe7d4 to 041abfe Compare November 9, 2021 11:28
@theStack
Copy link
Contributor Author

theStack commented Nov 9, 2021

Rebased on master.

@laanwj
Copy link
Member

laanwj commented Nov 10, 2021

Code review ACK 041abfe

laanwj added a commit to bitcoin-core/gui that referenced this pull request Nov 10, 2021
…se it per default

041abfe test: MiniWallet: add P2TR support and use it per default (Sebastian Falbesoner)
4a2edf2 test: generate blocks to MiniWallet address in rpc_blockchain.py (Sebastian Falbesoner)

Pull request description:

  Taproot activates in [about 19 days](https://taproot.watch/) (2716 blocks), and it'd be nice if we set a good example and also support it in our MiniWallet. This PR changes the default mode from P2WSH (segwit v0 output, bech32 address) to P2TR (segwit v1 output, bech32m address) transactions type with the _anyone-can-spend_ policy, i.e. a witness script of `OP_TRUE`. The transition is actually quite painless, one only needs one extra piece in the form of a internal public key that is passed in the control block on the witness stack, in order to trigger script-path spending. To keep things simple, the lowest possible valid x-only-public key with the value of 1 was chosen as internal key.
  Since many tests expect to find outputs for the default scriptPubKey of MiniWallet in the pre-mined chain of the test framework, the generation address is also changed from `ADDRESS_BCRT1_P2WSH_OP_TRUE` to `create_deterministic_address_bcrt1_p2tr_op_true()[0]` accordingly (see method `BitcoinTestFramework._initialize_chain(...)`). Note that the pre-mined chain is cached locally, so you probably have to delete the `./test/cache` folder first for the tests to pass again.

  In order to avoid unnecessary renames, the import of `ADDRESS_BCRT1_P2WSH_OP_TRUE` is eliminated in rpc_blockchain.py by generating blocks directly to the MiniWallet address by using the `self.generate(self.wallet, ...)` interface (see first commit).

ACKs for top commit:
  laanwj:
    Code review ACK 041abfe

Tree-SHA512: 876a5b0595333f9c96c68d5ecf2b4530aee2715aebb75a953f4f75ca12258bd7239210fcfa1ae044bee91489804c9c2f2a6a335bd46c3ac701873d32e3a4f49d
@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".

@maflcko maflcko closed this Nov 10, 2021
@theStack theStack deleted the 202110-test-MiniWallet-change_P2WSH_to_P2TR branch November 10, 2021 11:59
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 10, 2021
@michaelfolkson
Copy link
Contributor

Why was this closed?

@fanquake
Copy link
Member

Why was this closed?

Because it was merged.

@michaelfolkson
Copy link
Contributor

Ok I must be being dumb :) But this is a PR that is marked as closed on GitHub rather than marked as merged. It isn't an issue that can be closed when a separate PR fixes the issue. It is a PR and PRs are marked as merged rather than closed if they are merged...

@fanquake
Copy link
Member

Sometimes GitHub just doesn't work properly, and PRs that have been merged via the merge script don't actually get displayed as "merged" on GitHub. It's not entirely clear why this happens, and iirc there is an issue open for it on GitHubs support forum. This has happened number of time over the last few months.

@bitcoin bitcoin locked and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants