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

wallet, rpc: add listdescriptors command #20226

Merged
merged 1 commit into from Jan 28, 2021

Conversation

S3RK
Copy link
Contributor

@S3RK S3RK commented Oct 23, 2020

Looking for concept ACKs

Rationale: allow users to inspect the contents of their newly created descriptor wallets.

Currently the command only returns xpubs which is not very useful in itself, but there are multiples ways to extend it:

The output is compatible with importdescriptors command so it could be easily used for backup/recover purposes.

Output example:

[
  {
    "desc": "wpkh(tpubD6NzVbkrYhZ4WW6E2ZETFyNfq2hfF23SKxqSGFvUpPAY58jmmuBybwqwFihAyQPk9KnwTt5516NDZRJ7k5QPeKjy7wuVd5WvXNxwwAs5tUD/*)#nhavpr5h",
    "timestamp": 1296688602,
    "active": false,
    "range": [
      0,
      999
    ],
    "next": 0
  }
]

src/wallet/rpcdump.cpp Show resolved Hide resolved
src/wallet/rpcdump.cpp Outdated Show resolved Hide resolved
src/wallet/rpcdump.cpp Outdated Show resolved Hide resolved
@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 19, 2020

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Member

@promag promag left a comment

Choose a reason for hiding this comment

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

Before going further with this we need to ensure access to ScriptPubKeyMan instances are thread safe and decide their life cycle.

At the moment CWallet::AddWalletDescriptor mutates m_spk_managers, m_internal_spk_managers and m_external_spk_managers while also destroying a DescriptorScriptPubKeyMan.

A simple solution to fix this in this new RPC is to lock cs_wallet but I'm not sure if this is the way to go. cc @achow101

src/wallet/rpcdump.cpp Outdated Show resolved Hide resolved
@S3RK
Copy link
Contributor Author

S3RK commented Dec 10, 2020

@promag For now I updated the code to acquire cs_wallet which seems reasonable and I don't see better alternatives anyway.

@achow101
Copy link
Member

Locking cs_wallet should be sufficient.

Concept ACK.

Can you add some tests for this?

@Sjors
Copy link
Member

Sjors commented Jan 1, 2021

Concept ACK

1 similar comment
@jonatack
Copy link
Contributor

Concept ACK

@S3RK
Copy link
Contributor Author

S3RK commented Jan 21, 2021

Added functional test

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

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

utACK 425403c modulo linter issue

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

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

re-utACK 0e31abf

Copy link
Member

@achow101 achow101 left a comment

Choose a reason for hiding this comment

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

ACK 0e31abf

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

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

Needs:

diff --git a/test/functional/wallet_listdescriptors.py b/test/functional/wallet_listdescriptors.py
index c825c8680e8..d0604d199e5 100755
--- a/test/functional/wallet_listdescriptors.py
+++ b/test/functional/wallet_listdescriptors.py
@@ -7,7 +7,10 @@
 from test_framework.descriptors import (
     descsum_create
 )
-from test_framework.test_framework import BitcoinTestFramework
+from test_framework.test_framework import (
+    BitcoinTestFramework,
+    SkipTest,
+)
 from test_framework.util import (
     assert_equal,
     assert_raises_rpc_error,
@@ -19,6 +22,8 @@ class ReceivedByTest(BitcoinTestFramework):
         self.num_nodes = 1
 
     def skip_test_if_missing_module(self):
+        if not self.options.descriptors:
+            raise SkipTest("This test only supports descriptor wallets.")
         self.skip_if_no_wallet()
 
     # do not create any wallet by default

@S3RK
Copy link
Contributor Author

S3RK commented Jan 27, 2021

@luke-jr interesting point, thanks. I took a different approach which is more consistent with other descriptor specific tests. I made the test work regardless of whether --descriptors is set.

@achow101 There are two more tests so far that run only with --descriptors flag:

wallet_descriptor
wallet_importdescriptors

I tested and both of them would work without the flag set. I suggest that we remove that flag from test_runner.py for those tests since it doesn't affect the behaviour. What do you think?

@luke-jr
Copy link
Member

luke-jr commented Jan 27, 2021

@luke-jr interesting point, thanks. I took a different approach which is more consistent with other descriptor specific tests. I made the test work regardless of whether --descriptors is set.

But as-is, the test FAILS without --descriptors set...?

@achow101
Copy link
Member

I tested and both of them would work without the flag set. I suggest that we remove that flag from test_runner.py for those tests since it doesn't affect the behaviour. What do you think?

I have planned improvements for that, namely to not make tests dependent on --descriptors.

But as-is, the test FAILS without --descriptors set...?

It does not fail without --descriptors. It basically just ignores --descriptors and --legacy-wallet as a couple of tests already do.

In the interest of getting this merged, I think it is fine to leave the test as is and resolve the --descriptors problem with the similar tests together.

@achow101
Copy link
Member

re-ACK bbb34e9

Copy link
Contributor

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Tested ACK bbb34e9 rebased to master

A few comments below. Happy to re-ACK quickly if you update.

src/wallet/rpcdump.cpp Outdated Show resolved Hide resolved
test/functional/wallet_listdescriptors.py Outdated Show resolved Hide resolved
src/wallet/rpcdump.cpp Show resolved Hide resolved
src/wallet/rpcdump.cpp Outdated Show resolved Hide resolved
@jonatack
Copy link
Contributor

re-ACK 647b81b rebased to master, debug builds cleanly, reviewed diff since last review, tested with a descriptor wallet (and with a legacy wallet)

help output

listdescriptors

List descriptors imported into a descriptor-enabled wallet.
Result:
[                               (json array) Response is an array of descriptor objects
  {                             (json object)
    "desc" : "str",             (string) Descriptor string representation
    "timestamp" : n,            (numeric) The creation time of the descriptor
    "active" : true|false,      (boolean) Activeness flag
    "internal" : true|false,    (boolean, optional) Whether this is internal or external descriptor; defined only for active descriptors
    "range" : [                 (json array, optional) Defined only for ranged descriptors
      n,                        (numeric) Range start inclusive
      n                         (numeric) Range end inclusive
    ],
    "next" : n                  (numeric, optional) The next index to generate addresses from; defined only for ranged descriptors
  },
  ...
]

Examples:
> bitcoin-cli listdescriptors 
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "listdescriptors", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/

@achow101
Copy link
Member

re-ACK 647b81b

Changes since last just address the review comments.

@jonatack
Copy link
Contributor

Needs a release note (can be done in a follow-up.)

@meshcollider
Copy link
Contributor

re-utACK

@meshcollider meshcollider merged commit 9deba2d into bitcoin:master Jan 28, 2021
1 check passed
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 28, 2021
647b81b wallet, rpc: add listdescriptors command (Ivan Metlushko)

Pull request description:

  Looking for concept ACKs

  **Rationale**: allow users to inspect the contents of their newly created descriptor wallets.

  Currently the command only returns xpubs which is not very useful in itself, but there are multiples ways to extend it:
   * add an option to export xprv
   * with bitcoin#19136 it'll be possible to return normalised descriptors suitable for a watch-only purposes

  The output is compatible with `importdescriptors` command so it could be easily used for backup/recover purposes.

  **Output example:**
  ```json
  [
    {
      "desc": "wpkh(tpubD6NzVbkrYhZ4WW6E2ZETFyNfq2hfF23SKxqSGFvUpPAY58jmmuBybwqwFihAyQPk9KnwTt5516NDZRJ7k5QPeKjy7wuVd5WvXNxwwAs5tUD/*)#nhavpr5h",
      "timestamp": 1296688602,
      "active": false,
      "range": [
        0,
        999
      ],
      "next": 0
    }
  ]
  ```

ACKs for top commit:
  jonatack:
    re-ACK 647b81b rebased to master, debug builds cleanly, reviewed diff since last review, tested with a descriptor wallet (and with a legacy wallet)
  achow101:
    re-ACK 647b81b

Tree-SHA512: 51a3620bb17c836c52cecb066d4fa9d5ff418af56809046eaee0528c4dc240a4e90fff5711ba96e399c6664e00b9ee8194e33852b1b9e75af18061296e19a8a7
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Jan 28, 2021
S3RK added a commit to S3RK/bitcoin that referenced this pull request Feb 1, 2021
S3RK added a commit to S3RK/bitcoin that referenced this pull request Feb 1, 2021
S3RK added a commit to S3RK/bitcoin that referenced this pull request Feb 2, 2021
@S3RK S3RK deleted the listdescriptors branch February 2, 2021 07:40
MarcoFalke pushed a commit that referenced this pull request Feb 4, 2021
51f3752 Add release notes for listdescriptors RPC (Ivan Metlushko)

Pull request description:

  Original PR is #20226

ACKs for top commit:
  jonatack:
    ACK 51f3752
  jonasschnelli:
    ACK 51f3752

Tree-SHA512: e8091d01b99a3effcd6c1738e7363a44858ba9bcf6bd99bf60f2025a25db83fc8d61354ab2002365b56071b9f3693c7d534153a259b5ebc91cbcf8d13f6555f1
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 4, 2021
51f3752 Add release notes for listdescriptors RPC (Ivan Metlushko)

Pull request description:

  Original PR is bitcoin#20226

ACKs for top commit:
  jonatack:
    ACK 51f3752
  jonasschnelli:
    ACK 51f3752

Tree-SHA512: e8091d01b99a3effcd6c1738e7363a44858ba9bcf6bd99bf60f2025a25db83fc8d61354ab2002365b56071b9f3693c7d534153a259b5ebc91cbcf8d13f6555f1
fanquake added a commit that referenced this pull request Apr 2, 2021
2e5f7de wallet, rpc: update listdescriptors response format (Ivan Metlushko)

Pull request description:

  Update `listdescriptors` response format according to [RPC interface guidelines](https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#rpc-interface-guidelines).

  This is a follow up for #20226

  **Before:**
  ```
  Result:
  [                               (json array) Response is an array of descriptor objects
    {                             (json object)
      "desc" : "str",             (string) Descriptor string representation
      "timestamp" : n,            (numeric) The creation time of the descriptor
      "active" : true|false,      (boolean) Activeness flag
      "internal" : true|false,    (boolean, optional) Whether this is internal or external descriptor; defined only for active descriptors
      "range" : [                 (json array, optional) Defined only for ranged descriptors
        n,                        (numeric) Range start inclusive
        n                         (numeric) Range end inclusive
      ],
      "next" : n                  (numeric, optional) The next index to generate addresses from; defined only for ranged descriptors
    },
    ...
  ]
  ```

  **After:**
  ```
  Result:
  {                                 (json object)
    "wallet_name" : "str",          (string) Name of wallet this operation was performed on
    "descriptors" : [               (json array) Array of descriptor objects
      {                             (json object)
        "desc" : "str",             (string) Descriptor string representation
        "timestamp" : n,            (numeric) The creation time of the descriptor
        "active" : true|false,      (boolean) Activeness flag
        "internal" : true|false,    (boolean, optional) Whether this is internal or external descriptor; defined only for active descriptors
        "range" : [                 (json array, optional) Defined only for ranged descriptors
          n,                        (numeric) Range start inclusive
          n                         (numeric) Range end inclusive
        ],
        "next" : n                  (numeric, optional) The next index to generate addresses from; defined only for ranged descriptors
      },
      ...
    ]
  }
  ```

ACKs for top commit:
  achow101:
    re-ACK 2e5f7de
  meshcollider:
    utACK 2e5f7de
  jonatack:
    re-ACK 2e5f7de

Tree-SHA512: 49bf73e46e2a61003ce594a4bfc506eb9592ccb799c2909c43a1a527490a4b4009f78dc09f3d47b4e945d3d7bb3cd2632cf48c5ace5feed5066158cc010dddc1
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 2, 2021
2e5f7de wallet, rpc: update listdescriptors response format (Ivan Metlushko)

Pull request description:

  Update `listdescriptors` response format according to [RPC interface guidelines](https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#rpc-interface-guidelines).

  This is a follow up for bitcoin#20226

  **Before:**
  ```
  Result:
  [                               (json array) Response is an array of descriptor objects
    {                             (json object)
      "desc" : "str",             (string) Descriptor string representation
      "timestamp" : n,            (numeric) The creation time of the descriptor
      "active" : true|false,      (boolean) Activeness flag
      "internal" : true|false,    (boolean, optional) Whether this is internal or external descriptor; defined only for active descriptors
      "range" : [                 (json array, optional) Defined only for ranged descriptors
        n,                        (numeric) Range start inclusive
        n                         (numeric) Range end inclusive
      ],
      "next" : n                  (numeric, optional) The next index to generate addresses from; defined only for ranged descriptors
    },
    ...
  ]
  ```

  **After:**
  ```
  Result:
  {                                 (json object)
    "wallet_name" : "str",          (string) Name of wallet this operation was performed on
    "descriptors" : [               (json array) Array of descriptor objects
      {                             (json object)
        "desc" : "str",             (string) Descriptor string representation
        "timestamp" : n,            (numeric) The creation time of the descriptor
        "active" : true|false,      (boolean) Activeness flag
        "internal" : true|false,    (boolean, optional) Whether this is internal or external descriptor; defined only for active descriptors
        "range" : [                 (json array, optional) Defined only for ranged descriptors
          n,                        (numeric) Range start inclusive
          n                         (numeric) Range end inclusive
        ],
        "next" : n                  (numeric, optional) The next index to generate addresses from; defined only for ranged descriptors
      },
      ...
    ]
  }
  ```

ACKs for top commit:
  achow101:
    re-ACK 2e5f7de
  meshcollider:
    utACK 2e5f7de
  jonatack:
    re-ACK 2e5f7de

Tree-SHA512: 49bf73e46e2a61003ce594a4bfc506eb9592ccb799c2909c43a1a527490a4b4009f78dc09f3d47b4e945d3d7bb3cd2632cf48c5ace5feed5066158cc010dddc1
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants