Clean up encrypted_batch in wallet #14139

issue domob1812 openend this issue on September 3, 2018
  1. domob1812 commented at 4:03 pm on September 3, 2018: contributor

    For #14138 I took a look at encrypted_batch in the wallet code. My understanding may be incorrect, as the code around it is undocumented and quite messy. But as far as I understand, CWallet::encrypted_batch is only used in these places:

    • The destructor, simply to free it.
    • AddKeyPubKeyWithDB: If not set initially, it is set to the passed-in reference and reset to nullptr before exiting the function.
    • AddCryptedKey: It is read if non-null, not changed.
    • EncryptWallet: It is expected that encrypted_batch is null initially. Then it is set to a newly allocated object, used, feed and reset to nullptr again before exiting the function.

    To me, it seems that there is no way through which encrypted_batch can be non-null except temporarily while executing either AddKeyPubKeyWithDB or EncryptWallet. Thus I feel like this can be cleaned up and clarified quite a bit. For instance:

    • Make it explicit that the member variable / CWallet instance never owns the associated memory; it is just a simple reference passed down to AddCryptedKey.
    • Accordingly, do not do anything about it in the destructor.
    • Use a std::unique_ptr on the stack in EncryptWallet to hold the memory.

    One could even go a step further and use RAII to set/restore encrypted_batch in both AddKeyPubKeyWithDB and EncryptWallet rather than doing it in the current “unsafe” way.

    Am I missing something here, or is my understanding correct? If it is, then I’m happy to prepare a clean up PR for this.

  2. fanquake added the label Wallet on Sep 3, 2018
  3. domob1812 referenced this in commit 6ec0b50a24 on Sep 4, 2018
  4. domob1812 referenced this in commit 373ab6bb63 on Sep 4, 2018
  5. domob1812 commented at 9:31 am on September 4, 2018: contributor
    As this is probably easier to judge based on actual code, I’ve implemented the proposed changes in #14144.
  6. domob1812 referenced this in commit 2ce94ccc4a on Sep 25, 2018
  7. domob1812 referenced this in commit 578a7333c9 on Sep 25, 2018
  8. domob1812 referenced this in commit fca2f4e2f5 on Oct 24, 2018
  9. domob1812 referenced this in commit 77a2ff4459 on Oct 24, 2018
  10. domob1812 referenced this in commit 7e55af9af3 on Dec 14, 2018
  11. domob1812 referenced this in commit f4243e3eb0 on Dec 14, 2018
  12. domob1812 referenced this in commit fdcdd8505d on Jan 15, 2019
  13. domob1812 referenced this in commit 151ada53e8 on Jan 15, 2019
  14. domob1812 referenced this in commit 610ee17dc9 on Jul 13, 2019
  15. domob1812 referenced this in commit 10d8b984d6 on Jul 13, 2019
  16. MarcoFalke commented at 10:31 pm on April 26, 2020: member

    The feature request didn’t seem to attract much attention in the past. Also, the issue seems not important enough right now to keep it sitting around idle in the list of open issues.

    Closing due to lack of interest. Pull requests with improvements are always welcome.

  17. MarcoFalke closed this on Apr 26, 2020

  18. 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: 2024-11-17 12:12 UTC

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