-
Notifications
You must be signed in to change notification settings - Fork 38.7k
[WIP] wallet: ensure wallet files are not reused across chains #14533
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
[WIP] wallet: ensure wallet files are not reused across chains #14533
Conversation
|
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. |
|
Genesis block isn't sufficient, a lot of altcoins share genesis blocks. :( Also there should be a way to override, since moving wallet files between forks is a common way of collecting fork coins-- obviously not something you'd want to happen accidentally but fine as an unsupported "you get to keep both pieces" option. |
b019568 to
da99bd1
Compare
|
@gmaxwell, thanks for the suggestion. Just added an override option |
da99bd1 to
81f1124
Compare
|
Implemented the new check via This can be tested with the following function test (here two disconnected nodes in regtest mode generate two different chains with the same genesis, so can be used to model fork coins with shared genesis): # ...
self.log.info("Generating initial distinct blockchains")
self.nodes[0].generate(5)
self.nodes[1].generate(5)
self.log.info("Creating wallets")
w0_path = os.path.join(self.nodes[0].datadir, 'w0')
w1_path = os.path.join(self.nodes[1].datadir, 'w1')
self.nodes[0].createwallet(w0_path)
self.nodes[1].createwallet(w1_path)
self.log.info("Restarting nodes") # to close wallets
self.stop_node(0)
self.stop_node(1)
self.start_node(0)
self.start_node(1)
self.log.info("Loading wallet")
print(self.nodes[0].loadwallet(w1_path)) # this should fail with wallet reuse errorNot sure if this needs a separate test though, so any suggestions on which one should have it appended? |
81f1124 to
ddeb3df
Compare
|
It doesn't seem like a good idea to prevent a wallet from opening in the case of even a 1 block reorg IMO. Maybe checking 6 blocks back in the chain or something would be better? Concept ACK though, I think this is still a nice check to have A new test file here would be fine too I think, but you also need to fix up the existing tests to work with this change too, travis is failing on some of them |
src/wallet/wallet.cpp
Outdated
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.
Maybe walletInstance->WalletLogPrintf the hashes or something too
d22a8a4 to
884781a
Compare
884781a to
9ffb1c6
Compare
src/wallet/init.cpp
Outdated
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.
I'm not sure this should really be an option?
src/wallet/init.cpp
Outdated
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.
If there is an option, the name -walletcrosschain might be better.
src/wallet/wallet.cpp
Outdated
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.
This comment's described behaviour is definitely wrong: the best known block could be a stale block!
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.
Indeed, but this is going away after the @meshcollider's comments are addressed. I didn't have much time lately, will do it sometime the next two weeks.
9ffb1c6 to
11f3568
Compare
11f3568 to
dc48765
Compare
| Needs rebase |
| There hasn't been much activity lately and the patch still needs rebase, so I am closing this for now. Please let me know when you want to continue working on this, so the pull request can be re-opened. |
|
Not sure, but it may be more important to add this check with the new "Open Wallet -> Other..." GUI feature in #15204 to prevent mistakenly loading incompatible wallets. |
|
Looks like I completely forgot about this one. Updated and tested the old branch yesterday - https://github.com/mrwhythat/bitcoin/tree/wallet-file-reuse-prevention. Can it be reopened or should I just open another PR? |
|
I'm unable to re-open this PR, so creating a new one should be ok. |
This implements a proposal in #12805.
I follow the suggestion by @ryanofsky and compare a genesis block hash, extracted from wallet's best block locator, to an
chainActive's genesis block hash. If they don't match, the error is reported.