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

Bugfix: RPC/Wallet: Include HD key metadata in dumpwallet #11803

Open
wants to merge 4 commits into
base: master
from

Conversation

Projects
None yet
9 participants
@luke-jr
Member

luke-jr commented Nov 30, 2017

When restoring a backup, we should restore the wallet metadata. This moves some of it out of "comment" sections so that it can be sensibly handled by parsing tools.

(importwallet doesn't currently support it, but that's another matter to address)

@promag

Update test? Squash 2nd and 3rd commits?

@@ -660,19 +660,26 @@ UniValue dumpwallet(const JSONRPCRequest& request)
std::string strAddr = CBitcoinAddress(keyid).ToString();
CKey key;
if (pwallet->GetKey(keyid, key)) {
CKeyMetadata meta;

This comment has been minimized.

@promag

promag Dec 1, 2017

Member

In this case how about:

CKeyMetadata meta = pwallet->mapKeyMetadata[keyid];

This comment has been minimized.

@luke-jr

luke-jr Dec 1, 2017

Member

operator[] can also create map items. Even if this never occurs, it needs to generate code for it.

This comment has been minimized.

@promag

promag Jan 30, 2018

Member

Right, off topic, but if above was changed to const CWallet * const pwallet then that would be false.

This comment has been minimized.

@luke-jr

luke-jr Feb 26, 2018

Member

operator[] isn't valid at all on const maps AFAIK...?

This comment has been minimized.

@promag

promag Feb 26, 2018

Member

Indeed! Sorry for the noise.

This comment has been minimized.

@luke-jr

luke-jr Nov 3, 2018

Member

n.b. C++11 added std::map::at, but this isn't useful since we need to correctly handle the case where there is no metadata.

file << "inactivehdmaster=1";
} else {
file << "change=1";
}
file << strprintf(" # addr=%s%s\n", strAddr, (pwallet->mapKeyMetadata[keyid].hdKeypath.size() > 0 ? " hdkeypath="+pwallet->mapKeyMetadata[keyid].hdKeypath : ""));
file << strprintf(" # addr=%s%s\n", strAddr, (meta.hdKeypath.empty() ? "" : (" hdkeypath=" + meta.hdKeypath)));

This comment has been minimized.

@promag

promag Dec 1, 2017

Member

Nit, partial unrelated change to what commit stands for.

file << "inactivehdmaster=1";
} else {
file << "change=1";
}
file << strprintf(" # addr=%s%s\n", strAddr, (pwallet->mapKeyMetadata[keyid].hdKeypath.size() > 0 ? " hdkeypath="+pwallet->mapKeyMetadata[keyid].hdKeypath : ""));
if (!meta.hdKeypath.empty()) {
file << " hdkeypath=" + meta.hdKeypath;

This comment has been minimized.

@jonasschnelli

jonasschnelli Dec 1, 2017

Member

What is the reason to move this out of the comment section?

This comment has been minimized.

@luke-jr

luke-jr Dec 1, 2017

Member

It's metadata that should be restored. (our importwallet doesn't support it, but that's another matter)

@jonasschnelli

This comment has been minimized.

Member

jonasschnelli commented Dec 1, 2017

@luke-jr: can you please elaborate a little bit what situation this PR does improve?

@laanwj

This comment has been minimized.

Member

laanwj commented Jan 30, 2018

@luke-jr Can you please answer @jonasschnelli 's question? There is no rationale in the OP at all.

@luke-jr

This comment has been minimized.

Member

luke-jr commented Jan 30, 2018

@MarcoFalke

This comment has been minimized.

Member

MarcoFalke commented Jan 30, 2018

That should probably be moved to the OP, so it is recoverable from the merge commit body. (Note that we put the OP text in the merge commit body)

@MarcoFalke

This comment has been minimized.

Member

MarcoFalke commented Mar 19, 2018

Needs rebase if still relevant

@luke-jr

This comment has been minimized.

Member

luke-jr commented Mar 31, 2018

Rebased

@MarcoFalke

This comment has been minimized.

Member

MarcoFalke commented May 21, 2018

Needs rebase due to merge of #12924

@DrahtBot DrahtBot removed the Needs rebase label Nov 4, 2018

@bitcoin bitcoin deleted a comment from ismail120572 Nov 5, 2018

@MeshCollider

This comment has been minimized.

Member

MeshCollider commented Nov 10, 2018

Tested ACK 17d609c

This isn't really a bugfix because there is no bug in the codebase which is fixed right? But I agree its a sensible change.

Supporting it with importwallet is definitely something that needs to be done, ideally that should be done at the same time because they're mirror functions. But this doesn't break compatibility with the current importwallet so it should be ok to leave it for a future PR.

@luke-jr

This comment has been minimized.

Member

luke-jr commented Nov 10, 2018

I think it's a bugfix because without it (and another fix to importwallet), dump/import will produce a wallet missing the key metadata. Isn't the goal of these RPCs to produce the same wallet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment