Skip to content

Conversation

@jonatack
Copy link
Member

@jonatack jonatack commented Mar 20, 2023

Based on discussion and concept ACKed in #27138, add a warnings field to RPCs createwallet, loadwallet, unloadwallet, and restorewallet as a JSON array of strings to replace the warning string field in these 4 RPCs. The idea is to more gracefully handle multiple warning messages and for consistency with other wallet RPCs. Then, deprecate the latter fields, which represent all the remaining RPC warning fields.

The first commit f73782a implements #27138 (comment) as an alternative to #27138. One of those two could potentially be backported to our currently supported releases.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 20, 2023

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK 1440000bytes, vasild, pinheadmz, achow101
Approach ACK TheCharlatan

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #bitcoin-core/gui/650 (Add Import to Wallet GUI by KolbyML)
  • #27322 (move-only: IsDeprecatedRPCEnabled to rpc/util to fix CI builds when called from wallet by jonatack)
  • #27138 (rpc, test: remove newline escape sequence from wallet warning fields by jonatack)
  • #26840 (refactor: importpubkey, importprivkey, importaddress, importmulti, and importdescriptors rpc by KolbyML)
  • #25722 (refactor: Use util::Result class for wallet loading by ryanofsky)

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.

@jonatack jonatack changed the title Add "warnings"/deprecate warning {create,load,unload,restore}wallet, deprecate "warning" Add "warnings"/deprecate "warning" in {create,load,unload,restore}wallet, deprecate Mar 20, 2023
@jonatack jonatack changed the title Add "warnings"/deprecate "warning" in {create,load,unload,restore}wallet, deprecate Add "warnings"/deprecate "warning" in {create,load,unload,restore}wallet Mar 20, 2023
@jonatack jonatack changed the title Add "warnings"/deprecate "warning" in {create,load,unload,restore}wallet Add "warnings", deprecate "warning" in {create,load,unload,restore}wallet Mar 20, 2023
@jonatack jonatack force-pushed the 2023-03-migrate-wallet-warning-fields-to-warnings branch from e266277 to 6a5ceb3 Compare March 20, 2023 02:58
Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

Concept ACK

@jonatack jonatack force-pushed the 2023-03-migrate-wallet-warning-fields-to-warnings branch from 6a5ceb3 to 748e755 Compare March 23, 2023 21:09
@jonatack jonatack force-pushed the 2023-03-migrate-wallet-warning-fields-to-warnings branch 2 times, most recently from cf8c237 to 452d869 Compare March 23, 2023 22:39
@jonatack jonatack force-pushed the 2023-03-migrate-wallet-warning-fields-to-warnings branch 4 times, most recently from f3cb41f to eaa6785 Compare March 30, 2023 03:03
@jonatack jonatack marked this pull request as ready for review March 30, 2023 12:53
@jonatack jonatack force-pushed the 2023-03-migrate-wallet-warning-fields-to-warnings branch from eaa6785 to e67da5f Compare March 30, 2023 22:38
Copy link
Member

@pinheadmz pinheadmz left a comment

Choose a reason for hiding this comment

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

concept ACK

Light code review. I prefer this to #27138 it seems like the right move. Built and ran tests, played with interface, nice!

--> bccli -regtest -named createwallet wallet_name=oops2 descriptors=false passphrase=""
{
  "name": "oops2",
  "warnings": [
    "Empty string given as passphrase, wallet will not be encrypted.",
    "Wallet created successfully. The legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future."
  ]
}

I did a quick search for other RPCs that string together warnings, I think getblockchaininfo still does - worth including here?

Also, the GUI: I don't think encrypting wallet with a blank passphrase is possible from the UI so I don't know if there is a way to see multiple warnings in production, or if that is already handled.

@jonatack
Copy link
Member Author

jonatack commented Apr 4, 2023

Thanks for testing!

I did a quick search for other RPCs that string together warnings, I think getblockchaininfo still does - worth including here?

Info getter RPCs getblockchaininfo, getmininginfo and getnetworkinfo return a different kind of warnings -- global ones unrelated to an operation performed by the RPC -- and have their own GetWarnings helper in src/warnings, which is also called by the GUI via getWarnings. They don't seem tightly related to the ones here.

