[RFC] Wallet Class Structure Changes #16165

issue achow101 opened this issue on June 7, 2019
  1. achow101 commented at 11:41 AM on June 7, 2019: member

    A writeup of the proposed changes to the wallet class structure can be found on the devwiki: https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Class-Structure-Changes

    Please make comment about it here and suggest/make changes if necessary.

  2. meshcollider added the label Brainstorming on Jun 7, 2019
  3. meshcollider added the label Wallet on Jun 7, 2019
  4. laanwj added this to the "Chasing Concept ACK" column in a project

  5. ryanofsky commented at 1:32 PM on June 7, 2019: member

    The wiki page mentions "address types" lots of places. Can it be updated to clarify specifically what the address types are in each context? I can't figure out which places it is referring to legacy/bech32/p2sh segwit types, or change / non-change types, or both.

  6. meshcollider commented at 1:51 PM on June 7, 2019: contributor

    @ryanofsky there would be option for all six combinations of change/address. They might all point to the same SPKManager, or all different.

  7. ryanofsky commented at 6:55 PM on June 11, 2019: member

    Thanks, and concept ACK from me! I think the design description is clear and seems workable. The prerequisites section of the page is probably the weakest part and might be confusing to anyone who didn't overhear achow and meshcollider debating it. But it's less important because it's only describing temporary steps. @sipa, it's probably be good if you could read the wiki page and provide basic feedback. Like whether it seems fine, or has any obvious problems. And whether it's clear, or are has parts that are confusing or ambiguous.

  8. ryanofsky commented at 5:50 PM on June 12, 2019: member

    It might be worth incorporating information from sipa's wallet_and_segwit.md gist https://gist.github.com/sipa/125cfa1615946d0c3f3eec2ad7f250a2 to the new document. Or linking to it. Or updating it and making it a wiki page of its own.

  9. achow101 commented at 7:24 PM on June 12, 2019: member

    I think a lot of things in the wiki page cover stuff discussed in that gist. I've added a link to it in the wiki page.

  10. fanquake added the label Needs Conceptual Review on Jun 17, 2019
  11. sipa commented at 9:55 PM on June 18, 2019: member

    Concept ACK.

    I'm not sure that ScriptPubKeyManager needs to inherit SigningProvider directly; doing so may require having a lot of information permanently cached (in order to be able to derive all scripts on the fly, for example).

    An alternative is to have the box directly expose an IsMine(scriptPubKey) function, but instead of directly implementing SigningProvider, have it expose a GetSigningProvider(scriptPubKey), which would (for descriptor wallets) look up which index the scriptPubKey is constructed with (using the same precomputed table as IsMine uses), and then populate a FlatSigningProvider with just the keys/scripts necessary for that index.

  12. jb55 commented at 6:07 PM on June 19, 2019: member

    I think inheritance is over abused in general, so Concept ACK since we are getting rid of inheritance layers. Passing interfaces around is all you really need for 99% of use cases, otherwise you tend to have uncompositional and complect code because your design gets tangled in the inheritance hierarchy.

  13. jnewbery commented at 8:23 PM on June 19, 2019: member

    Concept ACK

  14. jnewbery added this to the "Issues" column in a project

  15. l2a5b1 commented at 11:05 AM on June 30, 2019: contributor

    From the Wallet-Class-Structure-Changes document:

    The inheritance chain from SigningProvider should be condensed and the scopes slightly changed ... SigningProvider -> CBasicKeyStore (renamed) -> CWallet

    Any thoughts on using composition of CBasicKeyStore (renamed) over inheritance by making CBasicKeyStore (renamed) a member of CWallet that is owned by CWallet?

    Using composition over inheritance feels like a much better design (but it could be that I am missing key design considerations to keep the inheritance).

  16. achow101 commented at 10:27 PM on July 5, 2019: member

    An alternative is to have the box directly expose an IsMine(scriptPubKey) function, but instead of directly implementing SigningProvider, have it expose a GetSigningProvider(scriptPubKey), which would (for descriptor wallets) look up which index the scriptPubKey is constructed with (using the same precomputed table as IsMine uses), and then populate a FlatSigningProvider with just the keys/scripts necessary for that index.

    I've decided to go with this approach. ScriptPubKeyMan will not inherit anything.

  17. hugohn commented at 2:20 PM on July 10, 2019: contributor

    Concept ACK. Love this design direction which makes things more modular and gets rid of inheritance hell.

    I have a few questions. From the proposal:

    At the end of this refactoring, the stack will be: SigningProvider -> CBasicKeyStore (renamed) -> CWallet

    Also:

    CWallet will need to be standalone there is no need for CWallet to be a SigningProvider

    So if CWallet "is-NOT-a" SigningProvider, then why have it as part of the inheritance tree at all?

    Taking it further, could we maybe get rid of this inheritance tree altogether by either (a) merging CBasicKeyStore into SigningProvider, just like what @achow101 is proposing for CKeyStore? or (b) converting it to a "has-a" relationship? So a SigningProvider could have a CBasicKeyStore to help manage its own keys. But a CBasicKeyStore is-NOT-a SigningProvider (which makes more sense to me, it's not intuitive that a KeyStore is also a SigningProvider).

    (a) makes more sense if a KeyStore always has to be a part of a SigningProvider (and nowhere else). (b) makes more sense if a stand-alone KeyStore could be a useful thing, without the ability to sign.

    In general, I think most of the class relationships modeled here sound like classic has-a, not is-a relationships.

  18. fanquake removed the label Needs Conceptual Review on Jul 11, 2019
  19. fanquake removed this from the "Chasing Concept ACK" column in a project

  20. achow101 commented at 5:37 AM on June 12, 2020: member

    Completed in #17261

  21. achow101 closed this on Jun 12, 2020

  22. DrahtBot locked this on Feb 15, 2022

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 00:14 UTC

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