mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Complete implementation of Proof-of-Service
- Ensures ports remain open and client are responsive to IX requests. - Completely 100% decentralized. This farms out the work of checking the masternode network to the masternode network. 1% of the network is determistically selected to check another 1% of the network each block. It takes six separate checks to deactivate a node, thus making it tamper proof. - Nodes are kept in the masternode list if they fail enough PoSe checks to deactivate. They will continue to be checked until the operator fixes them. However they will not be paid while they're failing checks.
This commit is contained in:
parent
3fdb01087d
commit
e5267319ef
@ -53,6 +53,7 @@ BITCOIN_CORE_H = \
|
||||
limitedmap.h \
|
||||
main.h \
|
||||
masternode.h \
|
||||
masternode-pos.h \
|
||||
masternodeman.h \
|
||||
masternodeconfig.h \
|
||||
miner.h \
|
||||
@ -154,6 +155,7 @@ libdarkcoin_common_a_SOURCES = \
|
||||
darksend.cpp \
|
||||
darksend-relay.cpp \
|
||||
masternode.cpp \
|
||||
masternode-pos.cpp \
|
||||
masternodeman.cpp \
|
||||
masternodeconfig.cpp \
|
||||
instantx.cpp \
|
||||
|
@ -56,13 +56,11 @@ void CActiveMasternode::ManageStatus()
|
||||
return;
|
||||
}
|
||||
|
||||
if(Params().NetworkID() == CChainParams::MAIN){
|
||||
if(!ConnectNode((CAddress)service, service.ToString().c_str())){
|
||||
notCapableReason = "Could not connect to " + service.ToString();
|
||||
status = MASTERNODE_NOT_CAPABLE;
|
||||
LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason.c_str());
|
||||
return;
|
||||
}
|
||||
if(!ConnectNode((CAddress)service, service.ToString().c_str())){
|
||||
notCapableReason = "Could not connect to " + service.ToString();
|
||||
status = MASTERNODE_NOT_CAPABLE;
|
||||
LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if(pwalletMain->IsLocked()){
|
||||
|
@ -23,8 +23,8 @@ static const int64_t DARKSEND_POOL_MAX = (999.99*COIN);
|
||||
one party without comprimising the security of InstantX
|
||||
(1000/2150.0)**15 = 1.031e-05
|
||||
*/
|
||||
#define INSTANTX_SIGNATURES_REQUIRED 20
|
||||
#define INSTANTX_SIGNATURES_TOTAL 30
|
||||
#define INSTANTX_SIGNATURES_REQUIRED 15
|
||||
#define INSTANTX_SIGNATURES_TOTAL 20
|
||||
|
||||
#define MASTERNODE_NOT_PROCESSED 0 // initial state
|
||||
#define MASTERNODE_IS_CAPABLE 1
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "masternodeman.h"
|
||||
#include "instantx.h"
|
||||
#include "ui_interface.h"
|
||||
;
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
@ -243,7 +243,7 @@ int64_t CreateNewLock(CTransaction tx)
|
||||
|
||||
CTransactionLock newLock;
|
||||
newLock.nBlockHeight = nBlockHeight;
|
||||
newLock.nExpiration = GetTime()+(60*60); //locks expire after 15 minutes (6 confirmations)
|
||||
newLock.nExpiration = GetTime()+(60*60); //locks expire after 60 minutes (6 confirmations)
|
||||
newLock.nTimeout = GetTime()+(60*5);
|
||||
newLock.txHash = tx.GetHash();
|
||||
mapTxLocks.insert(make_pair(tx.GetHash(), newLock));
|
||||
@ -252,6 +252,8 @@ int64_t CreateNewLock(CTransaction tx)
|
||||
if(fDebug) LogPrintf("CreateNewLock - Transaction Lock Exists %s !\n", tx.GetHash().ToString().c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
return nBlockHeight;
|
||||
}
|
||||
|
||||
@ -449,6 +451,27 @@ void CleanTransactionLocksList()
|
||||
if(GetTime() > it->second.nExpiration){ //keep them for an hour
|
||||
LogPrintf("Removing old transaction lock %s\n", it->second.txHash.ToString().c_str());
|
||||
|
||||
// loop through masternodes that responded
|
||||
for(int nRank = 0; nRank <= INSTANTX_SIGNATURES_TOTAL; nRank++)
|
||||
{
|
||||
CMasternode* pmn = mnodeman.GetMasternodeByRank(nRank, it->second.nBlockHeight, MIN_INSTANTX_PROTO_VERSION);
|
||||
if(!pmn) continue;
|
||||
|
||||
bool fFound = false;
|
||||
BOOST_FOREACH(CConsensusVote& v, it->second.vecConsensusVotes)
|
||||
{
|
||||
if(pmn->vin == v.vinMasternode){ //Masternode responded
|
||||
fFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!fFound){
|
||||
//increment a scanning error
|
||||
CMasternodeScanningError mnse(pmn->vin, SCANNING_ERROR_IX_NO_RESPONSE, it->second.nBlockHeight);
|
||||
pmn->ApplyScanningError(mnse);
|
||||
}
|
||||
}
|
||||
|
||||
if(mapTxLockReq.count(it->second.txHash)){
|
||||
CTransaction& tx = mapTxLockReq[it->second.txHash];
|
||||
|
||||
|
13
src/main.cpp
13
src/main.cpp
@ -3242,6 +3242,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
|
||||
if (!fImporting && !fReindex && chainActive.Height() > Checkpoints::GetTotalBlocksEstimate()){
|
||||
darkSendPool.NewBlock();
|
||||
masternodePayments.ProcessBlock(GetHeight()+10);
|
||||
mnscan.DoMasternodePOSChecks();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3903,6 +3904,8 @@ bool static AlreadyHave(const CInv& inv)
|
||||
return mapSporks.count(inv.hash);
|
||||
case MSG_MASTERNODE_WINNER:
|
||||
return mapSeenMasternodeVotes.count(inv.hash);
|
||||
case MSG_MASTERNODE_SCANNING_ERROR:
|
||||
return mapMasternodeScanningErrors.count(inv.hash);
|
||||
}
|
||||
// Don't know what it is, just say we already got one
|
||||
return true;
|
||||
@ -4063,6 +4066,15 @@ void static ProcessGetData(CNode* pfrom)
|
||||
pushed = true;
|
||||
}
|
||||
}
|
||||
if (!pushed && inv.type == MSG_MASTERNODE_SCANNING_ERROR) {
|
||||
if(mapMasternodeScanningErrors.count(inv.hash)){
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss.reserve(1000);
|
||||
ss << mapMasternodeScanningErrors[inv.hash];
|
||||
pfrom->PushMessage("mnse", ss);
|
||||
pushed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pushed) {
|
||||
vNotFound.push_back(inv);
|
||||
@ -4824,6 +4836,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
ProcessMessageMasternodePayments(pfrom, strCommand, vRecv);
|
||||
ProcessMessageInstantX(pfrom, strCommand, vRecv);
|
||||
ProcessSpork(pfrom, strCommand, vRecv);
|
||||
ProcessMessageMasternodePOS(pfrom, strCommand, vRecv);
|
||||
}
|
||||
|
||||
|
||||
|
242
src/masternode-pos.cpp
Normal file
242
src/masternode-pos.cpp
Normal file
@ -0,0 +1,242 @@
|
||||
|
||||
|
||||
|
||||
#include "bignum.h"
|
||||
#include "sync.h"
|
||||
#include "net.h"
|
||||
#include "key.h"
|
||||
#include "util.h"
|
||||
#include "script.h"
|
||||
#include "base58.h"
|
||||
#include "protocol.h"
|
||||
#include "activemasternode.h"
|
||||
#include "masternodeman.h"
|
||||
#include "spork.h"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include "masternodeman.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
|
||||
std::map<uint256, CMasternodeScanningError> mapMasternodeScanningErrors;
|
||||
CMasternodeScanning mnscan;
|
||||
|
||||
/*
|
||||
Masternode - Proof of Service
|
||||
|
||||
-- What it checks
|
||||
|
||||
1.) Making sure Masternodes have their ports open
|
||||
2.) Are responding to requests made by the network
|
||||
|
||||
-- How it works
|
||||
|
||||
When a block comes in, DoMasternodePOS is executed if the client is a
|
||||
masternode. Using the deterministic ranking algorithm up to 1% of the masternode
|
||||
network is checked each block.
|
||||
|
||||
A port is opened from Masternode A to Masternode B, if successful then nothing happens.
|
||||
If there is an error, a CMasternodeScanningError object is propagated with an error code.
|
||||
Errors are applied to the Masternodes and a score is incremented within the masternode object,
|
||||
after a threshold is met, the masternode goes into an error state. Each cycle the score is
|
||||
decreased, so if the masternode comes back online it will return to the list.
|
||||
|
||||
Masternodes in a error state do not receive payment.
|
||||
|
||||
-- Future expansion
|
||||
|
||||
We want to be able to prove the nodes have many qualities such as a specific CPU speed, bandwidth,
|
||||
and dedicated storage. E.g. We could require a full node be a computer running 2GHz with 10GB of space.
|
||||
|
||||
*/
|
||||
|
||||
void ProcessMessageMasternodePOS(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
|
||||
{
|
||||
if(fLiteMode) return; //disable all darksend/masternode related functionality
|
||||
if(!IsSporkActive(SPORK_7_MASTERNODE_SCANNING)) return;
|
||||
if(IsInitialBlockDownload()) return;
|
||||
|
||||
if (strCommand == "mnse") //Masternode Scanning Error
|
||||
{
|
||||
|
||||
LogPrintf("ProcessMessageMasternodePOS::mnse\n");
|
||||
CDataStream vMsg(vRecv);
|
||||
CMasternodeScanningError mnse;
|
||||
vRecv >> mnse;
|
||||
|
||||
CInv inv(MSG_MASTERNODE_SCANNING_ERROR, mnse.GetHash());
|
||||
pfrom->AddInventoryKnown(inv);
|
||||
|
||||
if(mapMasternodeScanningErrors.count(mnse.GetHash())){
|
||||
return;
|
||||
}
|
||||
mapMasternodeScanningErrors.insert(make_pair(mnse.GetHash(), mnse));
|
||||
|
||||
if(!mnse.IsValid())
|
||||
{
|
||||
LogPrintf("MasternodePOS::mnse - Invalid object\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Lowest masternodes in rank check the highest each block
|
||||
int a = mnodeman.GetMasternodeRank(mnse.vinMasternodeA, mnse.nBlockHeight, MIN_MASTERNODE_POS_PROTO_VERSION);
|
||||
if(a > GetCountScanningPerBlock())
|
||||
{
|
||||
LogPrintf("MasternodePOS::mnse - MasternodeA ranking is too high\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int b = mnodeman.GetMasternodeRank(mnse.vinMasternodeB, mnse.nBlockHeight, MIN_MASTERNODE_POS_PROTO_VERSION, false);
|
||||
if(b < mnodeman.CountMasternodesAboveProtocol(MIN_MASTERNODE_POS_PROTO_VERSION)-GetCountScanningPerBlock())
|
||||
{
|
||||
LogPrintf("MasternodePOS::mnse - MasternodeB ranking is too low\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!mnse.SignatureValid()){
|
||||
LogPrintf("MasternodePOS::mnse - Bad masternode message\n");
|
||||
return;
|
||||
}
|
||||
|
||||
CMasternode* pmn = mnodeman.Find(mnse.vinMasternodeB);
|
||||
if(pmn == NULL) return;
|
||||
|
||||
pmn->ApplyScanningError(mnse);
|
||||
mnse.Relay();
|
||||
}
|
||||
}
|
||||
|
||||
// Returns how many masternodes are allowed to scan each block
|
||||
int GetCountScanningPerBlock()
|
||||
{
|
||||
return std::max(1, mnodeman.CountMasternodesAboveProtocol(MIN_MASTERNODE_POS_PROTO_VERSION)/100);
|
||||
}
|
||||
|
||||
|
||||
void CMasternodeScanning::CleanMasternodeScanningErrors()
|
||||
{
|
||||
if(chainActive.Tip() == NULL) return;
|
||||
|
||||
std::map<uint256, CMasternodeScanningError>::iterator it = mapMasternodeScanningErrors.begin();
|
||||
|
||||
while(it != mapMasternodeScanningErrors.end()) {
|
||||
if(GetTime() > it->second.nExpiration){ //keep them for an hour
|
||||
LogPrintf("Removing old masternode scanning error %s\n", it->second.GetHash().ToString().c_str());
|
||||
|
||||
mapMasternodeScanningErrors.erase(it++);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Check other masternodes to make sure they're running correctly
|
||||
void CMasternodeScanning::DoMasternodePOSChecks()
|
||||
{
|
||||
if(!fMasterNode) return;
|
||||
if(fLiteMode) return; //disable all darksend/masternode related functionality
|
||||
if(!IsSporkActive(SPORK_7_MASTERNODE_SCANNING)) return;
|
||||
if(IsInitialBlockDownload()) return;
|
||||
|
||||
int a = mnodeman.GetMasternodeRank(activeMasternode.vin, chainActive.Tip()->nHeight, MIN_MASTERNODE_POS_PROTO_VERSION);
|
||||
if(a > GetCountScanningPerBlock()){
|
||||
// we don't need to do anything this block
|
||||
return;
|
||||
}
|
||||
|
||||
// The lowest ranking nodes (Masternode A) check the highest ranking nodes (Masternode B)
|
||||
CMasternode* pmn = mnodeman.GetMasternodeByRank(mnodeman.CountMasternodesAboveProtocol(MIN_MASTERNODE_POS_PROTO_VERSION)-a, chainActive.Tip()->nHeight, MIN_MASTERNODE_POS_PROTO_VERSION, false);
|
||||
if(pmn == NULL) return;
|
||||
|
||||
// -- first check : Port is open
|
||||
|
||||
if(!ConnectNode((CAddress)pmn->addr, NULL, true)){
|
||||
// we couldn't connect to the node, let's send a scanning error
|
||||
CMasternodeScanningError mnse(activeMasternode.vin, pmn->vin, SCANNING_ERROR_NO_RESPONSE, chainActive.Tip()->nHeight);
|
||||
mnse.Sign();
|
||||
mapMasternodeScanningErrors.insert(make_pair(mnse.GetHash(), mnse));
|
||||
mnse.Relay();
|
||||
}
|
||||
|
||||
// success
|
||||
CMasternodeScanningError mnse(activeMasternode.vin, pmn->vin, SCANNING_SUCCESS, chainActive.Tip()->nHeight);
|
||||
mnse.Sign();
|
||||
mapMasternodeScanningErrors.insert(make_pair(mnse.GetHash(), mnse));
|
||||
mnse.Relay();
|
||||
}
|
||||
|
||||
bool CMasternodeScanningError::SignatureValid()
|
||||
{
|
||||
std::string errorMessage;
|
||||
std::string strMessage = vinMasternodeA.ToString() + vinMasternodeB.ToString() +
|
||||
boost::lexical_cast<std::string>(nBlockHeight) + boost::lexical_cast<std::string>(nErrorType);
|
||||
|
||||
CMasternode* pmn = mnodeman.Find(vinMasternodeA);
|
||||
|
||||
if(pmn == NULL)
|
||||
{
|
||||
LogPrintf("CMasternodeScanningError::SignatureValid() - Unknown Masternode\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
CScript pubkey;
|
||||
pubkey.SetDestination(pmn->pubkey2.GetID());
|
||||
CTxDestination address1;
|
||||
ExtractDestination(pubkey, address1);
|
||||
CBitcoinAddress address2(address1);
|
||||
|
||||
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchMasterNodeSignature, strMessage, errorMessage)) {
|
||||
LogPrintf("CMasternodeScanningError::SignatureValid() - Verify message failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CMasternodeScanningError::Sign()
|
||||
{
|
||||
std::string errorMessage;
|
||||
|
||||
CKey key2;
|
||||
CPubKey pubkey2;
|
||||
std::string strMessage = vinMasternodeA.ToString() + vinMasternodeB.ToString() +
|
||||
boost::lexical_cast<std::string>(nBlockHeight) + boost::lexical_cast<std::string>(nErrorType);
|
||||
|
||||
if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, key2, pubkey2))
|
||||
{
|
||||
LogPrintf("CMasternodeScanningError::Sign() - ERROR: Invalid masternodeprivkey: '%s'\n", errorMessage.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
CScript pubkey;
|
||||
pubkey.SetDestination(pubkey2.GetID());
|
||||
CTxDestination address1;
|
||||
ExtractDestination(pubkey, address1);
|
||||
CBitcoinAddress address2(address1);
|
||||
//LogPrintf("signing pubkey2 %s \n", address2.ToString().c_str());
|
||||
|
||||
if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchMasterNodeSignature, key2)) {
|
||||
LogPrintf("CMasternodeScanningError::Sign() - Sign message failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!darkSendSigner.VerifyMessage(pubkey2, vchMasterNodeSignature, strMessage, errorMessage)) {
|
||||
LogPrintf("CMasternodeScanningError::Sign() - Verify message failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMasternodeScanningError::Relay()
|
||||
{
|
||||
CInv inv(MSG_MASTERNODE_SCANNING_ERROR, GetHash());
|
||||
|
||||
vector<CInv> vInv;
|
||||
vInv.push_back(inv);
|
||||
LOCK(cs_vNodes);
|
||||
BOOST_FOREACH(CNode* pnode, vNodes){
|
||||
pnode->PushMessage("inv", vInv);
|
||||
}
|
||||
}
|
115
src/masternode-pos.h
Normal file
115
src/masternode-pos.h
Normal file
@ -0,0 +1,115 @@
|
||||
|
||||
|
||||
// Copyright (c) 2014-2015 The Dash developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef MASTERNODE_POS_H
|
||||
#define MASTERNODE_POS_H
|
||||
|
||||
#include "bignum.h"
|
||||
#include "sync.h"
|
||||
#include "net.h"
|
||||
#include "key.h"
|
||||
#include "core.h"
|
||||
#include "util.h"
|
||||
#include "script.h"
|
||||
#include "base58.h"
|
||||
#include "main.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
|
||||
class CMasternodeScanning;
|
||||
class CMasternodeScanningError;
|
||||
|
||||
extern map<uint256, CMasternodeScanningError> mapMasternodeScanningErrors;
|
||||
extern CMasternodeScanning mnscan;
|
||||
|
||||
static const int MIN_MASTERNODE_POS_PROTO_VERSION = 70066;
|
||||
|
||||
/*
|
||||
1% of the network is scanned every 2.5 minutes, making a full
|
||||
round of scanning take about 4.16 hours. We're targeting about
|
||||
a day of proof-of-service errors for complete removal from the
|
||||
masternode system.
|
||||
*/
|
||||
static const int MASTERNODE_SCANNING_ERROR_THESHOLD = 6;
|
||||
|
||||
#define SCANNING_SUCCESS 1
|
||||
#define SCANNING_ERROR_NO_RESPONSE 2
|
||||
#define SCANNING_ERROR_IX_NO_RESPONSE 3
|
||||
#define SCANNING_ERROR_MAX 3
|
||||
|
||||
void ProcessMessageMasternodePOS(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
||||
|
||||
class CMasternodeScanning
|
||||
{
|
||||
public:
|
||||
void DoMasternodePOSChecks();
|
||||
void CleanMasternodeScanningErrors();
|
||||
};
|
||||
|
||||
// Returns how many masternodes are allowed to scan each block
|
||||
int GetCountScanningPerBlock();
|
||||
|
||||
class CMasternodeScanningError
|
||||
{
|
||||
public:
|
||||
CTxIn vinMasternodeA;
|
||||
CTxIn vinMasternodeB;
|
||||
int nErrorType;
|
||||
int nExpiration;
|
||||
int nBlockHeight;
|
||||
std::vector<unsigned char> vchMasterNodeSignature;
|
||||
|
||||
CMasternodeScanningError ()
|
||||
{
|
||||
vinMasternodeA = CTxIn();
|
||||
vinMasternodeB = CTxIn();
|
||||
nErrorType = 0;
|
||||
nExpiration = GetTime()+(60*60);
|
||||
nBlockHeight = 0;
|
||||
}
|
||||
|
||||
CMasternodeScanningError (CTxIn& vinMasternodeAIn, CTxIn& vinMasternodeBIn, int nErrorTypeIn, int nBlockHeightIn)
|
||||
{
|
||||
vinMasternodeA = vinMasternodeAIn;
|
||||
vinMasternodeB = vinMasternodeBIn;
|
||||
nErrorType = nErrorTypeIn;
|
||||
nExpiration = GetTime()+(60*60);
|
||||
nBlockHeight = nBlockHeightIn;
|
||||
}
|
||||
|
||||
CMasternodeScanningError (CTxIn& vinMasternodeBIn, int nErrorTypeIn, int nBlockHeightIn)
|
||||
{
|
||||
//just used for IX, MasternodeA is any client
|
||||
vinMasternodeA = CTxIn();
|
||||
vinMasternodeB = vinMasternodeBIn;
|
||||
nErrorType = nErrorTypeIn;
|
||||
nExpiration = GetTime()+(60*60);
|
||||
nBlockHeight = nBlockHeightIn;
|
||||
}
|
||||
|
||||
uint256 GetHash() const {return SerializeHash(*this);}
|
||||
|
||||
bool SignatureValid();
|
||||
bool Sign();
|
||||
bool IsExpired() {return GetTime() > nExpiration;}
|
||||
void Relay();
|
||||
bool IsValid() {
|
||||
return (nErrorType > 0 && nErrorType <= SCANNING_ERROR_MAX);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
(
|
||||
READWRITE(vinMasternodeA);
|
||||
READWRITE(vinMasternodeB);
|
||||
READWRITE(nErrorType);
|
||||
READWRITE(nExpiration);
|
||||
READWRITE(nBlockHeight);
|
||||
READWRITE(vchMasterNodeSignature);
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -210,6 +210,12 @@ void CMasternode::Check()
|
||||
{
|
||||
LOCK(cs_main);
|
||||
|
||||
if(nScanningErrorCount >= MASTERNODE_SCANNING_ERROR_THESHOLD)
|
||||
{
|
||||
activeState = MASTERNODE_POS_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
//once spent, stop doing the checks
|
||||
if(activeState == MASTERNODE_VIN_SPENT) return;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2012 The Bitcoin developers
|
||||
// Copyright (c) 2014-2015 The Dash developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef MASTERNODE_H
|
||||
@ -15,6 +14,7 @@
|
||||
#include "script.h"
|
||||
#include "base58.h"
|
||||
#include "main.h"
|
||||
#include "masternode-pos.h"
|
||||
|
||||
#define MASTERNODE_NOT_PROCESSED 0 // initial state
|
||||
#define MASTERNODE_IS_CAPABLE 1
|
||||
@ -47,7 +47,8 @@ enum masternodeState {
|
||||
MASTERNODE_ENABLED = 1,
|
||||
MASTERNODE_EXPIRED = 2,
|
||||
MASTERNODE_VIN_SPENT = 3,
|
||||
MASTERNODE_REMOVE = 4
|
||||
MASTERNODE_REMOVE = 4,
|
||||
MASTERNODE_POS_ERROR = 5
|
||||
};
|
||||
|
||||
void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
||||
@ -78,6 +79,8 @@ public:
|
||||
bool allowFreeTx;
|
||||
int protocolVersion;
|
||||
int64_t nLastDsq; //the dsq count from the last dsq broadcast of this node
|
||||
int nScanningErrorCount;
|
||||
int nLastScanningErrorBlockHeight;
|
||||
|
||||
CMasternode();
|
||||
CMasternode(const CMasternode& other);
|
||||
@ -196,6 +199,23 @@ public:
|
||||
|
||||
return cacheInputAge+(chainActive.Tip()->nHeight-cacheInputAgeBlock);
|
||||
}
|
||||
|
||||
void ApplyScanningError(CMasternodeScanningError& mnse)
|
||||
{
|
||||
if(!mnse.IsValid()) return;
|
||||
|
||||
if(mnse.nBlockHeight == nLastScanningErrorBlockHeight) return;
|
||||
nLastScanningErrorBlockHeight = mnse.nBlockHeight;
|
||||
|
||||
if(mnse.nErrorType == SCANNING_SUCCESS){
|
||||
nScanningErrorCount--;
|
||||
if(nScanningErrorCount < 0) nScanningErrorCount = 0;
|
||||
} else { //all other codes are equally as bad
|
||||
nScanningErrorCount++;
|
||||
if(nScanningErrorCount > MASTERNODE_SCANNING_ERROR_THESHOLD*2) nScanningErrorCount = MASTERNODE_SCANNING_ERROR_THESHOLD*2;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// for storing the winning payments
|
||||
|
@ -366,7 +366,7 @@ CMasternode* CMasternodeMan::GetCurrentMasterNode(int mod, int64_t nBlockHeight,
|
||||
return winner;
|
||||
}
|
||||
|
||||
int CMasternodeMan::GetMasternodeRank(const CTxIn& vin, int64_t nBlockHeight, int minProtocol)
|
||||
int CMasternodeMan::GetMasternodeRank(const CTxIn& vin, int64_t nBlockHeight, int minProtocol, bool fOnlyActive)
|
||||
{
|
||||
std::vector<pair<unsigned int, CTxIn> > vecMasternodeScores;
|
||||
|
||||
@ -376,7 +376,7 @@ int CMasternodeMan::GetMasternodeRank(const CTxIn& vin, int64_t nBlockHeight, in
|
||||
mn.Check();
|
||||
|
||||
if(mn.protocolVersion < minProtocol) continue;
|
||||
if(!mn.IsEnabled()) {
|
||||
if(fOnlyActive && !mn.IsEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -400,7 +400,7 @@ int CMasternodeMan::GetMasternodeRank(const CTxIn& vin, int64_t nBlockHeight, in
|
||||
return -1;
|
||||
}
|
||||
|
||||
CMasternode* CMasternodeMan::GetMasternodeByRank(int nRank, int64_t nBlockHeight, int minProtocol)
|
||||
CMasternode* CMasternodeMan::GetMasternodeByRank(int nRank, int64_t nBlockHeight, int minProtocol, bool fOnlyActive)
|
||||
{
|
||||
std::vector<pair<unsigned int, CTxIn> > vecMasternodeScores;
|
||||
|
||||
@ -410,7 +410,7 @@ CMasternode* CMasternodeMan::GetMasternodeByRank(int nRank, int64_t nBlockHeight
|
||||
mn.Check();
|
||||
|
||||
if(mn.protocolVersion < minProtocol) continue;
|
||||
if(!mn.IsEnabled()) {
|
||||
if(fOnlyActive && !mn.IsEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -118,8 +118,8 @@ public:
|
||||
|
||||
std::vector<CMasternode> GetFullMasternodeVector() { Check(); return vMasternodes; }
|
||||
|
||||
int GetMasternodeRank(const CTxIn &vin, int64_t nBlockHeight, int minProtocol=0);
|
||||
CMasternode* GetMasternodeByRank(int nRank, int64_t nBlockHeight, int minProtocol=0);
|
||||
int GetMasternodeRank(const CTxIn &vin, int64_t nBlockHeight, int minProtocol=0, bool fOnlyActive=true);
|
||||
CMasternode* GetMasternodeByRank(int nRank, int64_t nBlockHeight, int minProtocol=0, bool fOnlyActive=true);
|
||||
|
||||
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
||||
|
||||
|
@ -25,6 +25,7 @@ static const char* ppszTypeName[] =
|
||||
"unknown",
|
||||
"unknown",
|
||||
"unknown",
|
||||
"unknown",
|
||||
"unknown"
|
||||
};
|
||||
|
||||
|
@ -138,7 +138,8 @@ enum
|
||||
MSG_TXLOCK_REQUEST,
|
||||
MSG_TXLOCK_VOTE,
|
||||
MSG_SPORK,
|
||||
MSG_MASTERNODE_WINNER
|
||||
MSG_MASTERNODE_WINNER,
|
||||
MSG_MASTERNODE_SCANNING_ERROR
|
||||
};
|
||||
|
||||
#endif // __INCLUDED_PROTOCOL_H__
|
||||
|
@ -601,7 +601,17 @@ Value masternodelist(const Array& params, bool fHelp)
|
||||
if(strMode == "active"){
|
||||
if(strFilter !="" && strFilter != (mn.IsEnabled() ? "true" : "false") &&
|
||||
mn.addr.ToString().find(strFilter) == string::npos) continue;
|
||||
obj.push_back(Pair(strAddr, (int)mn.IsEnabled()));
|
||||
|
||||
|
||||
std::string strStatus = "ACTIVE";
|
||||
|
||||
if(mn.activeState == MASTERNODE_ENABLED) strStatus = "ENABLED";
|
||||
if(mn.activeState == MASTERNODE_EXPIRED) strStatus = "EXPIRED";
|
||||
if(mn.activeState == MASTERNODE_VIN_SPENT) strStatus = "VIN_SPENT";
|
||||
if(mn.activeState == MASTERNODE_REMOVE) strStatus = "REMOVE";
|
||||
if(mn.activeState == MASTERNODE_POS_ERROR) strStatus = "POS_ERROR";
|
||||
|
||||
obj.push_back(Pair(strAddr, strStatus.c_str()));
|
||||
} else if (strMode == "activeseconds") {
|
||||
if(strFilter !="" && mn.addr.ToString().find(strFilter) == string::npos) continue;
|
||||
obj.push_back(Pair(strAddr, (int64_t)(mn.lastTimeSeen - mn.sigTime)));
|
||||
|
@ -87,7 +87,7 @@ bool IsSporkActive(int nSporkID)
|
||||
if(nSporkID == SPORK_2_INSTANTX) r = SPORK_2_INSTANTX_DEFAULT;
|
||||
if(nSporkID == SPORK_3_INSTANTX_BLOCK_FILTERING) r = SPORK_3_INSTANTX_BLOCK_FILTERING_DEFAULT;
|
||||
if(nSporkID == SPORK_5_MAX_VALUE) r = SPORK_5_MAX_VALUE_DEFAULT;
|
||||
if(nSporkID == SPORK_6_REPLAY_BLOCKS) r = SPORK_6_REPLAY_BLOCKS_DEFAULT;
|
||||
if(nSporkID == SPORK_7_MASTERNODE_SCANNING) r = SPORK_7_MASTERNODE_SCANNING;
|
||||
|
||||
if(r == 0) LogPrintf("GetSpork::Unknown Spork %d\n", nSporkID);
|
||||
}
|
||||
@ -108,7 +108,7 @@ int GetSporkValue(int nSporkID)
|
||||
if(nSporkID == SPORK_2_INSTANTX) r = SPORK_2_INSTANTX_DEFAULT;
|
||||
if(nSporkID == SPORK_3_INSTANTX_BLOCK_FILTERING) r = SPORK_3_INSTANTX_BLOCK_FILTERING_DEFAULT;
|
||||
if(nSporkID == SPORK_5_MAX_VALUE) r = SPORK_5_MAX_VALUE_DEFAULT;
|
||||
if(nSporkID == SPORK_6_REPLAY_BLOCKS) r = SPORK_6_REPLAY_BLOCKS_DEFAULT;
|
||||
if(nSporkID == SPORK_7_MASTERNODE_SCANNING) r = SPORK_7_MASTERNODE_SCANNING;
|
||||
|
||||
if(r == 0) LogPrintf("GetSpork::Unknown Spork %d\n", nSporkID);
|
||||
}
|
||||
@ -118,10 +118,6 @@ int GetSporkValue(int nSporkID)
|
||||
|
||||
void ExecuteSpork(int nSporkID, int nValue)
|
||||
{
|
||||
//replay and process blocks (to sync to the longest chain after disabling sporks)
|
||||
if(nSporkID == SPORK_6_REPLAY_BLOCKS){
|
||||
DisconnectBlocksAndReprocess(nValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -220,7 +216,7 @@ int CSporkManager::GetSporkIDByName(std::string strName)
|
||||
if(strName == "SPORK_2_INSTANTX") return SPORK_2_INSTANTX;
|
||||
if(strName == "SPORK_3_INSTANTX_BLOCK_FILTERING") return SPORK_3_INSTANTX_BLOCK_FILTERING;
|
||||
if(strName == "SPORK_5_MAX_VALUE") return SPORK_5_MAX_VALUE;
|
||||
if(strName == "SPORK_6_REPLAY_BLOCKS") return SPORK_6_REPLAY_BLOCKS;
|
||||
if(strName == "SPORK_7_MASTERNODE_SCANNING") return SPORK_7_MASTERNODE_SCANNING;
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -231,7 +227,7 @@ std::string CSporkManager::GetSporkNameByID(int id)
|
||||
if(id == SPORK_2_INSTANTX) return "SPORK_2_INSTANTX";
|
||||
if(id == SPORK_3_INSTANTX_BLOCK_FILTERING) return "SPORK_3_INSTANTX_BLOCK_FILTERING";
|
||||
if(id == SPORK_5_MAX_VALUE) return "SPORK_5_MAX_VALUE";
|
||||
if(id == SPORK_6_REPLAY_BLOCKS) return "SPORK_6_REPLAY_BLOCKS";
|
||||
if(id == SPORK_7_MASTERNODE_SCANNING) return "SPORK_7_MASTERNODE_SCANNING";
|
||||
|
||||
return "Unknown";
|
||||
}
|
@ -24,14 +24,14 @@ using namespace boost;
|
||||
#define SPORK_3_INSTANTX_BLOCK_FILTERING 10002
|
||||
#define SPORK_4_NOTUSED 10003
|
||||
#define SPORK_5_MAX_VALUE 10004
|
||||
#define SPORK_6_REPLAY_BLOCKS 10005
|
||||
#define SPORK_6_NOTUSED 10005
|
||||
#define SPORK_7_MASTERNODE_SCANNING 10006
|
||||
|
||||
#define SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT_DEFAULT 1424217600 //2015-2-18
|
||||
#define SPORK_2_INSTANTX_DEFAULT 978307200 //2001-1-1
|
||||
#define SPORK_3_INSTANTX_BLOCK_FILTERING_DEFAULT 1424217600 //2015-2-18
|
||||
#define SPORK_4_RECONVERGE_DEFAULT 1420070400 //2047-1-1
|
||||
#define SPORK_5_MAX_VALUE_DEFAULT 1000 //1000 DRK
|
||||
#define SPORK_6_REPLAY_BLOCKS_DEFAULT 0
|
||||
#define SPORK_7_MASTERNODE_SCANNING_DEFAULT 978307200 //2001-1-1
|
||||
|
||||
class CSporkMessage;
|
||||
class CSporkManager;
|
||||
|
Loading…
Reference in New Issue
Block a user