-
Notifications
You must be signed in to change notification settings - Fork 37.7k
wallet: check when create wallets for the reserved name "wallets" #21073
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
Conversation
Please add some explanation, why is "wallets" a special name? Wallets are created, by default, in a directory named "wallets" but I don't see how creating a sub-directory in that named wallet should be problematic? (and if so, isn't that a bug to be fixed and a functional test added for instead of worked around?) |
Sorry, but afaics u can not test this with regtest,signet or testnet that effects only mainnet nodes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is a reserved word
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording wallets is reserved from use
is better.
@laanwj CLICK MEdiff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index 4bda73599..5a2ca8af3 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -403,7 +403,8 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
n = self.nodes[i]
if wallet_name is not None:
n.createwallet(wallet_name=wallet_name, descriptors=self.options.descriptors, load_on_startup=True)
- n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase')
+ if self.chain != "main":
+ n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase')
def run_test(self):
"""Tests must override this method to define test logic"""
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index 123c48852..24806eab2 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -399,7 +399,10 @@ def get_auth_cookie(datadir, chain):
:
@@ -403,7 +403,8 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
n = self.nodes[i]
if wallet_name is not None:
n.createwallet(wallet_name=wallet_name, descriptors=self.options.descriptors, load_on_startup=True)
- n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase')
+ if self.chain != "main":
+ n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase')
def run_test(self):
"""Tests must override this method to define test logic"""
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index 123c48852..24806eab2 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -399,7 +399,10 @@ def get_auth_cookie(datadir, chain):
assert password is None # Ensure that there is only one rpcpassword line
password = line.split("=")[1].strip("\n")
try:
- with open(os.path.join(datadir, chain, ".cookie"), 'r', encoding="ascii") as f:
+ subdir = chain
+ if subdir == "main":
+ subdir = ""
+ with open(os.path.join(datadir, subdir, ".cookie"), 'r', encoding="ascii") as f:
userpass = f.read()
split_userpass = userpass.split(':')
user = split_userpass[0]
@@ -413,7 +416,10 @@ def get_auth_cookie(datadir, chain):
# If a cookie file exists in the given datadir, delete it.
def delete_cookie_file(datadir, chain):
- if os.path.isfile(os.path.join(datadir, chain, ".cookie")):
+ subdir = chain
+ if chain == "main":
+ subdir = ""
+ if os.path.isfile(os.path.join(datadir, subdir, ".cookie")):
logger.debug("Deleting leftover cookie file")
os.remove(os.path.join(datadir, chain, ".cookie"))
diff --git a/test/functional/wallet_mainnet_test.py b/test/functional/wallet_mainnet_test.py
new file mode 100755
index 000000000..cb78239fc
--- /dev/null
+++ b/test/functional/wallet_mainnet_test.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+# Copyright (c) 2017-2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+"""Test if on mainnet wallets can vanish unaccesable.
+
+Verify that a bitcoind mainet node will not loose wallets on new startup
+"""
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import (
+ assert_equal,
+ assert_raises_rpc_error,
+)
+import collections
+
+class WalletStartupTest(BitcoinTestFramework):
+
+ def set_test_params(self):
+ self.chain = 'main'
+ self.num_nodes = 1
+ self.setup_clean_chain = True
+
+ def run_test(self):
+ self.log.info('test if we still have the original wallets key')
+ #self.nodes[0].createwallet("") //uncoment this line, if u run the test against current master
+ self.nodes[0].createwallet("w1")
+ self.nodes[0].createwallet("w2")
+ assert_equal(self.nodes[0].listwallets(), ['', 'w1', 'w2'])
+ self.log.info(self.nodes[0].listwallets())
+ n = self.nodes[0].get_wallet_rpc('')
+ address = n.getnewaddress()
+ self.nodes[0].createwallet("wallets")
+ n = self.nodes[0].get_wallet_rpc('')
+ self.log.info('now restart node')
+ self.restart_node(0)
+ self.log.info(self.nodes[0].listwallets())
+ n = self.nodes[0].get_wallet_rpc('')
+ #assert_raises_rpc_error(-4, " is not known", n.dumpprivkey, address)
+ n.dumpprivkey(address)
+
+if __name__ == '__main__':
+ WalletStartupTest().main()
just patch and run That should raise on releases above 0.17 an error that there is no key for the wallet address. |
This should be unrelated to the chain. As long as there is a |
Should, yes, but... It seams to me clear that testing i.g. only confirms the test to run correct. So this PR here is more a reminder fix and TODO. |
8b669e1
to
04a0af9
Compare
I thought about that and but if we want to support seamless upgrade and use of older releases i see not much other way, considering that this effects also new sqlite wallets from newer releases, it seams to me the right way to just skip creating a wallets root subdir by chance. |
de95270
to
d7b5a50
Compare
bugfix. wallets is no longer the safe word ;-)
mainchain and testchains could behave different. So make sure we can now easy test this.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
🐙 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". |
There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
1 similar comment
There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
We allow since 0.17 to create a wallet with the the name or dirprefix :"wallets".
That might be not a good idea and we should discourage users to do that to prevent unexpected boating accidents and whale heart attacks.
edit@saibato
The wallets subdir is not created when chain == 'main' by default to allow the node to support upgrading or using older walletdirs or datadirs created by older core releases,
testing could not catch this since this effects only mannet nodes, -regtest behave different and there we don't have this issue.