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

Add scripts to dumpwallet RPC #11667

Merged
merged 7 commits into from Dec 21, 2017
Merged

Add scripts to dumpwallet RPC #11667

merged 7 commits into from Dec 21, 2017

Conversation

meshcollider
Copy link
Contributor

@meshcollider meshcollider commented Nov 12, 2017

As discussed in #11289 (comment), adds the CScripts from the wallet to the dumpwallet RPC and then allows them to be imported with the importwallet RPC. Includes a basic test, and modifies the helptext of the dumpwallet RPC.

Notes:

  • Reviewers: use ?w=1 to avoid the indentation-only change in commit Add scripts to importwallet RPC
  • currently the scripts are followed with # addr= comments just as the other keys are, unsure if this might confuse users into thinking all the scripts are for valid P2SH addresses though, but I don't think that should be an issue.
  • there are no birthtimes for scripts, so script imports don't affect rescans
  • importwallet imports the CScripts but I'm not sure how to approach specifying whether scripts are for P2SH addresses, BIP173 addresses, etc. whether that matters or not. Otherwise the RPC helptext might just need modification.

Fixes #11715

@meshcollider
Copy link
Contributor Author

@TheBlueMatt @laanwj you might want to take a look after the discussion in the other PR

@laanwj
Copy link
Member

laanwj commented Nov 13, 2017

Concept ACK, thanks for having a shot at this,will review in detail later.

@jonasschnelli
Copy link
Contributor

Concept ACK
Maybe importwallet should get an overhauled description (currently "\nImports keys from a wallet dump file (see dumpwallet)....?
Should we returns warning when importwallet was importing scripts?

@meshcollider
Copy link
Contributor Author

@jonasschnelli

Should we returns warning when importwallet was importing scripts?

you mean like a warning about manually rescanning or something? Just to let the user know it contained scripts too?

Copy link
Member

@promag promag left a comment

Choose a reason for hiding this comment

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

cs_wallet should be locked in dumpwallet?

GetAllReserveKeys() is not protected, worst, it returns a const reference.

And now with the extra GetCScripts() this should be "atomic", IMO.

std::string address = EncodeDestination(scriptid);
if(pwallet->GetCScript(scriptid, script)) {
file << strprintf("%s 0 script=1", HexStr(script.begin(), script.end()));
file << strprintf(" # addr=%s\n", address);
Copy link
Member

Choose a reason for hiding this comment

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

We don't test the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, unsure what you mean? Discussed on IRC

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, address is parsed in

key_label, comment = line.split("#")
# key = key_label.split(" ")[0]
keytype = key_label.split(" ")[2]
if len(comment) > 1:
addr_keypath = comment.split(" addr=")[1]
addr = addr_keypath.split(" ")[0]
keypath = None

@@ -89,6 +89,10 @@ Low-level RPC changes
- `dumpwallet` no longer allows overwriting files. This is a security measure
as well as prevents dangerous user mistakes.

- `dumpwallet` now includes hex-encoded scripts from the wallet in the dumpfile, and
`importwallet` now imports these scripts, but corresponding addresses may not be added
correctly or a manual rescan may be required to find transactions.
Copy link
Member

Choose a reason for hiding this comment

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

to find relevant transactions or something along that.

@meshcollider
Copy link
Contributor Author

@promag

cs_wallet should be locked in dumpwallet?

It is locked on line 630 right? LOCK2(cs_main, pwallet->cs_wallet);

@meshcollider
Copy link
Contributor Author

Fixed @promag's comment nit, thanks :)

The release notes and comment change may still need modification based on what needs to be said about BIP173, etc.

@promag
Copy link
Member

promag commented Nov 15, 2017

How about const map<>& GetScripts() const, which returns mapScripts, to avoid the set creation and copy and lookups added further? Not sure about cs_KeyStore.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

utACK 468771372c96378268272971212943e7b46596cb

@@ -694,6 +696,15 @@ UniValue dumpwallet(const JSONRPCRequest& request)
}
}
file << "\n";
for (const CScriptID &scriptid : scripts) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not dumping the information in m_script_metadata. At very least, should add a comment with possible todo here to include metadata in the future. Or you could implement a minimal version of this by adding an EncodeDumpTime(m_script_metadata.at(scriptid)nCreateTime) field to the output. It would also be possible to extend GetKeyBirthTimes to work with scripts and derive birth times from transaction times, and sort output by these times, to make script output consistent with key output.

Copy link
Contributor

@ryanofsky ryanofsky Dec 18, 2017

Choose a reason for hiding this comment

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

It would also be good to either dump or add a TODO for dumping WitnessV0ScriptHash and WitnessV0KeyHash keys and scripts.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would also be good to either dump or add a TODO for dumping WitnessV0ScriptHash and WitnessV0KeyHash keys and scripts.

Aren't WitnessV0* scripts and keys also included in mapScripts and mapKeys? Or do you mean like witness derivatives of "normal" keys?

Yeah, they are. I was thinking of mapAddressBook entries, but these aren't exported at all by dumpwallet.

@meshcollider
Copy link
Contributor Author

meshcollider commented Dec 20, 2017

@ryanofsky m_script_metadata didn't actually exist at the time I made this PR, you introduced it in 11854, so I've rebased onto master to use it. Aren't WitnessV0* scripts and keys also included in mapScripts and mapKeys? Or do you mean like witness derivatives of "normal" keys?

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

utACK 656fde5, only change since last review is the new script metadata commit.

@laanwj
Copy link
Member

laanwj commented Dec 21, 2017

utACK 656fde5

Thanks for adding release notes!

@laanwj laanwj merged commit 656fde5 into bitcoin:master Dec 21, 2017
laanwj added a commit that referenced this pull request Dec 21, 2017
656fde5 Add script birthtime metadata to dump and import wallet (MeshCollider)
1bab9b2 Add script dump note to RPC help text and release notes (MeshCollider)
68c1e00 Add test for importwallet (MeshCollider)
9e1184d Add dumpwallet scripts test (MeshCollider)
ef0c730 Add scripts to importwallet RPC (MeshCollider)
b702ae8 Add CScripts to dumpwallet RPC (MeshCollider)
cdc260a Add GetCScripts to CBasicKeyStore (MeshCollider)

Pull request description:

  As discussed in #11289 (comment), adds the CScripts from the wallet to the `dumpwallet` RPC and then allows them to be imported with the `importwallet` RPC. Includes a basic test, and modifies the helptext of the dumpwallet RPC.

  Notes:
  - Reviewers: use `?w=1` to avoid the indentation-only change in commit `Add scripts to importwallet RPC `
  - currently the scripts are followed with `# addr=` comments just as the other keys are, unsure if this might confuse users into thinking all the scripts are for valid P2SH addresses though, but I don't think that should be an issue.
  - there are no birthtimes for scripts, so script imports don't affect rescans
  - `importwallet` imports the CScripts but I'm not sure how to approach specifying whether scripts are for P2SH addresses, BIP173 addresses, etc. whether that matters or not. Otherwise the RPC helptext might just need modification.

  Fixes #11715

Tree-SHA512: 36c55837b3a58b9d3499d4c0c2ae82153d62aa71919e751574651b63a1d2b8ecc83796db4553cc65dad9b5341c3a42ae2fcf4d62598c30af267f8e1461ba8272
@meshcollider meshcollider deleted the 201710_dumpwallet_scripts branch December 21, 2017 19:40
str4d pushed a commit to str4d/zcash that referenced this pull request Dec 19, 2019
Zcash: Excludes changes to importwallet (missing bitcoin/bitcoin#11667)
and ProcessImport (missing bitcoin/bitcoin#7551).
zkbot added a commit to zcash/zcash that referenced this pull request Dec 19, 2019
Bitcoin wallet PRs 3

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#7687
- bitcoin/bitcoin#11116
  - Excludes SegWit tests
  - Excludes `isInvalid` code (which is part of the SegWit support structure)
- bitcoin/bitcoin#13002
  - Excludes changes to `importwallet` (missing bitcoin/bitcoin#11667)
  - Excludes changes to `ProcessImport` (missing bitcoin/bitcoin#7551)
  - Third commit was rewritten to add an internal SigVersion argument (which we didn't have because it was added to support SegWit logic).
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Mar 23, 2020
656fde5 Add script birthtime metadata to dump and import wallet (MeshCollider)
1bab9b2 Add script dump note to RPC help text and release notes (MeshCollider)
68c1e00 Add test for importwallet (MeshCollider)
9e1184d Add dumpwallet scripts test (MeshCollider)
ef0c730 Add scripts to importwallet RPC (MeshCollider)
b702ae8 Add CScripts to dumpwallet RPC (MeshCollider)
cdc260a Add GetCScripts to CBasicKeyStore (MeshCollider)

Pull request description:

  As discussed in bitcoin#11289 (comment), adds the CScripts from the wallet to the `dumpwallet` RPC and then allows them to be imported with the `importwallet` RPC. Includes a basic test, and modifies the helptext of the dumpwallet RPC.

  Notes:
  - Reviewers: use `?w=1` to avoid the indentation-only change in commit `Add scripts to importwallet RPC `
  - currently the scripts are followed with `# addr=` comments just as the other keys are, unsure if this might confuse users into thinking all the scripts are for valid P2SH addresses though, but I don't think that should be an issue.
  - there are no birthtimes for scripts, so script imports don't affect rescans
  - `importwallet` imports the CScripts but I'm not sure how to approach specifying whether scripts are for P2SH addresses, BIP173 addresses, etc. whether that matters or not. Otherwise the RPC helptext might just need modification.

  Fixes bitcoin#11715

Tree-SHA512: 36c55837b3a58b9d3499d4c0c2ae82153d62aa71919e751574651b63a1d2b8ecc83796db4553cc65dad9b5341c3a42ae2fcf4d62598c30af267f8e1461ba8272
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Mar 28, 2020
656fde5 Add script birthtime metadata to dump and import wallet (MeshCollider)
1bab9b2 Add script dump note to RPC help text and release notes (MeshCollider)
68c1e00 Add test for importwallet (MeshCollider)
9e1184d Add dumpwallet scripts test (MeshCollider)
ef0c730 Add scripts to importwallet RPC (MeshCollider)
b702ae8 Add CScripts to dumpwallet RPC (MeshCollider)
cdc260a Add GetCScripts to CBasicKeyStore (MeshCollider)

Pull request description:

  As discussed in bitcoin#11289 (comment), adds the CScripts from the wallet to the `dumpwallet` RPC and then allows them to be imported with the `importwallet` RPC. Includes a basic test, and modifies the helptext of the dumpwallet RPC.

  Notes:
  - Reviewers: use `?w=1` to avoid the indentation-only change in commit `Add scripts to importwallet RPC `
  - currently the scripts are followed with `# addr=` comments just as the other keys are, unsure if this might confuse users into thinking all the scripts are for valid P2SH addresses though, but I don't think that should be an issue.
  - there are no birthtimes for scripts, so script imports don't affect rescans
  - `importwallet` imports the CScripts but I'm not sure how to approach specifying whether scripts are for P2SH addresses, BIP173 addresses, etc. whether that matters or not. Otherwise the RPC helptext might just need modification.

  Fixes bitcoin#11715

Tree-SHA512: 36c55837b3a58b9d3499d4c0c2ae82153d62aa71919e751574651b63a1d2b8ecc83796db4553cc65dad9b5341c3a42ae2fcf4d62598c30af267f8e1461ba8272
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Mar 29, 2020
656fde5 Add script birthtime metadata to dump and import wallet (MeshCollider)
1bab9b2 Add script dump note to RPC help text and release notes (MeshCollider)
68c1e00 Add test for importwallet (MeshCollider)
9e1184d Add dumpwallet scripts test (MeshCollider)
ef0c730 Add scripts to importwallet RPC (MeshCollider)
b702ae8 Add CScripts to dumpwallet RPC (MeshCollider)
cdc260a Add GetCScripts to CBasicKeyStore (MeshCollider)

Pull request description:

  As discussed in bitcoin#11289 (comment), adds the CScripts from the wallet to the `dumpwallet` RPC and then allows them to be imported with the `importwallet` RPC. Includes a basic test, and modifies the helptext of the dumpwallet RPC.

  Notes:
  - Reviewers: use `?w=1` to avoid the indentation-only change in commit `Add scripts to importwallet RPC `
  - currently the scripts are followed with `# addr=` comments just as the other keys are, unsure if this might confuse users into thinking all the scripts are for valid P2SH addresses though, but I don't think that should be an issue.
  - there are no birthtimes for scripts, so script imports don't affect rescans
  - `importwallet` imports the CScripts but I'm not sure how to approach specifying whether scripts are for P2SH addresses, BIP173 addresses, etc. whether that matters or not. Otherwise the RPC helptext might just need modification.

  Fixes bitcoin#11715

Tree-SHA512: 36c55837b3a58b9d3499d4c0c2ae82153d62aa71919e751574651b63a1d2b8ecc83796db4553cc65dad9b5341c3a42ae2fcf4d62598c30af267f8e1461ba8272
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Mar 31, 2020
656fde5 Add script birthtime metadata to dump and import wallet (MeshCollider)
1bab9b2 Add script dump note to RPC help text and release notes (MeshCollider)
68c1e00 Add test for importwallet (MeshCollider)
9e1184d Add dumpwallet scripts test (MeshCollider)
ef0c730 Add scripts to importwallet RPC (MeshCollider)
b702ae8 Add CScripts to dumpwallet RPC (MeshCollider)
cdc260a Add GetCScripts to CBasicKeyStore (MeshCollider)

Pull request description:

  As discussed in bitcoin#11289 (comment), adds the CScripts from the wallet to the `dumpwallet` RPC and then allows them to be imported with the `importwallet` RPC. Includes a basic test, and modifies the helptext of the dumpwallet RPC.

  Notes:
  - Reviewers: use `?w=1` to avoid the indentation-only change in commit `Add scripts to importwallet RPC `
  - currently the scripts are followed with `# addr=` comments just as the other keys are, unsure if this might confuse users into thinking all the scripts are for valid P2SH addresses though, but I don't think that should be an issue.
  - there are no birthtimes for scripts, so script imports don't affect rescans
  - `importwallet` imports the CScripts but I'm not sure how to approach specifying whether scripts are for P2SH addresses, BIP173 addresses, etc. whether that matters or not. Otherwise the RPC helptext might just need modification.

  Fixes bitcoin#11715

Tree-SHA512: 36c55837b3a58b9d3499d4c0c2ae82153d62aa71919e751574651b63a1d2b8ecc83796db4553cc65dad9b5341c3a42ae2fcf4d62598c30af267f8e1461ba8272
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Mar 31, 2020
656fde5 Add script birthtime metadata to dump and import wallet (MeshCollider)
1bab9b2 Add script dump note to RPC help text and release notes (MeshCollider)
68c1e00 Add test for importwallet (MeshCollider)
9e1184d Add dumpwallet scripts test (MeshCollider)
ef0c730 Add scripts to importwallet RPC (MeshCollider)
b702ae8 Add CScripts to dumpwallet RPC (MeshCollider)
cdc260a Add GetCScripts to CBasicKeyStore (MeshCollider)

Pull request description:

  As discussed in bitcoin#11289 (comment), adds the CScripts from the wallet to the `dumpwallet` RPC and then allows them to be imported with the `importwallet` RPC. Includes a basic test, and modifies the helptext of the dumpwallet RPC.

  Notes:
  - Reviewers: use `?w=1` to avoid the indentation-only change in commit `Add scripts to importwallet RPC `
  - currently the scripts are followed with `# addr=` comments just as the other keys are, unsure if this might confuse users into thinking all the scripts are for valid P2SH addresses though, but I don't think that should be an issue.
  - there are no birthtimes for scripts, so script imports don't affect rescans
  - `importwallet` imports the CScripts but I'm not sure how to approach specifying whether scripts are for P2SH addresses, BIP173 addresses, etc. whether that matters or not. Otherwise the RPC helptext might just need modification.

  Fixes bitcoin#11715

Tree-SHA512: 36c55837b3a58b9d3499d4c0c2ae82153d62aa71919e751574651b63a1d2b8ecc83796db4553cc65dad9b5341c3a42ae2fcf4d62598c30af267f8e1461ba8272
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 1, 2020
656fde5 Add script birthtime metadata to dump and import wallet (MeshCollider)
1bab9b2 Add script dump note to RPC help text and release notes (MeshCollider)
68c1e00 Add test for importwallet (MeshCollider)
9e1184d Add dumpwallet scripts test (MeshCollider)
ef0c730 Add scripts to importwallet RPC (MeshCollider)
b702ae8 Add CScripts to dumpwallet RPC (MeshCollider)
cdc260a Add GetCScripts to CBasicKeyStore (MeshCollider)

Pull request description:

  As discussed in bitcoin#11289 (comment), adds the CScripts from the wallet to the `dumpwallet` RPC and then allows them to be imported with the `importwallet` RPC. Includes a basic test, and modifies the helptext of the dumpwallet RPC.

  Notes:
  - Reviewers: use `?w=1` to avoid the indentation-only change in commit `Add scripts to importwallet RPC `
  - currently the scripts are followed with `# addr=` comments just as the other keys are, unsure if this might confuse users into thinking all the scripts are for valid P2SH addresses though, but I don't think that should be an issue.
  - there are no birthtimes for scripts, so script imports don't affect rescans
  - `importwallet` imports the CScripts but I'm not sure how to approach specifying whether scripts are for P2SH addresses, BIP173 addresses, etc. whether that matters or not. Otherwise the RPC helptext might just need modification.

  Fixes bitcoin#11715

Tree-SHA512: 36c55837b3a58b9d3499d4c0c2ae82153d62aa71919e751574651b63a1d2b8ecc83796db4553cc65dad9b5341c3a42ae2fcf4d62598c30af267f8e1461ba8272
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Jun 30, 2021
656fde5 Add script birthtime metadata to dump and import wallet (MeshCollider)
1bab9b2 Add script dump note to RPC help text and release notes (MeshCollider)
68c1e00 Add test for importwallet (MeshCollider)
9e1184d Add dumpwallet scripts test (MeshCollider)
ef0c730 Add scripts to importwallet RPC (MeshCollider)
b702ae8 Add CScripts to dumpwallet RPC (MeshCollider)
cdc260a Add GetCScripts to CBasicKeyStore (MeshCollider)

Pull request description:

  As discussed in bitcoin#11289 (comment), adds the CScripts from the wallet to the `dumpwallet` RPC and then allows them to be imported with the `importwallet` RPC. Includes a basic test, and modifies the helptext of the dumpwallet RPC.

  Notes:
  - Reviewers: use `?w=1` to avoid the indentation-only change in commit `Add scripts to importwallet RPC `
  - currently the scripts are followed with `# addr=` comments just as the other keys are, unsure if this might confuse users into thinking all the scripts are for valid P2SH addresses though, but I don't think that should be an issue.
  - there are no birthtimes for scripts, so script imports don't affect rescans
  - `importwallet` imports the CScripts but I'm not sure how to approach specifying whether scripts are for P2SH addresses, BIP173 addresses, etc. whether that matters or not. Otherwise the RPC helptext might just need modification.

  Fixes bitcoin#11715

Tree-SHA512: 36c55837b3a58b9d3499d4c0c2ae82153d62aa71919e751574651b63a1d2b8ecc83796db4553cc65dad9b5341c3a42ae2fcf4d62598c30af267f8e1461ba8272
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dumpwallet problem
6 participants