"Wallet birthdays": store key create time; calc whole-wallet birthday #1863

pull jgarzik wants to merge 2 commits into bitcoin:master from jgarzik:keytime changing 4 files +142 −38
  1. jgarzik commented at 4:23 PM on September 24, 2012: contributor

    This creates a new serialized structure CKeyMetadata, and stores it alongside each newly created key. This data is used to calculate a whole-wallet birthday.

    Wallet rescan is optimized using this information, to skip reading and scanning blocks earlier than the wallet birthday.

  2. laanwj commented at 6:44 AM on September 25, 2012: member

    I certainly think this is useful data to keep around.

    But, as precise time is a rare thing, for the wallet scan optimization to be exact (the "7200 seconds leeway" makes me a bit uneasy), would it maybe make sense to store a block chain height of first use? Now that we have key metadata anyway...

  3. gavinandresen commented at 2:25 PM on September 25, 2012: contributor

    7200 seconds is two hours, which matches the blockchain rules (new blocks must have timestamps no more than 2 hours in the future, if I recall correctly).

    And I think keys are properly thought of as independent of any one particular blockchain, so absolute time of creation is the right notion.

  4. laanwj commented at 2:40 PM on September 25, 2012: member

    Yes, but you are using the local time of the machine that creates the key, at the time the key is generated. I don't think this should be ultimately trusted information (ie, reliable enough to base important optimizations on).

  5. jgarzik commented at 10:04 PM on September 26, 2012: contributor

    <shrug> The rescan optimization can do "X - 24 hours" and still be quite effective.

    One secondary goal along with storing key time is running in client-mode may be optimized to ignore all blocks older than the wallet birthday.

  6. sipa commented at 2:10 PM on September 28, 2012: member

    Sounds like a good idea. I prefer keeping a timestamp + lee way, rather than storing blockchain height, as the latter is context that can change during reorganisations.

    For deterministic wallet, the meta data object could be extended.

    I haven't tested this.

  7. in src/rpcdump.cpp:None in d5f79e7e34 outdated
      47 | @@ -48,6 +48,10 @@ Value importprivkey(const Array& params, bool fHelp)
      48 |  
      49 |      if (!fGood) throw JSONRPCError(-5,"Invalid private key");
      50 |  
      51 | +    int64 nKeyCreateTime = GetTime();
    


    sipa commented at 1:54 PM on October 7, 2012:

    nKeyCreateTime defaults to the current time? Doesn't that break compatibility? (importprivkey currently rescans the entire history).

    I'd prefer the current time to be the default (as is implemented here), but I'm afraid it will cause issues.

  8. BitcoinPullTester commented at 1:50 AM on October 21, 2012: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/fefb9e12b1be676ffff49fccb8be52ae1c65e779 for binaries and test log.

  9. kjj2 commented at 5:56 PM on October 29, 2012: none

    This is a very important feature for multisig. While you can do everything with the raw TX API, just importing the keys and spending from the wallet as usual is much easier, and will remain so for probably quite a while. For me, this patch would have saved a couple of hours worth of rescan time while I was testing multisig.

    One possible addition... When doing a rescan, can we detect the time or height of the first appearance of a key, and store that if the birthdate isn't already known? This will be useful when someone later dumps them or has to import a whole wallet.

    Oh, and maybe also change WIF to support metadata embedding.

  10. gavinandresen commented at 9:31 PM on October 29, 2012: contributor

    RE: "just importing the keys and spending from the wallet..." : I think we should strongly encourage people to keep private keys private, and not get into the habit of exporting/importing them. If you are sending private keys around for anything other than backup then you're probably Doing It Wrong(tm).

  11. kjj2 commented at 12:50 PM on October 30, 2012: none

    I suspect that for a while to come, the most common usage of multisig will be one time cold storage wallets. You generate some keys, send coins to them, and then later, you redeem whatever is in them. Importing the privkey is the simplest way to do that, and however wrong it may be, I'll bet you a dollar that lots of people are going to do it.

  12. sipa commented at 1:13 PM on October 30, 2012: member

    I think we need a standard way of encoding a private key + a txid for such purposes, as that is enough for instant spending without rescanning history at all (however long it is ago).

  13. schildbach commented at 1:28 PM on October 30, 2012: contributor

    Bitcoin Wallet and MultiBit can already exchange private keys against each other by using a text based export format. It's basically one base58-encoded key per line, optionally with a key creation time in ISO8601 format. The whole file can be AES encrypted in a way that also openssl can be used to decrypt.

    I think it's time that we document this format properly and maybe propose it as a BIP.

  14. jim618 commented at 5:13 PM on October 30, 2012: none

    I am happy to write up the existing key exchange format Andreas and I are using as a BIP if someone gives me a number. It gives a concrete format to critique and improve upon as required.

  15. sipa commented at 6:16 PM on April 7, 2013: member

    Hmm, mind rebasing this @jgarzik? I think we forgot about this somehow.

  16. gmaxwell commented at 9:25 PM on April 7, 2013: contributor

    Did this get derailed due to not having a serialization for it?

  17. sipa commented at 9:47 PM on April 7, 2013: member

    I'm planning to rebase my wallet JSON dump/import RPC patch from 2 years ago, given that there's apparently many people who feel the need to toy with wallets, but shoot themself in the foot by working with individual keys instead of whole wallets. Key birthdates could nice be serialized in that.

  18. jgarzik commented at 5:38 AM on April 8, 2013: contributor

    @sipa will put it on the todo list. @gmaxwell No real blocker other than it seemed like @gavinandresen grumped over this pull request in general. :)

  19. gavinandresen commented at 1:39 PM on April 8, 2013: contributor

    Yeah, but I grump over everything, it is my Prime Directive.

  20. jgarzik commented at 11:12 PM on April 8, 2013: contributor

    It looks like a rebase is not trivial, due to some wallet changes in the interim. Not difficult, but not trivial either.

  21. jgarzik commented at 7:27 PM on May 24, 2013: contributor

    Rebased.

  22. in src/walletdb.cpp:None in cf5e5bd97d outdated
     179 | @@ -180,6 +180,7 @@ void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountin
     180 |      return DB_LOAD_OK;
     181 |  }
     182 |  
     183 | +static unsigned int nKeys = 0, nCKeys = 0, nKeyMeta = 0;
    


    sipa commented at 3:53 AM on May 30, 2013:

    This is very ugly...

  23. sipa commented at 3:56 AM on May 30, 2013: member

    Apart from those static counter variables, ACK on the code changes. A more efficient wallet serialization format (where metadata is stored together with the keys) would be nice, but I guess that can easily be done together with a wallet format overhaul.

  24. jgarzik commented at 4:02 AM on May 30, 2013: contributor

    @sipa agree that the static counters are ugly

  25. jgarzik commented at 3:01 PM on May 31, 2013: contributor

    @sipa Added commit to encapsulate the static variables, and some existing variables held across invocations from multiple callers, into CWalletScanState.

  26. jgarzik commented at 3:03 PM on May 31, 2013: contributor

    Also note that this pull request introduces an extensible key-metadata object in the wallet, fully versioned. It is now easier to add other metadata to each key.

  27. jgarzik commented at 6:52 PM on May 31, 2013: contributor

    Merged with upstream

  28. sipa commented at 8:45 AM on June 1, 2013: member

    ACK code changes; didn't test yet. Can you rebase instead of doing merges?

  29. laanwj commented at 12:15 PM on June 2, 2013: member

    ACK on code changes

  30. sipa commented at 6:27 AM on June 10, 2013: member

    I'd like to merge this, can you squash the merge commit?

  31. Wallet: store key creation time. Calculate whole-wallet birthday.
    This also encapsulate wallet-read state information into CWalletScanState.
    3869fb89b6
  32. Wallet: optimize rescan to skip blocks prior to birthday 8da9dd0725
  33. jgarzik commented at 2:07 PM on June 10, 2013: contributor

    Rebased

  34. sipa referenced this in commit 61983b3d16 on Jun 10, 2013
  35. sipa merged this on Jun 10, 2013
  36. sipa closed this on Jun 10, 2013

  37. jgarzik deleted the branch on Aug 24, 2014
  38. fanquake deleted a comment on Jul 18, 2019
  39. KolbyML referenced this in commit ad15bce2f5 on Dec 5, 2020
  40. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-19 12:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me