@@ -186,7 +186,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
186
186
}
187
187
188
188
bool fRateCheckBypassed = false ;
189
- if (!MasternodeRateCheck (govobj, true , false , fRateCheckBypassed )) {
189
+ if (!MasternodeRateCheck (govobj, UPDATE_FAIL_ONLY , false , fRateCheckBypassed )) {
190
190
LogPrintf (" MNGOVERNANCEOBJECT -- masternode rate check failed - %s - (current block height %d) \n " , strHash, nCachedBlockHeight);
191
191
return ;
192
192
}
@@ -209,7 +209,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
209
209
}
210
210
211
211
if (fRateCheckBypassed ) {
212
- if (!MasternodeRateCheck (govobj, true , true , fRateCheckBypassed )) {
212
+ if (!MasternodeRateCheck (govobj, UPDATE_FAIL_ONLY , true , fRateCheckBypassed )) {
213
213
LogPrintf (" MNGOVERNANCEOBJECT -- masternode rate check failed (after signature verification) - %s - (current block height %d) \n " , strHash, nCachedBlockHeight);
214
214
return ;
215
215
}
@@ -219,14 +219,20 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
219
219
220
220
govobj.UpdateSentinelVariables (); // this sets local vars in object
221
221
222
- if (AddGovernanceObject (govobj, pfrom))
222
+ bool fAddToSeen = true ;
223
+ if (AddGovernanceObject (govobj, fAddToSeen , pfrom))
223
224
{
224
225
LogPrintf (" MNGOVERNANCEOBJECT -- %s new\n " , strHash);
225
226
govobj.Relay ();
226
227
}
227
228
228
- // UPDATE THAT WE'VE SEEN THIS OBJECT
229
- mapSeenGovernanceObjects.insert (std::make_pair (nHash, SEEN_OBJECT_IS_VALID));
229
+ if (fAddToSeen ) {
230
+ // UPDATE THAT WE'VE SEEN THIS OBJECT
231
+ mapSeenGovernanceObjects.insert (std::make_pair (nHash, SEEN_OBJECT_IS_VALID));
232
+ // Update the rate buffer
233
+ MasternodeRateCheck (govobj, UPDATE_TRUE, true , fRateCheckBypassed );
234
+ }
235
+
230
236
masternodeSync.AddedGovernanceItem ();
231
237
232
238
@@ -305,13 +311,15 @@ void CGovernanceManager::CheckOrphanVotes(CGovernanceObject& govobj, CGovernance
305
311
fRateChecksEnabled = true ;
306
312
}
307
313
308
- bool CGovernanceManager::AddGovernanceObject (CGovernanceObject& govobj, CNode* pfrom)
314
+ bool CGovernanceManager::AddGovernanceObject (CGovernanceObject& govobj, bool & fAddToSeen , CNode* pfrom)
309
315
{
310
316
LOCK2 (cs_main, cs);
311
317
std::string strError = " " ;
312
318
313
319
DBG ( cout << " CGovernanceManager::AddGovernanceObject START" << endl; );
314
320
321
+ fAddToSeen = true ;
322
+
315
323
uint256 nHash = govobj.GetHash ();
316
324
317
325
// MAKE SURE THIS OBJECT IS OK
@@ -341,6 +349,8 @@ bool CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CNode* p
341
349
}
342
350
343
351
if (!UpdateCurrentWatchdog (govobj)) {
352
+ // Allow wd's which are not current to be reprocessed
353
+ fAddToSeen = false ;
344
354
if (pfrom && (nHashWatchdogCurrent != uint256 ())) {
345
355
pfrom->PushInventory (CInv (MSG_GOVERNANCE_OBJECT, nHashWatchdogCurrent));
346
356
}
@@ -806,13 +816,13 @@ void CGovernanceManager::Sync(CNode* pfrom, const uint256& nProp, const CBloomFi
806
816
LogPrintf (" CGovernanceManager::Sync -- sent %d objects and %d votes to peer=%d\n " , nObjCount, nVoteCount, pfrom->id );
807
817
}
808
818
809
- bool CGovernanceManager::MasternodeRateCheck (const CGovernanceObject& govobj, bool fUpdateLast )
819
+ bool CGovernanceManager::MasternodeRateCheck (const CGovernanceObject& govobj, update_mode_enum_t eUpdateLast )
810
820
{
811
821
bool fRateCheckBypassed = false ;
812
- return MasternodeRateCheck (govobj, fUpdateLast , true , fRateCheckBypassed );
822
+ return MasternodeRateCheck (govobj, eUpdateLast , true , fRateCheckBypassed );
813
823
}
814
824
815
- bool CGovernanceManager::MasternodeRateCheck (const CGovernanceObject& govobj, bool fUpdateLast , bool fForce , bool & fRateCheckBypassed )
825
+ bool CGovernanceManager::MasternodeRateCheck (const CGovernanceObject& govobj, update_mode_enum_t eUpdateLast , bool fForce , bool & fRateCheckBypassed )
816
826
{
817
827
LOCK (cs);
818
828
@@ -840,7 +850,7 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
840
850
txout_m_it it = mapLastMasternodeObject.find (vin.prevout );
841
851
842
852
if (it == mapLastMasternodeObject.end ()) {
843
- if (fUpdateLast ) {
853
+ if (eUpdateLast == UPDATE_TRUE ) {
844
854
it = mapLastMasternodeObject.insert (txout_m_t::value_type (vin.prevout , last_object_rec (true ))).first ;
845
855
switch (nObjectType) {
846
856
case GOVERNANCE_OBJECT_TRIGGER:
@@ -878,44 +888,54 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
878
888
double dMaxRate = 1.1 / nSuperblockCycleSeconds;
879
889
double dRate = 0.0 ;
880
890
CRateCheckBuffer buffer;
891
+ CRateCheckBuffer* pBuffer = NULL ;
881
892
switch (nObjectType) {
882
893
case GOVERNANCE_OBJECT_TRIGGER:
883
894
// Allow 1 trigger per mn per cycle, with a small fudge factor
895
+ pBuffer = &it->second .triggerBuffer ;
884
896
dMaxRate = 2 * 1.1 / double (nSuperblockCycleSeconds);
885
- buffer = it->second .triggerBuffer ;
886
- buffer.AddTimestamp (nTimestamp);
887
- dRate = buffer.GetRate ();
888
- if (fUpdateLast ) {
889
- it->second .triggerBuffer .AddTimestamp (nTimestamp);
890
- }
891
897
break ;
892
898
case GOVERNANCE_OBJECT_WATCHDOG:
899
+ pBuffer = &it->second .watchdogBuffer ;
893
900
dMaxRate = 2 * 1.1 / 3600 .;
894
- buffer = it->second .watchdogBuffer ;
895
- buffer.AddTimestamp (nTimestamp);
896
- dRate = buffer.GetRate ();
897
- if (fUpdateLast ) {
898
- it->second .watchdogBuffer .AddTimestamp (nTimestamp);
899
- }
900
901
break ;
901
902
default :
902
903
break ;
903
904
}
904
905
905
- if (dRate < dMaxRate) {
906
- if (fUpdateLast ) {
907
- it->second .fStatusOK = true ;
908
- }
909
- return true ;
906
+ if (!pBuffer) {
907
+ LogPrintf (" CGovernanceManager::MasternodeRateCheck -- Internal Error returning false, NULL ptr found for object %s masternode vin = %s, timestamp = %d, current time = %d\n " ,
908
+ strHash, vin.prevout .ToStringShort (), nTimestamp, nNow);
909
+ return false ;
910
910
}
911
- else {
912
- if (fUpdateLast ) {
911
+
912
+ buffer = *pBuffer;
913
+ buffer.AddTimestamp (nTimestamp);
914
+ dRate = buffer.GetRate ();
915
+
916
+ bool fRateOK = ( dRate < dMaxRate );
917
+
918
+ switch (eUpdateLast) {
919
+ case UPDATE_TRUE:
920
+ pBuffer->AddTimestamp (nTimestamp);
921
+ it->second .fStatusOK = fRateOK ;
922
+ break ;
923
+ case UPDATE_FAIL_ONLY:
924
+ if (!fRateOK ) {
925
+ pBuffer->AddTimestamp (nTimestamp);
913
926
it->second .fStatusOK = false ;
914
927
}
928
+ default :
929
+ return true ;
915
930
}
916
931
917
- LogPrintf (" CGovernanceManager::MasternodeRateCheck -- Rate too high: object hash = %s, masternode vin = %s, object timestamp = %d, rate = %f, max rate = %f\n " ,
918
- strHash, vin.prevout .ToStringShort (), nTimestamp, dRate, dMaxRate);
932
+ if (fRateOK ) {
933
+ return true ;
934
+ }
935
+ else {
936
+ LogPrintf (" CGovernanceManager::MasternodeRateCheck -- Rate too high: object hash = %s, masternode vin = %s, object timestamp = %d, rate = %f, max rate = %f\n " ,
937
+ strHash, vin.prevout .ToStringShort (), nTimestamp, dRate, dMaxRate);
938
+ }
919
939
return false ;
920
940
}
921
941
@@ -1007,7 +1027,8 @@ void CGovernanceManager::CheckMasternodeOrphanObjects()
1007
1027
continue ;
1008
1028
}
1009
1029
1010
- if (AddGovernanceObject (govobj)) {
1030
+ bool fAddToSeen = true ;
1031
+ if (AddGovernanceObject (govobj, fAddToSeen )) {
1011
1032
LogPrintf (" CGovernanceManager::CheckMasternodeOrphanObjects -- %s new\n " , govobj.GetHash ().ToString ());
1012
1033
govobj.Relay ();
1013
1034
mapMasternodeOrphanObjects.erase (it++);
0 commit comments