refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet #17304

pull achow101 wants to merge 18 commits into bitcoin:master from achow101:wallet-box-pr-3 changing 5 files +415 −229
  1. achow101 commented at 7:03 pm on October 29, 2019: member

    Moves several more key management and metadata functions into LegacyScriptPubKeyMan from CWallet to further separate the two.

    Note to reviewers: All of the if (auto spk_man = walletInstance->m_spk_man.get()) { blocks will be replaced with for loops in the next PR so you may see some things in those blocks that don’t necessarily make sense with an if but will with a for.

  2. fanquake added the label Refactoring on Oct 29, 2019
  3. fanquake added the label Wallet on Oct 29, 2019
  4. in src/wallet/scriptpubkeyman.cpp:323 in a5ca4664e7 outdated
    319@@ -320,8 +320,7 @@ void LegacyScriptPubKeyMan::UpgradeKeyMetadata()
    320             }
    321         }
    322     }
    323-    batch.reset(); //write before setting the flag
    324-    m_storage.SetWalletFlag(WALLET_FLAG_KEY_ORIGIN_METADATA);
    325+    batch.reset();
    


    ryanofsky commented at 7:26 pm on October 29, 2019:

    In commit “Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata” (a5ca4664e74201a08cef1d147ed4446fd74784f8)

    Could drop this reset line since batch is going out of scope anyway.


    achow101 commented at 10:09 pm on October 29, 2019:
    Done
  5. in src/wallet/scriptpubkeyman.cpp:302 in a5ca4664e7 outdated
    319@@ -320,8 +320,7 @@ void LegacyScriptPubKeyMan::UpgradeKeyMetadata()
    320             }
    321         }
    322     }
    323-    batch.reset(); //write before setting the flag
    324-    m_storage.SetWalletFlag(WALLET_FLAG_KEY_ORIGIN_METADATA);
    


    ryanofsky commented at 7:37 pm on October 29, 2019:

    In commit “Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata” (a5ca4664e74201a08cef1d147ed4446fd74784f8):

    Would it be possible to drop the WalletStorage SetWalletFlag method entirely after this? I don’t see another call even in #17261


    achow101 commented at 10:10 pm on October 29, 2019:
    Added a commit dropping SetWalletFlag. Also checked it isn’t being used in Descriptor wallets.
  6. in src/wallet/scriptpubkeyman.cpp:878 in d35a98b6e0 outdated
    873@@ -874,7 +874,8 @@ void LegacyScriptPubKeyMan::SetHDSeed(const CPubKey& seed)
    874     newHdChain.seed_id = seed.GetID();
    875     SetHDChain(newHdChain, false);
    876     NotifyCanGetAddressesChanged();
    877-    m_wallet.UnsetWalletFlag(WALLET_FLAG_BLANK_WALLET);
    878+    WalletBatch batch(m_storage.GetDatabase());
    879+    m_storage.UnsetWalletFlagWithDB(batch, WALLET_FLAG_BLANK_WALLET);
    


    ryanofsky commented at 7:48 pm on October 29, 2019:

    In commit “Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed” (d35a98b6e04a3750c48bf21af64d0375fe2ae395)

    All the UnsetWalletFlagWithDB calls are just unsetting WALLET_FLAG_BLANK_WALLET. Maybe WalletStorage should just have a specific UnsetBlankWalletFlag method and not expose more general flag set/unset methods. With multiple key managers per wallet, it might be safer if individual key managers don’t have ability to arbitrarily set flags shared with other key managers.


    achow101 commented at 10:12 pm on October 29, 2019:
    Added a commit changing those to UnsetBlankWalletFlag. Also checked DescriptorScriptPubKeyMan doesn’t use UnsetWalletFlag.
  7. in src/wallet/wallet.cpp:1407 in 974d7749f1 outdated
    1400@@ -1401,9 +1401,17 @@ bool CWallet::ImportScriptPubKeys(const std::string& label, const std::set<CScri
    1401         return false;
    1402     }
    1403     AssertLockHeld(spk_man->cs_wallet);
    1404-    if (!spk_man->ImportScriptPubKeys(label, script_pub_keys, have_solving_data, apply_label, timestamp)) {
    1405+    if (!spk_man->ImportScriptPubKeys(script_pub_keys, have_solving_data, timestamp)) {
    1406         return false;
    1407     }
    1408+    WalletBatch batch(*database);
    


    ryanofsky commented at 7:51 pm on October 29, 2019:

    In commit “Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys” (974d7749f1d9e55a01a2e30db2bdf6b89c18baff)

    Could skip this whole block of code if apply_label is false


    achow101 commented at 10:12 pm on October 29, 2019:
    Done
  8. in src/wallet/rpcwallet.cpp:3768 in bdb538d2fa outdated
    3774-    if (!meta) {
    3775-        auto it = pwallet->m_script_metadata.find(CScriptID(scriptPubKey));
    3776-        if (it != pwallet->m_script_metadata.end()) {
    3777-            meta = &it->second;
    3778+        if (!meta) {
    3779+            meta = spk_man->GetMetadata(CScriptID(scriptPubKey));
    


    ryanofsky commented at 8:02 pm on October 29, 2019:

    In commit “Refactor: Move GetMetadata code out of getaddressinfo” (bdb538d2fa8b171f1a96580a0f0a7395d52b336e)

    It doesn’t seem strictly true that this commit doesn’t change behavior. Before the code was looking up key_id only in mapKeyMetadata and CScriptID(scriptPubKey) only in m_script_metadata. Now it is looking up both values in both maps, which I guess is fine, but maybe more confusing and less efficient.

    I think it’d probably be clearer and more type-safe to have separate GetKeyMetadata and GetScriptMetadata methods.


    achow101 commented at 9:57 pm on October 29, 2019:
    From the ScriptPubKeyMan design view, it doesn’t make sense to have different metadata for keys and scripts, at least exposed publicly to the wallet. It should really be GetMetadata that takes a scriptPubKey, but it fit better to use uint160 for right now.
  9. DrahtBot commented at 8:07 pm on October 29, 2019: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #17283 (rpc: improve getaddressinfo test coverage, help, code docs by jonatack)
    • #17237 (wallet: LearnRelatedScripts only if KeepDestination by promag)
    • #16946 (wallet: include a checksum of encrypted private keys by achow101)
    • #16910 (wallet: reduce loading time by using unordered maps by achow101)
    • #16224 (gui: Bilingual GUI error messages by hebasto)
    • #15761 (Replace -upgradewallet startup option with upgradewallet RPC by achow101)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  10. in src/wallet/scriptpubkeyman.cpp:292 in 8c47cb9202 outdated
    286@@ -287,6 +287,23 @@ bool LegacyScriptPubKeyMan::TopUp(unsigned int size)
    287     return TopUpKeyPool(size);
    288 }
    289 
    290+void LegacyScriptPubKeyMan::MarkUnusedAddresses(const CScript& script)
    291+{
    292+    AssertLockHeld(cs_wallet);
    


    ryanofsky commented at 8:09 pm on October 29, 2019:

    In commit “Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe” (8c47cb9202e27a86609d7b3af91dee1f09468125)

    Note for other reviews: lock assert added here is needed to satisfy clang lock annotations and be able to call MarkReserveKeysAsUsed below. This line will be replaced by LOCK(cs_KeyStore); later in commit “Locking: Lock cs_KeyStore instead of cs_main in legacy keyman” 87cc2282b278d3891fc59823d883eef112606da9 from #17261

  11. in src/wallet/scriptpubkeyman.cpp:300 in 8c47cb9202 outdated
    295+        std::map<CKeyID, int64_t>::const_iterator mi = m_pool_key_to_index.find(keyid);
    296+        if (mi != m_pool_key_to_index.end()) {
    297+            WalletLogPrintf("%s: Detected a used keypool key, mark all keypool key up to this key as used\n", __func__);
    298+            MarkReserveKeysAsUsed(mi->second);
    299+
    300+            if (!TopUpKeyPool()) {
    


    ryanofsky commented at 8:28 pm on October 29, 2019:

    In commit “Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe” (8c47cb9202e27a86609d7b3af91dee1f09468125)

    Note for other reviewers: The LegacyScriptPubKeyMan::TopUp call in the previous code is changed to a LegacyScriptPubKeyMan::TopUpKeyPool call here. The two methods will do the exact same thing even after all the other changes in #17261, so there is no difference in behavior.

    It seems like the pattern is just to always call TopUp() externally and always call TopUpKeyPool() internally, but it’s not clear why the two methods are separate and I think it probably would clearer to combine them.


    Sjors commented at 6:17 pm on October 31, 2019:
    I’m also a bit confused about the distinction between TopUpKeyPool() and Topup(). In the native descriptor wallet PR there’s an internal call to Topup() inside DescriptorScriptPubKeyMan::GetNewDestination and DescriptorScriptPubKeyMan::MarkUnusedAddresses: https://github.com/bitcoin/bitcoin/pull/16528/files#diff-5462ceb8a760a507152ab8b76bd48774R1459

    achow101 commented at 6:35 pm on October 31, 2019:
    In LegacyScriptPubKeyMan, TopUp() and TopUpKeyPool() are the same. Since TopUpKeyPool was already being used throughout existing CWallet code that was moved into LegacyScriptPubKeyMan, I decided to let those calls just keep using TopUpKeyPool. But for the ScriptPubKeyMan interface itself, I wanted it to be named TopUp because that conceptually made more sense than calling it TopUpKeyPool.

    ryanofsky commented at 6:44 pm on October 31, 2019:
    Any reason you would not want to rename TopUpKeyPool method to TopUp and call it everywhere instead of having two LegacyScriptPubKeyMan methods that do the same thing?
  12. in src/wallet/scriptpubkeyman.cpp:283 in 80a44800f3 outdated
    281+}
    282+
    283+void LegacyScriptPubKeyMan::ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey)
    284+{
    285+    ReturnKey(index, internal, pubkey);
    286+}
    


    ryanofsky commented at 8:37 pm on October 29, 2019:

    In commit “Refactor: Add new ScriptPubKeyMan virtual methods” (80a44800f35c3183edd8fc0914ed8edbd5c5887b)

    Note for other reviewers: after future changes in #17261 there are some differences in functionality between the Reserve/Keep/Return destination methods and the Reserve/Keep/Return key methods, and they are called from different places, so there’s some justification for keeping them separate, though I think ideally we could follow up by combining them, or at least making clear what the differences in behavior are supposed to be between the two sets of functions.

  13. in src/wallet/scriptpubkeyman.cpp:379 in 3814d7550c outdated
    361@@ -362,6 +362,41 @@ bool LegacyScriptPubKeyMan::CanGetAddresses(bool internal)
    362     return keypool_has_keys;
    363 }
    364 
    365+bool LegacyScriptPubKeyMan::Upgrade(int prev_version, std::string& error)
    366+{
    367+    AssertLockHeld(cs_wallet);
    


    ryanofsky commented at 8:43 pm on October 29, 2019:

    In commit “Refactor: Move Upgrade code out of CWallet::CreateWalletFromFile” (3814d7550ca2d53a9aa1613d61f79dc72b95770b)

    I think this added lock assert line is not actually necessary and could be dropped. Clang compiler seems fine without out it as of this commit.


    achow101 commented at 10:12 pm on October 29, 2019:
    Removed

    ryanofsky commented at 12:20 pm on October 30, 2019:

    re: #17304 (review)

    Removed

    The lock assert probably needs to be added back. I’m not sure why clang for me wasn’t showing the same error, but clang on travis legitimately errors that it needs the assert to call `MarkPreSplitKeys():

    0wallet/scriptpubkeyman.cpp:399:9: error: calling function 'MarkPreSplitKeys' requires holding mutex 'cs_wallet' exclusively [-Werror,-Wthread-safety-analysis]
    1        MarkPreSplitKeys();
    

    achow101 commented at 3:29 pm on October 30, 2019:
    Added it back in.
  14. in src/wallet/wallet.cpp:3802 in e1b1702449 outdated
    3799+        int64_t time_first_key = std::numeric_limits<int64_t>::max();
    3800+        if (auto spk_man = walletInstance->m_spk_man.get()) {
    3801+            time_first_key = std::min(time_first_key, spk_man->GetTimeFirstKey());
    3802+        }
    3803+        if (time_first_key) {
    3804+            if (Optional<int> first_block = locked_chain->findFirstBlockWithTimeAndHeight(time_first_key - TIMESTAMP_WINDOW, rescan_height, nullptr)) {
    


    ryanofsky commented at 8:58 pm on October 29, 2019:

    In commit “Refactor: Move nTimeFirstKey accesses out of CWallet” (e1b1702449a9172185d4bfb5e9043748328132ee)

    I think the numeric_limits approach is not the clearest here, because if wallet doesn’t have any key managers, the code winds up calling findFirstBlock with an strange 0x7fffffffffffffff - TIMESTAMP_WINDOW value.

    Better I think to use optional instead:

    0Optional<int64_t> first_time;
    1if (auto spk_man = walletInstance->m_spk_man.get()) {
    2    int64_t time = spk_man->GetTimeFirstKey();
    3    if (!first_time || time < *first_time) first_time = time;
    4}
    5if (time_first_key) {
    6    if (Optional<int> first_block = locked_chain->findFirstBlockWithTimeAndHeight(*first_time - TIMESTAMP_WINDOW, rescan_height, nullptr)) {
    7        rescan_height = *first_block;
    8    }
    9}
    

    achow101 commented at 10:12 pm on October 29, 2019:
    Made it an optional
  15. in src/wallet/wallet.cpp:3632 in f95750d52a outdated
    3629-            CPubKey seed = walletInstance->m_spk_man->GenerateNewSeed();
    3630-            walletInstance->m_spk_man->SetHDSeed(seed);
    3631-        }
    3632-
    3633-        // Top up the keypool
    3634-        if (walletInstance->m_spk_man->CanGenerateKeys() && !walletInstance->m_spk_man->TopUp()) {
    


    ryanofsky commented at 9:07 pm on October 29, 2019:

    In commit “Refactor: Move SetupGeneration code out of CWallet” (f95750d52a21a69ad55db8422f10c563fb9e08ac)

    Note for other reviews: Previous code was calling TopUp, while new code is calling SetupGeneration which calls NewKeyPool which calls TopUpKeyPool. I think the effect is basically the same because fFirstRun is true here so the additional ErasePool calls in NewKeyPool should have no effect.

  16. in src/wallet/wallet.cpp:215 in f95750d52a outdated
    209@@ -210,9 +210,11 @@ WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString&
    210             }
    211 
    212             // Set a seed for the wallet
    213-            CPubKey master_pub_key = wallet->m_spk_man->GenerateNewSeed();
    214-            wallet->m_spk_man->SetHDSeed(master_pub_key);
    215-            wallet->m_spk_man->NewKeyPool();
    216+            {
    217+                if (auto spk_man = wallet->m_spk_man.get()) {
    218+                    spk_man->SetupGeneration();
    


    ryanofsky commented at 9:15 pm on October 29, 2019:

    In commit “Refactor: Move SetupGeneration code out of CWallet” (f95750d52a21a69ad55db8422f10c563fb9e08ac)

    Should this be checking the return code from SetupGeneration and setting an error if it fails? Old code wasn’t checking the return value from NewKeyPool either, but that doesn’t seem right.


    achow101 commented at 10:15 pm on October 29, 2019:
    It should. Done.
  17. ryanofsky approved
  18. ryanofsky commented at 9:18 pm on October 29, 2019: member
    Code review ACK e1b1702449a9172185d4bfb5e9043748328132ee. Left comments and suggestions which could be followed up later if we want to avoid losing momentum on #17261
  19. achow101 force-pushed on Oct 29, 2019
  20. ryanofsky approved
  21. ryanofsky commented at 10:30 pm on October 29, 2019: member
    Code review ACK 5631c01c845b1fb9a91e0b40709ceaac204fbb5d. Just a bunch of suggested changes made since the last review.
  22. ryanofsky commented at 10:37 pm on October 29, 2019: member

    Not sure what your preference is @achow101, but it might be a good idea to replace #17261 with #17304 on the high priority review list https://github.com/bitcoin/bitcoin/projects/8, since #17261 builds on #17304.

    This PR is also just making small and mostly obvious changes, so it should be more approachable for reviewers.

  23. achow101 commented at 10:58 pm on October 29, 2019: member

    Not sure what your preference is @achow101, but it might be a good idea to replace #17261 with #17304 on the high priority review list https://github.com/bitcoin/bitcoin/projects/8, since #17261 builds on #17304.

    Yeah, it should replace that. #17261 was added to the list before I made this pr.

  24. instagibbs commented at 3:13 pm on October 30, 2019: member

    mac build errors

    0Makefile:8720: recipe for target 'wallet/libbitcoin_wallet_a-scriptpubkeyman.o' failed
    1wallet/scriptpubkeyman.cpp:399:9: error: calling function 'MarkPreSplitKeys' requires holding mutex 'cs_wallet' exclusively [-Werror,-Wthread-safety-analysis]
    2        MarkPreSplitKeys();
    3        ^
    
  25. achow101 force-pushed on Oct 30, 2019
  26. ryanofsky approved
  27. ryanofsky commented at 3:45 pm on October 30, 2019: member
    Code review ACK b04a526aea91ba4caddbde1a1313a1dbf46bc5e5. Only change is adding back missing lock assert.
  28. ryanofsky added this to the "Blockers" column in a project

  29. ryanofsky commented at 1:28 pm on October 31, 2019: member
    This PR has 18 commits, so it could be useful to get some Approach ACKS here on whether it’s a reasonable size, or should be made smaller by dropping some number of commits, or dropping particular commits that seem more difficult to review. All of the commits should be small and straightforward, but it is also easily possible to scale back this PR if necessary.
  30. in src/wallet/scriptpubkeyman.cpp:267 in 80a44800f3 outdated
    264@@ -265,6 +265,31 @@ bool LegacyScriptPubKeyMan::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
    265     return true;
    266 }
    267 
    268+bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool)
    269+{
    270+    {
    


    instagibbs commented at 3:09 pm on October 31, 2019:
    why the scope here?

    achow101 commented at 4:08 pm on October 31, 2019:
    A lock is going to be added in the next step

    ryanofsky commented at 5:03 pm on October 31, 2019:

    A lock is going to be added in the next step

    The scope isn’t needed even with the lock and all other changes from #17261:

    https://github.com/bitcoin/bitcoin/blob/35b0f7b5447bce4eef360c7e4237a928bb0eba3c/src/wallet/scriptpubkeyman.cpp#L275-L290

    But I don’t think it’s a big deal. Could clean this up later if reservekey and reservedestination methods are merged later (https://github.com/bitcoin/bitcoin/pull/17304#discussion_r340311958)


    achow101 commented at 5:46 pm on October 31, 2019:
    I’ll just leave this as is so it can get merged sooner :)
  31. in src/wallet/wallet.cpp:3810 in b04a526aea outdated
    3803@@ -3804,8 +3804,13 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
    3804 
    3805         // No need to read and scan block if block was created before
    3806         // our wallet birthday (as adjusted for block time variability)
    3807-        if (walletInstance->nTimeFirstKey) {
    3808-            if (Optional<int> first_block = locked_chain->findFirstBlockWithTimeAndHeight(walletInstance->nTimeFirstKey - TIMESTAMP_WINDOW, rescan_height, nullptr)) {
    3809+        Optional<int64_t> time_first_key;
    3810+        if (auto spk_man = walletInstance->m_spk_man.get()) {
    3811+            int64_t time = spk_man->GetTimeFirstKey();
    3812+            if (!time_first_key || time < *time_first_key) time_first_key = time;
    


    instagibbs commented at 3:35 pm on October 31, 2019:
    I realize this is stopping mid-way, but this was slightly confusing. Add a comment saying this is temporarily going to always be true until a loop is introduced?

    achow101 commented at 4:09 pm on October 31, 2019:
    That generally applies throughout this PR. So I guess a note to reviewers in the thread should be good enough?

    instagibbs commented at 4:15 pm on October 31, 2019:
    ok! Consider this your note, future reviewers
  32. instagibbs approved
  33. instagibbs commented at 3:36 pm on October 31, 2019: member

    ACK with non-blocking nits

    “Refactor: Move GetMetadata code out of getaddressinfo” more accurately: “Refactor: Remove direct accesses to key metadata code from getaddressinfo”

    same type of message nit for “Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile” and “Refactor: Move SetupGeneration code out of CWallet”

  34. Sjors commented at 5:32 pm on October 31, 2019: member
    I’m going through these commits now. I’ve seen this code a few times before, but if others want to eject one or more commits to get it merged faster, that could make sense.
  35. in src/wallet/wallet.cpp:575 in ef97f0b545 outdated
    565@@ -561,11 +566,11 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
    566         Unlock(strWalletPassphrase);
    567 
    568         // if we are using HD, replace the HD seed with a new one
    569-        if (m_spk_man->IsHDEnabled()) {
    570-            m_spk_man->SetHDSeed(m_spk_man->GenerateNewSeed());
    571+        if (auto spk_man = m_spk_man.get()) {
    572+            if (spk_man->IsHDEnabled()) {
    573+                spk_man->SetupGeneration(true);
    


    ryanofsky commented at 5:56 pm on October 31, 2019:

    In commit “Refactor: Move SetupGeneration code out of CWallet” (ef97f0b5451e4959c0d0bf649a71eec9b226210e)

    No need to change now, but it seems like it’d probably be a good idea to check for an error from SetupGeneration here as well.

  36. Sjors commented at 8:11 pm on October 31, 2019: member
    Code review ACK up to b04a526aea91ba4caddbde1a1313a1dbf46bc5e5.
  37. in src/wallet/scriptpubkeyman.h:349 in 8bdac65e4c outdated
    295@@ -282,6 +296,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
    296     //! Fetches a pubkey from mapWatchKeys if it exists there
    297     bool GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const;
    298 
    299+    /* SigningProvider overrides */
    


    promag commented at 0:42 am on November 2, 2019:

    8bdac65e4c705f9f55c93b43792d036229cc9d5a

    Sorry for nit picking here, but is this really necessary? What should be the rule of thumb?


    achow101 commented at 2:44 am on November 2, 2019:
    Is what necessary?

    promag commented at 10:02 am on November 2, 2019:
    The category comment.
  38. in src/wallet/wallet.cpp:3059 in bf5f6c5214 outdated
    3044     auto spk_man = m_spk_man.get();
    3045     if (spk_man) {
    3046-        result = spk_man->GetNewDestination(type, label, dest, error);
    3047+        result = spk_man->GetNewDestination(type, dest, error);
    3048+    }
    3049+    if (result) {
    


    promag commented at 0:50 am on November 2, 2019:

    bf5f6c5214706ef61f80c46063061a624c3d505b

    This should be in the above if?


    achow101 commented at 2:46 am on November 2, 2019:
    Does it really matter?

    promag commented at 10:06 am on November 2, 2019:

    No, just that it looks like a leftover where before result could be changed in between.

    Actually I think this would look better without the result variable.

    You can resolve this.

  39. in src/wallet/wallet.cpp:263 in 2590266c19 outdated
    252@@ -253,6 +253,7 @@ void CWallet::UpgradeKeyMetadata()
    253     if (m_spk_man) {
    254         m_spk_man->UpgradeKeyMetadata();
    255     }
    256+    SetWalletFlag(WALLET_FLAG_KEY_ORIGIN_METADATA);
    


    promag commented at 0:55 am on November 2, 2019:

    2590266c193d27c979ad6287d72555ca3df630bc

    What if IsLocked()?


    ryanofsky commented at 2:34 am on November 2, 2019:

    re: #17304 (review)

    2590266

    What if IsLocked()?

    Nice catch! This seems like a bug. I think either the m_storage.IsLocked() || m_storage.IsWalletFlagSet(WALLET_FLAG_KEY_ORIGIN_METADATA) check should move from LegacyScriptPubKeyMan::UpgradeKeyMetadata to CWallet::UpgradeKeyMetadata, or preferably, theSetWalletFlag(WALLET_FLAG_KEY_ORIGIN_METADATA) call should move back in the other direction.

    It’s also unclear why UpgradeKeyMetadata shoud be a virtual method instead of being specific to the LegacyScriptPubKeyMan class. It doesn’t seem like non-legacy keyman types should implement this upgrade function or be accessing this wallet flag.


    ryanofsky commented at 2:42 am on November 2, 2019:
    It seems like the CWallet::UpgradeKeyMetadata() and ScriptPubKeyMan::::UpgradeKeyMetadata() methods could both be dropped and walletdb.cpp could call pwallet->GetLegacyScriptPubKeyMan() and LegacyScriptPubKeyMan::UpgradeKeyMetadata directly for compatibility.

    achow101 commented at 2:55 am on November 2, 2019:
    Changed to be non-virtual and moved that check out to CWallet.
  40. in src/wallet/wallet.cpp:1411 in 26fef3a525 outdated
    1405@@ -1406,9 +1406,19 @@ bool CWallet::ImportScriptPubKeys(const std::string& label, const std::set<CScri
    1406         return false;
    1407     }
    1408     AssertLockHeld(spk_man->cs_wallet);
    1409-    if (!spk_man->ImportScriptPubKeys(label, script_pub_keys, have_solving_data, apply_label, timestamp)) {
    1410+    if (!spk_man->ImportScriptPubKeys(script_pub_keys, have_solving_data, timestamp)) {
    1411         return false;
    1412     }
    1413+    if (apply_label) {
    1414+        WalletBatch batch(*database);
    


    promag commented at 1:06 am on November 2, 2019:

    26fef3a525fd98f8205fd2f859f476fbf2cc6fcd

    Just noting that there’s actually a behavior change here - now if LegacyScriptPubKeyMan::ImportScriptPubKeys fails no label is applied.

    Also, another change, which I think is harmless, is that now 2 batches are always used - easily “reverted” by passing the batch to LegacyScriptPubKeyMan::ImportScriptPubKeys from this method.


    achow101 commented at 2:49 am on November 2, 2019:
    Those are harmless. ImportScriptPubKeys only fails when writing to the database fails, so you’ll have bigger problems if that happens.
  41. promag commented at 1:25 am on November 2, 2019: member
    Light code review ACK b04a526aea91ba4caddbde1a1313a1dbf46bc5e5 with some comments.
  42. achow101 force-pushed on Nov 2, 2019
  43. MOVEONLY: Reorder LegacyScriptPubKeyMan methods
    Can verify move-only with:
    
        git log -p -n1 --color-moved
    
    This commit is move-only and doesn't change code or affect behavior.
    b4cb18bce3
  44. Refactor: Declare LegacyScriptPubKeyMan methods as virtual
    This commit does not change behavior.
    533d8b364f
  45. Refactor: Add new ScriptPubKeyMan virtual methods
    This commit does not change behavior.
    acedc5b823
  46. Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination
    This commit does not change behavior.
    769acef857
  47. Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata
    This commit does not change behavior.
    4c5491f99c
  48. Remove SetWalletFlag from WalletStorage
    SetWalletFlag is unused.
    
    Does not change any behavior
    0391aba52d
  49. Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed
    This commit does not change behavior.
    78e7cbc7ba
  50. refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan
    ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank
    wallet flag. Just make that it's own function and not expose the flag
    writing directly.
    
    This does not change behavior.
    fc2867fdf5
  51. Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys
    This commit does not change behavior.
    67be6b9e21
  52. Refactor: Move LoadKey LegacyScriptPubKeyMan method definition
    This commit does not change behavior.
    9716bbe0f8
  53. Refactor: Move GetMetadata code out of getaddressinfo
    Easier to review ignoring whitespace:
    
        git log -p -n1 -w
    
    This commit does not change behavior.
    a18edd7b38
  54. Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe
    This commit does not change behavior.
    46865ec958
  55. Refactor: Move Upgrade code out of CWallet::CreateWalletFromFile
    This commit does not change behavior.
    8b0d82bb42
  56. Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile
    This commit does not change behavior.
    f45d12b36c
  57. Refactor: Move SetupGeneration code out of CWallet
    This commit does not change behavior.
    0eac7088ab
  58. Refactor: Move RewriteDB code out of CWallet
    This commit does not change behavior.
    089e17d45c
  59. Refactor: Move GetKeypoolSize code out of CWallet
    This commit does not change behavior.
    7ef47b88e6
  60. Refactor: Move nTimeFirstKey accesses out of CWallet
    This commit does not change behavior.
    152b0a00d8
  61. achow101 force-pushed on Nov 2, 2019
  62. ryanofsky approved
  63. ryanofsky commented at 3:07 am on November 2, 2019: member
    Code review ACK 707a8178109b75fb672f233f57c3c5db952ad5f1. Only change since last review is the fix to UpgradeKeyMetaData to avoid setting WALLET_FLAG_KEY_ORIGIN_METADATA when the wallet is locked.
  64. laanwj commented at 11:17 am on November 2, 2019: member
    code review ACK 152b0a00d8e681dd098f6b548447b82ab54ebe3c
  65. Sjors commented at 5:27 pm on November 2, 2019: member

    re-ACK 152b0a00d8e681dd098f6b548447b82ab54ebe3c

    If you can append a commit to get rid of unused variable warnings in rpcdump.cpp that would be nice though (see #17338 by @jonatack).

    0 wallet/rpcdump.cpp:137:28: error: unused variable 'spk_man' [-Werror,-Wunused-variable]
    1    LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
    
  66. promag commented at 10:15 pm on November 3, 2019: member
    Code review ACK 152b0a00d8e681dd098f6b548447b82ab54ebe3c.
  67. laanwj referenced this in commit bbc9e4133c on Nov 4, 2019
  68. laanwj merged this on Nov 4, 2019
  69. laanwj closed this on Nov 4, 2019

  70. fanquake removed this from the "Blockers" column in a project

  71. ryanofsky added this to the "PRs" column in a project

  72. ryanofsky referenced this in commit 62164302db on Nov 5, 2019
  73. ryanofsky referenced this in commit 346019f99b on Nov 5, 2019
  74. ryanofsky referenced this in commit f33936f4dc on Nov 5, 2019
  75. ryanofsky referenced this in commit b89bb40a34 on Nov 5, 2019
  76. ryanofsky referenced this in commit 1c93192ae6 on Nov 5, 2019
  77. ryanofsky referenced this in commit 3498f932b2 on Nov 5, 2019
  78. ryanofsky referenced this in commit b910aa245c on Nov 5, 2019
  79. ryanofsky referenced this in commit 5ed6daf4b7 on Nov 5, 2019
  80. fanquake moved this from the "PRs" to the "Done" column in a project

  81. ryanofsky referenced this in commit 3b8126bb16 on Nov 5, 2019
  82. ryanofsky referenced this in commit eb74fd5e33 on Nov 5, 2019
  83. ryanofsky referenced this in commit db89930a3d on Nov 5, 2019
  84. ryanofsky referenced this in commit 5b3a0b4fbe on Nov 5, 2019
  85. ryanofsky referenced this in commit fdd1b6486f on Nov 5, 2019
  86. ryanofsky referenced this in commit 494273bee6 on Nov 5, 2019
  87. ryanofsky referenced this in commit 49492e6d4a on Nov 5, 2019
  88. ryanofsky referenced this in commit fed8b28c99 on Nov 5, 2019
  89. ryanofsky referenced this in commit e7c2161f90 on Nov 5, 2019
  90. ryanofsky referenced this in commit 4cc3e56f2f on Nov 5, 2019
  91. ryanofsky referenced this in commit dab002546d on Nov 5, 2019
  92. ryanofsky referenced this in commit 1f54dd2184 on Nov 5, 2019
  93. ryanofsky referenced this in commit 4a0abf694e on Nov 6, 2019
  94. ryanofsky referenced this in commit 491a599b37 on Nov 6, 2019
  95. ryanofsky referenced this in commit bfd826a675 on Nov 6, 2019
  96. ryanofsky referenced this in commit 05b224a175 on Nov 6, 2019
  97. laanwj referenced this in commit 976cc766c4 on Nov 6, 2019
  98. sidhujag referenced this in commit 19238f8e6c on Nov 7, 2019
  99. HashUnlimited referenced this in commit 5a7db3b40f on Apr 17, 2020
  100. HashUnlimited referenced this in commit 70c6c86e0c on Apr 17, 2020
  101. HashUnlimited referenced this in commit 7c36cfedf0 on Apr 17, 2020
  102. HashUnlimited referenced this in commit bec485abd7 on Apr 17, 2020
  103. jasonbcox referenced this in commit 9e67a76f84 on Aug 8, 2020
  104. jasonbcox referenced this in commit 65b5027b77 on Aug 8, 2020
  105. deadalnix referenced this in commit 5c6f38dc13 on Aug 8, 2020
  106. jasonbcox referenced this in commit 7814f68f17 on Aug 8, 2020
  107. deadalnix referenced this in commit 31181accc2 on Aug 8, 2020
  108. jasonbcox referenced this in commit 1b72f8e386 on Aug 8, 2020
  109. deadalnix referenced this in commit c503f48dd9 on Aug 8, 2020
  110. deadalnix referenced this in commit 09a9643db9 on Aug 8, 2020
  111. jasonbcox referenced this in commit f1019d1508 on Aug 8, 2020
  112. jasonbcox referenced this in commit 3ae76c3580 on Aug 8, 2020
  113. jasonbcox referenced this in commit 01966b4f82 on Aug 8, 2020
  114. jasonbcox referenced this in commit 6ef446c956 on Aug 8, 2020
  115. jasonbcox referenced this in commit 362966c0db on Aug 8, 2020
  116. jasonbcox referenced this in commit 0495ea4238 on Aug 8, 2020
  117. jasonbcox referenced this in commit c8f95523f6 on Aug 8, 2020
  118. jasonbcox referenced this in commit f3e3433a59 on Aug 8, 2020
  119. jasonbcox referenced this in commit be3af3b674 on Aug 8, 2020
  120. jasonbcox referenced this in commit b109466921 on Aug 8, 2020
  121. jasonbcox referenced this in commit 0b5daf4ba8 on Sep 11, 2020
  122. jasonbcox referenced this in commit fa3481add5 on Sep 11, 2020
  123. jasonbcox referenced this in commit 709706b9d7 on Sep 11, 2020
  124. jasonbcox referenced this in commit 7e4e5d2a9f on Sep 11, 2020
  125. sidhujag referenced this in commit 682a4772a0 on Nov 10, 2020
  126. DrahtBot locked this on Dec 16, 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: 2024-12-18 03:12 UTC

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