Skip to content

Commit fb01c5a

Browse files
Merge #6868: refactor: replace RecursiveMutex with Mutex in meta store/info and add thread-safety annotations; avoid re-entrant locking
191c79c refactor: update thread-safety annotations to use EXCLUSIVE_LOCKS_REQUIRED for various methods in meta store and info (pasta) 41e4324 masternode: replace RecursiveMutex with Mutex in meta store/info and add thread-safety annotations (LOCKS_EXCLUDED); avoid re-entrant locking (pasta) Pull request description: ## Issue being fixed or feature implemented Convert mutex from Recursive to non-recursive ## What was done? _Describe your changes in detail_ ## How Has This Been Tested? _Please describe in detail how you tested your changes._ _Include details of your testing environment, and the tests you ran to see how your change affects other areas of the code, etc._ ## Breaking Changes _Please describe any breaking changes your code introduces_ ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] 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 - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK 191c79c kwvg: utACK 191c79c Tree-SHA512: 93255cf4c5d99c3dbd7f05f7f55156b9b56bd2e2b4b9618f92cea94c2d95dbc5bbcba7cb4351846b05286642ddf4b4c8340bd803edfeb4cb068df3c7b6e42e59
2 parents 2e6d8f2 + 191c79c commit fb01c5a

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/masternode/meta.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void CMasternodeMetaInfo::RemoveGovernanceObject(const uint256& nGovernanceObjec
6666
mapGovernanceObjectsVotedOn.erase(nGovernanceObjectHash);
6767
}
6868

69-
CMasternodeMetaInfoPtr CMasternodeMetaMan::GetMetaInfo(const uint256& proTxHash, bool fCreate)
69+
CMasternodeMetaInfoPtr CMasternodeMetaMan::GetMetaInfo(const uint256& proTxHash, bool fCreate) EXCLUSIVE_LOCKS_REQUIRED(!cs)
7070
{
7171
LOCK(cs);
7272
auto it = metaInfos.find(proTxHash);
@@ -115,28 +115,28 @@ bool CMasternodeMetaMan::AddGovernanceVote(const uint256& proTxHash, const uint2
115115
return true;
116116
}
117117

118-
void CMasternodeMetaMan::RemoveGovernanceObject(const uint256& nGovernanceObjectHash)
118+
void CMasternodeMetaMan::RemoveGovernanceObject(const uint256& nGovernanceObjectHash) EXCLUSIVE_LOCKS_REQUIRED(!cs)
119119
{
120120
LOCK(cs);
121121
for(const auto& p : metaInfos) {
122122
p.second->RemoveGovernanceObject(nGovernanceObjectHash);
123123
}
124124
}
125125

126-
std::vector<uint256> CMasternodeMetaMan::GetAndClearDirtyGovernanceObjectHashes()
126+
std::vector<uint256> CMasternodeMetaMan::GetAndClearDirtyGovernanceObjectHashes() EXCLUSIVE_LOCKS_REQUIRED(!cs)
127127
{
128128
std::vector<uint256> vecTmp;
129129
WITH_LOCK(cs, vecTmp.swap(vecDirtyGovernanceObjectHashes));
130130
return vecTmp;
131131
}
132132

133-
bool CMasternodeMetaMan::AlreadyHavePlatformBan(const uint256& inv_hash) const
133+
bool CMasternodeMetaMan::AlreadyHavePlatformBan(const uint256& inv_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
134134
{
135135
LOCK(cs);
136136
return m_seen_platform_bans.exists(inv_hash);
137137
}
138138

139-
std::optional<PlatformBanMessage> CMasternodeMetaMan::GetPlatformBan(const uint256& inv_hash) const
139+
std::optional<PlatformBanMessage> CMasternodeMetaMan::GetPlatformBan(const uint256& inv_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
140140
{
141141
LOCK(cs);
142142
PlatformBanMessage ret;
@@ -147,13 +147,13 @@ std::optional<PlatformBanMessage> CMasternodeMetaMan::GetPlatformBan(const uint2
147147
return ret;
148148
}
149149

150-
void CMasternodeMetaMan::RememberPlatformBan(const uint256& inv_hash, PlatformBanMessage&& msg)
150+
void CMasternodeMetaMan::RememberPlatformBan(const uint256& inv_hash, PlatformBanMessage&& msg) EXCLUSIVE_LOCKS_REQUIRED(!cs)
151151
{
152152
LOCK(cs);
153153
m_seen_platform_bans.insert(inv_hash, std::move(msg));
154154
}
155155

156-
std::string MasternodeMetaStore::ToString() const
156+
std::string MasternodeMetaStore::ToString() const EXCLUSIVE_LOCKS_REQUIRED(!cs)
157157
{
158158
LOCK(cs);
159159
return strprintf("Masternodes: meta infos object count: %d, nDsqCount: %d", metaInfos.size(), nDsqCount);

src/masternode/meta.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CMasternodeMetaInfo
3535
friend class CMasternodeMetaMan;
3636

3737
private:
38-
mutable RecursiveMutex cs;
38+
mutable Mutex cs;
3939

4040
uint256 proTxHash GUARDED_BY(cs);
4141

@@ -127,14 +127,14 @@ class MasternodeMetaStore
127127
protected:
128128
static const std::string SERIALIZATION_VERSION_STRING;
129129

130-
mutable RecursiveMutex cs;
130+
mutable Mutex cs;
131131
std::map<uint256, CMasternodeMetaInfoPtr> metaInfos GUARDED_BY(cs);
132132
// keep track of dsq count to prevent masternodes from gaming coinjoin queue
133133
std::atomic<int64_t> nDsqCount{0};
134134

135135
public:
136136
template<typename Stream>
137-
void Serialize(Stream &s) const
137+
void Serialize(Stream &s) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
138138
{
139139
LOCK(cs);
140140
std::vector<CMasternodeMetaInfo> tmpMetaInfo;
@@ -145,7 +145,7 @@ class MasternodeMetaStore
145145
}
146146

147147
template<typename Stream>
148-
void Unserialize(Stream &s)
148+
void Unserialize(Stream &s) EXCLUSIVE_LOCKS_REQUIRED(!cs)
149149
{
150150
Clear();
151151

@@ -163,14 +163,14 @@ class MasternodeMetaStore
163163
}
164164
}
165165

166-
void Clear()
166+
void Clear() EXCLUSIVE_LOCKS_REQUIRED(!cs)
167167
{
168168
LOCK(cs);
169169

170170
metaInfos.clear();
171171
}
172172

173-
std::string ToString() const;
173+
std::string ToString() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
174174
};
175175

176176
/**
@@ -233,7 +233,7 @@ class CMasternodeMetaMan : public MasternodeMetaStore
233233

234234
bool IsValid() const { return is_valid; }
235235

236-
CMasternodeMetaInfoPtr GetMetaInfo(const uint256& proTxHash, bool fCreate = true);
236+
CMasternodeMetaInfoPtr GetMetaInfo(const uint256& proTxHash, bool fCreate = true) EXCLUSIVE_LOCKS_REQUIRED(!cs);
237237

238238
int64_t GetDsqCount() const { return nDsqCount; }
239239
int64_t GetDsqThreshold(const uint256& proTxHash, int nMnCount);
@@ -242,13 +242,13 @@ class CMasternodeMetaMan : public MasternodeMetaStore
242242
void DisallowMixing(const uint256& proTxHash);
243243

244244
bool AddGovernanceVote(const uint256& proTxHash, const uint256& nGovernanceObjectHash);
245-
void RemoveGovernanceObject(const uint256& nGovernanceObjectHash);
245+
void RemoveGovernanceObject(const uint256& nGovernanceObjectHash) EXCLUSIVE_LOCKS_REQUIRED(!cs);
246246

247-
std::vector<uint256> GetAndClearDirtyGovernanceObjectHashes();
247+
std::vector<uint256> GetAndClearDirtyGovernanceObjectHashes() EXCLUSIVE_LOCKS_REQUIRED(!cs);
248248

249-
bool AlreadyHavePlatformBan(const uint256& inv_hash) const;
250-
std::optional<PlatformBanMessage> GetPlatformBan(const uint256& inv_hash) const;
251-
void RememberPlatformBan(const uint256& inv_hash, PlatformBanMessage&& msg);
249+
bool AlreadyHavePlatformBan(const uint256& inv_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
250+
std::optional<PlatformBanMessage> GetPlatformBan(const uint256& inv_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
251+
void RememberPlatformBan(const uint256& inv_hash, PlatformBanMessage&& msg) EXCLUSIVE_LOCKS_REQUIRED(!cs);
252252
};
253253

254254
#endif // BITCOIN_MASTERNODE_META_H

0 commit comments

Comments
 (0)