@@ -88,14 +88,15 @@ class CGovernanceObject
8888public: // Types
8989 using vote_m_t = std::map<COutPoint, vote_rec_t >;
9090
91- private :
91+ public :
9292 // / critical section to protect the inner data structures
9393 mutable RecursiveMutex cs;
9494
95+ private:
9596 Governance::Object m_obj;
9697
9798 // / time this object was marked for deletion
98- int64_t nDeletionTime{0 };
99+ int64_t nDeletionTime GUARDED_BY (cs) {0 };
99100
100101 // / is valid by blockchain
101102 bool fCachedLocalValidity {false };
@@ -121,14 +122,14 @@ class CGovernanceObject
121122 bool fDirtyCache {true };
122123
123124 // / Object is no longer of interest
124- bool fExpired {false };
125+ bool fExpired GUARDED_BY (cs) {false };
125126
126127 // / Failed to parse object data
127128 bool fUnparsable {false };
128129
129- vote_m_t mapCurrentMNVotes;
130+ vote_m_t mapCurrentMNVotes GUARDED_BY (cs) ;
130131
131- CGovernanceObjectVoteFile fileVotes;
132+ CGovernanceObjectVoteFile fileVotes GUARDED_BY (cs) ;
132133
133134public:
134135 CGovernanceObject ();
@@ -141,18 +142,31 @@ class CGovernanceObject
141142 bool IsSetCachedDelete () const { return fCachedDelete ; }
142143 bool IsSetCachedEndorsed () const { return fCachedEndorsed ; }
143144 bool IsSetDirtyCache () const { return fDirtyCache ; }
144- bool IsSetExpired () const { return fExpired ; }
145+ bool IsSetExpired () const EXCLUSIVE_LOCKS_REQUIRED(!cs)
146+ {
147+ return WITH_LOCK (cs, return fExpired );
148+ }
145149 GovernanceObject GetObjectType () const { return m_obj.type ; }
146150 int64_t GetCreationTime () const { return m_obj.time ; }
147- int64_t GetDeletionTime () const { return nDeletionTime; }
151+ int64_t GetDeletionTime () const EXCLUSIVE_LOCKS_REQUIRED(!cs)
152+ {
153+ return WITH_LOCK (cs, return nDeletionTime);
154+ }
148155
149- const CGovernanceObjectVoteFile& GetVoteFile () const { return fileVotes; }
156+ const CGovernanceObjectVoteFile& GetVoteFile () const EXCLUSIVE_LOCKS_REQUIRED(cs)
157+ {
158+ AssertLockHeld (cs);
159+ return fileVotes;
160+ }
150161 const COutPoint& GetMasternodeOutpoint () const { return m_obj.masternodeOutpoint ; }
151162 const Governance::Object& Object () const { return m_obj; }
152163 const uint256& GetCollateralHash () const { return m_obj.collateralHash ; }
153164
154165 // Setters
155- void SetExpired () { fExpired = true ; }
166+ void SetExpired () EXCLUSIVE_LOCKS_REQUIRED(!cs)
167+ {
168+ WITH_LOCK (cs, fExpired = true );
169+ }
156170 void SetMasternodeOutpoint (const COutPoint& outpoint);
157171 void SetSignature (Span<const uint8_t > sig);
158172
@@ -177,9 +191,10 @@ class CGovernanceObject
177191
178192 void UpdateSentinelVariables (const CDeterministicMNList& tip_mn_list);
179193
180- void PrepareDeletion (int64_t nDeletionTime_)
194+ void PrepareDeletion (int64_t nDeletionTime_) EXCLUSIVE_LOCKS_REQUIRED(!cs)
181195 {
182196 fCachedDelete = true ;
197+ LOCK (cs);
183198 if (nDeletionTime == 0 ) {
184199 nDeletionTime = nDeletionTime_;
185200 }
@@ -211,15 +226,27 @@ class CGovernanceObject
211226
212227 // SERIALIZER
213228
214- SERIALIZE_METHODS (CGovernanceObject, obj)
229+ template <typename Stream>
230+ void Serialize (Stream& s) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
215231 {
216232 // SERIALIZE DATA FOR SAVING/LOADING OR NETWORK FUNCTIONS
217- READWRITE (obj. m_obj ) ;
233+ s << m_obj;
218234 if (s.GetType () & SER_DISK) {
219235 // Only include these for the disk file format
220- READWRITE (obj.nDeletionTime , obj.fExpired , obj.mapCurrentMNVotes , obj.fileVotes );
236+ LOCK (cs);
237+ s << nDeletionTime << fExpired << mapCurrentMNVotes << fileVotes;
221238 }
239+ }
222240
241+ template <typename Stream>
242+ void Unserialize (Stream& s) EXCLUSIVE_LOCKS_REQUIRED(!cs)
243+ {
244+ s >> m_obj;
245+ if (s.GetType () & SER_DISK) {
246+ // Only include these for the disk file format
247+ LOCK (cs);
248+ s >> nDeletionTime >> fExpired >> mapCurrentMNVotes >> fileVotes;
249+ }
223250 // AFTER DESERIALIZATION OCCURS, CACHED VARIABLES MUST BE CALCULATED MANUALLY
224251 }
225252
0 commit comments