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] HD Wallet - v2. #1327

Merged
merged 51 commits into from
Mar 11, 2020

Conversation

furszy
Copy link

@furszy furszy commented Feb 10, 2020

HD Wallet implementation (BIP44 derivation path) streamlined to upstream flow and db object's serialization storage.

Summarizing few important changes of this work:


Restructured over latest upstream's architecture.

Meaning that this new wallet code organization will make easier most of the upcoming backports, having it as the base structure for every feature that we have and new ones that we will be implementing. Introducing the ScriptPubKeyMan (short for ScriptPubKeyManager) for managing scriptPubKeys and their associated scripts and keys, more information about the wallet class architecture can be found here and here.

Supporting pre and post HD wallet keys.

This means that old wallets that want to upgrade to HD wallet, can do it directly within the wallet. No need to move the balance to a fresh new wallet. Can import single private keys too, the wallet will continue storing and managing them in parallel of the hd seed derived keys.

Key Metadata Upgrade

The key metadata has been upgraded to support key origin (hd path) and the hd seed identifier.

HD Master Seed.

The master seed is being managed by the keystore, same as with new and old keys (Single flow for both of them).

Staking addresses derivation path.

The "change" level in the BIP44 definition has been extended to support staking addresses generation. We will have three different purposes:

  1. External receiving addresses.
  2. Internal receiving addresses.
  3. Staking addresses, (external receiving addresses starting with an 'S' for staking contracts).

A really short view of the HD classes structure:

CWallet ---> SPKM ---> HDChain —> chain_counters.

Upgrade to HD wallet flow.

The automatic upgrade can be done starting the node with the flag -upgradewallet or going to settings and pressing on the Upgrade Wallet button.

RPC commands:

New commands:

sethdseed set a new HD wallet seed.
getaddressinfo obtains the address information, including the key derivation path.

Upgraded commands:

dumpwallet : HD wallet export included into the flow.

Tests:

Most of the previous functional test has been upgraded to support and verify HD functionality.

  • wallet_backup.py
  • wallet_keypool.py
  • wallet_topup_keypool.py
  • wallet_basic.py
  • wallet_dump.py

New functional test created:

  • wallet_hd.py .
  • upgrade_wallet.py.

Next PRs

  • Improve scripts management (multisig - P2CS).
  • Further wallet.h/cpp cleanup. Continue decoupling the keys/scripts management to the SPKM box. (This work will need several PRs more).
  • Upgrade from encrypted wallet.

@furszy furszy self-assigned this Feb 10, 2020
Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

Not an in-depth review, but a reminder of a previously discussed topic.

looks like init.cpp's help message was changed previously (and in error, at the time) to reflect a much smaller number of default keypairs. but now that keypairs are tied to a deterministic "seed", there is no real benefit in pre-generating 1000 keypairs.

src/wallet/wallet.cpp Outdated Show resolved Hide resolved
@furszy furszy added the Wallet label Feb 12, 2020
@furszy furszy force-pushed the 2020_hd_wallet_rebased_7_feb branch from 18b3a6b to 3549d2a Compare February 12, 2020 19:15
@furszy furszy changed the title [WIP] HD Wallet - v2. HD Wallet - v2. Feb 14, 2020
Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

Code ACK with few questions.
Fantastic job 🍻

Will give it some more live testing.

