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: add migration to regenerate missing change addresses (WIP) #415

Merged
merged 8 commits into from
Aug 17, 2020

Conversation

chjj
Copy link
Contributor

@chjj chjj commented Mar 31, 2020

See #414, #413, #411

lib/wallet/walletdb.js Outdated Show resolved Hide resolved
@pinheadmz pinheadmz added this to the 2.1.6 milestone May 6, 2020
@chjj chjj force-pushed the change-migration branch from 76b4eac to c4a2e18 Compare May 26, 2020 12:33
@chjj
Copy link
Contributor Author

chjj commented May 26, 2020

Rebased and addressed nits.

@codecov-commenter
Copy link

codecov-commenter commented May 26, 2020

Codecov Report

Merging #415 into master will increase coverage by 0.08%.
The diff coverage is 93.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #415      +/-   ##
==========================================
+ Coverage   62.53%   62.62%   +0.08%     
==========================================
  Files         129      129              
  Lines       34866    34913      +47     
  Branches     5926     5933       +7     
==========================================
+ Hits        21805    21864      +59     
+ Misses      13061    13049      -12     
Impacted Files Coverage Δ
lib/wallet/layout.js 100.00% <ø> (ø)
lib/wallet/plugin.js 100.00% <ø> (ø)
lib/wallet/walletdb.js 79.34% <89.65%> (+0.43%) ⬆️
lib/wallet/wallet.js 74.19% <100.00%> (+0.24%) ⬆️
lib/protocol/consensus.js 88.77% <0.00%> (-1.03%) ⬇️
lib/net/hostlist.js 50.29% <0.00%> (-0.36%) ⬇️
lib/covenants/rules.js 73.04% <0.00%> (-0.15%) ⬇️
lib/script/script.js 59.32% <0.00%> (-0.09%) ⬇️
lib/wallet/txdb.js 85.11% <0.00%> (+0.06%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a3049d5...c25799d. Read the comment docs.

@pinheadmz pinheadmz mentioned this pull request May 26, 2020
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.

Sweet thanks for the rebase. Tested with #417 can be merged together or separately...

ACK c4a2e18

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

ACK c4a2e185c2442d43f65027d61a0ca52d84d6cfdb
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAl7ND3AACgkQ5+KYS2KJ
yTqZTBAAx1zc9mSfMCPt55/rXqCwQilU6TKW57husOT24jF++hwHAG6t4EULrvOn
gp5tUJx8zaP6E1WZlrWITyr2sKGqI5oxmiZjLdySvoxWU2kpp/8vqXIoZcsBwj2b
QhFLjTYYMlXnkMAzMRRxeD04vydmtqQa1DDcoaDkraO8OKPNKpxOR/13fq1SQn9N
Wt+UuTDm1bXEnX9pfYYyf6aA4n88FlFIl6kvwYCJ9evKze0yH7ERc3vR/ex86bzW
GmCwk4drBN2pThkzT3s7Q80+X1JtKLN+E7RGEmm+Z34aXRVVJRQCpe7MvdiTxeAG
jE8lTNEqVVvKZ4eYdxdbrQIK+eiUawPoAQFXh1AwhvyfbMWzeDAvWwaiiyUwNw8e
ad/6jqcchjmY+6SVq6ATX+JumiH9nh7n099JBcjsWCPvRZFgnjlMHFOadbPwKiv5
P+nLlmBEwe3iyLQ+Sk7Zhmbuyt0O6cXMHhh8WMMi+KwP41INU2uNMwA3//f9204G
2P1qngV+sXRUEF6EYRX4SqA1nTZYOcNdaLRu6nHaFG8dD32Mbocga6hxMBdTffv2
Jl52t68FChUcbL/OsUgnXa6My9Iq9ZabVmDOZdlHotfg5xVHW1kLUuC5lkZGAiA5
pHqLBFZGr9psclRZKOP35WQxdVa1di5wpKzAg9voohUhc6tAvD4=
=zZR9
-----END PGP SIGNATURE-----

pinheadmz's public key is on keybase

@pinheadmz
Copy link
Member

rebase to 1351d80:

Screen Shot 2020-07-22 at 2 59 07 PM

log message can be tested by adding this diff to the test:

diff --git a/test/wallet-change-test.js b/test/wallet-change-test.js
index 39376570..39d142d0 100644
--- a/test/wallet-change-test.js
+++ b/test/wallet-change-test.js
@@ -19,7 +19,9 @@ const node = new FullNode({
   prefix: path,
   memory: false,
   network: 'regtest',
-  plugins: [require('../lib/wallet/plugin')]
+  plugins: [require('../lib/wallet/plugin')],
+  logConsole: true,
+  logLevel: 'debug'
 });

 const {wdb} = node.require('walletdb');

@pinheadmz pinheadmz requested a review from tynes July 22, 2020 19:10
@pinheadmz
Copy link
Member

@turbomaze

@pinheadmz
Copy link
Member

New thoughts on this, after testing #480 and having a hard time getting it to work.

Here's what I think the flow could be for this PR:

  1. Upgraded hsd checks for walletDB version on launch, if it is not updated, quit the process with an error and instructions to back up wallet db and then...
  2. To upgrade hsd, launch with extra option --migrate-wallet-to-0 or something in addition to all other params you normally launch with

This way, all the migration logic can stay in hsd, no external scripts. The user adds the option to all their normal options whatever they are, including prefix and network and all that, so the migration process already has all the data it needs (this is an issue passing all that to the migration script). The user can back up their walletDB any way they want to (we will have to remove the backup logic form this PR as well) and the if the user decides NOT to migrate they still have the option to revert hsd to the last version and relaunch before anything has happened to their data.

Thoughts @tynes @turbomaze ?

@pinheadmz
Copy link
Member

Rebase to c25799d :

New flow works like this:

  • User upgrades to this version of hsd
  • Every time new version of hsd is run, check DB migration id
    • if migration ID is present, continue with normal operation
    • if ID is NOT present, scan for missing change addresses:
      • This may take some time (a warning is needed in changelog)
      • The database is not altered in anyway
      • If all addresses are present, DB migration ID is saved, continue with normal operation
      • if addresses are missing, quit and throw an error:

Screen Shot 2020-08-07 at 2 51 17 PM

  • Affected user starts again, this time adding --wallet-migrate=0 to their launch.
    • above sequence is run again
      • this time, if addresses are missing they are regenerated and saved
      • wallet automatically initiates a rescan

Screen Shot 2020-08-07 at 3 03 03 PM

  • Because a rescan is required, a standalone wallet user will have to ensure that the wallet node is connected to a hsd full node

Test script: https://gist.github.com/pinheadmz/25fcd11ec8ba3916830ebc01d888bd7b
This script checks out the old version of hsd, manually creates change addresses and dumps a wallet backup. Then it checks out this branch, runs the migration flag and dumps the wallet again.

@pinheadmz
Copy link
Member

@tynes @turbomaze if you guys are cool with this new scheme I'll spell it all out in the changelog in the next commit,

lib/wallet/walletdb.js Show resolved Hide resolved
lib/wallet/walletdb.js Show resolved Hide resolved
@turbomaze
Copy link
Contributor

@tynes @turbomaze if you guys are cool with this new scheme I'll spell it all out in the changelog in the next commit,

Looks great!

@pinheadmz
Copy link
Member

rebase to 1789576:
rebase on master

@coveralls
Copy link

coveralls commented Aug 11, 2020

Pull Request Test Coverage Report for Build 204277284

  • 42 of 45 (93.33%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 59.124%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/wallet/walletdb.js 26 29 89.66%
Totals Coverage Status
Change from base Build 204174244: 0.1%
Covered Lines: 19348
Relevant Lines: 30451

💛 - Coveralls

@pinheadmz
Copy link
Member

Ok added a message to the changelog - I think this is done. @chjj @tynes @turbomaze looking for final ACKs and then I say we merge and release hsd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants