2016-12-20 14:26:45 +01:00
|
|
|
// Copyright (c) 2014-2017 The Dash Core developers
|
2014-12-09 02:17:57 +01:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2016-09-16 00:00:06 +02:00
|
|
|
|
2014-12-09 02:17:57 +01:00
|
|
|
#ifndef MASTERNODE_H
|
|
|
|
#define MASTERNODE_H
|
|
|
|
|
|
|
|
#include "key.h"
|
2017-08-09 02:19:06 +02:00
|
|
|
#include "validation.h"
|
2016-09-16 00:00:06 +02:00
|
|
|
#include "net.h"
|
2016-11-23 16:30:36 +01:00
|
|
|
#include "spork.h"
|
2015-04-03 00:51:08 +02:00
|
|
|
#include "timedata.h"
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
class CMasternode;
|
2015-04-17 17:10:38 +02:00
|
|
|
class CMasternodeBroadcast;
|
|
|
|
class CMasternodePing;
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2016-12-24 03:49:13 +01:00
|
|
|
static const int MASTERNODE_CHECK_SECONDS = 5;
|
|
|
|
static const int MASTERNODE_MIN_MNB_SECONDS = 5 * 60;
|
|
|
|
static const int MASTERNODE_MIN_MNP_SECONDS = 10 * 60;
|
|
|
|
static const int MASTERNODE_EXPIRATION_SECONDS = 65 * 60;
|
|
|
|
static const int MASTERNODE_WATCHDOG_MAX_SECONDS = 120 * 60;
|
|
|
|
static const int MASTERNODE_NEW_START_REQUIRED_SECONDS = 180 * 60;
|
|
|
|
|
|
|
|
static const int MASTERNODE_POSE_BAN_MAX_SCORE = 5;
|
2017-07-04 19:31:57 +02:00
|
|
|
|
2015-07-14 07:25:07 +02:00
|
|
|
//
|
|
|
|
// The Masternode Ping Class : Contains a different serialize method for sending pings from masternodes throughout the network
|
|
|
|
//
|
|
|
|
|
2017-07-10 16:41:42 +02:00
|
|
|
// sentinel version before sentinel ping implementation
|
|
|
|
#define DEFAULT_SENTINEL_VERSION 0x010001
|
|
|
|
|
2015-07-14 07:25:07 +02:00
|
|
|
class CMasternodePing
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTxIn vin;
|
|
|
|
uint256 blockHash;
|
|
|
|
int64_t sigTime; //mnb message times
|
|
|
|
std::vector<unsigned char> vchSig;
|
2017-07-04 19:31:57 +02:00
|
|
|
bool fSentinelIsCurrent; // true if last sentinel ping was actual
|
|
|
|
uint32_t nSentinelVersion; // MSB is always 0, other 3 bits corresponds to x.x.x version scheme
|
2015-07-14 07:25:07 +02:00
|
|
|
//removed stop
|
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
CMasternodePing() :
|
|
|
|
vin(),
|
|
|
|
blockHash(),
|
|
|
|
sigTime(0),
|
2017-07-04 19:31:57 +02:00
|
|
|
vchSig(),
|
|
|
|
fSentinelIsCurrent(false),
|
2017-07-10 16:41:42 +02:00
|
|
|
nSentinelVersion(DEFAULT_SENTINEL_VERSION)
|
2016-09-16 00:00:06 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
CMasternodePing(CTxIn& vinNew);
|
2015-07-14 07:25:07 +02:00
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
READWRITE(vin);
|
|
|
|
READWRITE(blockHash);
|
|
|
|
READWRITE(sigTime);
|
|
|
|
READWRITE(vchSig);
|
2017-07-04 19:31:57 +02:00
|
|
|
if(ser_action.ForRead() && (s.size() == 0))
|
2017-07-10 16:41:42 +02:00
|
|
|
{
|
|
|
|
fSentinelIsCurrent = false;
|
|
|
|
nSentinelVersion = DEFAULT_SENTINEL_VERSION;
|
2017-07-04 19:31:57 +02:00
|
|
|
return;
|
2017-07-10 16:41:42 +02:00
|
|
|
}
|
2017-07-04 19:31:57 +02:00
|
|
|
READWRITE(fSentinelIsCurrent);
|
|
|
|
READWRITE(nSentinelVersion);
|
2015-07-14 07:25:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void swap(CMasternodePing& first, CMasternodePing& second) // nothrow
|
|
|
|
{
|
|
|
|
// enable ADL (not necessary in our case, but good practice)
|
|
|
|
using std::swap;
|
|
|
|
|
|
|
|
// by swapping the members of two classes,
|
|
|
|
// the two classes are effectively swapped
|
|
|
|
swap(first.vin, second.vin);
|
|
|
|
swap(first.blockHash, second.blockHash);
|
|
|
|
swap(first.sigTime, second.sigTime);
|
|
|
|
swap(first.vchSig, second.vchSig);
|
2017-07-04 19:31:57 +02:00
|
|
|
swap(first.fSentinelIsCurrent, second.fSentinelIsCurrent);
|
|
|
|
swap(first.nSentinelVersion, second.nSentinelVersion);
|
2015-07-14 07:25:07 +02:00
|
|
|
}
|
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
uint256 GetHash() const
|
|
|
|
{
|
|
|
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
|
|
|
ss << vin;
|
|
|
|
ss << sigTime;
|
|
|
|
return ss.GetHash();
|
|
|
|
}
|
|
|
|
|
2016-12-24 03:49:13 +01:00
|
|
|
bool IsExpired() { return GetTime() - sigTime > MASTERNODE_NEW_START_REQUIRED_SECONDS; }
|
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode);
|
|
|
|
bool CheckSignature(CPubKey& pubKeyMasternode, int &nDos);
|
2016-11-30 20:32:36 +01:00
|
|
|
bool SimpleCheck(int& nDos);
|
2016-12-26 07:44:48 +01:00
|
|
|
bool CheckAndUpdate(CMasternode* pmn, bool fFromNewBroadcast, int& nDos);
|
2016-09-16 00:00:06 +02:00
|
|
|
void Relay();
|
|
|
|
|
2015-07-14 07:25:07 +02:00
|
|
|
CMasternodePing& operator=(CMasternodePing from)
|
|
|
|
{
|
|
|
|
swap(*this, from);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
friend bool operator==(const CMasternodePing& a, const CMasternodePing& b)
|
|
|
|
{
|
|
|
|
return a.vin == b.vin && a.blockHash == b.blockHash;
|
|
|
|
}
|
|
|
|
friend bool operator!=(const CMasternodePing& a, const CMasternodePing& b)
|
|
|
|
{
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-12-24 03:49:13 +01:00
|
|
|
struct masternode_info_t
|
|
|
|
{
|
2016-10-17 20:54:28 +02:00
|
|
|
masternode_info_t()
|
|
|
|
: vin(),
|
|
|
|
addr(),
|
|
|
|
pubKeyCollateralAddress(),
|
|
|
|
pubKeyMasternode(),
|
|
|
|
sigTime(0),
|
|
|
|
nLastDsq(0),
|
|
|
|
nTimeLastChecked(0),
|
|
|
|
nTimeLastPaid(0),
|
|
|
|
nTimeLastWatchdogVote(0),
|
2017-02-10 01:56:52 +01:00
|
|
|
nTimeLastPing(0),
|
2016-10-17 20:54:28 +02:00
|
|
|
nActiveState(0),
|
|
|
|
nProtocolVersion(0),
|
|
|
|
fInfoValid(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
CTxIn vin;
|
|
|
|
CService addr;
|
|
|
|
CPubKey pubKeyCollateralAddress;
|
|
|
|
CPubKey pubKeyMasternode;
|
|
|
|
int64_t sigTime; //mnb message time
|
|
|
|
int64_t nLastDsq; //the dsq count from the last dsq broadcast of this node
|
|
|
|
int64_t nTimeLastChecked;
|
|
|
|
int64_t nTimeLastPaid;
|
|
|
|
int64_t nTimeLastWatchdogVote;
|
2017-02-10 01:56:52 +01:00
|
|
|
int64_t nTimeLastPing;
|
2016-10-17 20:54:28 +02:00
|
|
|
int nActiveState;
|
|
|
|
int nProtocolVersion;
|
|
|
|
bool fInfoValid;
|
|
|
|
};
|
2015-07-14 07:25:07 +02:00
|
|
|
|
2014-12-31 03:54:00 +01:00
|
|
|
//
|
2015-03-05 09:10:15 +01:00
|
|
|
// The Masternode Class. For managing the Darksend process. It contains the input of the 1000DRK, signature to prove
|
2014-12-09 02:17:57 +01:00
|
|
|
// it's the one who own that ip address and code for calculating the payment election.
|
2014-12-31 03:54:00 +01:00
|
|
|
//
|
2015-02-23 21:01:21 +01:00
|
|
|
class CMasternode
|
2014-12-09 02:17:57 +01:00
|
|
|
{
|
2015-02-23 21:01:21 +01:00
|
|
|
private:
|
|
|
|
// critical section to protect the inner data structures
|
|
|
|
mutable CCriticalSection cs;
|
2016-09-16 00:00:06 +02:00
|
|
|
|
2014-12-09 02:17:57 +01:00
|
|
|
public:
|
2015-03-24 02:59:12 +01:00
|
|
|
enum state {
|
2015-08-05 05:16:29 +02:00
|
|
|
MASTERNODE_PRE_ENABLED,
|
|
|
|
MASTERNODE_ENABLED,
|
|
|
|
MASTERNODE_EXPIRED,
|
2016-09-16 00:00:06 +02:00
|
|
|
MASTERNODE_OUTPOINT_SPENT,
|
2016-12-24 03:49:13 +01:00
|
|
|
MASTERNODE_UPDATE_REQUIRED,
|
2016-10-20 23:11:30 +02:00
|
|
|
MASTERNODE_WATCHDOG_EXPIRED,
|
2016-12-24 03:49:13 +01:00
|
|
|
MASTERNODE_NEW_START_REQUIRED,
|
2016-10-20 23:11:30 +02:00
|
|
|
MASTERNODE_POSE_BAN
|
2015-03-24 02:59:12 +01:00
|
|
|
};
|
|
|
|
|
2017-07-13 11:38:00 +02:00
|
|
|
enum CollateralStatus {
|
|
|
|
COLLATERAL_OK,
|
|
|
|
COLLATERAL_UTXO_NOT_FOUND,
|
|
|
|
COLLATERAL_INVALID_AMOUNT
|
|
|
|
};
|
|
|
|
|
2014-12-09 02:17:57 +01:00
|
|
|
CTxIn vin;
|
2015-02-23 21:01:21 +01:00
|
|
|
CService addr;
|
2016-09-16 00:00:06 +02:00
|
|
|
CPubKey pubKeyCollateralAddress;
|
|
|
|
CPubKey pubKeyMasternode;
|
|
|
|
CMasternodePing lastPing;
|
2016-03-15 00:16:29 +01:00
|
|
|
std::vector<unsigned char> vchSig;
|
2015-07-14 07:25:07 +02:00
|
|
|
int64_t sigTime; //mnb message time
|
2016-09-16 00:00:06 +02:00
|
|
|
int64_t nLastDsq; //the dsq count from the last dsq broadcast of this node
|
|
|
|
int64_t nTimeLastChecked;
|
2016-09-11 22:22:37 +02:00
|
|
|
int64_t nTimeLastPaid;
|
2016-10-17 20:54:28 +02:00
|
|
|
int64_t nTimeLastWatchdogVote;
|
2016-09-16 00:00:06 +02:00
|
|
|
int nActiveState;
|
2016-09-11 22:22:37 +02:00
|
|
|
int nCacheCollateralBlock;
|
2016-09-16 00:00:06 +02:00
|
|
|
int nBlockLastPaid;
|
|
|
|
int nProtocolVersion;
|
2016-10-20 23:11:30 +02:00
|
|
|
int nPoSeBanScore;
|
2016-10-30 21:56:47 +01:00
|
|
|
int nPoSeBanHeight;
|
2016-09-16 00:00:06 +02:00
|
|
|
bool fAllowMixingTx;
|
|
|
|
bool fUnitTest;
|
2015-07-14 07:25:07 +02:00
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
// KEEP TRACK OF GOVERNANCE ITEMS EACH MASTERNODE HAS VOTE UPON FOR RECALCULATION
|
2016-10-17 20:54:28 +02:00
|
|
|
std::map<uint256, int> mapGovernanceObjectsVotedOn;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
CMasternode();
|
|
|
|
CMasternode(const CMasternode& other);
|
2015-07-14 07:25:07 +02:00
|
|
|
CMasternode(const CMasternodeBroadcast& mnb);
|
2016-09-16 00:00:06 +02:00
|
|
|
CMasternode(CService addrNew, CTxIn vinNew, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, int nProtocolVersionIn);
|
2015-04-17 17:10:38 +02:00
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
LOCK(cs);
|
|
|
|
READWRITE(vin);
|
|
|
|
READWRITE(addr);
|
|
|
|
READWRITE(pubKeyCollateralAddress);
|
|
|
|
READWRITE(pubKeyMasternode);
|
|
|
|
READWRITE(lastPing);
|
|
|
|
READWRITE(vchSig);
|
|
|
|
READWRITE(sigTime);
|
|
|
|
READWRITE(nLastDsq);
|
|
|
|
READWRITE(nTimeLastChecked);
|
|
|
|
READWRITE(nTimeLastPaid);
|
2016-10-17 20:54:28 +02:00
|
|
|
READWRITE(nTimeLastWatchdogVote);
|
2016-09-16 00:00:06 +02:00
|
|
|
READWRITE(nActiveState);
|
|
|
|
READWRITE(nCacheCollateralBlock);
|
|
|
|
READWRITE(nBlockLastPaid);
|
|
|
|
READWRITE(nProtocolVersion);
|
2016-10-20 23:11:30 +02:00
|
|
|
READWRITE(nPoSeBanScore);
|
2016-10-30 21:56:47 +01:00
|
|
|
READWRITE(nPoSeBanHeight);
|
2016-09-16 00:00:06 +02:00
|
|
|
READWRITE(fAllowMixingTx);
|
|
|
|
READWRITE(fUnitTest);
|
2016-10-17 20:54:28 +02:00
|
|
|
READWRITE(mapGovernanceObjectsVotedOn);
|
2016-09-16 00:00:06 +02:00
|
|
|
}
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2015-02-23 21:01:21 +01:00
|
|
|
void swap(CMasternode& first, CMasternode& second) // nothrow
|
2014-12-09 02:17:57 +01:00
|
|
|
{
|
2015-02-23 21:01:21 +01:00
|
|
|
// enable ADL (not necessary in our case, but good practice)
|
|
|
|
using std::swap;
|
|
|
|
|
|
|
|
// by swapping the members of two classes,
|
|
|
|
// the two classes are effectively swapped
|
|
|
|
swap(first.vin, second.vin);
|
|
|
|
swap(first.addr, second.addr);
|
2016-09-16 00:00:06 +02:00
|
|
|
swap(first.pubKeyCollateralAddress, second.pubKeyCollateralAddress);
|
|
|
|
swap(first.pubKeyMasternode, second.pubKeyMasternode);
|
|
|
|
swap(first.lastPing, second.lastPing);
|
2016-03-15 00:16:29 +01:00
|
|
|
swap(first.vchSig, second.vchSig);
|
2015-03-01 16:38:53 +01:00
|
|
|
swap(first.sigTime, second.sigTime);
|
2016-09-16 00:00:06 +02:00
|
|
|
swap(first.nLastDsq, second.nLastDsq);
|
|
|
|
swap(first.nTimeLastChecked, second.nTimeLastChecked);
|
2016-09-11 22:22:37 +02:00
|
|
|
swap(first.nTimeLastPaid, second.nTimeLastPaid);
|
2016-10-17 20:54:28 +02:00
|
|
|
swap(first.nTimeLastWatchdogVote, second.nTimeLastWatchdogVote);
|
2016-09-16 00:00:06 +02:00
|
|
|
swap(first.nActiveState, second.nActiveState);
|
2016-09-11 22:22:37 +02:00
|
|
|
swap(first.nCacheCollateralBlock, second.nCacheCollateralBlock);
|
2016-09-16 00:00:06 +02:00
|
|
|
swap(first.nBlockLastPaid, second.nBlockLastPaid);
|
|
|
|
swap(first.nProtocolVersion, second.nProtocolVersion);
|
2016-10-20 23:11:30 +02:00
|
|
|
swap(first.nPoSeBanScore, second.nPoSeBanScore);
|
2016-10-30 21:56:47 +01:00
|
|
|
swap(first.nPoSeBanHeight, second.nPoSeBanHeight);
|
2016-09-16 00:00:06 +02:00
|
|
|
swap(first.fAllowMixingTx, second.fAllowMixingTx);
|
|
|
|
swap(first.fUnitTest, second.fUnitTest);
|
2016-10-17 20:54:28 +02:00
|
|
|
swap(first.mapGovernanceObjectsVotedOn, second.mapGovernanceObjectsVotedOn);
|
2015-02-23 21:01:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
// CALCULATE A RANK AGAINST OF GIVEN BLOCK
|
2016-10-13 11:45:18 +02:00
|
|
|
arith_uint256 CalculateScore(const uint256& blockHash);
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
bool UpdateFromNewBroadcast(CMasternodeBroadcast& mnb);
|
2015-04-16 16:08:06 +02:00
|
|
|
|
2017-07-13 11:38:00 +02:00
|
|
|
static CollateralStatus CheckCollateral(CTxIn vin);
|
|
|
|
static CollateralStatus CheckCollateral(CTxIn vin, int& nHeight);
|
2016-09-16 00:00:06 +02:00
|
|
|
void Check(bool fForce = false);
|
2015-02-23 21:01:21 +01:00
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
bool IsBroadcastedWithin(int nSeconds) { return GetAdjustedTime() - sigTime < nSeconds; }
|
2015-04-17 17:10:38 +02:00
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
bool IsPingedWithin(int nSeconds, int64_t nTimeToCheckAt = -1)
|
2014-12-09 02:17:57 +01:00
|
|
|
{
|
2016-09-16 00:00:06 +02:00
|
|
|
if(lastPing == CMasternodePing()) return false;
|
|
|
|
|
|
|
|
if(nTimeToCheckAt == -1) {
|
|
|
|
nTimeToCheckAt = GetAdjustedTime();
|
|
|
|
}
|
|
|
|
return nTimeToCheckAt - lastPing.sigTime < nSeconds;
|
2014-12-09 02:17:57 +01:00
|
|
|
}
|
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
bool IsEnabled() { return nActiveState == MASTERNODE_ENABLED; }
|
|
|
|
bool IsPreEnabled() { return nActiveState == MASTERNODE_PRE_ENABLED; }
|
2016-10-20 23:11:30 +02:00
|
|
|
bool IsPoSeBanned() { return nActiveState == MASTERNODE_POSE_BAN; }
|
2016-12-24 03:49:13 +01:00
|
|
|
// NOTE: this one relies on nPoSeBanScore, not on nActiveState as everything else here
|
2016-10-20 23:11:30 +02:00
|
|
|
bool IsPoSeVerified() { return nPoSeBanScore <= -MASTERNODE_POSE_BAN_MAX_SCORE; }
|
2016-12-24 03:49:13 +01:00
|
|
|
bool IsExpired() { return nActiveState == MASTERNODE_EXPIRED; }
|
|
|
|
bool IsOutpointSpent() { return nActiveState == MASTERNODE_OUTPOINT_SPENT; }
|
|
|
|
bool IsUpdateRequired() { return nActiveState == MASTERNODE_UPDATE_REQUIRED; }
|
2016-10-17 20:54:28 +02:00
|
|
|
bool IsWatchdogExpired() { return nActiveState == MASTERNODE_WATCHDOG_EXPIRED; }
|
2016-12-24 03:49:13 +01:00
|
|
|
bool IsNewStartRequired() { return nActiveState == MASTERNODE_NEW_START_REQUIRED; }
|
|
|
|
|
|
|
|
static bool IsValidStateForAutoStart(int nActiveStateIn)
|
|
|
|
{
|
|
|
|
return nActiveStateIn == MASTERNODE_ENABLED ||
|
|
|
|
nActiveStateIn == MASTERNODE_PRE_ENABLED ||
|
|
|
|
nActiveStateIn == MASTERNODE_EXPIRED ||
|
|
|
|
nActiveStateIn == MASTERNODE_WATCHDOG_EXPIRED;
|
|
|
|
}
|
2016-10-17 20:54:28 +02:00
|
|
|
|
2016-11-23 16:30:36 +01:00
|
|
|
bool IsValidForPayment()
|
|
|
|
{
|
|
|
|
if(nActiveState == MASTERNODE_ENABLED) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(!sporkManager.IsSporkActive(SPORK_14_REQUIRE_SENTINEL_FLAG) &&
|
|
|
|
(nActiveState == MASTERNODE_WATCHDOG_EXPIRED)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-12 09:04:06 +02:00
|
|
|
/// Is the input associated with collateral public key? (and there is 1000 DASH - checking if valid masternode)
|
|
|
|
bool IsInputAssociatedWithPubkey();
|
|
|
|
|
2016-10-10 11:13:07 +02:00
|
|
|
bool IsValidNetAddr();
|
2016-12-15 17:27:24 +01:00
|
|
|
static bool IsValidNetAddr(CService addrIn);
|
2016-10-10 11:13:07 +02:00
|
|
|
|
2016-10-30 21:56:47 +01:00
|
|
|
void IncreasePoSeBanScore() { if(nPoSeBanScore < MASTERNODE_POSE_BAN_MAX_SCORE) nPoSeBanScore++; }
|
|
|
|
void DecreasePoSeBanScore() { if(nPoSeBanScore > -MASTERNODE_POSE_BAN_MAX_SCORE) nPoSeBanScore--; }
|
|
|
|
|
2016-10-17 20:54:28 +02:00
|
|
|
masternode_info_t GetInfo();
|
|
|
|
|
2016-10-26 23:21:39 +02:00
|
|
|
static std::string StateToString(int nStateIn);
|
|
|
|
std::string GetStateString() const;
|
|
|
|
std::string GetStatus() const;
|
2014-12-31 03:54:00 +01:00
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
int GetCollateralAge();
|
2015-07-19 17:49:46 +02:00
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
int GetLastPaidTime() { return nTimeLastPaid; }
|
|
|
|
int GetLastPaidBlock() { return nBlockLastPaid; }
|
|
|
|
void UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScanBack);
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
// KEEP TRACK OF EACH GOVERNANCE ITEM INCASE THIS NODE GOES OFFLINE, SO WE CAN RECALC THEIR STATUS
|
|
|
|
void AddGovernanceVote(uint256 nGovernanceObjectHash);
|
|
|
|
// RECALCULATE CACHED STATUS FLAGS FOR ALL AFFECTED OBJECTS
|
|
|
|
void FlagGovernanceItemsAsDirty();
|
2016-10-17 20:54:28 +02:00
|
|
|
|
|
|
|
void RemoveGovernanceObject(uint256 nGovernanceObjectHash);
|
|
|
|
|
2017-07-04 19:31:57 +02:00
|
|
|
void UpdateWatchdogVoteTime(uint64_t nVoteTime = 0);
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
CMasternode& operator=(CMasternode from)
|
2014-12-09 02:17:57 +01:00
|
|
|
{
|
2016-09-16 00:00:06 +02:00
|
|
|
swap(*this, from);
|
|
|
|
return *this;
|
2014-12-09 02:17:57 +01:00
|
|
|
}
|
2016-09-16 00:00:06 +02:00
|
|
|
friend bool operator==(const CMasternode& a, const CMasternode& b)
|
2015-08-05 05:16:29 +02:00
|
|
|
{
|
2016-09-16 00:00:06 +02:00
|
|
|
return a.vin == b.vin;
|
2015-08-05 05:16:29 +02:00
|
|
|
}
|
2016-09-16 00:00:06 +02:00
|
|
|
friend bool operator!=(const CMasternode& a, const CMasternode& b)
|
|
|
|
{
|
|
|
|
return !(a.vin == b.vin);
|
2015-03-31 03:14:44 +02:00
|
|
|
}
|
|
|
|
|
2014-12-09 02:17:57 +01:00
|
|
|
};
|
|
|
|
|
2015-04-17 17:10:38 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// The Masternode Broadcast Class : Contains a different serialize method for sending masternodes through the network
|
|
|
|
//
|
|
|
|
|
|
|
|
class CMasternodeBroadcast : public CMasternode
|
|
|
|
{
|
|
|
|
public:
|
2016-07-29 07:32:08 +02:00
|
|
|
|
2017-01-01 18:48:53 +01:00
|
|
|
bool fRecovery;
|
|
|
|
|
|
|
|
CMasternodeBroadcast() : CMasternode(), fRecovery(false) {}
|
|
|
|
CMasternodeBroadcast(const CMasternode& mn) : CMasternode(mn), fRecovery(false) {}
|
2016-09-16 00:00:06 +02:00
|
|
|
CMasternodeBroadcast(CService addrNew, CTxIn vinNew, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, int nProtocolVersionIn) :
|
2017-01-01 18:48:53 +01:00
|
|
|
CMasternode(addrNew, vinNew, pubKeyCollateralAddressNew, pubKeyMasternodeNew, nProtocolVersionIn), fRecovery(false) {}
|
2015-04-17 17:10:38 +02:00
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
READWRITE(vin);
|
|
|
|
READWRITE(addr);
|
2016-09-16 00:00:06 +02:00
|
|
|
READWRITE(pubKeyCollateralAddress);
|
|
|
|
READWRITE(pubKeyMasternode);
|
2016-03-15 00:16:29 +01:00
|
|
|
READWRITE(vchSig);
|
2015-04-17 17:10:38 +02:00
|
|
|
READWRITE(sigTime);
|
2016-09-16 00:00:06 +02:00
|
|
|
READWRITE(nProtocolVersion);
|
2015-07-14 07:25:07 +02:00
|
|
|
READWRITE(lastPing);
|
2015-04-17 17:10:38 +02:00
|
|
|
}
|
2015-06-24 01:44:31 +02:00
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
uint256 GetHash() const
|
|
|
|
{
|
2015-06-09 15:22:31 +02:00
|
|
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
2017-03-14 07:22:00 +01:00
|
|
|
ss << vin;
|
|
|
|
ss << pubKeyCollateralAddress;
|
|
|
|
ss << sigTime;
|
2015-06-09 15:22:31 +02:00
|
|
|
return ss.GetHash();
|
2015-04-22 16:33:44 +02:00
|
|
|
}
|
2015-04-17 17:10:38 +02:00
|
|
|
|
2016-09-16 00:00:06 +02:00
|
|
|
/// Create Masternode broadcast, needs to be relayed manually after that
|
|
|
|
static bool Create(CTxIn vin, CService service, CKey keyCollateralAddressNew, CPubKey pubKeyCollateralAddressNew, CKey keyMasternodeNew, CPubKey pubKeyMasternodeNew, std::string &strErrorRet, CMasternodeBroadcast &mnbRet);
|
|
|
|
static bool Create(std::string strService, std::string strKey, std::string strTxHash, std::string strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast &mnbRet, bool fOffline = false);
|
|
|
|
|
2016-10-20 23:11:30 +02:00
|
|
|
bool SimpleCheck(int& nDos);
|
|
|
|
bool Update(CMasternode* pmn, int& nDos);
|
|
|
|
bool CheckOutpoint(int& nDos);
|
2016-09-16 00:00:06 +02:00
|
|
|
|
|
|
|
bool Sign(CKey& keyCollateralAddress);
|
|
|
|
bool CheckSignature(int& nDos);
|
|
|
|
void Relay();
|
2015-04-17 17:10:38 +02:00
|
|
|
};
|
|
|
|
|
2016-10-20 23:11:30 +02:00
|
|
|
class CMasternodeVerification
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTxIn vin1;
|
|
|
|
CTxIn vin2;
|
|
|
|
CService addr;
|
|
|
|
int nonce;
|
|
|
|
int nBlockHeight;
|
|
|
|
std::vector<unsigned char> vchSig1;
|
|
|
|
std::vector<unsigned char> vchSig2;
|
|
|
|
|
|
|
|
CMasternodeVerification() :
|
|
|
|
vin1(),
|
|
|
|
vin2(),
|
|
|
|
addr(),
|
|
|
|
nonce(0),
|
|
|
|
nBlockHeight(0),
|
|
|
|
vchSig1(),
|
|
|
|
vchSig2()
|
|
|
|
{}
|
|
|
|
|
|
|
|
CMasternodeVerification(CService addr, int nonce, int nBlockHeight) :
|
|
|
|
vin1(),
|
|
|
|
vin2(),
|
|
|
|
addr(addr),
|
|
|
|
nonce(nonce),
|
|
|
|
nBlockHeight(nBlockHeight),
|
|
|
|
vchSig1(),
|
|
|
|
vchSig2()
|
|
|
|
{}
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
READWRITE(vin1);
|
|
|
|
READWRITE(vin2);
|
|
|
|
READWRITE(addr);
|
|
|
|
READWRITE(nonce);
|
|
|
|
READWRITE(nBlockHeight);
|
|
|
|
READWRITE(vchSig1);
|
|
|
|
READWRITE(vchSig2);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint256 GetHash() const
|
|
|
|
{
|
|
|
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
|
|
|
ss << vin1;
|
|
|
|
ss << vin2;
|
|
|
|
ss << addr;
|
|
|
|
ss << nonce;
|
|
|
|
ss << nBlockHeight;
|
|
|
|
return ss.GetHash();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Relay() const
|
|
|
|
{
|
|
|
|
CInv inv(MSG_MASTERNODE_VERIFY, GetHash());
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
g_connman->RelayInv(inv);
|
2016-10-20 23:11:30 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-09 03:36:33 +02:00
|
|
|
#endif
|