importprivkey / rescan does not always work currently.
Use case:
- dumpprivkey with a balance
- close bitcoin
- delete wallet.dat
- start bitcoin
- importprivkey
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.