-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Fix importprivkey / rescan #3502
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
Conversation
|
Keys and addresses don't have balances. You're not supposed to use import/dump privkey like this. Just backupwallet for backups. |
|
Though I agree with Luke's opinion here, it's not an excuse for broken functionality. If you're using dumpprivkey/importprivkey, you're already managing your wallet at the per key level, and as we have rpc methods for that, they should work. |
|
Agree with @luke-jr here. What you are doing is very dangerous. You should never assume that the balance is only on one key. Many people lost their coins this way. This is exactly what dumpwallet/importwallet is for which is in master (and will be in 0.9). These methods export and import all the keys in your wallet. Code changes look ok to me though... |
|
OH, this probably explains some misbehavior I saw with salvagewallet missing outputs! See, look at how much easier slacking off and not investigating the cause was… |
|
Can we get some ACKs/NACKs here? This is a very simple patch, and if it solves a problem (and in the correct way) it should be in 0.9 IMO. |
|
This is not the correct way to solve the problem, IMHO. We should set |
|
I do agree that import/dump need a way to deal with birthdates, though. I suggest adding a bool to dumpprivkey [includebirth=false], which if set, outputs a string privkey@unixtimestamp. Importprivkey can then support keys in that format too, and set the imported key's timestamp to the provided one, instead of 1. |
|
I have now updated to what @sipa suggested. About the import/dump of birthdate: Also maybe adding a little checksum at least to the timestamp would be good, I think, as importing a private key should be guaranteed to work. If checksum wrong, set timestamp to 1. |
|
@cozz I consider this function micro-management. We provide it, so it must work. But in general, I'd very much prefer to encourage entire wallet dumping/importing ( Regarding a version number rather than a boolean... meh, I don't think we'll add many more versions later for the same typo of keys. |
|
Haven't tested, but ACK code changes. |
|
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/1f12844fc03dfc1863ea9a5096f8650c64a0b2ac for binaries and test log. |
|
ACK (much easier to review with this localized change) |
1f12844 Fix importprivkey / rescan (Cozz Lovan)
importprivkey / rescan does not always work currently.
Use case:
Result:
rescan fails because wallet uses nTimeFirstKey of the other keys.
Setting
pwalletMain->nTimeFirstKey = 1;
solves the problem in this case, scanning the chain from genesis.
But I if import with rescan=false, then close bitcoin and do
bitcoin-qt -rescan
this fails again. Because nCreateTime of the metadata is zero,
and now nTimeFirstKey is set to zero, but overwritten later again,
because if(0) is false. So setting this to 1 solves the problem.
Further ideas, not part of this pull:
dumprivkey could export nCreationTime as well.
importprivkey would then have distinguish between old and new format.
rescan from the genesis block could reassign all nCreationTime.