2018-09-28 09:56:17 +02:00
|
|
|
// Copyright (c) 2014-2018 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
|
|
|
|
2018-03-15 20:09:06 +01:00
|
|
|
#include <univalue.h>
|
|
|
|
|
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
|
|
|
|
2017-07-13 11:38:00 +02:00
|
|
|
struct ExpirationInfo {
|
2018-09-28 09:56:17 +02:00
|
|
|
ExpirationInfo(int64_t _nExpirationTime, int _idFrom) :
|
|
|
|
nExpirationTime(_nExpirationTime), idFrom(_idFrom) {}
|
2017-07-13 11:38:00 +02:00
|
|
|
|
|
|
|
int64_t nExpirationTime;
|
|
|
|
NodeId idFrom;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::pair<CGovernanceObject, ExpirationInfo> object_info_pair_t;
|
2016-11-24 19:12:05 +01:00
|
|
|
|
2016-12-14 16:28:55 +01:00
|
|
|
static const int RATE_BUFFER_SIZE = 5;
|
|
|
|
|
2018-04-20 12:53:23 +02:00
|
|
|
class CRateCheckBuffer
|
|
|
|
{
|
2016-12-14 16:28:55 +01:00
|
|
|
private:
|
|
|
|
std::vector<int64_t> vecTimestamps;
|
|
|
|
|
|
|
|
int nDataStart;
|
|
|
|
|
|
|
|
int nDataEnd;
|
|
|
|
|
|
|
|
bool fBufferEmpty;
|
|
|
|
|
|
|
|
public:
|
2018-09-28 09:56:17 +02:00
|
|
|
CRateCheckBuffer() :
|
|
|
|
vecTimestamps(RATE_BUFFER_SIZE),
|
|
|
|
nDataStart(0),
|
|
|
|
nDataEnd(0),
|
|
|
|
fBufferEmpty(true)
|
|
|
|
{
|
|
|
|
}
|
2016-12-14 16:28:55 +01:00
|
|
|
|
|
|
|
void AddTimestamp(int64_t nTimestamp)
|
|
|
|
{
|
2018-09-28 09:56:17 +02:00
|
|
|
if ((nDataEnd == nDataStart) && !fBufferEmpty) {
|
2016-12-14 16:28:55 +01:00
|
|
|
// 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;
|
2018-02-21 20:26:53 +01:00
|
|
|
int64_t nMin = std::numeric_limits<int64_t>::max();
|
2018-09-28 09:56:17 +02:00
|
|
|
if (fBufferEmpty) {
|
2016-12-14 16:28:55 +01:00
|
|
|
return nMin;
|
|
|
|
}
|
|
|
|
do {
|
2018-09-28 09:56:17 +02:00
|
|
|
if (vecTimestamps[nIndex] < nMin) {
|
2016-12-14 16:28:55 +01:00
|
|
|
nMin = vecTimestamps[nIndex];
|
|
|
|
}
|
|
|
|
nIndex = (nIndex + 1) % RATE_BUFFER_SIZE;
|
2018-09-28 09:56:17 +02:00
|
|
|
} while (nIndex != nDataEnd);
|
2016-12-14 16:28:55 +01:00
|
|
|
return nMin;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t GetMaxTimestamp()
|
|
|
|
{
|
|
|
|
int nIndex = nDataStart;
|
|
|
|
int64_t nMax = 0;
|
2018-09-28 09:56:17 +02:00
|
|
|
if (fBufferEmpty) {
|
2016-12-14 16:28:55 +01:00
|
|
|
return nMax;
|
|
|
|
}
|
|
|
|
do {
|
2018-09-28 09:56:17 +02:00
|
|
|
if (vecTimestamps[nIndex] > nMax) {
|
2016-12-14 16:28:55 +01:00
|
|
|
nMax = vecTimestamps[nIndex];
|
|
|
|
}
|
|
|
|
nIndex = (nIndex + 1) % RATE_BUFFER_SIZE;
|
2018-09-28 09:56:17 +02:00
|
|
|
} while (nIndex != nDataEnd);
|
2016-12-14 16:28:55 +01:00
|
|
|
return nMax;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetCount()
|
|
|
|
{
|
|
|
|
int nCount = 0;
|
2018-09-28 09:56:17 +02:00
|
|
|
if (fBufferEmpty) {
|
2016-12-14 16:28:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2018-09-28 09:56:17 +02:00
|
|
|
if (nDataEnd > nDataStart) {
|
2016-12-14 16:28:55 +01:00
|
|
|
nCount = nDataEnd - nDataStart;
|
2018-09-28 09:56:17 +02:00
|
|
|
} else {
|
2016-12-14 16:28:55 +01:00
|
|
|
nCount = RATE_BUFFER_SIZE - nDataStart + nDataEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
double GetRate()
|
|
|
|
{
|
|
|
|
int nCount = GetCount();
|
2018-09-28 09:56:17 +02:00
|
|
|
if (nCount < RATE_BUFFER_SIZE) {
|
2016-12-14 16:28:55 +01:00
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
int64_t nMin = GetMinTimestamp();
|
|
|
|
int64_t nMax = GetMaxTimestamp();
|
2018-09-28 09:56:17 +02:00
|
|
|
if (nMin == nMax) {
|
2016-12-14 16:28:55 +01:00
|
|
|
// 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>
|
2017-09-19 21:36:55 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action)
|
2016-12-14 16:28:55 +01:00
|
|
|
{
|
|
|
|
READWRITE(vecTimestamps);
|
|
|
|
READWRITE(nDataStart);
|
|
|
|
READWRITE(nDataEnd);
|
|
|
|
READWRITE(fBufferEmpty);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 {
|
2018-09-28 09:56:17 +02:00
|
|
|
last_object_rec(bool fStatusOKIn = true) :
|
|
|
|
triggerBuffer(),
|
|
|
|
fStatusOK(fStatusOKIn)
|
|
|
|
{
|
|
|
|
}
|
2016-12-08 21:00:49 +01:00
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2017-09-19 21:36:55 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action)
|
2016-12-08 21:00:49 +01:00
|
|
|
{
|
2016-12-14 16:28:55 +01:00
|
|
|
READWRITE(triggerBuffer);
|
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;
|
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;
|
|
|
|
|
2018-02-06 12:08:43 +01:00
|
|
|
typedef CacheMap<uint256, CGovernanceObject*> object_ref_cm_t;
|
2016-11-13 18:52:34 +01:00
|
|
|
|
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;
|
|
|
|
|
2018-02-06 12:08:43 +01:00
|
|
|
typedef CacheMap<uint256, CGovernanceVote> vote_cm_t;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2018-02-06 12:08:43 +01:00
|
|
|
typedef CacheMultiMap<uint256, vote_time_pair_t> vote_cmm_t;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
typedef object_m_t::size_type size_type;
|
|
|
|
|
2018-09-28 09:56:17 +02: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;
|
|
|
|
|
2017-07-13 11:38:00 +02:00
|
|
|
typedef std::map<COutPoint, int> txout_int_m_t;
|
|
|
|
|
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;
|
|
|
|
|
2017-07-13 11:38:00 +02:00
|
|
|
typedef std::map<uint256, object_info_pair_t> object_info_m_t;
|
2016-11-24 19:12:05 +01:00
|
|
|
|
2017-07-13 11:38:00 +02:00
|
|
|
typedef object_info_m_t::iterator object_info_m_it;
|
2016-11-24 19:12:05 +01:00
|
|
|
|
2017-07-13 11:38:00 +02:00
|
|
|
typedef object_info_m_t::const_iterator object_info_m_cit;
|
2016-11-24 19:12:05 +01:00
|
|
|
|
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-19 18:51:15 +02:00
|
|
|
int64_t nTimeLastDiff;
|
2017-08-25 14:57:05 +02:00
|
|
|
|
|
|
|
// keep track of current block height
|
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
|
|
|
|
2017-07-13 11:38:00 +02:00
|
|
|
object_info_m_t mapMasternodeOrphanObjects;
|
|
|
|
txout_int_m_t mapMasternodeOrphanCounter;
|
2016-11-12 02:51:45 +01:00
|
|
|
|
2017-07-05 02:31:50 +02:00
|
|
|
object_m_t mapPostponedObjects;
|
|
|
|
hash_s_t setAdditionalRelayObjects;
|
|
|
|
|
2018-02-06 12:08:43 +01:00
|
|
|
object_ref_cm_t cmapVoteToObject;
|
2016-11-13 18:52:34 +01:00
|
|
|
|
2018-02-06 12:08:43 +01:00
|
|
|
vote_cm_t cmapInvalidVotes;
|
2016-11-13 18:52:34 +01:00
|
|
|
|
2018-02-06 12:08:43 +01:00
|
|
|
vote_cmm_t cmmapOrphanVotes;
|
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-09-15 20:05:03 +02:00
|
|
|
class ScopedLockBool
|
2017-07-05 02:31:50 +02:00
|
|
|
{
|
2017-09-15 20:05:03 +02:00
|
|
|
bool& ref;
|
|
|
|
bool fPrevValue;
|
2017-07-05 02:31:50 +02:00
|
|
|
|
|
|
|
public:
|
2018-09-28 09:56:17 +02:00
|
|
|
ScopedLockBool(CCriticalSection& _cs, bool& _ref, bool _value) :
|
|
|
|
ref(_ref)
|
2017-07-05 02:31:50 +02:00
|
|
|
{
|
2017-09-15 20:05:03 +02:00
|
|
|
AssertLockHeld(_cs);
|
|
|
|
fPrevValue = ref;
|
|
|
|
ref = _value;
|
2017-07-05 02:31:50 +02:00
|
|
|
}
|
|
|
|
|
2017-09-15 20:05:03 +02:00
|
|
|
~ScopedLockBool()
|
2017-07-05 02:31:50 +02:00
|
|
|
{
|
2017-09-15 20:05:03 +02:00
|
|
|
ref = fPrevValue;
|
2017-07-05 02:31:50 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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() {}
|
|
|
|
|
|
|
|
/**
|
2017-02-16 14:01:00 +01:00
|
|
|
* This is called by AlreadyHave in net_processing.cpp as part of the inventory
|
2016-11-13 18:52:34 +01:00
|
|
|
* retrieval process. Returns true if we want to retrieve the object, otherwise
|
|
|
|
* false. (Note logic is inverted in AlreadyHave).
|
|
|
|
*/
|
|
|
|
bool ConfirmInventoryRequest(const CInv& inv);
|
|
|
|
|
2018-02-12 13:49:28 +01:00
|
|
|
void SyncSingleObjAndItsVotes(CNode* pnode, const uint256& nProp, const CBloomFilter& filter, CConnman& connman);
|
2018-03-20 12:04:59 +01:00
|
|
|
void SyncAll(CNode* pnode, CConnman& connman) const;
|
2016-11-13 18:52:34 +01:00
|
|
|
|
2017-02-06 14:31:37 +01:00
|
|
|
void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);
|
2016-11-13 18:52:34 +01:00
|
|
|
|
2017-09-19 16:51:38 +02:00
|
|
|
void DoMaintenance(CConnman& connman);
|
2016-04-09 22:31:01 +02:00
|
|
|
|
2018-03-20 12:04:59 +01:00
|
|
|
CGovernanceObject* FindGovernanceObject(const uint256& nHash);
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2018-04-20 12:53:23 +02:00
|
|
|
// These commands are only used in RPC
|
2018-03-20 12:04:59 +01:00
|
|
|
std::vector<CGovernanceVote> GetMatchingVotes(const uint256& nParentHash) const;
|
|
|
|
std::vector<CGovernanceVote> GetCurrentVotes(const uint256& nParentHash, const COutPoint& mnCollateralOutpointFilter) const;
|
|
|
|
std::vector<const CGovernanceObject*> GetAllNewerThan(int64_t nMoreThanTime) const;
|
2016-04-09 22:31:01 +02:00
|
|
|
|
2018-07-12 11:08:43 +02:00
|
|
|
void AddGovernanceObject(CGovernanceObject& govobj, CConnman& connman, CNode* pfrom = nullptr);
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
void UpdateCachesAndClean();
|
2016-04-09 21:57:53 +02:00
|
|
|
|
2018-09-28 09:56:17 +02: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();
|
2018-02-06 12:08:43 +01:00
|
|
|
cmapVoteToObject.Clear();
|
|
|
|
cmapInvalidVotes.Clear();
|
|
|
|
cmmapOrphanVotes.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;
|
2018-03-15 20:09:06 +01:00
|
|
|
UniValue ToJson() const;
|
2016-04-09 21:57:53 +02:00
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2018-09-28 09:56:17 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action)
|
|
|
|
{
|
2016-08-17 09:08:25 +02:00
|
|
|
LOCK(cs);
|
2016-11-13 18:52:34 +01:00
|
|
|
std::string strVersion;
|
2018-09-28 09:56:17 +02:00
|
|
|
if (ser_action.ForRead()) {
|
2016-11-13 18:52:34 +01:00
|
|
|
READWRITE(strVersion);
|
2018-09-28 09:56:17 +02:00
|
|
|
} else {
|
2016-11-13 18:52:34 +01:00
|
|
|
strVersion = SERIALIZATION_VERSION_STRING;
|
|
|
|
READWRITE(strVersion);
|
|
|
|
}
|
2017-07-12 22:08:06 +02:00
|
|
|
|
|
|
|
READWRITE(mapErasedGovernanceObjects);
|
2018-02-06 12:08:43 +01:00
|
|
|
READWRITE(cmapInvalidVotes);
|
|
|
|
READWRITE(cmmapOrphanVotes);
|
2016-05-13 18:03:01 +02:00
|
|
|
READWRITE(mapObjects);
|
2016-12-08 21:00:49 +01:00
|
|
|
READWRITE(mapLastMasternodeObject);
|
2018-09-28 09:56:17 +02:00
|
|
|
if (ser_action.ForRead() && (strVersion != SERIALIZATION_VERSION_STRING)) {
|
2016-11-13 18:52:34 +01:00
|
|
|
Clear();
|
|
|
|
return;
|
|
|
|
}
|
2016-04-09 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:56:17 +02:00
|
|
|
void UpdatedBlockTip(const CBlockIndex* pindex, CConnman& connman);
|
2018-03-20 12:04:59 +01:00
|
|
|
int64_t GetLastDiffTime() const { return nTimeLastDiff; }
|
2016-09-12 09:40:00 +02:00
|
|
|
void UpdateLastDiffTime(int64_t nTimeIn) { nTimeLastDiff = nTimeIn; }
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2018-03-20 12:04:59 +01:00
|
|
|
int GetCachedBlockHeight() const { return nCachedBlockHeight; }
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
// Accessors for thread-safe access to maps
|
2018-03-20 12:04:59 +01:00
|
|
|
bool HaveObjectForHash(const uint256& nHash) const;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2018-03-20 12:04:59 +01:00
|
|
|
bool HaveVoteForHash(const uint256& nHash) const;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2017-02-17 21:08:41 +01:00
|
|
|
int GetVoteCount() const;
|
|
|
|
|
2018-03-20 12:04:59 +01:00
|
|
|
bool SerializeObjectForHash(const uint256& nHash, CDataStream& ss) const;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2018-03-20 12:04:59 +01:00
|
|
|
bool SerializeVoteForHash(const uint256& nHash, CDataStream& ss) const;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2017-07-05 02:31:50 +02:00
|
|
|
void AddPostponedObject(const CGovernanceObject& govobj)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
mapPostponedObjects.insert(std::make_pair(govobj.GetHash(), govobj));
|
|
|
|
}
|
|
|
|
|
2018-03-20 12:04:59 +01:00
|
|
|
void AddSeenGovernanceObject(const uint256& nHash, int status);
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2018-03-20 12:04:59 +01:00
|
|
|
void AddSeenVote(const uint256& nHash, int status);
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2017-08-23 16:22:23 +02:00
|
|
|
void MasternodeRateUpdate(const CGovernanceObject& govobj);
|
|
|
|
|
|
|
|
bool MasternodeRateCheck(const CGovernanceObject& govobj, bool fUpdateFailStatus = false);
|
2016-09-05 01:44:10 +02:00
|
|
|
|
2017-08-23 16:22:23 +02:00
|
|
|
bool MasternodeRateCheck(const CGovernanceObject& govobj, bool fUpdateFailStatus, bool fForce, bool& fRateCheckBypassed);
|
2016-12-11 07:17:38 +01:00
|
|
|
|
2018-09-28 09:56:17 +02:00
|
|
|
bool ProcessVoteAndRelay(const CGovernanceVote& vote, CGovernanceException& exception, CConnman& connman)
|
|
|
|
{
|
2018-07-12 11:08:43 +02:00
|
|
|
bool fOK = ProcessVote(nullptr, vote, exception, connman);
|
2018-09-28 09:56:17 +02:00
|
|
|
if (fOK) {
|
2017-09-19 16:51:38 +02:00
|
|
|
vote.Relay(connman);
|
2016-12-07 05:16:34 +01:00
|
|
|
}
|
|
|
|
return fOK;
|
2016-11-13 18:52:34 +01:00
|
|
|
}
|
|
|
|
|
2017-09-19 16:51:38 +02:00
|
|
|
void CheckMasternodeOrphanVotes(CConnman& connman);
|
2016-11-13 18:52:34 +01:00
|
|
|
|
2017-09-19 16:51:38 +02:00
|
|
|
void CheckMasternodeOrphanObjects(CConnman& connman);
|
2016-11-12 02:51:45 +01:00
|
|
|
|
2017-09-19 16:51:38 +02:00
|
|
|
void CheckPostponedObjects(CConnman& connman);
|
2017-07-05 02:31:50 +02:00
|
|
|
|
2018-09-28 09:56:17 +02:00
|
|
|
bool AreRateChecksEnabled() const
|
|
|
|
{
|
2016-11-18 15:17:22 +01:00
|
|
|
LOCK(cs);
|
|
|
|
return fRateChecksEnabled;
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:21:50 +01:00
|
|
|
void InitOnLoad();
|
|
|
|
|
2017-09-19 16:51:38 +02:00
|
|
|
int RequestGovernanceObjectVotes(CNode* pnode, CConnman& connman);
|
|
|
|
int RequestGovernanceObjectVotes(const std::vector<CNode*>& vNodesCopy, CConnman& connman);
|
2017-01-17 21:02:38 +01:00
|
|
|
|
2016-11-05 17:13:30 +01:00
|
|
|
private:
|
2017-09-19 16:51:38 +02:00
|
|
|
void RequestGovernanceObject(CNode* pfrom, const uint256& nHash, CConnman& connman, bool fUseFilter = false);
|
2016-11-13 18:52:34 +01:00
|
|
|
|
|
|
|
void AddInvalidVote(const CGovernanceVote& vote)
|
|
|
|
{
|
2018-02-06 12:08:43 +01:00
|
|
|
cmapInvalidVotes.Insert(vote.GetHash(), vote);
|
2016-11-13 18:52:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddOrphanVote(const CGovernanceVote& vote)
|
|
|
|
{
|
2018-02-06 12:08:43 +01:00
|
|
|
cmmapOrphanVotes.Insert(vote.GetHash(), vote_time_pair_t(vote, GetAdjustedTime() + GOVERNANCE_ORPHAN_EXPIRATION_TIME));
|
2016-11-13 18:52:34 +01:00
|
|
|
}
|
|
|
|
|
2017-09-19 16:51:38 +02:00
|
|
|
bool ProcessVote(CNode* pfrom, const CGovernanceVote& vote, CGovernanceException& exception, CConnman& connman);
|
2016-11-13 18:52:34 +01:00
|
|
|
|
|
|
|
/// 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);
|
|
|
|
|
2017-09-19 16:51:38 +02:00
|
|
|
void CheckOrphanVotes(CGovernanceObject& govobj, CGovernanceException& exception, CConnman& connman);
|
2016-11-13 18:52:34 +01:00
|
|
|
|
|
|
|
void RebuildIndexes();
|
|
|
|
|
2016-11-05 17:13:30 +01:00
|
|
|
void AddCachedTriggers();
|
|
|
|
|
2017-09-19 16:51:38 +02:00
|
|
|
void RequestOrphanObjects(CConnman& connman);
|
2017-03-06 08:46:59 +01:00
|
|
|
|
|
|
|
void CleanOrphanObjects();
|
2018-11-29 19:51:53 +01:00
|
|
|
|
|
|
|
// TODO can be removed after full DIP3 deployment
|
|
|
|
unsigned int GetMinVoteTime();
|
|
|
|
void ClearPreDIP3Votes();
|
2016-04-09 21:57:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|