src/wallet/scriptpubkeyman.h Outdated Show resolved Hide resolved
src/wallet/scriptpubkeyman.cpp Outdated Show resolved Hide resolved
src/wallet/scriptpubkeyman.cpp Outdated Show resolved Hide resolved
src/wallet/rpcwallet.cpp Outdated Show resolved Hide resolved
src/wallet/scriptpubkeyman.cpp Outdated Show resolved Hide resolved
src/wallet/scriptpubkeyman.cpp Outdated Show resolved Hide resolved
test/functional/test_runner.py Outdated Show resolved Hide resolved
if (boost::algorithm::starts_with(vstr[nStr], "label=")) {
else if (type == "hdseed")
fLabel = false;
if (boost::algorithm::starts_with(type, "label=")) {

Choose a reason for hiding this comment

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

guess this can be else if too

src/wallet/hdchain.h Show resolved Hide resolved
src/wallet/rpcdump.cpp Outdated Show resolved Hide resolved
@random-zebra
Copy link

This change is pretty important and user-facing so, imo, there should be a separate paragraph for it in the release notes (with indications for upgrade/backup best practice).
Also the rpc section needs to be completed:

  • new rpc: sethdseed and getaddressinfo
  • indication for getinfo: keypoolsize only counts external keys

@random-zebra random-zebra added this to the 4.1.0 milestone Feb 21, 2020
@random-zebra random-zebra added the Needs Release Notes Placeholder tag for anything needing mention in the "Notable Changes" section of release notes label Feb 21, 2020
src/wallet/wallet.h Outdated Show resolved Hide resolved
@furszy
Copy link
Author

furszy commented Feb 22, 2020

Updated following @random-zebra' comments 👌 .

@furszy furszy force-pushed the 2020_hd_wallet_rebased_7_feb branch from e45d2c2 to ff77b5a Compare February 22, 2020 14:51
test/functional/test_runner.py Outdated Show resolved Hide resolved
src/wallet/scriptpubkeyman.cpp Outdated Show resolved Hide resolved
@furszy furszy force-pushed the 2020_hd_wallet_rebased_7_feb branch from ff77b5a to f9e929c Compare February 22, 2020 17:30
@furszy
Copy link
Author

furszy commented Feb 23, 2020

I skipped the last comment, sorry. Yeah @random-zebra, will write a separate release notes section for this. Agree that it's needed.

Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

couple styling changes, and a question

src/wallet/rpcwallet.cpp Show resolved Hide resolved
src/wallet/rpcwallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

looks like some missing upgrade functionality

src/init.cpp Show resolved Hide resolved
@akshaynexus
Copy link

is there any method to extract the mnemonic via the rpc commands if any?

@furszy
Copy link
Author

furszy commented Feb 25, 2020

@akshaynexus there is no mnemonic. BIP39 was not implemented.

If you meant the seed, you can export it calling dumpwallet. It will export pre and post HD keys all together, including the master seed.

@akshaynexus
Copy link

Oh ok

@furszy
Copy link
Author

furszy commented Mar 1, 2020

Upgrade wallet from non-HD to HD functional test included, PR details updated. All good, travis passing.

@furszy furszy force-pushed the 2020_hd_wallet_rebased_7_feb branch from ff2fefa to 5748d39 Compare March 4, 2020 14:53
@furszy
Copy link
Author

furszy commented Mar 4, 2020

PR rebased, had conflicts after #1337 merge.

random-zebra
random-zebra previously approved these changes Mar 4, 2020
Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

Few nits here and there. Think this is pretty close to merge. Still missing release notes

src/wallet/scriptpubkeyman.cpp Outdated Show resolved Hide resolved
src/wallet/scriptpubkeyman.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.cpp Outdated Show resolved Hide resolved
test/functional/wallet_upgrade.py Outdated Show resolved Hide resolved
test/functional/wallet_upgrade.py Outdated Show resolved Hide resolved
test/functional/wallet_upgrade.py Outdated Show resolved Hide resolved
Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

Good opportunity to fix the paths in wallet_dump.py as well.

test/functional/wallet_dump.py Outdated Show resolved Hide resolved
@furszy furszy force-pushed the 2020_hd_wallet_rebased_7_feb branch from 29f040c to 1cccdea Compare March 6, 2020 19:31
@furszy furszy requested a review from random-zebra March 6, 2020 19:53
@furszy
Copy link
Author

furszy commented Mar 6, 2020

PR updated with the release notes. Let me know about any typo or needed change there.

@random-zebra random-zebra added enhancement GUI RPC and removed Needs Release Notes Placeholder tag for anything needing mention in the "Notable Changes" section of release notes labels Mar 8, 2020
@Fuzzbawls
Copy link
Collaborator

Seems like there may have been some commits left out. Reading your changes to the release notes; i'm not seeing anything during running or code review that adds a new topbar icon or a GUI notification of running a non-HD wallet. There also isn't the upgradewallet RPC command that is referenced.

@furszy
Copy link
Author

furszy commented Mar 9, 2020

@Fuzzbawls yes, working in another branch. I just cherry-picked the release notes change here to merge this PR and not continue making it bigger.
The plan is push the upgradewallet from encrypted file and the GUI upgrade notification flow in a subsequent PR.

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

sethdseed can't be used with arguments at the moment, as it doesn't interpret the first one as boolean.
Need to add {"sethdseed", 0} to vRPCConvertParams in rpc/client.cpp

@furszy
Copy link
Author

furszy commented Mar 9, 2020

@random-zebra done.

@random-zebra
Copy link

Yes, this looks quite good by now. I think it can be merged and anything else can be addressed in successive pull requests.

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

ACK 818dac7

Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

ACK 818dac7

@Fuzzbawls Fuzzbawls changed the title HD Wallet - v2. [Wallet] HD Wallet - v2. Mar 11, 2020
@furszy furszy merged commit d58fd6f into PIVX-Project:master Mar 11, 2020
random-zebra added a commit to random-zebra/PIVX that referenced this pull request Mar 18, 2020
0e969f1 [GUI] Launch upgrade wallet dialog at the wallet's startup. (furszy)
7c468ce [Trivial] Method brackets jump lines. (furszy)
42ed283 [GUI] Upgrade wallet to HD functionality connected. (furszy)
c29d34e [GUI] isHDEnabled & upgradeWallet methods created. (furszy)

Pull request description:

  This was built on top of PIVX-Project#1399.

  Essentially connecting the HD wallet upgrade to the GUI as it was defined in the release-notes in PIVX-Project#1327.

ACKs for top commit:
  random-zebra:
    ACK 0e969f1
  Fuzzbawls:
    ACK 0e969f1

Tree-SHA512: 8d6ee4a5c53b2bead2303b8fd241ef7404ee5cb62599118e3328073b7ce6b5b63d7555bb5d26e5d3b266514476d81d1deb3f42c738216ea788c87babc019cf88
@furszy furszy deleted the 2020_hd_wallet_rebased_7_feb branch November 29, 2022 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants