@@ -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
}
@@ -229,6 +229,8 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
229
229
if (fAddToSeen ) {
230
230
// UPDATE THAT WE'VE SEEN THIS OBJECT
231
231
mapSeenGovernanceObjects.insert (std::make_pair (nHash, SEEN_OBJECT_IS_VALID));
232
+ // Update the rate buffer
233
+ MasternodeRateCheck (govobj, UPDATE_TRUE, true , fRateCheckBypassed );
232
234
}
233
235
234
236
masternodeSync.AddedGovernanceItem ();
@@ -814,13 +816,13 @@ void CGovernanceManager::Sync(CNode* pfrom, const uint256& nProp, const CBloomFi
814
816
LogPrintf (" CGovernanceManager::Sync -- sent %d objects and %d votes to peer=%d\n " , nObjCount, nVoteCount, pfrom->id );
815
817
}
816
818
817
- bool CGovernanceManager::MasternodeRateCheck (const CGovernanceObject& govobj, bool fUpdateLast )
819
+ bool CGovernanceManager::MasternodeRateCheck (const CGovernanceObject& govobj, update_mode_enum_t eUpdateLast )
818
820
{
819
821
bool fRateCheckBypassed = false ;
820
- return MasternodeRateCheck (govobj, fUpdateLast , true , fRateCheckBypassed );
822
+ return MasternodeRateCheck (govobj, eUpdateLast , true , fRateCheckBypassed );
821
823
}
822
824
823
- 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 )
824
826
{
825
827
LOCK (cs);
826
828
@@ -848,7 +850,7 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
848
850
txout_m_it it = mapLastMasternodeObject.find (vin.prevout );
849
851
850
852
if (it == mapLastMasternodeObject.end ()) {
851
- if (fUpdateLast ) {
853
+ if (eUpdateLast == UPDATE_TRUE ) {
852
854
it = mapLastMasternodeObject.insert (txout_m_t::value_type (vin.prevout , last_object_rec (true ))).first ;
853
855
switch (nObjectType) {
854
856
case GOVERNANCE_OBJECT_TRIGGER:
@@ -886,44 +888,54 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
886
888
double dMaxRate = 1.1 / nSuperblockCycleSeconds;
887
889
double dRate = 0.0 ;
888
890
CRateCheckBuffer buffer;
891
+ CRateCheckBuffer* pBuffer = NULL ;
889
892
switch (nObjectType) {
890
893
case GOVERNANCE_OBJECT_TRIGGER:
891
894
// Allow 1 trigger per mn per cycle, with a small fudge factor
895
+ pBuffer = &it->second .triggerBuffer ;
892
896
dMaxRate = 2 * 1.1 / double (nSuperblockCycleSeconds);
893
- buffer = it->second .triggerBuffer ;
894
- buffer.AddTimestamp (nTimestamp);
895
- dRate = buffer.GetRate ();
896
- if (fUpdateLast ) {
897
- it->second .triggerBuffer .AddTimestamp (nTimestamp);
898
- }
899
897
break ;
900
898
case GOVERNANCE_OBJECT_WATCHDOG:
899
+ pBuffer = &it->second .watchdogBuffer ;
901
900
dMaxRate = 2 * 1.1 / 3600 .;
902
- buffer = it->second .watchdogBuffer ;
903
- buffer.AddTimestamp (nTimestamp);
904
- dRate = buffer.GetRate ();
905
- if (fUpdateLast ) {
906
- it->second .watchdogBuffer .AddTimestamp (nTimestamp);
907
- }
908
901
break ;
909
902
default :
910
903
break ;
911
904
}
912
905
913
- if (dRate < dMaxRate) {
914
- if (fUpdateLast ) {
915
- it->second .fStatusOK = true ;
916
- }
917
- 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 ;
918
910
}
919
- else {
920
- 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);
921
926
it->second .fStatusOK = false ;
922
927
}
928
+ default :
929
+ return true ;
923
930
}
924
931
925
- LogPrintf (" CGovernanceManager::MasternodeRateCheck -- Rate too high: object hash = %s, masternode vin = %s, object timestamp = %d, rate = %f, max rate = %f\n " ,
926
- 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
+ }
927
939
return false ;
928
940
}
929
941
0 commit comments