Also, the GUI: I don't think encrypting wallet with a blank passphrase is possible from the UI so I don't know if there is a way to see multiple warnings in production, or if that is already handled.

I think the GUI handles these operations at a higher (non-RPC) layer, e.g. wallet, interfaces, qt, so these changes shouldn't be applicable to it.

git grep "loadWallet\|createWallet\|restoreWallet\|UnloadWallet\|handleUnload" src/interfaces/wallet.h src/wallet/interfaces.cpp src/qt

src/interfaces/wallet.h:282:    virtual std::unique_ptr<Handler> handleUnload(UnloadFn fn) = 0;
src/interfaces/wallet.h:323:    virtual util::Result<std::unique_ptr<Wallet>> createWallet(const std::string& name, const SecureString& passphrase, uint64_t wallet_creation_flags, std::vector<bilingual_str>& warnings) = 0;
src/interfaces/wallet.h:326:    virtual util::Result<std::unique_ptr<Wallet>> loadWallet(const std::string& name, std::vector<bilingual_str>& warnings) = 0;
src/interfaces/wallet.h:332:    virtual util::Result<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) = 0;
src/interfaces/wallet.h:341:    //! createWallet and loadWallet above, and also triggered when wallets are
src/qt/bitcoingui.cpp:111:        connect(walletFrame, &WalletFrame::createWalletButtonClicked, [this] {
src/qt/walletcontroller.cpp:233:        createWallet();
src/qt/walletcontroller.cpp:240:void CreateWalletActivity::createWallet()
src/qt/walletcontroller.cpp:265:        auto wallet{node().walletLoader().createWallet(name, m_passphrase, flags, m_warning_message)};
src/qt/walletcontroller.cpp:319:            createWallet();
src/qt/walletcontroller.cpp:354:        auto wallet{node().walletLoader().loadWallet(path, m_warning_message)};
src/qt/walletcontroller.cpp:406:        auto wallet{node().walletLoader().restoreWallet(backup_file, wallet_name, m_warning_message)};
src/qt/walletcontroller.h:128:    void createWallet();
src/qt/walletframe.cpp:51:    connect(create_wallet_button, &QPushButton::clicked, this, &WalletFrame::createWalletButtonClicked);
src/qt/walletframe.h:50:    void createWalletButtonClicked();
src/qt/walletmodel.cpp:429:    m_handler_unload = m_wallet->handleUnload(std::bind(&NotifyUnload, this));
src/wallet/interfaces.cpp:488:    std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
src/wallet/interfaces.cpp:533:    ~WalletLoaderImpl() override { UnloadWallets(m_context); }
src/wallet/interfaces.cpp:555:    util::Result<std::unique_ptr<Wallet>> createWallet(const std::string& name, const SecureString& passphrase, uint64_t wallet_creation_flags, std::vector<bilingual_str>& warnings) override
src/wallet/interfaces.cpp:571:    util::Result<std::unique_ptr<Wallet>> loadWallet(const std::string& name, std::vector<bilingual_str>& warnings) override
src/wallet/interfaces.cpp:585:    util::Result<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) override

Copy link
Member

@pinheadmz pinheadmz left a comment

Choose a reason for hiding this comment

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

code review ACK @ e67da5fedd526c38e030d6d18f3678313a683dc9

A few questions.

Copy link
Contributor

@sedited sedited left a comment

Choose a reason for hiding this comment

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

Approach ACK

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK e67da5fedd526c38e030d6d18f3678313a683dc9

Some non-blockers below.

- clarify that there can be multiple warning messages
- specify the correct wallet action
- describe the use of newlines as delimiters
This new "warnings" field is a JSON array of strings intended to replace the
"warning" string field in these four RPCs, to better handle returning multiple
warning messages and for consistency with other wallet RPCs.
and clarify the "warning" field behavior.
This string field has been replaced in these four RPCs by a "warnings" field
returning a JSON array of strings.
and add the walletutil.h include header for WALLET_FLAG_AVOID_REUSE that was
already missing before this change.

WALLET_FLAG_CAVEATS is only used in one RPC, so no need to encumber wallet.h and
wallet.cpp with it, along with all of the files that include wallet.h during
their compilation. Also apply clang-format per:

git diff -U0 HEAD~1.. | ./contrib/devtools/clang-format-diff.py -p1 -i -v
as these RPCs have a "warnings" field, not a "warning" one.
@jonatack jonatack force-pushed the 2023-03-migrate-wallet-warning-fields-to-warnings branch from e67da5f to 7ccdd74 Compare April 10, 2023 17:45
@jonatack
Copy link
Member Author

Thank you @pinheadmz, @vasild and @TheCharlatan. Repushed to address feedback, should be trivial to re-ACK.

git diff e67da5f 7ccdd74

diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp
index fc7d5a5c282..fb175fa2532 100644
--- a/src/wallet/rpc/backup.cpp
+++ b/src/wallet/rpc/backup.cpp
@@ -1379,7 +1379,7 @@ RPCHelpMan importmulti()
 
         for (const UniValue& data : requests.getValues()) {
             const int64_t timestamp = std::max(GetImportTimestamp(data, now), minimumTimestamp);
-            const UniValue& result = ProcessImport(*pwallet, data, timestamp);
+            const UniValue result = ProcessImport(*pwallet, data, timestamp);
             response.push_back(result);
 
             if (!fRescan) {
@@ -1675,7 +1675,7 @@ RPCHelpMan importdescriptors()
         for (const UniValue& request : requests.getValues()) {
             // This throws an error if "timestamp" doesn't exist
             const int64_t timestamp = std::max(GetImportTimestamp(request, now), minimum_timestamp);
-            const UniValue& result = ProcessDescriptorImport(*pwallet, request, timestamp);
+            const UniValue result = ProcessDescriptorImport(*pwallet, request, timestamp);
             response.push_back(result);
 
             if (lowest_timestamp > timestamp ) {
@@ -1903,7 +1903,7 @@ RPCHelpMan restorewallet()
             RPCResult::Type::OBJ, "", "",
             {
                 {RPCResult::Type::STR, "name", "The wallet name if restored successfully."},
-                {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning messages, if any, related to restoring the wallet. Multiple messages will be delimited by newline escape sequences (\"\\n\"). (DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed.)"},
+                {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning messages, if any, related to restoring the wallet. Multiple messages will be delimited by newlines. (DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed.)"},
                 {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to restoring the wallet.",
                 {
                     {RPCResult::Type::STR, "", ""},
diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp
index 33466510b03..ea3507bc751 100644
--- a/src/wallet/rpc/wallet.cpp
+++ b/src/wallet/rpc/wallet.cpp
@@ -13,6 +13,7 @@
 #include <wallet/rpc/wallet.h>
 #include <wallet/rpc/util.h>
 #include <wallet/wallet.h>
+#include <wallet/walletutil.h>
 
 #include <optional>
 
@@ -215,7 +216,7 @@ static RPCHelpMan loadwallet()
                     RPCResult::Type::OBJ, "", "",
                     {
                         {RPCResult::Type::STR, "name", "The wallet name if loaded successfully."},
-                        {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning messages, if any, related to loading the wallet. Multiple messages will be delimited by newline escape sequences (\"\\n\"). (DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed.)"},
+                        {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning messages, if any, related to loading the wallet. Multiple messages will be delimited by newlines. (DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed.)"},
                         {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to loading the wallet.",
                         {
                             {RPCResult::Type::STR, "", ""},
@@ -350,7 +351,7 @@ static RPCHelpMan createwallet()
             RPCResult::Type::OBJ, "", "",
             {
                 {RPCResult::Type::STR, "name", "The wallet name if created successfully. If the wallet was created using a full path, the wallet_name will be the full path."},
-                {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning messages, if any, related to creating the wallet. Multiple messages will be delimited by newline escape sequences (\"\\n\"). (DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed.)"},
+                {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning messages, if any, related to creating the wallet. Multiple messages will be delimited by newlines. (DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed.)"},
                 {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to creating the wallet.",
                 {
                     {RPCResult::Type::STR, "", ""},
@@ -444,7 +445,7 @@ static RPCHelpMan unloadwallet()
                     {"load_on_startup", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED, "Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged."},
                 },
                 RPCResult{RPCResult::Type::OBJ, "", "", {
-                    {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning messages, if any, related to unloading the wallet. Multiple messages will be delimited by newline escape sequences (\"\\n\"). (DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed.)"},
+                    {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning messages, if any, related to unloading the wallet. Multiple messages will be delimited by newlines. (DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed.)"},
                     {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to unloading the wallet.",
                     {
                         {RPCResult::Type::STR, "", ""},
diff --git a/test/functional/wallet_backwards_compatibility.py b/test/functional/wallet_backwards_compatibility.py
index e02b0c318e9..a6401a76c13 100755
--- a/test/functional/wallet_backwards_compatibility.py
+++ b/test/functional/wallet_backwards_compatibility.py
@@ -265,7 +265,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
             )
             load_res = node_master.loadwallet("u1_v16")
             # Make sure this wallet opens without warnings. See https://github.com/bitcoin/bitcoin/pull/19054
-            if '"warnings"' in node_master.help("loadwallet"):
+            if int(node_master.getnetworkinfo()["version"]) >= 249900:
                 # loadwallet#warnings (added in v25) -- only present if there is a warning
                 assert "warnings" not in load_res
             else:
diff --git a/test/functional/wallet_createwallet.py b/test/functional/wallet_createwallet.py
index dc24151f77b..58cc6befbd3 100755
--- a/test/functional/wallet_createwallet.py
+++ b/test/functional/wallet_createwallet.py
@@ -197,7 +197,7 @@ class CreateWalletTest(BitcoinTestFramework):
         self.log.info('Test "warning" field deprecation, i.e. not returned without -deprecatedrpc=walletwarningfield')
         self.restart_node(0, extra_args=[])
         result = self.nodes[0].createwallet(wallet_name="w7_again", disable_private_keys=False, blank=False, passphrase="")
-        assert_equal(set([*result]), {"name", "warnings"})
+        assert "warning" not in result
 

@achow101 achow101 added this to the 25.0 milestone Apr 11, 2023
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

utACK 7ccdd74

@DrahtBot DrahtBot requested review from pinheadmz and vasild April 11, 2023 07:33
Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK 7ccdd74

@achow101 achow101 removed this from the 25.0 milestone Apr 11, 2023
Copy link
Member

@pinheadmz pinheadmz left a comment

Choose a reason for hiding this comment

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

re-ACK 7ccdd74

confirmed trivial diff since last review, ran unit and functional tests locally, ran in regtest one more time to check UX with and without deprecated rpc flag

Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

ACK 7ccdd741fe1544c13b2a9b7baa5c5727e84d6e55
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmQ20YEACgkQ5+KYS2KJ
yTqF/Q/8DnfN9Esae47Y1bvswkY5oX93SBB59pUEOHSxfTugRWFr18xZyUZI3zHz
kK8SFsVEXfm7lWTdMiRLjDSthFcsHMnzv+JNc76qvFuOhD5TYHkX81V7fUXSiDiS
VaODlGlVS/Cw6KoOQ52WWXltJxt0bIxPZMYBrtSus7poarSuCaOsXDqCaU+Ma6SM
KglES3j1+M4f7FIPUD6QVzHbhfYddTnFuwsBAgwMBxb/c7O8JrEWwxem80vc2jH4
9erbjBhF8YotvH4ici8Xl0bO6/FmpldLz3CNRqbl7tYJOIxU+z+WsgpcI+D9C2jQ
NXOIL6bKCHom8MlOBJpTez892wRoTjV6SXNHa1TrlGuRFUVQpTb8QWMiP4RmSuFm
UcDyuwLkDOUGx09SviS2FjZA1BBogCsWiwD7ZpoBcW1sXqmFqGL9VCGrAzmuwqcd
9xDn9vbzcvSEx8JdQvDYRpjdnQ8y2yt1VsgbpABRtb8uj16GLT1WiDCMFJFGxkV+
3dSIIHe7DnNSw30v8YFoBYCbrXQBJLhNGu1AsLmlQJ3rpiULOAklRqWV4tE22cp8
BU8g9003FTC5gBTJlyXDdZTVkh82ucuTWAlpFQysHXswunmP6nmYvMDhWjSPf46d
jdhQo38SR7lZQ49cetwAOOy2G7TxOm7T0/vts2HUCp8Pyx6sjBo=
=Q/2X
-----END PGP SIGNATURE-----

pinheadmz's public key is on keybase

@achow101
Copy link
Member

ACK 7ccdd74

@achow101 achow101 merged commit 6a16732 into bitcoin:master Apr 12, 2023
@jonatack jonatack deleted the 2023-03-migrate-wallet-warning-fields-to-warnings branch April 12, 2023 17:13
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 12, 2023
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Apr 18, 2023
- clarify that there can be multiple warning messages
- specify the correct wallet action
- describe the use of newlines as delimiters

Github-Pull: bitcoin#27279
Rebased-From: f73782a
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 18, 2023
dc711fb doc: update 24.1 release notes (fanquake)
fc8c1a8 doc: fix/improve warning helps in {create,load,unload,restore}wallet (Jon Atack)
3a26b19 bugfix: rest: avoid segfault for invalid URI (pablomartin4btc)
c40b1da depends: fix compiling bdb with clang-16 on aarch64 (fanquake)
0bac52d Don't return OutputType::UNKNOWN in ParseOutputType (Pttn)

Pull request description:

  Backports:
  * bitcoin#27279 (only f73782a)
  * bitcoin#27462
  * bitcoin#27468
  * bitcoin#27473

ACKs for top commit:
  stickies-v:
    ACK dc711fb
  hebasto:
    re-ACK dc711fb
  jonatack:
    ACK dc711fb

Tree-SHA512: 72c673be82689e3c3a1c2564a1fdd6afe0b357b7aa8bec9524fe6999804fbccf310da0b074e647af14b753e5e695024e268fe4f69aa58747f541f7f429ebede6
achow101 added a commit that referenced this pull request Jun 16, 2023
…d,restore,unload}wallet

5524fa0 doc: add release note about removal of `deprecatedrpc=walletwarningfield` flag (Sebastian Falbesoner)
5c77db7 Restorewallet/createwallet help documentation fixups/improvements (Jon Atack)
a00ae31 rpc: remove deprecated "warning" field from {create,load,restore,unload}wallet (Sebastian Falbesoner)

Pull request description:

  The "warning" string field for wallet creating/loading RPCs (`createwallet`, `loadwallet`, `unloadwallet` and `restorewallet`) has been deprecated with the configuration option `-deprecatedrpc=walletwarningfield` in PR #27279 (released in v25.0). For the next release v26.0, the field and the configuration option can be removed.

ACKs for top commit:
  achow101:
    ACK 5524fa0
  jonatack:
    ACK 5524fa0

Tree-SHA512: 8212f72067d08095304018b8a95d2ebef630004b65123483fbbfb078cc5709c2d825bbc35b16ea5f6b28ae7377347382d7e9afaf7bdbf0575d2c229d970784de
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 19, 2023
…ate,load,restore,unload}wallet

5524fa0 doc: add release note about removal of `deprecatedrpc=walletwarningfield` flag (Sebastian Falbesoner)
5c77db7 Restorewallet/createwallet help documentation fixups/improvements (Jon Atack)
a00ae31 rpc: remove deprecated "warning" field from {create,load,restore,unload}wallet (Sebastian Falbesoner)

Pull request description:

  The "warning" string field for wallet creating/loading RPCs (`createwallet`, `loadwallet`, `unloadwallet` and `restorewallet`) has been deprecated with the configuration option `-deprecatedrpc=walletwarningfield` in PR bitcoin#27279 (released in v25.0). For the next release v26.0, the field and the configuration option can be removed.

ACKs for top commit:
  achow101:
    ACK 5524fa0
  jonatack:
    ACK 5524fa0

Tree-SHA512: 8212f72067d08095304018b8a95d2ebef630004b65123483fbbfb078cc5709c2d825bbc35b16ea5f6b28ae7377347382d7e9afaf7bdbf0575d2c229d970784de
@bitcoin bitcoin locked and limited conversation to collaborators Apr 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants