Merge #15530: doc: Move wallet lock annotations to header
faebd2ef40
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
This commit is contained in:
commit
726d0668ff
2 changed files with 33 additions and 34 deletions
|
@ -193,7 +193,7 @@ CPubKey CWallet::GenerateNewKey(WalletBatch &batch, bool internal)
|
|||
{
|
||||
assert(!IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
|
||||
assert(!IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET));
|
||||
AssertLockHeld(cs_wallet); // mapKeyMetadata
|
||||
AssertLockHeld(cs_wallet);
|
||||
bool fCompressed = CanSupportFeature(FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets
|
||||
|
||||
CKey secret;
|
||||
|
@ -281,9 +281,9 @@ void CWallet::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata& metadata, CKey
|
|||
throw std::runtime_error(std::string(__func__) + ": Writing HD chain model failed");
|
||||
}
|
||||
|
||||
bool CWallet::AddKeyPubKeyWithDB(WalletBatch &batch, const CKey& secret, const CPubKey &pubkey)
|
||||
bool CWallet::AddKeyPubKeyWithDB(WalletBatch& batch, const CKey& secret, const CPubKey& pubkey)
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // mapKeyMetadata
|
||||
AssertLockHeld(cs_wallet);
|
||||
|
||||
// Make sure we aren't adding private keys to private key disabled wallets
|
||||
assert(!IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
|
||||
|
@ -345,16 +345,16 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey,
|
|||
}
|
||||
}
|
||||
|
||||
void CWallet::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &meta)
|
||||
void CWallet::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata& meta)
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // mapKeyMetadata
|
||||
AssertLockHeld(cs_wallet);
|
||||
UpdateTimeFirstKey(meta.nCreateTime);
|
||||
mapKeyMetadata[keyID] = meta;
|
||||
}
|
||||
|
||||
void CWallet::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &meta)
|
||||
void CWallet::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata& meta)
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // m_script_metadata
|
||||
AssertLockHeld(cs_wallet);
|
||||
UpdateTimeFirstKey(meta.nCreateTime);
|
||||
m_script_metadata[script_id] = meta;
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ bool CWallet::WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey,
|
|||
|
||||
void CWallet::UpgradeKeyMetadata()
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // mapKeyMetadata
|
||||
AssertLockHeld(cs_wallet);
|
||||
if (IsLocked() || IsWalletFlagSet(WALLET_FLAG_KEY_ORIGIN_METADATA)) {
|
||||
return;
|
||||
}
|
||||
|
@ -569,7 +569,7 @@ void CWallet::ChainStateFlushed(const CBlockLocator& loc)
|
|||
|
||||
void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in, bool fExplicit)
|
||||
{
|
||||
LOCK(cs_wallet); // nWalletVersion
|
||||
LOCK(cs_wallet);
|
||||
if (nWalletVersion >= nVersion)
|
||||
return;
|
||||
|
||||
|
@ -593,7 +593,7 @@ void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in,
|
|||
|
||||
bool CWallet::SetMaxVersion(int nVersion)
|
||||
{
|
||||
LOCK(cs_wallet); // nWalletVersion, nWalletMaxVersion
|
||||
LOCK(cs_wallet);
|
||||
// cannot downgrade below current version
|
||||
if (nWalletVersion > nVersion)
|
||||
return false;
|
||||
|
@ -877,9 +877,9 @@ DBErrors CWallet::ReorderTransactions()
|
|||
return DBErrors::LOAD_OK;
|
||||
}
|
||||
|
||||
int64_t CWallet::IncOrderPosNext(WalletBatch *batch)
|
||||
int64_t CWallet::IncOrderPosNext(WalletBatch* batch)
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // nOrderPosNext
|
||||
AssertLockHeld(cs_wallet);
|
||||
int64_t nRet = nOrderPosNext++;
|
||||
if (batch) {
|
||||
batch->WriteOrderPosNext(nOrderPosNext);
|
||||
|
@ -2614,9 +2614,9 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
|
|||
return res;
|
||||
}
|
||||
|
||||
bool CWallet::SignTransaction(CMutableTransaction &tx)
|
||||
bool CWallet::SignTransaction(CMutableTransaction& tx)
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // mapWallet
|
||||
AssertLockHeld(cs_wallet);
|
||||
|
||||
// sign the new tx
|
||||
int nIn = 0;
|
||||
|
@ -3230,8 +3230,8 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
|
|||
|
||||
DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut)
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // mapWallet
|
||||
DBErrors nZapSelectTxRet = WalletBatch(*database,"cr+").ZapSelectTx(vHashIn, vHashOut);
|
||||
AssertLockHeld(cs_wallet);
|
||||
DBErrors nZapSelectTxRet = WalletBatch(*database, "cr+").ZapSelectTx(vHashIn, vHashOut);
|
||||
for (uint256 hash : vHashOut) {
|
||||
const auto& it = mapWallet.find(hash);
|
||||
wtxOrdered.erase(it->second.m_it_wtxOrdered);
|
||||
|
@ -3257,7 +3257,6 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
|
|||
MarkDirty();
|
||||
|
||||
return DBErrors::LOAD_OK;
|
||||
|
||||
}
|
||||
|
||||
DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx>& vWtx)
|
||||
|
@ -3377,7 +3376,7 @@ bool CWallet::NewKeyPool()
|
|||
|
||||
size_t CWallet::KeypoolCountExternalKeys()
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // setExternalKeyPool
|
||||
AssertLockHeld(cs_wallet);
|
||||
return setExternalKeyPool.size() + set_pre_split_keypool.size();
|
||||
}
|
||||
|
||||
|
@ -3641,7 +3640,7 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances(interfaces::Chain:
|
|||
|
||||
std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings()
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // mapWallet
|
||||
AssertLockHeld(cs_wallet);
|
||||
std::set< std::set<CTxDestination> > groupings;
|
||||
std::set<CTxDestination> grouping;
|
||||
|
||||
|
@ -3809,25 +3808,25 @@ void CWallet::MarkReserveKeysAsUsed(int64_t keypool_id)
|
|||
|
||||
void CWallet::LockCoin(const COutPoint& output)
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // setLockedCoins
|
||||
AssertLockHeld(cs_wallet);
|
||||
setLockedCoins.insert(output);
|
||||
}
|
||||
|
||||
void CWallet::UnlockCoin(const COutPoint& output)
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // setLockedCoins
|
||||
AssertLockHeld(cs_wallet);
|
||||
setLockedCoins.erase(output);
|
||||
}
|
||||
|
||||
void CWallet::UnlockAllCoins()
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // setLockedCoins
|
||||
AssertLockHeld(cs_wallet);
|
||||
setLockedCoins.clear();
|
||||
}
|
||||
|
||||
bool CWallet::IsLockedCoin(uint256 hash, unsigned int n) const
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // setLockedCoins
|
||||
AssertLockHeld(cs_wallet);
|
||||
COutPoint outpt(hash, n);
|
||||
|
||||
return (setLockedCoins.count(outpt) > 0);
|
||||
|
@ -3835,7 +3834,7 @@ bool CWallet::IsLockedCoin(uint256 hash, unsigned int n) const
|
|||
|
||||
void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts) const
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // setLockedCoins
|
||||
AssertLockHeld(cs_wallet);
|
||||
for (std::set<COutPoint>::iterator it = setLockedCoins.begin();
|
||||
it != setLockedCoins.end(); it++) {
|
||||
COutPoint outpt = (*it);
|
||||
|
@ -3845,8 +3844,8 @@ void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts) const
|
|||
|
||||
/** @} */ // end of Actions
|
||||
|
||||
void CWallet::GetKeyBirthTimes(interfaces::Chain::Lock& locked_chain, std::map<CTxDestination, int64_t> &mapKeyBirth) const {
|
||||
AssertLockHeld(cs_wallet); // mapKeyMetadata
|
||||
void CWallet::GetKeyBirthTimes(interfaces::Chain::Lock& locked_chain, std::map<CTxDestination, int64_t>& mapKeyBirth) const {
|
||||
AssertLockHeld(cs_wallet);
|
||||
mapKeyBirth.clear();
|
||||
|
||||
// get birth times for keys with metadata
|
||||
|
@ -4125,7 +4124,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
|||
}
|
||||
}
|
||||
|
||||
int prev_version = walletInstance->nWalletVersion;
|
||||
int prev_version = walletInstance->GetVersion();
|
||||
if (gArgs.GetBoolArg("-upgradewallet", fFirstRun))
|
||||
{
|
||||
int nMaxVersion = gArgs.GetArg("-upgradewallet", 0);
|
||||
|
@ -4150,8 +4149,8 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
|||
LOCK(walletInstance->cs_wallet);
|
||||
|
||||
// Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT
|
||||
int max_version = walletInstance->nWalletVersion;
|
||||
if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >=FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) {
|
||||
int max_version = walletInstance->GetVersion();
|
||||
if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) {
|
||||
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."));
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -648,7 +648,7 @@ private:
|
|||
WalletBatch *encrypted_batch GUARDED_BY(cs_wallet) = nullptr;
|
||||
|
||||
//! the current wallet version: clients below this version are not able to load the wallet
|
||||
int nWalletVersion = FEATURE_BASE;
|
||||
int nWalletVersion GUARDED_BY(cs_wallet){FEATURE_BASE};
|
||||
|
||||
//! the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded
|
||||
int nWalletMaxVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
|
||||
|
@ -698,11 +698,11 @@ private:
|
|||
CHDChain hdChain;
|
||||
|
||||
/* HD derive new child key (on internal or external chain) */
|
||||
void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata& metadata, CKey& secret, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
void DeriveNewChildKey(WalletBatch& batch, CKeyMetadata& metadata, CKey& secret, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
|
||||
std::set<int64_t> setInternalKeyPool;
|
||||
std::set<int64_t> setInternalKeyPool GUARDED_BY(cs_wallet);
|
||||
std::set<int64_t> setExternalKeyPool GUARDED_BY(cs_wallet);
|
||||
std::set<int64_t> set_pre_split_keypool;
|
||||
std::set<int64_t> set_pre_split_keypool GUARDED_BY(cs_wallet);
|
||||
int64_t m_max_keypool_index GUARDED_BY(cs_wallet) = 0;
|
||||
std::map<CKeyID, int64_t> m_pool_key_to_index;
|
||||
std::atomic<uint64_t> m_wallet_flags{0};
|
||||
|
@ -1065,7 +1065,7 @@ public:
|
|||
|
||||
unsigned int GetKeyPoolSize() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // set{Ex,In}ternalKeyPool
|
||||
AssertLockHeld(cs_wallet);
|
||||
return setInternalKeyPool.size() + setExternalKeyPool.size();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue