Skip to content

Commit 726d066

Browse files
author
MarcoFalke
committed
Merge #15530: doc: Move wallet lock annotations to header
faebd2e doc: Move wallet lock annotations to header (MarcoFalke) Pull request description: We put the annotations in a central place (the header) as opposed to spreading them over the cpp files, where they easily get outdated. Tree-SHA512: 18d8c7329efd3471713de18fe8d63d67c50fcb9fa99bc372294d829aa7668ea33e10d44e9e50121a04d8cc3302d5fd7759224f7935451a4693c4498a555257e6
2 parents 3515612 + faebd2e commit 726d066

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

src/wallet/wallet.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ CPubKey CWallet::GenerateNewKey(WalletBatch &batch, bool internal)
193193
{
194194
assert(!IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
195195
assert(!IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET));
196-
AssertLockHeld(cs_wallet); // mapKeyMetadata
196+
AssertLockHeld(cs_wallet);
197197
bool fCompressed = CanSupportFeature(FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets
198198

199199
CKey secret;
@@ -281,9 +281,9 @@ void CWallet::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata& metadata, CKey
281281
throw std::runtime_error(std::string(__func__) + ": Writing HD chain model failed");
282282
}
283283

284-
bool CWallet::AddKeyPubKeyWithDB(WalletBatch &batch, const CKey& secret, const CPubKey &pubkey)
284+
bool CWallet::AddKeyPubKeyWithDB(WalletBatch& batch, const CKey& secret, const CPubKey& pubkey)
285285
{
286-
AssertLockHeld(cs_wallet); // mapKeyMetadata
286+
AssertLockHeld(cs_wallet);
287287

288288
// Make sure we aren't adding private keys to private key disabled wallets
289289
assert(!IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
@@ -345,16 +345,16 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey,
345345
}
346346
}
347347

348-
void CWallet::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &meta)
348+
void CWallet::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata& meta)
349349
{
350-
AssertLockHeld(cs_wallet); // mapKeyMetadata
350+
AssertLockHeld(cs_wallet);
351351
UpdateTimeFirstKey(meta.nCreateTime);
352352
mapKeyMetadata[keyID] = meta;
353353
}
354354

355-
void CWallet::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &meta)
355+
void CWallet::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata& meta)
356356
{
357-
AssertLockHeld(cs_wallet); // m_script_metadata
357+
AssertLockHeld(cs_wallet);
358358
UpdateTimeFirstKey(meta.nCreateTime);
359359
m_script_metadata[script_id] = meta;
360360
}
@@ -367,7 +367,7 @@ bool CWallet::WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey,
367367

368368
void CWallet::UpgradeKeyMetadata()
369369
{
370-
AssertLockHeld(cs_wallet); // mapKeyMetadata
370+
AssertLockHeld(cs_wallet);
371371
if (IsLocked() || IsWalletFlagSet(WALLET_FLAG_KEY_ORIGIN_METADATA)) {
372372
return;
373373
}
@@ -569,7 +569,7 @@ void CWallet::ChainStateFlushed(const CBlockLocator& loc)
569569

570570
void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in, bool fExplicit)
571571
{
572-
LOCK(cs_wallet); // nWalletVersion
572+
LOCK(cs_wallet);
573573
if (nWalletVersion >= nVersion)
574574
return;
575575

@@ -593,7 +593,7 @@ void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in,
593593

594594
bool CWallet::SetMaxVersion(int nVersion)
595595
{
596-
LOCK(cs_wallet); // nWalletVersion, nWalletMaxVersion
596+
LOCK(cs_wallet);
597597
// cannot downgrade below current version
598598
if (nWalletVersion > nVersion)
599599
return false;
@@ -877,9 +877,9 @@ DBErrors CWallet::ReorderTransactions()
877877
return DBErrors::LOAD_OK;
878878
}
879879

880-
int64_t CWallet::IncOrderPosNext(WalletBatch *batch)
880+
int64_t CWallet::IncOrderPosNext(WalletBatch* batch)
881881
{
882-
AssertLockHeld(cs_wallet); // nOrderPosNext
882+
AssertLockHeld(cs_wallet);
883883
int64_t nRet = nOrderPosNext++;
884884
if (batch) {
885885
batch->WriteOrderPosNext(nOrderPosNext);
@@ -2614,9 +2614,9 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
26142614
return res;
26152615
}
26162616

2617-
bool CWallet::SignTransaction(CMutableTransaction &tx)
2617+
bool CWallet::SignTransaction(CMutableTransaction& tx)
26182618
{
2619-
AssertLockHeld(cs_wallet); // mapWallet
2619+
AssertLockHeld(cs_wallet);
26202620

26212621
// sign the new tx
26222622
int nIn = 0;
@@ -3230,8 +3230,8 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
32303230

32313231
DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut)
32323232
{
3233-
AssertLockHeld(cs_wallet); // mapWallet
3234-
DBErrors nZapSelectTxRet = WalletBatch(*database,"cr+").ZapSelectTx(vHashIn, vHashOut);
3233+
AssertLockHeld(cs_wallet);
3234+
DBErrors nZapSelectTxRet = WalletBatch(*database, "cr+").ZapSelectTx(vHashIn, vHashOut);
32353235
for (uint256 hash : vHashOut) {
32363236
const auto& it = mapWallet.find(hash);
32373237
wtxOrdered.erase(it->second.m_it_wtxOrdered);
@@ -3257,7 +3257,6 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
32573257
MarkDirty();
32583258

32593259
return DBErrors::LOAD_OK;
3260-
32613260
}
32623261

32633262
DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx>& vWtx)
@@ -3377,7 +3376,7 @@ bool CWallet::NewKeyPool()
33773376

33783377
size_t CWallet::KeypoolCountExternalKeys()
33793378
{
3380-
AssertLockHeld(cs_wallet); // setExternalKeyPool
3379+
AssertLockHeld(cs_wallet);
33813380
return setExternalKeyPool.size() + set_pre_split_keypool.size();
33823381
}
33833382

@@ -3641,7 +3640,7 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances(interfaces::Chain:
36413640

36423641
std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings()
36433642
{
3644-
AssertLockHeld(cs_wallet); // mapWallet
3643+
AssertLockHeld(cs_wallet);
36453644
std::set< std::set<CTxDestination> > groupings;
36463645
std::set<CTxDestination> grouping;
36473646

@@ -3809,33 +3808,33 @@ void CWallet::MarkReserveKeysAsUsed(int64_t keypool_id)
38093808

38103809
void CWallet::LockCoin(const COutPoint& output)
38113810
{
3812-
AssertLockHeld(cs_wallet); // setLockedCoins
3811+
AssertLockHeld(cs_wallet);
38133812
setLockedCoins.insert(output);
38143813
}
38153814

38163815
void CWallet::UnlockCoin(const COutPoint& output)
38173816
{
3818-
AssertLockHeld(cs_wallet); // setLockedCoins
3817+
AssertLockHeld(cs_wallet);
38193818
setLockedCoins.erase(output);
38203819
}
38213820

38223821
void CWallet::UnlockAllCoins()
38233822
{
3824-
AssertLockHeld(cs_wallet); // setLockedCoins
3823+
AssertLockHeld(cs_wallet);
38253824
setLockedCoins.clear();
38263825
}
38273826

38283827
bool CWallet::IsLockedCoin(uint256 hash, unsigned int n) const
38293828
{
3830-
AssertLockHeld(cs_wallet); // setLockedCoins
3829+
AssertLockHeld(cs_wallet);
38313830
COutPoint outpt(hash, n);
38323831

38333832
return (setLockedCoins.count(outpt) > 0);
38343833
}
38353834

38363835
void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts) const
38373836
{
3838-
AssertLockHeld(cs_wallet); // setLockedCoins
3837+
AssertLockHeld(cs_wallet);
38393838
for (std::set<COutPoint>::iterator it = setLockedCoins.begin();
38403839
it != setLockedCoins.end(); it++) {
38413840
COutPoint outpt = (*it);
@@ -3845,8 +3844,8 @@ void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts) const
38453844

38463845
/** @} */ // end of Actions
38473846

3848-
void CWallet::GetKeyBirthTimes(interfaces::Chain::Lock& locked_chain, std::map<CTxDestination, int64_t> &mapKeyBirth) const {
3849-
AssertLockHeld(cs_wallet); // mapKeyMetadata
3847+
void CWallet::GetKeyBirthTimes(interfaces::Chain::Lock& locked_chain, std::map<CTxDestination, int64_t>& mapKeyBirth) const {
3848+
AssertLockHeld(cs_wallet);
38503849
mapKeyBirth.clear();
38513850

38523851
// get birth times for keys with metadata
@@ -4125,7 +4124,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
41254124
}
41264125
}
41274126

4128-
int prev_version = walletInstance->nWalletVersion;
4127+
int prev_version = walletInstance->GetVersion();
41294128
if (gArgs.GetBoolArg("-upgradewallet", fFirstRun))
41304129
{
41314130
int nMaxVersion = gArgs.GetArg("-upgradewallet", 0);
@@ -4150,8 +4149,8 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
41504149
LOCK(walletInstance->cs_wallet);
41514150

41524151
// Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT
4153-
int max_version = walletInstance->nWalletVersion;
4154-
if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >=FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) {
4152+
int max_version = walletInstance->GetVersion();
4153+
if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) {
41554154
chain.initError(_("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use -upgradewallet=169900 or -upgradewallet with no version specified."));
41564155
return nullptr;
41574156
}

src/wallet/wallet.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
648648
WalletBatch *encrypted_batch GUARDED_BY(cs_wallet) = nullptr;
649649

650650
//! the current wallet version: clients below this version are not able to load the wallet
651-
int nWalletVersion = FEATURE_BASE;
651+
int nWalletVersion GUARDED_BY(cs_wallet){FEATURE_BASE};
652652

653653
//! the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded
654654
int nWalletMaxVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
@@ -698,11 +698,11 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
698698
CHDChain hdChain;
699699

700700
/* HD derive new child key (on internal or external chain) */
701-
void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata& metadata, CKey& secret, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
701+
void DeriveNewChildKey(WalletBatch& batch, CKeyMetadata& metadata, CKey& secret, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
702702

703-
std::set<int64_t> setInternalKeyPool;
703+
std::set<int64_t> setInternalKeyPool GUARDED_BY(cs_wallet);
704704
std::set<int64_t> setExternalKeyPool GUARDED_BY(cs_wallet);
705-
std::set<int64_t> set_pre_split_keypool;
705+
std::set<int64_t> set_pre_split_keypool GUARDED_BY(cs_wallet);
706706
int64_t m_max_keypool_index GUARDED_BY(cs_wallet) = 0;
707707
std::map<CKeyID, int64_t> m_pool_key_to_index;
708708
std::atomic<uint64_t> m_wallet_flags{0};
@@ -1065,7 +1065,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
10651065

10661066
unsigned int GetKeyPoolSize() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
10671067
{
1068-
AssertLockHeld(cs_wallet); // set{Ex,In}ternalKeyPool
1068+
AssertLockHeld(cs_wallet);
10691069
return setInternalKeyPool.size() + setExternalKeyPool.size();
10701070
}
10711071

0 commit comments

Comments
 (0)