Merge #6123: fix: avoid calling functions that change wallet state inside of assert(...)

121c032e41 fix: avoid calling functions that change wallet state inside of `assert(...)` (UdjinM6)

Pull request description:

  ## Issue being fixed or feature implemented
  Functions that change the state should not be called inside `assert`s

  kudos to @kwvg for noticing https://github.com/dashpay/dash/pull/6116#discussion_r1681163803

  ## What was done?
  Move them out

  ## How Has This Been Tested?

  ## Breaking Changes
  n/a

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  kwvg:
    LGTM, utACK 121c032e41
  PastaPastaPasta:
    utACK 121c032e41

Tree-SHA512: 42b6f55a62b05e3e632febf92f9d5ac63f32a7754fdd9dffa816d71cb0f72a32ac8315fba5ed96d8bc652728e768f2eb399e5ebb4aa39afe1546fa16e1046347
This commit is contained in:
pasta 2024-07-20 11:20:42 -05:00
commit 914a505d3a
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -268,17 +268,21 @@ bool LegacyScriptPubKeyMan::Encrypt(const CKeyingMaterial& master_key, WalletBat
}
if (!hdChainCurrent.IsNull()) {
assert(EncryptHDChain(master_key, m_hd_chain));
assert(LoadHDChain(m_hd_chain));
bool res = EncryptHDChain(master_key, m_hd_chain);
assert(res);
res = LoadHDChain(m_hd_chain);
assert(res);
CHDChain hdChainCrypted;
assert(GetHDChain(hdChainCrypted));
res = GetHDChain(hdChainCrypted);
assert(res);
// ids should match, seed hashes should not
assert(hdChainCurrent.GetID() == hdChainCrypted.GetID());
assert(hdChainCurrent.GetSeedHash() != hdChainCrypted.GetSeedHash());
assert(AddHDChain(*encrypted_batch, hdChainCrypted));
res = AddHDChain(*encrypted_batch, hdChainCrypted);
assert(res);
}
encrypted_batch = nullptr;