@@ -460,7 +460,11 @@ class CWalletTx : public CMerkleTx
460
460
CAmount GetDebit (const isminefilter& filter) const ;
461
461
CAmount GetCredit (const isminefilter& filter) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
462
462
CAmount GetImmatureCredit (bool fUseCache =true ) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
463
- CAmount GetAvailableCredit (bool fUseCache =true , const isminefilter& filter=ISMINE_SPENDABLE) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
463
+ // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
464
+ // annotation "EXCLUSIVE_LOCKS_REQUIRED(cs_main, pwallet->cs_wallet)". The
465
+ // annotation "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid
466
+ // having to resolve the issue of member access into incomplete type CWallet.
467
+ CAmount GetAvailableCredit (bool fUseCache =true , const isminefilter& filter=ISMINE_SPENDABLE) const NO_THREAD_SAFETY_ANALYSIS;
464
468
CAmount GetImmatureWatchOnlyCredit (const bool fUseCache =true ) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
465
469
CAmount GetChange () const ;
466
470
@@ -492,7 +496,13 @@ class CWalletTx : public CMerkleTx
492
496
/* * Pass this transaction to the mempool. Fails if absolute fee exceeds absurd fee. */
493
497
bool AcceptToMemoryPool (const CAmount& nAbsurdFee, CValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
494
498
495
- std::set<uint256> GetConflicts () const ;
499
+ // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
500
+ // annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation
501
+ // "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid having to
502
+ // resolve the issue of member access into incomplete type CWallet. Note
503
+ // that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)"
504
+ // in place.
505
+ std::set<uint256> GetConflicts () const NO_THREAD_SAFETY_ANALYSIS;
496
506
};
497
507
498
508
class COutput
@@ -591,13 +601,13 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
591
601
std::mutex mutexScanning;
592
602
friend class WalletRescanReserver ;
593
603
594
- WalletBatch *encrypted_batch = nullptr ;
604
+ WalletBatch *encrypted_batch GUARDED_BY (cs_wallet) = nullptr;
595
605
596
606
// ! the current wallet version: clients below this version are not able to load the wallet
597
607
int nWalletVersion = FEATURE_BASE;
598
608
599
609
// ! the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded
600
- int nWalletMaxVersion = FEATURE_BASE;
610
+ int nWalletMaxVersion GUARDED_BY (cs_wallet) = FEATURE_BASE;
601
611
602
612
int64_t nNextResend = 0 ;
603
613
int64_t nLastResend = 0 ;
@@ -609,9 +619,9 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
609
619
* mutated transactions where the mutant gets mined).
610
620
*/
611
621
typedef std::multimap<COutPoint, uint256> TxSpends;
612
- TxSpends mapTxSpends;
613
- void AddToSpends (const COutPoint& outpoint, const uint256& wtxid);
614
- void AddToSpends (const uint256& wtxid);
622
+ TxSpends mapTxSpends GUARDED_BY (cs_wallet) ;
623
+ void AddToSpends (const COutPoint& outpoint, const uint256& wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) ;
624
+ void AddToSpends (const uint256& wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) ;
615
625
616
626
/* *
617
627
* Add a transaction to the wallet, or update it. pIndex and posInBlock should
@@ -632,9 +642,9 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
632
642
void MarkConflicted (const uint256& hashBlock, const uint256& hashTx);
633
643
634
644
/* Mark a transaction's inputs dirty, thus forcing the outputs to be recomputed */
635
- void MarkInputsDirty (const CTransactionRef& tx);
645
+ void MarkInputsDirty (const CTransactionRef& tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) ;
636
646
637
- void SyncMetaData (std::pair<TxSpends::iterator, TxSpends::iterator>);
647
+ void SyncMetaData (std::pair<TxSpends::iterator, TxSpends::iterator>) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) ;
638
648
639
649
/* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected/ScanForWalletTransactions.
640
650
* Should be called with pindexBlock and posInBlock if this is for a transaction that is included in a block. */
@@ -647,13 +657,13 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
647
657
void DeriveNewChildKey (WalletBatch &batch, CKeyMetadata& metadata, CKey& secret, bool internal = false ) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
648
658
649
659
std::set<int64_t > setInternalKeyPool;
650
- std::set<int64_t > setExternalKeyPool;
660
+ std::set<int64_t > setExternalKeyPool GUARDED_BY (cs_wallet) ;
651
661
std::set<int64_t > set_pre_split_keypool;
652
- int64_t m_max_keypool_index = 0 ;
662
+ int64_t m_max_keypool_index GUARDED_BY (cs_wallet) = 0;
653
663
std::map<CKeyID, int64_t > m_pool_key_to_index;
654
664
std::atomic<uint64_t > m_wallet_flags{0 };
655
665
656
- int64_t nTimeFirstKey = 0 ;
666
+ int64_t nTimeFirstKey GUARDED_BY (cs_wallet) = 0;
657
667
658
668
/* *
659
669
* Private version of AddWatchOnly method which does not accept a
@@ -709,20 +719,20 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
709
719
* if they are not ours
710
720
*/
711
721
bool SelectCoins (const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet,
712
- const CCoinControl& coin_control, CoinSelectionParams& coin_selection_params, bool & bnb_used) const ;
722
+ const CCoinControl& coin_control, CoinSelectionParams& coin_selection_params, bool & bnb_used) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) ;
713
723
714
724
/* * Get a name for this wallet for logging/debugging purposes.
715
725
*/
716
726
const std::string& GetName () const { return m_name; }
717
727
718
728
void LoadKeyPool (int64_t nIndex, const CKeyPool &keypool) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
719
- void MarkPreSplitKeys ();
729
+ void MarkPreSplitKeys () EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) ;
720
730
721
731
// Map from Key ID to key metadata.
722
- std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
732
+ std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY (cs_wallet) ;
723
733
724
734
// Map from Script ID to key metadata (for watch-only keys).
725
- std::map<CScriptID, CKeyMetadata> m_script_metadata;
735
+ std::map<CScriptID, CKeyMetadata> m_script_metadata GUARDED_BY (cs_wallet) ;
726
736
727
737
typedef std::map<unsigned int , CMasterKey> MasterKeyMap;
728
738
MasterKeyMap mapMasterKeys;
@@ -739,17 +749,17 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
739
749
encrypted_batch = nullptr ;
740
750
}
741
751
742
- std::map<uint256, CWalletTx> mapWallet;
752
+ std::map<uint256, CWalletTx> mapWallet GUARDED_BY (cs_wallet) ;
743
753
744
754
typedef std::multimap<int64_t , CWalletTx*> TxItems;
745
755
TxItems wtxOrdered;
746
756
747
- int64_t nOrderPosNext = 0 ;
757
+ int64_t nOrderPosNext GUARDED_BY (cs_wallet) = 0;
748
758
uint64_t nAccountingEntryNumber = 0 ;
749
759
750
760
std::map<CTxDestination, CAddressBookData> mapAddressBook;
751
761
752
- std::set<COutPoint> setLockedCoins;
762
+ std::set<COutPoint> setLockedCoins GUARDED_BY (cs_wallet) ;
753
763
754
764
const CWalletTx* GetWalletTx (const uint256& hash) const ;
755
765
@@ -769,7 +779,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
769
779
/* *
770
780
* Find non-change parent output.
771
781
*/
772
- const CTxOut& FindNonChangeParentOutput (const CTransaction& tx, int output) const ;
782
+ const CTxOut& FindNonChangeParentOutput (const CTransaction& tx, int output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) ;
773
783
774
784
/* *
775
785
* Shuffle and select coins until nTargetValue is reached while avoiding
@@ -780,7 +790,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
780
790
bool SelectCoinsMinConf (const CAmount& nTargetValue, const CoinEligibilityFilter& eligibility_filter, std::vector<OutputGroup> groups,
781
791
std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet, const CoinSelectionParams& coin_selection_params, bool & bnb_used) const ;
782
792
783
- bool IsSpent (const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
793
+ bool IsSpent (const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_main, cs_wallet );
784
794
std::vector<OutputGroup> GroupOutputs (const std::vector<COutput>& outputs, bool single_coin) const ;
785
795
786
796
bool IsLockedCoin (uint256 hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
@@ -856,7 +866,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
856
866
857
867
void MarkDirty ();
858
868
bool AddToWallet (const CWalletTx& wtxIn, bool fFlushOnClose =true );
859
- void LoadToWallet (const CWalletTx& wtxIn);
869
+ void LoadToWallet (const CWalletTx& wtxIn) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) ;
860
870
void TransactionAddedToMempool (const CTransactionRef& tx) override ;
861
871
void BlockConnected (const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) override ;
862
872
void BlockDisconnected (const std::shared_ptr<const CBlock>& pblock) override ;
@@ -1000,7 +1010,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
1000
1010
int GetVersion () { LOCK (cs_wallet); return nWalletVersion; }
1001
1011
1002
1012
// ! Get wallet transactions that conflict with given transaction (spend same outputs)
1003
- std::set<uint256> GetConflicts (const uint256& txid) const ;
1013
+ std::set<uint256> GetConflicts (const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) ;
1004
1014
1005
1015
// ! Check if a given transaction has any of its outputs spent by another transaction in the wallet
1006
1016
bool HasWalletSpend (const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
@@ -1198,6 +1208,6 @@ class WalletRescanReserver
1198
1208
// Use DummySignatureCreator, which inserts 71 byte signatures everywhere.
1199
1209
// NOTE: this requires that all inputs must be in mapWallet (eg the tx should
1200
1210
// be IsAllFromMe).
1201
- int64_t CalculateMaximumSignedTxSize (const CTransaction &tx, const CWallet *wallet, bool use_max_sig = false );
1211
+ int64_t CalculateMaximumSignedTxSize (const CTransaction &tx, const CWallet *wallet, bool use_max_sig = false ) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet) ;
1202
1212
int64_t CalculateMaximumSignedTxSize (const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig = false );
1203
1213
#endif // BITCOIN_WALLET_WALLET_H
0 commit comments