From 4152eea1c183ee084eae6c973978569cac1ff10c Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Mon, 23 Mar 2015 05:59:22 -0700 Subject: [PATCH] fixed ranking issues for PoSe --- src/darksend.cpp | 2 +- src/masternode-pos.cpp | 22 +++++++++++++++------- src/masternode.h | 1 + src/masternodeman.cpp | 9 +++++++++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index 69f5d206a0..4f4d1b2951 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -197,7 +197,7 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand For added DDOS protection, clients can only relay through 20 nodes per block. */ int rank = mnodeman.GetMasternodeRank(activeMasternode.vin, dsr.nBlockHeight, MIN_POOL_PEER_PROTO_VERSION); - if(rank > 20){ + if(rank == -1 || rank > 20){ LogPrintf("dsr -- invalid relay Masternode! %s \n", activeMasternode.vin.ToString().c_str()); return; } diff --git a/src/masternode-pos.cpp b/src/masternode-pos.cpp index 39ec6aded1..8037b9b3a9 100644 --- a/src/masternode-pos.cpp +++ b/src/masternode-pos.cpp @@ -78,16 +78,22 @@ void ProcessMessageMasternodePOS(CNode* pfrom, std::string& strCommand, CDataStr return; } + int nBlockHeight = chainActive.Tip()->nHeight; + if(nBlockHeight - mnse.nBlockHeight > 10){ + LogPrintf("MasternodePOS::mnse - Too old\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()) + if(a == -1 || 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()) + if(b == -1 || b < mnodeman.CountMasternodesAboveProtocol(MIN_MASTERNODE_POS_PROTO_VERSION)-GetCountScanningPerBlock()) { LogPrintf("MasternodePOS::mnse - MasternodeB ranking is too low\n"); return; @@ -139,28 +145,30 @@ void CMasternodeScanning::DoMasternodePOSChecks() 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()){ + int nBlockHeight = chainActive.Tip()->nHeight-5; + + int a = mnodeman.GetMasternodeRank(activeMasternode.vin, nBlockHeight, MIN_MASTERNODE_POS_PROTO_VERSION); + if(a == -1 || 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); + CMasternode* pmn = mnodeman.GetMasternodeByRank(mnodeman.CountMasternodesAboveProtocol(MIN_MASTERNODE_POS_PROTO_VERSION)-a, nBlockHeight, 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); + CMasternodeScanningError mnse(activeMasternode.vin, pmn->vin, SCANNING_ERROR_NO_RESPONSE, nBlockHeight); mnse.Sign(); mapMasternodeScanningErrors.insert(make_pair(mnse.GetHash(), mnse)); mnse.Relay(); } // success - CMasternodeScanningError mnse(activeMasternode.vin, pmn->vin, SCANNING_SUCCESS, chainActive.Tip()->nHeight); + CMasternodeScanningError mnse(activeMasternode.vin, pmn->vin, SCANNING_SUCCESS, nBlockHeight); mnse.Sign(); mapMasternodeScanningErrors.insert(make_pair(mnse.GetHash(), mnse)); mnse.Relay(); diff --git a/src/masternode.h b/src/masternode.h index 4fe8d8f2c0..2ce1de2cd0 100644 --- a/src/masternode.h +++ b/src/masternode.h @@ -52,6 +52,7 @@ enum masternodeState { }; void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); +bool GetBlockHash(uint256& hash, int nBlockHeight); // // The Masternode Class. For managing the Darksend process. It contains the input of the 1000DRK, signature to prove diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 9f89dbe2b8..781d7c500c 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "masternodeman.h" +#include "masternode.h" #include "activemasternode.h" #include "darksend.h" #include "core.h" @@ -383,6 +384,10 @@ int CMasternodeMan::GetMasternodeRank(const CTxIn& vin, int64_t nBlockHeight, in { std::vector > vecMasternodeScores; + //make sure we know about this block + uint256 hash = 0; + if(!GetBlockHash(hash, nBlockHeight)) return -1; + // scan for winner BOOST_FOREACH(CMasternode& mn, vMasternodes) { @@ -418,6 +423,10 @@ std::vector > CMasternodeMan::GetMasternodeRanks(int64_t std::vector > vecMasternodeScores; std::vector > vecMasternodeRanks; + //make sure we know about this block + uint256 hash = 0; + if(!GetBlockHash(hash, nBlockHeight)) return vecMasternodeRanks; + // scan for winner BOOST_FOREACH(CMasternode& mn, vMasternodes) {