- Added const where possible

- Uncommented sync block
- Protocol min 70201
- Fixed bug which flags invalid votes incorrectly
- Formatting
This commit is contained in:
Evan Duffield 2016-06-06 16:06:52 -07:00
parent 487674f0c9
commit 15821fe2d4
7 changed files with 47 additions and 35 deletions

View File

@ -76,7 +76,8 @@ public:
return ret; return ret;
} }
uint256 GetHash(){ uint256 GetHash() const
{
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
ss << vinMasternode; ss << vinMasternode;
ss << nParentHash; ss << nParentHash;
@ -87,7 +88,7 @@ public:
} }
// GET HASH WITH DETERMINISTIC HASH OF PARENT-HASH/VOTE-TYPE // GET HASH WITH DETERMINISTIC HASH OF PARENT-HASH/VOTE-TYPE
uint256 GetTypeHash() uint256 GetTypeHash() const
{ {
// CALCULATE HOW TO STORE VOTE IN governance.mapVotes // CALCULATE HOW TO STORE VOTE IN governance.mapVotes

View File

@ -106,8 +106,9 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
LOCK(cs_budget); LOCK(cs_budget);
// GOVERANCE SYNCING FUNCTIONALITY // GOVERANCE SYNCING FUNCTIONALITY
if (strCommand == NetMsgType::MNGOVERNANCESYNC)
{
if (strCommand == NetMsgType::MNGOVERNANCESYNC) {
uint256 nProp; uint256 nProp;
vRecv >> nProp; vRecv >> nProp;
@ -125,11 +126,14 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
// ask for a specific proposal and it's votes // ask for a specific proposal and it's votes
Sync(pfrom, nProp); Sync(pfrom, nProp);
LogPrint("mngovernance", "syncing governance objects to our peer at %s\n", pfrom->addr.ToString()); LogPrint("mngovernance", "syncing governance objects to our peer at %s\n", pfrom->addr.ToString());
} }
// NEW GOVERNANCE OBJECT // NEW GOVERNANCE OBJECT
else if (strCommand == NetMsgType::MNGOVERNANCEOBJECT)
{
if (strCommand == NetMsgType::MNGOVERNANCEOBJECT) {
CGovernanceObject govobj; CGovernanceObject govobj;
vRecv >> govobj; vRecv >> govobj;
@ -165,11 +169,14 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
LogPrintf("Governance object - new! - %s\n", govobj.GetHash().ToString()); LogPrintf("Governance object - new! - %s\n", govobj.GetHash().ToString());
//We might have active votes for this proposal that are valid now //We might have active votes for this proposal that are valid now
CheckOrphanVotes(); CheckOrphanVotes();
} }
// NEW GOVERNANCE OBJECT VOTE // NEW GOVERNANCE OBJECT VOTE
else if (strCommand == NetMsgType::MNGOVERNANCEVOTE)
{
if (strCommand == NetMsgType::MNGOVERNANCEVOTE) {
CGovernanceVote vote; CGovernanceVote vote;
vRecv >> vote; vRecv >> vote;
vote.fValid = true; vote.fValid = true;
@ -186,13 +193,15 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
return; return;
} }
mapSeenVotes.insert(make_pair(vote.GetHash(), SEEN_OBJECT_IS_VALID));
if(!vote.IsValid(true)){ if(!vote.IsValid(true)){
LogPrintf("mngovernance - signature invalid\n"); LogPrintf("mngovernance - signature invalid\n");
if(masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20); if(masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20);
// it could just be a non-synced masternode // it could just be a non-synced masternode
mnodeman.AskForMN(pfrom, vote.vinMasternode); mnodeman.AskForMN(pfrom, vote.vinMasternode);
mapSeenVotes.insert(make_pair(vote.GetHash(), SEEN_OBJECT_ERROR_INVALID));
return; return;
} else {
mapSeenVotes.insert(make_pair(vote.GetHash(), SEEN_OBJECT_IS_VALID));
} }
std::string strError = ""; std::string strError = "";
@ -299,7 +308,7 @@ CGovernanceObject *CGovernanceManager::FindGovernanceObject(const std::string &s
return pGovObj; return pGovObj;
} }
CGovernanceObject *CGovernanceManager::FindGovernanceObject(uint256& nHash) CGovernanceObject *CGovernanceManager::FindGovernanceObject(const uint256& nHash)
{ {
LOCK(cs); LOCK(cs);
@ -469,7 +478,7 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp)
LogPrintf("CGovernanceManager::Sync - sent %d items\n", nInvCount); LogPrintf("CGovernanceManager::Sync - sent %d items\n", nInvCount);
} }
void CGovernanceManager::SyncParentObjectByVote(CNode* pfrom, CGovernanceVote& vote) void CGovernanceManager::SyncParentObjectByVote(CNode* pfrom, const CGovernanceVote& vote)
{ {
if(!mapAskedForGovernanceObject.count(vote.nParentHash)){ if(!mapAskedForGovernanceObject.count(vote.nParentHash)){
pfrom->PushMessage(NetMsgType::MNGOVERNANCESYNC, vote.nParentHash); pfrom->PushMessage(NetMsgType::MNGOVERNANCESYNC, vote.nParentHash);
@ -477,7 +486,7 @@ void CGovernanceManager::SyncParentObjectByVote(CNode* pfrom, CGovernanceVote& v
} }
} }
bool CGovernanceManager::UpdateGovernanceObject(CGovernanceVote& vote, CNode* pfrom, std::string& strError) bool CGovernanceManager::UpdateGovernanceObject(const CGovernanceVote& vote, CNode* pfrom, std::string& strError)
{ {
LOCK(cs); LOCK(cs);
@ -501,29 +510,30 @@ bool CGovernanceManager::UpdateGovernanceObject(CGovernanceVote& vote, CNode* pf
return AddOrUpdateVote(vote, strError); return AddOrUpdateVote(vote, strError);
} }
bool CGovernanceManager::AddOrUpdateVote(CGovernanceVote& vote, std::string& strError) bool CGovernanceManager::AddOrUpdateVote(const CGovernanceVote& vote, std::string& strError)
{ {
LOCK(cs); LOCK(cs);
// GET DETERMINISTIC HASH INCLUDING PARENT/TYPE // GET DETERMINISTIC HASH INCLUDING PARENT/TYPE
uint256 hash = vote.GetTypeHash(); uint256 nTypeHash = vote.GetTypeHash();
uint256 nHash = vote.GetHash();
if(mapVotesByType.count(hash)) if(mapVotesByType.count(nTypeHash))
{ {
if(mapVotesByType[hash].nTime > vote.nTime){ if(mapVotesByType[nTypeHash].nTime > vote.nTime){
strError = strprintf("new vote older than existing vote - %s", vote.GetHash().ToString()); strError = strprintf("new vote older than existing vote - %s", nTypeHash.ToString());
LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError); LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError);
return false; return false;
} }
if(vote.nTime - mapVotesByType[hash].nTime < GOVERNANCE_UPDATE_MIN){ if(vote.nTime - mapVotesByType[nTypeHash].nTime < GOVERNANCE_UPDATE_MIN){
strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotesByType[hash].nTime); strError = strprintf("time between votes is too soon - %s - %lli", nTypeHash.ToString(), vote.nTime - mapVotesByType[nHash].nTime);
LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError); LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError);
return false; return false;
} }
} }
mapVotesByType[vote.GetTypeHash()] = vote; mapVotesByType[nTypeHash] = vote;
mapVotesByHash[vote.GetHash()] = vote; mapVotesByHash[nHash] = vote;
return true; return true;
} }

View File

@ -98,13 +98,13 @@ public:
//void ResetSync(); //void ResetSync();
//void MarkSynced(); //void MarkSynced();
void Sync(CNode* node, uint256 nProp); void Sync(CNode* node, uint256 nProp);
void SyncParentObjectByVote(CNode* pfrom, CGovernanceVote& vote); void SyncParentObjectByVote(CNode* pfrom, const CGovernanceVote& vote);
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
void NewBlock(); void NewBlock();
CGovernanceObject *FindGovernanceObject(const std::string &strName); CGovernanceObject *FindGovernanceObject(const std::string &strName);
CGovernanceObject *FindGovernanceObject(uint256& nHash); CGovernanceObject *FindGovernanceObject(const uint256& nHash);
std::vector<CGovernanceObject*> GetAllProposals(int64_t nMoreThanTime); std::vector<CGovernanceObject*> GetAllProposals(int64_t nMoreThanTime);
@ -112,8 +112,8 @@ public:
bool IsBudgetPaymentBlock(int nBlockHeight); bool IsBudgetPaymentBlock(int nBlockHeight);
bool AddGovernanceObject (CGovernanceObject& govobj); bool AddGovernanceObject (CGovernanceObject& govobj);
bool UpdateGovernanceObject(CGovernanceVote& vote, CNode* pfrom, std::string& strError); bool UpdateGovernanceObject(const CGovernanceVote& vote, CNode* pfrom, std::string& strError);
bool AddOrUpdateVote(CGovernanceVote& vote, std::string& strError); bool AddOrUpdateVote(const CGovernanceVote& vote, std::string& strError);
std::string GetRequiredPaymentsString(int nBlockHeight); std::string GetRequiredPaymentsString(int nBlockHeight);
void CleanAndRemove(bool fSignatureCheck); void CleanAndRemove(bool fSignatureCheck);
void CheckAndRemove(); void CheckAndRemove();

View File

@ -390,14 +390,14 @@ void CMasternodeSync::Process()
// } // }
// } // }
// //we'll start rejecting votes if we accidentally get set as synced too soon, this allows plenty of time //we'll start rejecting votes if we accidentally get set as synced too soon, this allows plenty of time
// if(lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT){ if(lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT){
// GetNextAsset(); GetNextAsset();
// //try to activate our masternode if possible //try to activate our masternode if possible
// activeMasternode.ManageStatus(); activeMasternode.ManageStatus();
// return; return;
// } }
// requesting is the last thing we do, incase we needed to move to the next asset and we've requested from each peer already // requesting is the last thing we do, incase we needed to move to the next asset and we've requested from each peer already

View File

@ -9,9 +9,9 @@
#define MASTERNODE_SYNC_SPORKS 1 #define MASTERNODE_SYNC_SPORKS 1
#define MASTERNODE_SYNC_LIST 2 #define MASTERNODE_SYNC_LIST 2
#define MASTERNODE_SYNC_MNW 3 #define MASTERNODE_SYNC_MNW 3
#define MASTERNODE_SYNC_GOVERNANCE 4 #define MASTERNODE_SYNC_GOVERNANCE 4
#define MASTERNODE_SYNC_GOVOBJ 10 #define MASTERNODE_SYNC_GOVOBJ 10
#define MASTERNODE_SYNC_GOVERNANCE_FIN 11 #define MASTERNODE_SYNC_GOVERNANCE_FIN 11
#define MASTERNODE_SYNC_FAILED 998 #define MASTERNODE_SYNC_FAILED 998
#define MASTERNODE_SYNC_FINISHED 999 #define MASTERNODE_SYNC_FINISHED 999

View File

@ -152,6 +152,7 @@ UniValue mnsync(const UniValue& params, bool fHelp)
UniValue obj(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("IsBlockchainSynced", masternodeSync.IsBlockchainSynced())); obj.push_back(Pair("IsBlockchainSynced", masternodeSync.IsBlockchainSynced()));
obj.push_back(Pair("CurrentSyncingAssetName", masternodeSync.GetAssetName()));
obj.push_back(Pair("lastMasternodeList", masternodeSync.lastMasternodeList)); obj.push_back(Pair("lastMasternodeList", masternodeSync.lastMasternodeList));
obj.push_back(Pair("lastMasternodeWinner", masternodeSync.lastMasternodeWinner)); obj.push_back(Pair("lastMasternodeWinner", masternodeSync.lastMasternodeWinner));
obj.push_back(Pair("lastBudgetItem", masternodeSync.lastBudgetItem)); obj.push_back(Pair("lastBudgetItem", masternodeSync.lastBudgetItem));

View File

@ -22,10 +22,10 @@ static const int GETHEADERS_VERSION = 70077;
static const int MIN_PEER_PROTO_VERSION = 70103; static const int MIN_PEER_PROTO_VERSION = 70103;
//! minimum peer version accepted by DarksendPool //! minimum peer version accepted by DarksendPool
static const int MIN_POOL_PEER_PROTO_VERSION = 70200; static const int MIN_POOL_PEER_PROTO_VERSION = 70201;
//! minimum peer version for masternode budgets //! minimum peer version for masternode budgets
static const int MSG_GOVERNANCE_PEER_PROTO_VERSION = 70200; static const int MSG_GOVERNANCE_PEER_PROTO_VERSION = 70201;
//! minimum peer version for masternode winner broadcasts //! minimum peer version for masternode winner broadcasts
static const int MIN_MNW_PEER_PROTO_VERSION = 70103; static const int MIN_MNW_PEER_PROTO_VERSION = 70103;
@ -34,7 +34,7 @@ static const int MIN_MNW_PEER_PROTO_VERSION = 70103;
// V1 - Last protocol version before update // V1 - Last protocol version before update
// V2 - Newest protocol version // V2 - Newest protocol version
static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_1 = 70103; static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_1 = 70103;
static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_2 = 70200; static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_2 = 70201;
//! nTime field added to CAddress, starting with this version; //! nTime field added to CAddress, starting with this version;
//! if possible, avoid requesting addresses nodes older than this //! if possible, avoid requesting addresses nodes older than this