2016-12-20 14:26:45 +01:00
|
|
|
// Copyright (c) 2014-2017 The Dash Core developers
|
2016-04-09 21:57:53 +02:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2016-09-12 09:40:00 +02:00
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
#ifndef GOVERNANCE_H
|
|
|
|
#define GOVERNANCE_H
|
2016-04-09 21:57:53 +02:00
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
//#define ENABLE_DASH_DEBUG
|
|
|
|
|
2017-02-02 09:50:44 +01:00
|
|
|
#include "bloom.h"
|
2016-11-13 18:52:34 +01:00
|
|
|
#include "cachemap.h"
|
|
|
|
#include "cachemultimap.h"
|
2016-12-20 14:27:59 +01:00
|
|
|
#include "chain.h"
|
|
|
|
#include "governance-exceptions.h"
|
|
|
|
#include "governance-object.h"
|
|
|
|
#include "governance-vote.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "sync.h"
|
|
|
|
#include "timedata.h"
|
|
|
|
#include "util.h"
|
2016-04-16 19:19:17 +02:00
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
class CGovernanceManager;
|
2016-11-13 18:52:34 +01:00
|
|
|
class CGovernanceTriggerManager;
|
2016-09-12 09:40:00 +02:00
|
|
|
class CGovernanceObject;
|
|
|
|
class CGovernanceVote;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
extern CGovernanceManager governance;
|
2016-04-09 21:57:53 +02:00
|
|
|
|
2016-11-24 19:12:05 +01:00
|
|
|
typedef std::pair<CGovernanceObject, int64_t> object_time_pair_t;
|
|
|
|
|
2016-12-14 16:28:55 +01:00
|
|
|
static const int RATE_BUFFER_SIZE = 5;
|
|
|
|
|
|
|
|
class CRateCheckBuffer {
|
|
|
|
private:
|
|
|
|
std::vector<int64_t> vecTimestamps;
|
|
|
|
|
|
|
|
int nDataStart;
|
|
|
|
|
|
|
|
int nDataEnd;
|
|
|
|
|
|
|
|
bool fBufferEmpty;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CRateCheckBuffer()
|
|
|
|
: vecTimestamps(RATE_BUFFER_SIZE),
|
|
|
|
nDataStart(0),
|
|
|
|
nDataEnd(0),
|
|
|
|
fBufferEmpty(true)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void AddTimestamp(int64_t nTimestamp)
|
|
|
|
{
|
|
|
|
if((nDataEnd == nDataStart) && !fBufferEmpty) {
|
|
|
|
// Buffer full, discard 1st element
|
|
|
|
nDataStart = (nDataStart + 1) % RATE_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
vecTimestamps[nDataEnd] = nTimestamp;
|
|
|
|
nDataEnd = (nDataEnd + 1) % RATE_BUFFER_SIZE;
|
|
|
|
fBufferEmpty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t GetMinTimestamp()
|
|
|
|
{
|
|
|
|
int nIndex = nDataStart;
|
|
|
|
int64_t nMin = numeric_limits<int64_t>::max();
|
|
|
|
if(fBufferEmpty) {
|
|
|
|
return nMin;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
if(vecTimestamps[nIndex] < nMin) {
|
|
|
|
nMin = vecTimestamps[nIndex];
|
|
|
|
}
|
|
|
|
nIndex = (nIndex + 1) % RATE_BUFFER_SIZE;
|
|
|
|
} while(nIndex != nDataEnd);
|
|
|
|
return nMin;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t GetMaxTimestamp()
|
|
|
|
{
|
|
|
|
int nIndex = nDataStart;
|
|
|
|
int64_t nMax = 0;
|
|
|
|
if(fBufferEmpty) {
|
|
|
|
return nMax;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
if(vecTimestamps[nIndex] > nMax) {
|
|
|
|
nMax = vecTimestamps[nIndex];
|
|
|
|
}
|
|
|
|
nIndex = (nIndex + 1) % RATE_BUFFER_SIZE;
|
|
|
|
} while(nIndex != nDataEnd);
|
|
|
|
return nMax;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetCount()
|
|
|
|
{
|
|
|
|
int nCount = 0;
|
|
|
|
if(fBufferEmpty) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(nDataEnd > nDataStart) {
|
|
|
|
nCount = nDataEnd - nDataStart;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nCount = RATE_BUFFER_SIZE - nDataStart + nDataEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
double GetRate()
|
|
|
|
{
|
|
|
|
int nCount = GetCount();
|
|
|
|
if(nCount < 2) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
int64_t nMin = GetMinTimestamp();
|
|
|
|
int64_t nMax = GetMaxTimestamp();
|
|
|
|
if(nMin == nMax) {
|
|
|
|
// multiple objects with the same timestamp => infinite rate
|
|
|
|
return 1.0e10;
|
|
|
|
}
|
|
|
|
return double(nCount) / double(nMax - nMin);
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
|
|
|
|
{
|
|
|
|
READWRITE(vecTimestamps);
|
|
|
|
READWRITE(nDataStart);
|
|
|
|
READWRITE(nDataEnd);
|
|
|
|
READWRITE(fBufferEmpty);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-05 18:30:08 +02:00
|
|
|
enum update_mode_enum_t {
|
|
|
|
UPDATE_FALSE,
|
|
|
|
UPDATE_TRUE,
|
|
|
|
UPDATE_FAIL_ONLY
|
|
|
|
};
|
|
|
|
|
2016-04-09 21:57:53 +02:00
|
|
|
//
|
2016-04-09 22:31:01 +02:00
|
|
|
// Governance Manager : Contains all proposals for the budget
|
2016-04-09 21:57:53 +02:00
|
|
|
//
|
2016-04-09 22:31:01 +02:00
|
|
|
class CGovernanceManager
|
2016-04-09 21:57:53 +02:00
|
|
|
{
|
2016-11-13 18:52:34 +01:00
|
|
|
friend class CGovernanceObject;
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
public: // Types
|
2016-12-08 21:00:49 +01:00
|
|
|
struct last_object_rec {
|
2016-12-14 16:28:55 +01:00
|
|
|
last_object_rec(bool fStatusOKIn = true)
|
|
|
|
: triggerBuffer(),
|
|
|
|
watchdogBuffer(),
|
2016-12-11 07:17:38 +01:00
|
|
|
fStatusOK(fStatusOKIn)
|
2016-12-08 21:00:49 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
|
|
|
|
{
|
2016-12-14 16:28:55 +01:00
|
|
|
READWRITE(triggerBuffer);
|
|
|
|
READWRITE(watchdogBuffer);
|
2016-12-11 07:17:38 +01:00
|
|
|
READWRITE(fStatusOK);
|
2016-12-08 21:00:49 +01:00
|
|
|
}
|
|
|
|
|
2016-12-14 16:28:55 +01:00
|
|
|
CRateCheckBuffer triggerBuffer;
|
|
|
|
CRateCheckBuffer watchdogBuffer;
|
2016-12-11 07:17:38 +01:00
|
|
|
bool fStatusOK;
|
2016-12-08 21:00:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
typedef std::map<uint256, CGovernanceObject> object_m_t;
|
|
|
|
|
|
|
|
typedef object_m_t::iterator object_m_it;
|
|
|
|
|
|
|
|
typedef object_m_t::const_iterator object_m_cit;
|
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
typedef CacheMap<uint256, CGovernanceObject*> object_ref_cache_t;
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
typedef std::map<uint256, CGovernanceVote> vote_m_t;
|
|
|
|
|
|
|
|
typedef vote_m_t::iterator vote_m_it;
|
|
|
|
|
|
|
|
typedef vote_m_t::const_iterator vote_m_cit;
|
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
typedef CacheMap<uint256, CGovernanceVote> vote_cache_t;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-11-24 19:12:05 +01:00
|
|
|
typedef CacheMultiMap<uint256, vote_time_pair_t> vote_mcache_t;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
typedef object_m_t::size_type size_type;
|
|
|
|
|
2016-12-08 21:00:49 +01:00
|
|
|
typedef std::map<COutPoint, last_object_rec > txout_m_t;
|
2016-09-15 08:49:24 +02:00
|
|
|
|
|
|
|
typedef txout_m_t::iterator txout_m_it;
|
|
|
|
|
|
|
|
typedef txout_m_t::const_iterator txout_m_cit;
|
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
typedef std::set<uint256> hash_s_t;
|
|
|
|
|
|
|
|
typedef hash_s_t::iterator hash_s_it;
|
|
|
|
|
|
|
|
typedef hash_s_t::const_iterator hash_s_cit;
|
|
|
|
|
2016-11-24 19:12:05 +01:00
|
|
|
typedef std::map<uint256, object_time_pair_t> object_time_m_t;
|
|
|
|
|
|
|
|
typedef object_time_m_t::iterator object_time_m_it;
|
|
|
|
|
|
|
|
typedef object_time_m_t::const_iterator object_time_m_cit;
|
|
|
|
|
2016-11-25 15:08:48 +01:00
|
|
|
typedef std::map<uint256, int64_t> hash_time_m_t;
|
|
|
|
|
|
|
|
typedef hash_time_m_t::iterator hash_time_m_it;
|
|
|
|
|
|
|
|
typedef hash_time_m_t::const_iterator hash_time_m_cit;
|
|
|
|
|
2016-04-09 21:57:53 +02:00
|
|
|
private:
|
2016-11-13 18:52:34 +01:00
|
|
|
static const int MAX_CACHE_SIZE = 1000000;
|
|
|
|
|
|
|
|
static const std::string SERIALIZATION_VERSION_STRING;
|
2016-04-09 21:57:53 +02:00
|
|
|
|
2017-07-05 02:31:50 +02:00
|
|
|
static const int MAX_TIME_FUTURE_DEVIATION;
|
|
|
|
static const int RELIABLE_PROPAGATION_TIME;
|
|
|
|
|
2016-04-09 21:57:53 +02:00
|
|
|
// Keep track of current block index
|
|
|
|
const CBlockIndex *pCurrentBlockIndex;
|
|
|
|
|
2016-04-19 18:51:15 +02:00
|
|
|
int64_t nTimeLastDiff;
|
2016-08-17 09:08:25 +02:00
|
|
|
int nCachedBlockHeight;
|
2016-04-19 18:51:15 +02:00
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
// keep track of the scanning errors
|
|
|
|
object_m_t mapObjects;
|
2016-04-09 21:57:53 +02:00
|
|
|
|
2017-07-12 22:08:06 +02:00
|
|
|
// mapErasedGovernanceObjects contains key-value pairs, where
|
|
|
|
// key - governance object's hash
|
|
|
|
// value - expiration time for deleted objects
|
|
|
|
hash_time_m_t mapErasedGovernanceObjects;
|
2016-06-08 08:57:16 +02:00
|
|
|
|
2016-11-24 19:12:05 +01:00
|
|
|
object_time_m_t mapMasternodeOrphanObjects;
|
2016-11-12 02:51:45 +01:00
|
|
|
|
2017-07-05 02:31:50 +02:00
|
|
|
object_m_t mapPostponedObjects;
|
|
|
|
hash_s_t setAdditionalRelayObjects;
|
|
|
|
|
2016-11-25 15:08:48 +01:00
|
|
|
hash_time_m_t mapWatchdogObjects;
|
|
|
|
|
2017-02-22 19:29:30 +01:00
|
|
|
uint256 nHashWatchdogCurrent;
|
|
|
|
|
|
|
|
int64_t nTimeWatchdogCurrent;
|
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
object_ref_cache_t mapVoteToObject;
|
|
|
|
|
|
|
|
vote_cache_t mapInvalidVotes;
|
|
|
|
|
|
|
|
vote_mcache_t mapOrphanVotes;
|
2016-04-09 21:57:53 +02:00
|
|
|
|
2016-12-08 21:00:49 +01:00
|
|
|
txout_m_t mapLastMasternodeObject;
|
2016-09-05 01:44:10 +02:00
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
hash_s_t setRequestedObjects;
|
|
|
|
|
|
|
|
hash_s_t setRequestedVotes;
|
|
|
|
|
2016-11-18 15:17:22 +01:00
|
|
|
bool fRateChecksEnabled;
|
|
|
|
|
2017-07-05 02:31:50 +02:00
|
|
|
class CRateChecksGuard
|
|
|
|
{
|
|
|
|
CGovernanceManager& govman;
|
|
|
|
bool fRateChecksPrev;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CRateChecksGuard(bool value, CGovernanceManager& gm) : govman(gm)
|
|
|
|
{
|
|
|
|
ENTER_CRITICAL_SECTION(govman.cs)
|
|
|
|
fRateChecksPrev = govman.fRateChecksEnabled;
|
|
|
|
govman.fRateChecksEnabled = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
~CRateChecksGuard()
|
|
|
|
{
|
|
|
|
govman.fRateChecksEnabled = fRateChecksPrev;
|
|
|
|
LEAVE_CRITICAL_SECTION(govman.cs)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
public:
|
|
|
|
// critical section to protect the inner data structures
|
|
|
|
mutable CCriticalSection cs;
|
2016-09-12 09:40:00 +02:00
|
|
|
|
2016-09-05 01:44:10 +02:00
|
|
|
CGovernanceManager();
|
2016-04-09 21:57:53 +02:00
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
virtual ~CGovernanceManager() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called by AlreadyHave in main.cpp as part of the inventory
|
|
|
|
* retrieval process. Returns true if we want to retrieve the object, otherwise
|
|
|
|
* false. (Note logic is inverted in AlreadyHave).
|
|
|
|
*/
|
|
|
|
bool ConfirmInventoryRequest(const CInv& inv);
|
|
|
|
|
2017-02-02 09:50:44 +01:00
|
|
|
void Sync(CNode* node, const uint256& nProp, const CBloomFilter& filter);
|
2016-11-13 18:52:34 +01:00
|
|
|
|
2016-04-09 21:57:53 +02:00
|
|
|
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
2016-11-13 18:52:34 +01:00
|
|
|
|
2017-03-06 08:46:59 +01:00
|
|
|
void DoMaintenance();
|
2016-04-09 22:31:01 +02:00
|
|
|
|
2016-06-08 08:57:16 +02:00
|
|
|
CGovernanceObject *FindGovernanceObject(const uint256& nHash);
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
std::vector<CGovernanceVote> GetMatchingVotes(const uint256& nParentHash);
|
2016-11-22 20:26:36 +01:00
|
|
|
std::vector<CGovernanceVote> GetCurrentVotes(const uint256& nParentHash, const CTxIn& mnCollateralOutpointFilter);
|
2016-08-17 09:08:25 +02:00
|
|
|
std::vector<CGovernanceObject*> GetAllNewerThan(int64_t nMoreThanTime);
|
2016-04-09 22:31:01 +02:00
|
|
|
|
2016-04-09 21:57:53 +02:00
|
|
|
bool IsBudgetPaymentBlock(int nBlockHeight);
|
2017-07-05 02:31:50 +02:00
|
|
|
void AddGovernanceObject(CGovernanceObject& govobj, CNode* pfrom = NULL);
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-04-09 21:57:53 +02:00
|
|
|
std::string GetRequiredPaymentsString(int nBlockHeight);
|
2016-11-13 18:52:34 +01:00
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
void UpdateCachesAndClean();
|
2016-04-09 21:57:53 +02:00
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
void CheckAndRemove() {UpdateCachesAndClean();}
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
void Clear()
|
|
|
|
{
|
2016-04-09 21:57:53 +02:00
|
|
|
LOCK(cs);
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
LogPrint("gobject", "Governance object manager was cleared\n");
|
2016-05-13 18:03:01 +02:00
|
|
|
mapObjects.clear();
|
2017-07-12 22:08:06 +02:00
|
|
|
mapErasedGovernanceObjects.clear();
|
2016-11-29 01:01:03 +01:00
|
|
|
mapWatchdogObjects.clear();
|
2017-02-22 19:29:30 +01:00
|
|
|
nHashWatchdogCurrent = uint256();
|
|
|
|
nTimeWatchdogCurrent = 0;
|
2016-11-13 18:52:34 +01:00
|
|
|
mapVoteToObject.Clear();
|
|
|
|
mapInvalidVotes.Clear();
|
|
|
|
mapOrphanVotes.Clear();
|
2016-12-08 21:00:49 +01:00
|
|
|
mapLastMasternodeObject.clear();
|
2016-04-09 21:57:53 +02:00
|
|
|
}
|
2016-09-12 09:40:00 +02:00
|
|
|
|
2016-04-09 21:57:53 +02:00
|
|
|
std::string ToString() const;
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
2016-08-17 09:08:25 +02:00
|
|
|
LOCK(cs);
|
2016-11-13 18:52:34 +01:00
|
|
|
std::string strVersion;
|
|
|
|
if(ser_action.ForRead()) {
|
|
|
|
READWRITE(strVersion);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strVersion = SERIALIZATION_VERSION_STRING;
|
|
|
|
READWRITE(strVersion);
|
|
|
|
}
|
2017-07-12 22:08:06 +02:00
|
|
|
|
|
|
|
READWRITE(mapErasedGovernanceObjects);
|
2016-11-13 18:52:34 +01:00
|
|
|
READWRITE(mapInvalidVotes);
|
2016-05-23 19:58:39 +02:00
|
|
|
READWRITE(mapOrphanVotes);
|
2016-05-13 18:03:01 +02:00
|
|
|
READWRITE(mapObjects);
|
2016-11-29 01:01:03 +01:00
|
|
|
READWRITE(mapWatchdogObjects);
|
2017-02-22 19:29:30 +01:00
|
|
|
READWRITE(nHashWatchdogCurrent);
|
|
|
|
READWRITE(nTimeWatchdogCurrent);
|
2016-12-08 21:00:49 +01:00
|
|
|
READWRITE(mapLastMasternodeObject);
|
2016-11-13 18:52:34 +01:00
|
|
|
if(ser_action.ForRead() && (strVersion != SERIALIZATION_VERSION_STRING)) {
|
|
|
|
Clear();
|
|
|
|
return;
|
|
|
|
}
|
2016-04-09 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatedBlockTip(const CBlockIndex *pindex);
|
2016-09-12 09:40:00 +02:00
|
|
|
int64_t GetLastDiffTime() { return nTimeLastDiff; }
|
|
|
|
void UpdateLastDiffTime(int64_t nTimeIn) { nTimeLastDiff = nTimeIn; }
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
int GetCachedBlockHeight() { return nCachedBlockHeight; }
|
|
|
|
|
|
|
|
// Accessors for thread-safe access to maps
|
|
|
|
bool HaveObjectForHash(uint256 nHash);
|
|
|
|
|
|
|
|
bool HaveVoteForHash(uint256 nHash);
|
|
|
|
|
2017-02-17 21:08:41 +01:00
|
|
|
int GetVoteCount() const;
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
bool SerializeObjectForHash(uint256 nHash, CDataStream& ss);
|
|
|
|
|
|
|
|
bool SerializeVoteForHash(uint256 nHash, CDataStream& ss);
|
|
|
|
|
2017-07-05 02:31:50 +02:00
|
|
|
void AddPostponedObject(const CGovernanceObject& govobj)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
mapPostponedObjects.insert(std::make_pair(govobj.GetHash(), govobj));
|
|
|
|
}
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
void AddSeenGovernanceObject(uint256 nHash, int status);
|
|
|
|
|
|
|
|
void AddSeenVote(uint256 nHash, int status);
|
|
|
|
|
2017-04-05 18:30:08 +02:00
|
|
|
bool MasternodeRateCheck(const CGovernanceObject& govobj, update_mode_enum_t eUpdateLast = UPDATE_FALSE);
|
2016-09-05 01:44:10 +02:00
|
|
|
|
2017-04-05 18:30:08 +02:00
|
|
|
bool MasternodeRateCheck(const CGovernanceObject& govobj, update_mode_enum_t eUpdateLast, bool fForce, bool& fRateCheckBypassed);
|
2016-12-11 07:17:38 +01:00
|
|
|
|
2016-12-07 05:16:34 +01:00
|
|
|
bool ProcessVoteAndRelay(const CGovernanceVote& vote, CGovernanceException& exception) {
|
|
|
|
bool fOK = ProcessVote(NULL, vote, exception);
|
|
|
|
if(fOK) {
|
|
|
|
vote.Relay();
|
|
|
|
}
|
|
|
|
return fOK;
|
2016-11-13 18:52:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckMasternodeOrphanVotes();
|
|
|
|
|
2016-11-12 02:51:45 +01:00
|
|
|
void CheckMasternodeOrphanObjects();
|
|
|
|
|
2017-07-05 02:31:50 +02:00
|
|
|
void CheckPostponedObjects();
|
|
|
|
|
2016-11-18 15:17:22 +01:00
|
|
|
bool AreRateChecksEnabled() const {
|
|
|
|
LOCK(cs);
|
|
|
|
return fRateChecksEnabled;
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:21:50 +01:00
|
|
|
void InitOnLoad();
|
|
|
|
|
2017-02-17 21:08:41 +01:00
|
|
|
int RequestGovernanceObjectVotes(CNode* pnode);
|
|
|
|
int RequestGovernanceObjectVotes(const std::vector<CNode*>& vNodesCopy);
|
2017-01-17 21:02:38 +01:00
|
|
|
|
2016-11-05 17:13:30 +01:00
|
|
|
private:
|
2017-02-02 09:50:44 +01:00
|
|
|
void RequestGovernanceObject(CNode* pfrom, const uint256& nHash, bool fUseFilter = false);
|
2016-11-13 18:52:34 +01:00
|
|
|
|
|
|
|
void AddInvalidVote(const CGovernanceVote& vote)
|
|
|
|
{
|
|
|
|
mapInvalidVotes.Insert(vote.GetHash(), vote);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddOrphanVote(const CGovernanceVote& vote)
|
|
|
|
{
|
2016-11-24 19:12:05 +01:00
|
|
|
mapOrphanVotes.Insert(vote.GetHash(), vote_time_pair_t(vote, GetAdjustedTime() + GOVERNANCE_ORPHAN_EXPIRATION_TIME));
|
2016-11-13 18:52:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessVote(CNode* pfrom, const CGovernanceVote& vote, CGovernanceException& exception);
|
|
|
|
|
|
|
|
/// Called to indicate a requested object has been received
|
|
|
|
bool AcceptObjectMessage(const uint256& nHash);
|
|
|
|
|
|
|
|
/// Called to indicate a requested vote has been received
|
|
|
|
bool AcceptVoteMessage(const uint256& nHash);
|
|
|
|
|
|
|
|
static bool AcceptMessage(const uint256& nHash, hash_s_t& setHash);
|
|
|
|
|
2016-12-02 13:53:18 +01:00
|
|
|
void CheckOrphanVotes(CGovernanceObject& govobj, CGovernanceException& exception);
|
2016-11-13 18:52:34 +01:00
|
|
|
|
|
|
|
void RebuildIndexes();
|
|
|
|
|
|
|
|
/// Returns MN index, handling the case of index rebuilds
|
|
|
|
int GetMasternodeIndex(const CTxIn& masternodeVin);
|
|
|
|
|
|
|
|
void RebuildVoteMaps();
|
|
|
|
|
2016-11-05 17:13:30 +01:00
|
|
|
void AddCachedTriggers();
|
|
|
|
|
2017-02-22 19:29:30 +01:00
|
|
|
bool UpdateCurrentWatchdog(CGovernanceObject& watchdogNew);
|
|
|
|
|
2017-03-06 08:46:59 +01:00
|
|
|
void RequestOrphanObjects();
|
|
|
|
|
|
|
|
void CleanOrphanObjects();
|
|
|
|
|
2016-04-09 21:57:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|