add key generation type #5916

pull jonasschnelli wants to merge 3 commits into bitcoin:master from jonasschnelli:2015/03/keygentype changing 5 files +41 −3
  1. jonasschnelli commented at 1:00 PM on March 17, 2015: contributor

    A encrypted wallet can still hold keys which where created when the wallet was unencrypted. Could solve #3314.

    This PR will add a 8bit-flags-int to the CKeyMetadata class.

    listreceivedbyaddress will report whether the key was generated within a encrypted wallet or if it was imported throught importprivkey.

    If this gets conceptual ACKs id like to extend this to the UI level.

  2. laanwj added the label Wallet on Mar 18, 2015
  3. laanwj commented at 12:35 PM on March 18, 2015: member

    Remembering where a key comes from, yeah, why not.

  4. laanwj commented at 12:37 PM on March 18, 2015: member

    "generationtype" may not be the best name though; we also have "generated" for wallet transactions that shows whether the coins were mined.

  5. jonasschnelli commented at 1:20 PM on March 18, 2015: contributor

    What about using keyGenerationType?

  6. laanwj commented at 1:24 PM on March 18, 2015: member

    key_generation_type then, we don't tend to use lowerCamelCase in RPC

  7. jonasschnelli force-pushed on Mar 18, 2015
  8. jonasschnelli commented at 1:30 PM on March 18, 2015: contributor

    Right. Changed and pushed.

  9. laanwj commented at 8:37 AM on March 20, 2015: member

    Hm, one thought: Would the resulting wallet still be backwards compatible? We have a versioning/upgrade system for wallets, not sure if it should be used here.

  10. jonasschnelli commented at 9:02 AM on March 20, 2015: contributor

    Good point. I'll have to check/test the backward compatibility. I'm not sure what happens to the deserialization when there are one additional byte at the end.

  11. jonasschnelli commented at 10:20 AM on March 20, 2015: contributor

    It's backward and forward compatible. Tested.

    The 1byte flag added at the end of the CKeyMetadata serialization stream will be ignored when running (old) master-branch. Using a "new" wallet on a "old" bitcoind will still keep the key generation data because Metadata is somehow immutable (will only be created/changes when a key gets generated). Also testes with a full keypool generated with "key generation type".

    bildschirmfoto-2015-03-20-um-10 50 30

  12. jonasschnelli force-pushed on Mar 22, 2015
  13. laanwj commented at 4:39 PM on March 24, 2015: member

    SGTM, utACK

  14. in src/wallet/walletdb.h:None in b9bd7b2267 outdated
      41 | @@ -42,9 +42,15 @@ enum DBErrors
      42 |  class CKeyMetadata
      43 |  {
      44 |  public:
      45 | -    static const int CURRENT_VERSION=1;
      46 | +    static const int CURRENT_VERSION=2;
      47 | +    static const uint8_t KEY_GENERATION_TYPE_UNKNOWN       = 0x0001;
      48 | +    static const uint8_t KEY_GENERATION_TYPE_IMPORTED      = 0x0002;
      49 | +    static const uint8_t KEY_GENERATION_TYPE_UNENC_WALLET  = 0x0004;
      50 | +    static const uint8_t KEY_GENERATION_TYPE_ENC_WALLET    = 0x0008;
    


    luke-jr commented at 1:46 AM on June 2, 2015:

    Why are these 16-bit hex numbers for an 8-bit type?


    jonasschnelli commented at 7:12 PM on June 2, 2015:

    Yes. This is wrong. Changed and pushed.

  15. luke-jr commented at 1:47 AM on June 2, 2015: member

    I don't understand the term "generation" in this context.

  16. jonasschnelli commented at 7:06 PM on June 2, 2015: contributor

    @luke-jr: "generation" was the best i could find. What would you prefer (maybe something like "Key generation environment" or "key generation security context")?

  17. jonasschnelli force-pushed on Jun 2, 2015
  18. luke-jr commented at 5:17 AM on June 24, 2015: member

    "origin" perhaps.

    Also, this is lacking -upgradewallet logic. Even if old versions can handle it, third-party software might not.

  19. jonasschnelli commented at 7:15 AM on June 24, 2015: contributor

    @luke-jr: right, it missed the -upgradewallet approach. I aim for including the key origin/generation type in the new wallet.

  20. jonasschnelli force-pushed on Jun 24, 2015
  21. jonasschnelli commented at 7:55 AM on June 24, 2015: contributor

    Renamed to key origin and added wallet new wallet feature level 70000

  22. jonasschnelli force-pushed on Jun 24, 2015
  23. jonasschnelli force-pushed on Jul 5, 2015
  24. in src/wallet/rpcwallet.cpp:None in 322bff4ac9 outdated
    1170 | +        uint8_t keyFlags = 0;
    1171 | +        if (address.GetKeyID(keyID))
    1172 | +            keyFlags = pwalletMain->mapKeyMetadata[keyID].keyFlags;
    1173 | +
    1174 | +        std::string keyOrigin;
    1175 | +        if (keyFlags & CKeyMetadata::KEY_ORIGIN_UNKNOWN)
    


    luke-jr commented at 7:14 AM on July 11, 2015:

    Shouldn't this be used for actually unknown origins (eg, 0 or no-known-bits-set)?


    jonasschnelli commented at 7:24 AM on July 11, 2015:

    Yes. Agree with you. I will change this to not only holding KEY_ORIGIN within the flags... update is on the way.

  25. in src/wallet/walletdb.h:None in 322bff4ac9 outdated
      42 | @@ -43,8 +43,16 @@ class CKeyMetadata
      43 |  {
      44 |  public:
      45 |      static const int CURRENT_VERSION=1;
      46 | +    static const int VERSION_SUPPORT_FLAGS=2;
      47 | +    static const uint8_t KEY_ORIGIN_UNSET         = 0x0000;
      48 | +    static const uint8_t KEY_ORIGIN_UNKNOWN       = 0x0001;
      49 | +    static const uint8_t KEY_ORIGIN_IMPORTED      = 0x0002;
      50 | +    static const uint8_t KEY_ORIGIN_UNENC_WALLET  = 0x0004;
      51 | +    static const uint8_t KEY_ORIGIN_ENC_WALLET    = 0x0008;
    


    laanwj commented at 10:56 AM on July 21, 2015:

    I don't understand why you're using a bitfield here instead of an enumeration. Do combinations of these ever happen? In rpcwallet.cpp you squash it to one "enum" anyway. (or is eg IMPORTED ENC used to signify that the key was imported while the wallet was encrypted? If so, the rpc should probably return a list of flag strings instead of one string)


    jonasschnelli commented at 12:29 PM on July 21, 2015:

    At this point, it is probably the right approach (to use bitfield). It would mean to be extendable because it is a serialized and database stored uint8. Combinations should be possible. But i agree that the rpcwallet.cpp part should be better. Will take a look at it.


    laanwj commented at 12:38 PM on July 21, 2015:

    But an enumeration is extensible too, by adding entries. You could say that a bitfield limits extensibility as -at most- 8 flags are possible, whereas an enumeration allows for 256 discrete options in the same space. Unless combinations are meaningful, there is no need to use a bitfield. But I don't care deeply. It just seems weird, especially to have both an ENC and UNENC flag, they conflict)


    jonasschnelli commented at 12:44 PM on July 21, 2015:

    The main idea was to allow multiple key flags. Like (imported) AND (encrypted OR unencrypted) or potential new key flags like (UI OR RPC together with AND's above). I just thought when changing the database model, do it right and flexible.


    laanwj commented at 1:05 PM on July 21, 2015:

    That idea is good, but you're burning flags! You have only 8! At the least get rid of UNKNOWN as a flag, !x already implies that.


    jonasschnelli commented at 1:06 PM on July 21, 2015:

    Yeah. Agreed. Will remove it.

  26. jgarzik commented at 6:12 PM on September 15, 2015: contributor

    concept and code review ACK

  27. dcousens commented at 7:06 AM on September 16, 2015: contributor

    NACK on the bit flag, concept ACK on the general idea (tracking private key origin). An enumeration sounds fine.

  28. jonasschnelli commented at 1:17 PM on September 16, 2015: contributor

    @dcousens: i really like the idea of bit flags. IMO it is flexible, it could indicate different things like if a key was generated deterministic after bip32, etc. What are the downsides of the bit flags compared to a enum/int?

  29. dcousens commented at 2:44 PM on September 16, 2015: contributor

    @jonasschnelli I'd go so far to say that this could be user defined, as even a string type might be suitable. The bit flag idea seems very isolated and only useful for very specific applications.

    I don't really have a strong opinion either way on this, did you have a use case in mind?

    edit: in terms of #3314, a bit flag would make sense.

  30. laanwj commented at 1:18 PM on September 24, 2015: member

    I'd disagree with using a string type. It uses more memory and disk space (this is per key!), and is also worst for anything machine-understandable.

  31. add key generation type
    A encrypted wallet can still hold keys which where created when the wallet was unencrypted.
    
    This PR will add a 8bit-flags-int to the CKeyMetadata class.
    
    `listreceivedbyaddress` will report whether the key was generated within a enctypted wallet or if it was imported throught `importprivkey`
    1d6d3dad68
  32. renamed keyGenerationType to keyOrigin, added new wallet feature level f1fef042df
  33. Use a 32bit bitmask for key generation type, remove unset type d4142be472
  34. jonasschnelli force-pushed on Sep 24, 2015
  35. jonasschnelli commented at 2:51 PM on September 24, 2015: contributor

    Rebased and replace the 8bit bitfield with a 32bit bitfield, also removed the "unset" keyflag.

  36. luke-jr commented at 2:23 AM on October 23, 2015: member

    How will this top commit affect wallets with top-minus-one keyFlags? Bitcoin LJR includes the previous semantics, and it would be nice not to break loading such wallets. Maybe the wallet version can be bumped one to handle that case?

  37. jonasschnelli commented at 6:55 AM on October 23, 2015: contributor

    @luke-jr: hmm.. yes. This would be required unless we want to break LJR 0.11 wallets. I have plans to update this PR, but it will take some weeks (this PR has low prio). If anyone likes to take this over: go ahead.

  38. laanwj commented at 11:39 AM on February 10, 2016: member

    Rebased and replace the 8bit bitfield with a 32bit bitfield, also removed the "unset" keyflag.

    That's better. Concept ACK.

  39. btcdrak commented at 2:28 PM on April 5, 2016: contributor

    Concept ACK.

  40. luke-jr referenced this in commit 05e2221555 on Jun 27, 2016
  41. luke-jr referenced this in commit 7115804777 on Jun 27, 2016
  42. jonasschnelli commented at 1:06 PM on July 20, 2016: contributor

    Do we really need a minVersionBump for this change? This PRs minVersionBump to 70000 is kinda senseless.

    What about just detecting the change in the deserialization code? I guess every useable deserialization code (assume third party apps) can handle this.

  43. luke-jr commented at 5:25 PM on July 20, 2016: member

    Well, we don't want to add data unless the user upgrades their wallet explicitly (or makes a new one) either.

  44. jonasschnelli commented at 6:45 PM on July 20, 2016: contributor

    Well, we don't want to add data unless the user upgrades their wallet explicitly (or makes a new one) either.

    But this would make the upgraded wallet no longer work with older versions of bitcoin-core (<0.13 if we would merge this for 0.13) even with the fact that older version are capable of handling the changed/new CKeyMetadata format. This sounds inefficient to me.

  45. luke-jr commented at 10:21 PM on July 20, 2016: member

    Won't old versions currently strip off the key origin data, even if they load the wallet itself okay?

  46. jonasschnelli commented at 12:56 PM on August 9, 2016: contributor

    Closing in favor of #8471

  47. jonasschnelli closed this on Aug 9, 2016

  48. luke-jr referenced this in commit 7af5a0f1d6 on Jan 5, 2020
  49. luke-jr referenced this in commit 5321a6a55a on Jan 28, 2021
  50. MarcoFalke 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-13 18:15 UTC

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