mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
- Added const where possible
- Uncommented sync block - Protocol min 70201 - Fixed bug which flags invalid votes incorrectly - Formatting
This commit is contained in:
parent
487674f0c9
commit
15821fe2d4
@ -76,7 +76,8 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint256 GetHash(){
|
||||
uint256 GetHash() const
|
||||
{
|
||||
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
||||
ss << vinMasternode;
|
||||
ss << nParentHash;
|
||||
@ -87,7 +88,7 @@ public:
|
||||
}
|
||||
|
||||
// GET HASH WITH DETERMINISTIC HASH OF PARENT-HASH/VOTE-TYPE
|
||||
uint256 GetTypeHash()
|
||||
uint256 GetTypeHash() const
|
||||
{
|
||||
// CALCULATE HOW TO STORE VOTE IN governance.mapVotes
|
||||
|
||||
|
@ -106,8 +106,9 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
|
||||
LOCK(cs_budget);
|
||||
|
||||
// GOVERANCE SYNCING FUNCTIONALITY
|
||||
if (strCommand == NetMsgType::MNGOVERNANCESYNC)
|
||||
{
|
||||
|
||||
if (strCommand == NetMsgType::MNGOVERNANCESYNC) {
|
||||
uint256 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
|
||||
Sync(pfrom, nProp);
|
||||
LogPrint("mngovernance", "syncing governance objects to our peer at %s\n", pfrom->addr.ToString());
|
||||
|
||||
}
|
||||
|
||||
// NEW GOVERNANCE OBJECT
|
||||
else if (strCommand == NetMsgType::MNGOVERNANCEOBJECT)
|
||||
|
||||
{
|
||||
|
||||
if (strCommand == NetMsgType::MNGOVERNANCEOBJECT) {
|
||||
CGovernanceObject 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());
|
||||
//We might have active votes for this proposal that are valid now
|
||||
CheckOrphanVotes();
|
||||
|
||||
}
|
||||
|
||||
// NEW GOVERNANCE OBJECT VOTE
|
||||
else if (strCommand == NetMsgType::MNGOVERNANCEVOTE)
|
||||
|
||||
{
|
||||
|
||||
if (strCommand == NetMsgType::MNGOVERNANCEVOTE) {
|
||||
CGovernanceVote vote;
|
||||
vRecv >> vote;
|
||||
vote.fValid = true;
|
||||
@ -186,13 +193,15 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
|
||||
return;
|
||||
}
|
||||
|
||||
mapSeenVotes.insert(make_pair(vote.GetHash(), SEEN_OBJECT_IS_VALID));
|
||||
if(!vote.IsValid(true)){
|
||||
LogPrintf("mngovernance - signature invalid\n");
|
||||
if(masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20);
|
||||
// it could just be a non-synced masternode
|
||||
mnodeman.AskForMN(pfrom, vote.vinMasternode);
|
||||
mapSeenVotes.insert(make_pair(vote.GetHash(), SEEN_OBJECT_ERROR_INVALID));
|
||||
return;
|
||||
} else {
|
||||
mapSeenVotes.insert(make_pair(vote.GetHash(), SEEN_OBJECT_IS_VALID));
|
||||
}
|
||||
|
||||
std::string strError = "";
|
||||
@ -299,7 +308,7 @@ CGovernanceObject *CGovernanceManager::FindGovernanceObject(const std::string &s
|
||||
return pGovObj;
|
||||
}
|
||||
|
||||
CGovernanceObject *CGovernanceManager::FindGovernanceObject(uint256& nHash)
|
||||
CGovernanceObject *CGovernanceManager::FindGovernanceObject(const uint256& nHash)
|
||||
{
|
||||
LOCK(cs);
|
||||
|
||||
@ -469,7 +478,7 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp)
|
||||
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)){
|
||||
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);
|
||||
|
||||
@ -501,29 +510,30 @@ bool CGovernanceManager::UpdateGovernanceObject(CGovernanceVote& vote, CNode* pf
|
||||
return AddOrUpdateVote(vote, strError);
|
||||
}
|
||||
|
||||
bool CGovernanceManager::AddOrUpdateVote(CGovernanceVote& vote, std::string& strError)
|
||||
bool CGovernanceManager::AddOrUpdateVote(const CGovernanceVote& vote, std::string& strError)
|
||||
{
|
||||
LOCK(cs);
|
||||
|
||||
// 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){
|
||||
strError = strprintf("new vote older than existing vote - %s", vote.GetHash().ToString());
|
||||
if(mapVotesByType[nTypeHash].nTime > vote.nTime){
|
||||
strError = strprintf("new vote older than existing vote - %s", nTypeHash.ToString());
|
||||
LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError);
|
||||
return false;
|
||||
}
|
||||
if(vote.nTime - mapVotesByType[hash].nTime < GOVERNANCE_UPDATE_MIN){
|
||||
strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotesByType[hash].nTime);
|
||||
if(vote.nTime - mapVotesByType[nTypeHash].nTime < GOVERNANCE_UPDATE_MIN){
|
||||
strError = strprintf("time between votes is too soon - %s - %lli", nTypeHash.ToString(), vote.nTime - mapVotesByType[nHash].nTime);
|
||||
LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
mapVotesByType[vote.GetTypeHash()] = vote;
|
||||
mapVotesByHash[vote.GetHash()] = vote;
|
||||
mapVotesByType[nTypeHash] = vote;
|
||||
mapVotesByHash[nHash] = vote;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -98,13 +98,13 @@ public:
|
||||
//void ResetSync();
|
||||
//void MarkSynced();
|
||||
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 NewBlock();
|
||||
|
||||
CGovernanceObject *FindGovernanceObject(const std::string &strName);
|
||||
CGovernanceObject *FindGovernanceObject(uint256& nHash);
|
||||
CGovernanceObject *FindGovernanceObject(const uint256& nHash);
|
||||
|
||||
std::vector<CGovernanceObject*> GetAllProposals(int64_t nMoreThanTime);
|
||||
|
||||
@ -112,8 +112,8 @@ public:
|
||||
|
||||
bool IsBudgetPaymentBlock(int nBlockHeight);
|
||||
bool AddGovernanceObject (CGovernanceObject& govobj);
|
||||
bool UpdateGovernanceObject(CGovernanceVote& vote, CNode* pfrom, std::string& strError);
|
||||
bool AddOrUpdateVote(CGovernanceVote& vote, std::string& strError);
|
||||
bool UpdateGovernanceObject(const CGovernanceVote& vote, CNode* pfrom, std::string& strError);
|
||||
bool AddOrUpdateVote(const CGovernanceVote& vote, std::string& strError);
|
||||
std::string GetRequiredPaymentsString(int nBlockHeight);
|
||||
void CleanAndRemove(bool fSignatureCheck);
|
||||
void CheckAndRemove();
|
||||
|
@ -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
|
||||
// if(lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT){
|
||||
// GetNextAsset();
|
||||
//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){
|
||||
GetNextAsset();
|
||||
|
||||
// //try to activate our masternode if possible
|
||||
// activeMasternode.ManageStatus();
|
||||
// return;
|
||||
// }
|
||||
//try to activate our masternode if possible
|
||||
activeMasternode.ManageStatus();
|
||||
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
|
||||
|
||||
|
@ -9,9 +9,9 @@
|
||||
#define MASTERNODE_SYNC_SPORKS 1
|
||||
#define MASTERNODE_SYNC_LIST 2
|
||||
#define MASTERNODE_SYNC_MNW 3
|
||||
#define MASTERNODE_SYNC_GOVERNANCE 4
|
||||
#define MASTERNODE_SYNC_GOVOBJ 10
|
||||
#define MASTERNODE_SYNC_GOVERNANCE_FIN 11
|
||||
#define MASTERNODE_SYNC_GOVERNANCE 4
|
||||
#define MASTERNODE_SYNC_GOVOBJ 10
|
||||
#define MASTERNODE_SYNC_GOVERNANCE_FIN 11
|
||||
#define MASTERNODE_SYNC_FAILED 998
|
||||
#define MASTERNODE_SYNC_FINISHED 999
|
||||
|
||||
|
@ -152,6 +152,7 @@ UniValue mnsync(const UniValue& params, bool fHelp)
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
|
||||
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("lastMasternodeWinner", masternodeSync.lastMasternodeWinner));
|
||||
obj.push_back(Pair("lastBudgetItem", masternodeSync.lastBudgetItem));
|
||||
|
@ -22,10 +22,10 @@ static const int GETHEADERS_VERSION = 70077;
|
||||
static const int MIN_PEER_PROTO_VERSION = 70103;
|
||||
|
||||
//! 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
|
||||
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
|
||||
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
|
||||
// V2 - Newest protocol version
|
||||
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;
|
||||
//! if possible, avoid requesting addresses nodes older than this
|
||||
|
Loading…
Reference in New Issue
Block a user