Merge branch 'v0.12.1.x-cleanup' into v0.12.1.x

This commit is contained in:
Evan Duffield 2016-05-23 11:10:37 -07:00
commit 2afa20b8d7
11 changed files with 219 additions and 273 deletions

View File

@ -17,7 +17,7 @@
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 12
#define CLIENT_VERSION_REVISION 1
#define CLIENT_VERSION_BUILD 0
#define CLIENT_VERSION_BUILD 1
//! Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true

View File

@ -11,7 +11,7 @@
using namespace std;
class CBudgetVote;
class CGovernanceVote;
/**
* Triggers and Settings - 12.2

View File

@ -18,11 +18,11 @@
#include <boost/lexical_cast.hpp>
CBudgetVote::CBudgetVote()
CGovernanceVote::CGovernanceVote()
{
vinMasternode = CTxIn();
nParentHash = uint256();
nVoteAction = VOTE_ACTION_NONE;
nVoteSignal = VOTE_SIGNAL_NONE;
nVoteOutcome = VOTE_OUTCOME_NONE;
nTime = 0;
fValid = true;
@ -30,24 +30,24 @@ CBudgetVote::CBudgetVote()
vchSig.clear();
}
CBudgetVote::CBudgetVote(CTxIn vinMasternodeIn, uint256 nParentHashIn, int nVoteActionIn, int nVoteOutcomeIn)
CGovernanceVote::CGovernanceVote(CTxIn vinMasternodeIn, uint256 nParentHashIn, int nVoteSignalIn, int nVoteOutcomeIn)
{
vinMasternode = vinMasternodeIn;
nParentHash = nParentHashIn;
nVoteAction = nVoteActionIn;
nVoteSignal = nVoteSignalIn;
nVoteOutcome = nVoteOutcomeIn;
nTime = GetAdjustedTime();
fValid = true;
fSynced = false;
}
void CBudgetVote::Relay()
void CGovernanceVote::Relay()
{
CInv inv(MSG_BUDGET_VOTE, GetHash());
RelayInv(inv, MIN_BUDGET_PEER_PROTO_VERSION);
}
bool CBudgetVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
bool CGovernanceVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
{
// Choose coins to use
CPubKey pubKeyCollateralAddress;
@ -55,46 +55,46 @@ bool CBudgetVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
std::string errorMessage;
std::string strMessage = vinMasternode.prevout.ToStringShort() + "|" + nParentHash.ToString() + "|" +
boost::lexical_cast<std::string>(nVoteAction) + "|" + boost::lexical_cast<std::string>(nVoteOutcome) + "|" + boost::lexical_cast<std::string>(nTime);
boost::lexical_cast<std::string>(nVoteSignal) + "|" + boost::lexical_cast<std::string>(nVoteOutcome) + "|" + boost::lexical_cast<std::string>(nTime);
if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyMasternode)) {
LogPrintf("CBudgetVote::Sign - Error upon calling SignMessage");
LogPrintf("CGovernanceVote::Sign - Error upon calling SignMessage");
return false;
}
if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage)) {
LogPrintf("CBudgetVote::Sign - Error upon calling VerifyMessage");
LogPrintf("CGovernanceVote::Sign - Error upon calling VerifyMessage");
return false;
}
return true;
}
bool CBudgetVote::IsValid(bool fSignatureCheck)
bool CGovernanceVote::IsValid(bool fSignatureCheck)
{
if(nTime > GetTime() + (60*60)){
LogPrint("mngovernance", "CBudgetVote::IsValid() - vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", GetHash().ToString(), nTime, GetTime() + (60*60));
LogPrint("mngovernance", "CGovernanceVote::IsValid() - vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", GetHash().ToString(), nTime, GetTime() + (60*60));
return false;
}
// support up to 50 actions (implemented in sentinel)
if(nVoteAction > 50)
if(nVoteSignal > 50)
{
LogPrint("mngovernance", "CBudgetVote::IsValid() - Client attempted to vote on invalid action(%d) - %s\n", nVoteAction, GetHash().ToString());
LogPrint("mngovernance", "CGovernanceVote::IsValid() - Client attempted to vote on invalid action(%d) - %s\n", nVoteSignal, GetHash().ToString());
return false;
}
// 0=none, 1=yes, 2=no, 3=abstain. Beyond that reject votes
if(nVoteOutcome > 3)
{
LogPrint("mngovernance", "CBudgetVote::IsValid() - Client attempted to vote on invalid outcome(%d) - %s\n", nVoteAction, GetHash().ToString());
LogPrint("mngovernance", "CGovernanceVote::IsValid() - Client attempted to vote on invalid outcome(%d) - %s\n", nVoteSignal, GetHash().ToString());
return false;
}
CMasternode* pmn = mnodeman.Find(vinMasternode);
if(pmn == NULL)
{
LogPrint("mngovernance", "CBudgetVote::IsValid() - Unknown Masternode - %s\n", vinMasternode.ToString());
LogPrint("mngovernance", "CGovernanceVote::IsValid() - Unknown Masternode - %s\n", vinMasternode.ToString());
return false;
}
@ -102,10 +102,10 @@ bool CBudgetVote::IsValid(bool fSignatureCheck)
std::string errorMessage;
std::string strMessage = vinMasternode.prevout.ToStringShort() + "|" + nParentHash.ToString() + "|" +
boost::lexical_cast<std::string>(nVoteAction) + "|" + boost::lexical_cast<std::string>(nVoteOutcome) + "|" + boost::lexical_cast<std::string>(nTime);
boost::lexical_cast<std::string>(nVoteSignal) + "|" + boost::lexical_cast<std::string>(nVoteOutcome) + "|" + boost::lexical_cast<std::string>(nTime);
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)) {
LogPrintf("CBudgetVote::IsValid() - Verify message failed - Error: %s\n", errorMessage);
LogPrintf("CGovernanceVote::IsValid() - Verify message failed - Error: %s\n", errorMessage);
return false;
}

View File

@ -17,7 +17,7 @@
using namespace std;
class CBudgetVote;
class CGovernanceVote;
#define VOTE_OUTCOME_NONE 0
#define VOTE_OUTCOME_YES 1
@ -25,44 +25,43 @@ class CBudgetVote;
#define VOTE_OUTCOME_ABSTAIN 3
// INTENTION OF MASTERNODES REGARDING ITEM
#define VOTE_ACTION_NONE 0 // SIGNAL VARIOUS THINGS TO HAPPEN:
#define VOTE_ACTION_FUNDING 1 // -- fund this object for it's stated amount
#define VOTE_ACTION_VALID 2 // -- this object checks out to sentinel
#define VOTE_ACTION_DELETE 3 // -- this object should be deleted from memory entirely
#define VOTE_ACTION_CLEAR_REGISTERS 4 // -- this object's registers should be cleared (stored elsewhere, e.g. dashdrive)
#define VOTE_ACTION_ENDORSED 5 // -- officially endorsed by the network somehow (delegation)
#define VOTE_ACTION_RELEASE_BOUNTY1 6 // -- release the first bounty associated with this
#define VOTE_ACTION_RELEASE_BOUNTY2 7 // -- second
#define VOTE_ACTION_RELEASE_BOUNTY3 8 // -- third
#define VOTE_ACTION_NOOP1 9 // FOR FURTHER EXPANSION
#define VOTE_ACTION_NOOP2 10 //
#define VOTE_ACTION_NOOP3 11 //
#define VOTE_ACTION_NOOP4 12 //
#define VOTE_ACTION_NOOP5 13 //
#define VOTE_ACTION_NOOP6 14 //
#define VOTE_ACTION_NOOP7 15 //
#define VOTE_ACTION_CUSTOM_START 16 // SENTINEL CUSTOM ACTIONS
#define VOTE_ACTION_CUSTOM_END 35 // 16-35
#define VOTE_SIGNAL_NONE 0 // SIGNAL VARIOUS THINGS TO HAPPEN:
#define VOTE_SIGNAL_FUNDING 1 // -- fund this object for it's stated amount
#define VOTE_SIGNAL_VALID 2 // -- this object checks out to sentinel
#define VOTE_SIGNAL_DELETE 3 // -- this object should be deleted from memory entirely
#define VOTE_SIGNAL_CLEAR_REGISTERS 4 // -- this object's registers should be cleared (stored elsewhere, e.g. dashdrive)
#define VOTE_SIGNAL_ENDORSED 5 // -- officially endorsed by the network somehow (delegation)
#define VOTE_SIGNAL_RELEASE_BOUNTY1 6 // -- release the first bounty associated with this
#define VOTE_SIGNAL_RELEASE_BOUNTY2 7 // -- second
#define VOTE_SIGNAL_RELEASE_BOUNTY3 8 // -- third
#define VOTE_SIGNAL_NOOP1 9 // FOR FURTHER EXPANSION
#define VOTE_SIGNAL_NOOP2 10 //
#define VOTE_SIGNAL_NOOP3 11 //
#define VOTE_SIGNAL_NOOP4 12 //
#define VOTE_SIGNAL_NOOP5 13 //
#define VOTE_SIGNAL_NOOP6 14 //
#define VOTE_SIGNAL_NOOP7 15 //
#define VOTE_SIGNAL_CUSTOM_START 16 // SENTINEL CUSTOM ACTIONS
#define VOTE_SIGNAL_CUSTOM_END 35 // 16-35
//
// CBudgetVote - Allow a masternode node to vote and broadcast throughout the network
// CGovernanceVote - Allow a masternode node to vote and broadcast throughout the network
//
class CBudgetVote
class CGovernanceVote
{
//# ----
public:
bool fValid; //if the vote is currently valid / counted
bool fSynced; //if we've sent this to our peers
int nVoteAction; // see VOTE_ACTIONS above
int nVoteSignal; // see VOTE_ACTIONS above
CTxIn vinMasternode;
uint256 nParentHash;
int nVoteOutcome; // see VOTE_OUTCOMES above
int64_t nTime;
std::vector<unsigned char> vchSig;
CBudgetVote();
CBudgetVote(CTxIn vinMasternodeIn, uint256 nParentHashIn, int nVoteActionIn, int nVoteOutcomeIn);
CGovernanceVote();
CGovernanceVote(CTxIn vinMasternodeIn, uint256 nParentHashIn, int nVoteSignalIn, int nVoteOutcomeIn);
bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode);
bool IsValid(bool fSignatureCheck);
@ -81,7 +80,7 @@ public:
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
ss << vinMasternode;
ss << nParentHash;
ss << nVoteAction;
ss << nVoteSignal;
ss << nVoteOutcome;
ss << nTime;
return ss.GetHash();
@ -94,7 +93,7 @@ public:
READWRITE(vinMasternode);
READWRITE(nParentHash);
READWRITE(nVoteOutcome);
READWRITE(nVoteAction);
READWRITE(nVoteSignal);
READWRITE(nTime);
READWRITE(vchSig);
}
@ -107,11 +106,6 @@ public:
* -------------------------------
*
Class Structure:
// parent hash vote hash vote
std::map<uint256, std::map<uint256, CBudgetVote> > mapVotes;
GetVote(name, yes_no):
- caching function
- mark last accessed votes

View File

@ -23,8 +23,8 @@ class CNode;
CGovernanceManager governance;
CCriticalSection cs_budget;
std::map<uint256, int64_t> askedForSourceProposalOrBudget;
std::vector<CGovernanceObject> vecImmatureBudgetProposals;
std::map<uint256, int64_t> mapAskedForGovernanceObject;
std::vector<CGovernanceObject> vecImmatureGovernanceObjects;
int nSubmittedFinalBudget;
@ -79,11 +79,11 @@ bool IsCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::st
nConf = conf;
//if we're syncing we won't have instantX information, so accept 1 confirmation
if(conf >= BUDGET_FEE_CONFIRMATIONS){
if(conf >= GOVERNANCE_FEE_CONFIRMATIONS){
strError = "valid";
return true;
} else {
strError = strprintf("Collateral requires at least %d confirmations - %d confirmations", BUDGET_FEE_CONFIRMATIONS, conf);
strError = strprintf("Collateral requires at least %d confirmations - %d confirmations", GOVERNANCE_FEE_CONFIRMATIONS, conf);
LogPrintf ("CGovernanceObject::IsCollateralValid - %s - %d confirmations\n", strError, conf);
return false;
}
@ -94,28 +94,28 @@ void CGovernanceManager::CheckOrphanVotes()
LOCK(cs);
std::string strError = "";
std::map<uint256, CBudgetVote>::iterator it1 = mapOrphanMasternodeBudgetVotes.begin();
while(it1 != mapOrphanMasternodeBudgetVotes.end()){
if(UpdateProposal(((*it1).second), NULL, strError)){
std::map<uint256, CGovernanceVote>::iterator it1 = mapOrphanVotes.begin();
while(it1 != mapOrphanVotes.end()){
if(UpdateGovernanceObject(((*it1).second), NULL, strError)){
LogPrintf("CGovernanceManager::CheckOrphanVotes - Proposal/Budget is known, activating and removing orphan vote\n");
mapOrphanMasternodeBudgetVotes.erase(it1++);
mapOrphanVotes.erase(it1++);
} else {
++it1;
}
}
}
bool CGovernanceManager::AddProposal(CGovernanceObject& budgetProposal)
bool CGovernanceManager::AddGovernanceObject(CGovernanceObject& budgetProposal)
{
LOCK(cs);
std::string strError = "";
if(!budgetProposal.IsValid(pCurrentBlockIndex, strError)) {
LogPrintf("CGovernanceManager::AddProposal - invalid governance object - %s\n", strError);
LogPrintf("CGovernanceManager::AddGovernanceObject - invalid governance object - %s\n", strError);
return false;
}
if(mapObjects.count(budgetProposal.GetHash())) {
LogPrintf("CGovernanceManager::AddProposal - already have governance object - %s\n", strError);
LogPrintf("CGovernanceManager::AddGovernanceObject - already have governance object - %s\n", strError);
return false;
}
@ -151,9 +151,9 @@ CGovernanceObject *CGovernanceManager::FindProposal(const std::string &strName)
std::map<uint256, CGovernanceObject>::iterator it = mapObjects.begin();
while(it != mapObjects.end()){
if((*it).second.strName == strName && (*it).second.GetYesCount(VOTE_ACTION_FUNDING) > nYesCount){
if((*it).second.strName == strName && (*it).second.GetYesCount(VOTE_SIGNAL_FUNDING) > nYesCount){
pbudgetProposal = &((*it).second);
nYesCount = pbudgetProposal->GetYesCount(VOTE_ACTION_FUNDING);
nYesCount = pbudgetProposal->GetYesCount(VOTE_SIGNAL_FUNDING);
}
++it;
}
@ -252,12 +252,12 @@ void CGovernanceManager::NewBlock()
//remove invalid votes once in a while (we have to check the signatures and validity of every vote, somewhat CPU intensive)
std::map<uint256, int64_t>::iterator it = askedForSourceProposalOrBudget.begin();
while(it != askedForSourceProposalOrBudget.end()){
std::map<uint256, int64_t>::iterator it = mapAskedForGovernanceObject.begin();
while(it != mapAskedForGovernanceObject.end()){
if((*it).second > GetTime() - (60*60*24)){
++it;
} else {
askedForSourceProposalOrBudget.erase(it++);
mapAskedForGovernanceObject.erase(it++);
}
}
@ -267,8 +267,8 @@ void CGovernanceManager::NewBlock()
++it2;
}
std::vector<CGovernanceObject>::iterator it4 = vecImmatureBudgetProposals.begin();
while(it4 != vecImmatureBudgetProposals.end())
std::vector<CGovernanceObject>::iterator it4 = vecImmatureGovernanceObjects.begin();
while(it4 != vecImmatureGovernanceObjects.end())
{
std::string strError = "";
int nConf = 0;
@ -280,15 +280,15 @@ void CGovernanceManager::NewBlock()
// 12.1 -- fix below
// if(!(*it4).IsValid(pCurrentBlockIndex, strError)) {
// LogPrintf("mprop (immature) - invalid budget proposal - %s\n", strError);
// it4 = vecImmatureBudgetProposals.erase(it4);
// it4 = vecImmatureGovernanceObjects.erase(it4);
// continue;
// }
// CGovernanceObject budgetProposal((*it4));
// if(AddProposal(budgetProposal)) {(*it4).Relay();}
// if(AddGovernanceObject(budgetProposal)) {(*it4).Relay();}
// LogPrintf("mprop (immature) - new budget - %s\n", (*it4).GetHash().ToString());
// it4 = vecImmatureBudgetProposals.erase(it4);
// it4 = vecImmatureGovernanceObjects.erase(it4);
}
}
@ -325,7 +325,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
CGovernanceObject budgetProposalBroadcast;
vRecv >> budgetProposalBroadcast;
if(mapSeenMasternodeBudgetProposals.count(budgetProposalBroadcast.GetHash())){
if(mapSeenGovernanceObjects.count(budgetProposalBroadcast.GetHash())){
// TODO - print error code? what if it's GOVOBJ_ERROR_IMMATURE?
masternodeSync.AddedBudgetItem(budgetProposalBroadcast.GetHash());
return;
@ -336,21 +336,21 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
if(!IsCollateralValid(budgetProposalBroadcast.nFeeTXHash, budgetProposalBroadcast.GetHash(), strError, budgetProposalBroadcast.nTime, nConf, GOVERNANCE_FEE_TX)){
LogPrintf("Proposal FeeTX is not valid - %s - %s\n", budgetProposalBroadcast.nFeeTXHash.ToString(), strError);
//todo 12.1
//if(nConf >= 1) vecImmatureBudgetProposals.push_back(budgetProposalBroadcast);
//if(nConf >= 1) vecImmatureGovernanceObjects.push_back(budgetProposalBroadcast);
return;
}
if(!budgetProposalBroadcast.IsValid(pCurrentBlockIndex, strError)) {
mapSeenMasternodeBudgetProposals.insert(make_pair(budgetProposalBroadcast.GetHash(), SEEN_OBJECT_ERROR_INVALID));
mapSeenGovernanceObjects.insert(make_pair(budgetProposalBroadcast.GetHash(), SEEN_OBJECT_ERROR_INVALID));
LogPrintf("mprop - invalid budget proposal - %s\n", strError);
return;
}
if(AddProposal(budgetProposalBroadcast))
if(AddGovernanceObject(budgetProposalBroadcast))
{
budgetProposalBroadcast.Relay();
}
mapSeenMasternodeBudgetProposals.insert(make_pair(budgetProposalBroadcast.GetHash(), SEEN_OBJECT_IS_VALID));
mapSeenGovernanceObjects.insert(make_pair(budgetProposalBroadcast.GetHash(), SEEN_OBJECT_IS_VALID));
masternodeSync.AddedBudgetItem(budgetProposalBroadcast.GetHash());
LogPrintf("mprop - new budget - %s\n", budgetProposalBroadcast.GetHash().ToString());
@ -359,11 +359,11 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
}
if (strCommand == NetMsgType::MNGOVERNANCEVOTE) { //Masternode Vote
CBudgetVote vote;
CGovernanceVote vote;
vRecv >> vote;
vote.fValid = true;
if(mapSeenMasternodeBudgetVotes.count(vote.GetHash())){
if(mapSeenVotes.count(vote.GetHash())){
masternodeSync.AddedBudgetItem(vote.GetHash());
return;
}
@ -375,7 +375,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
return;
}
mapSeenMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), SEEN_OBJECT_IS_VALID));
mapSeenVotes.insert(make_pair(vote.GetHash(), SEEN_OBJECT_IS_VALID));
if(!vote.IsValid(true)){
LogPrintf("mvote - signature invalid\n");
if(masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20);
@ -385,7 +385,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
}
std::string strError = "";
if(UpdateProposal(vote, pfrom, strError)) {
if(UpdateGovernanceObject(vote, pfrom, strError)) {
vote.Relay();
masternodeSync.AddedBudgetItem(vote.GetHash());
}
@ -409,7 +409,7 @@ bool CGovernanceManager::PropExists(uint256 nHash)
// {
// LOCK(cs);
// std::map<uint256, std::map<uint256, CBudgetVote> >::iterator it1 = mapVotes.begin();
// std::map<uint256, std::map<uint256, CGovernanceVote> >::iterator it1 = mapVotes.begin();
// while(it1 != mapVotes.end()){
// (*it1).second.second.fSynced = false;
// ++it1;
@ -430,7 +430,7 @@ bool CGovernanceManager::PropExists(uint256 nHash)
// // this could screw up syncing, so let's log it
// LogPrintf("CGovernanceManager::MarkSynced\n");
// std::map<uint256, std::map<uint256, CBudgetVote> >::iterator it1 = mapVotes.begin();
// std::map<uint256, std::map<uint256, CGovernanceVote> >::iterator it1 = mapVotes.begin();
// while(it1 != mapVotes.end()){
// if((*it1).second.second.fValid)
// (*it1).second.second.fSynced = true;
@ -458,8 +458,8 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp)
int nInvCount = 0;
// sync gov objects
std::map<uint256, int>::iterator it1 = mapSeenMasternodeBudgetProposals.begin();
while(it1 != mapSeenMasternodeBudgetProposals.end()){
std::map<uint256, int>::iterator it1 = mapSeenGovernanceObjects.begin();
while(it1 != mapSeenGovernanceObjects.end()){
CGovernanceObject* pbudgetProposal = FindProposal((*it1).first);
if(pbudgetProposal && pbudgetProposal->fCachedValid && ((nProp == uint256() || ((*it1).first == nProp)))){
// Push the inventory budget proposal message over to the other client
@ -470,7 +470,7 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp)
}
// sync votes
std::map<uint256, CBudgetVote>::iterator it2 = mapVotes.begin();
std::map<uint256, CGovernanceVote>::iterator it2 = mapVotes.begin();
while(it2 != mapVotes.end()){
pfrom->PushInventory(CInv(MSG_BUDGET_VOTE, (*it2).first));
nInvCount++;
@ -482,7 +482,7 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp)
LogPrintf("CGovernanceManager::Sync - sent %d items\n", nInvCount);
}
bool CGovernanceManager::UpdateProposal(CBudgetVote& vote, CNode* pfrom, std::string& strError)
bool CGovernanceManager::UpdateGovernanceObject(CGovernanceVote& vote, CNode* pfrom, std::string& strError)
{
LOCK(cs);
@ -492,12 +492,12 @@ bool CGovernanceManager::UpdateProposal(CBudgetVote& vote, CNode* pfrom, std::st
// otherwise we'll think a full sync succeeded when they return a result
if(!masternodeSync.IsSynced()) return false;
LogPrintf("CGovernanceManager::UpdateProposal - Unknown proposal %d, asking for source proposal\n", vote.nParentHash.ToString());
mapOrphanMasternodeBudgetVotes[vote.nParentHash] = vote;
LogPrintf("CGovernanceManager::UpdateGovernanceObject - Unknown proposal %d, asking for source proposal\n", vote.nParentHash.ToString());
mapOrphanVotes[vote.nParentHash] = vote;
if(!askedForSourceProposalOrBudget.count(vote.nParentHash)){
if(!mapAskedForGovernanceObject.count(vote.nParentHash)){
pfrom->PushMessage(NetMsgType::MNGOVERNANCEVOTESYNC, vote.nParentHash);
askedForSourceProposalOrBudget[vote.nParentHash] = GetTime();
mapAskedForGovernanceObject[vote.nParentHash] = GetTime();
}
}
@ -509,12 +509,12 @@ bool CGovernanceManager::UpdateProposal(CBudgetVote& vote, CNode* pfrom, std::st
return AddOrUpdateVote(vote, strError);
}
bool CGovernanceManager::AddOrUpdateVote(CBudgetVote& vote, std::string& strError)
bool CGovernanceManager::AddOrUpdateVote(CGovernanceVote& vote, std::string& strError)
{
LOCK(cs);
// store newest vote per action
arith_uint256 a = UintToArith256(vote.nParentHash) + vote.nVoteAction;
arith_uint256 a = UintToArith256(vote.nParentHash) + vote.nVoteSignal;
uint256 hash2 = ArithToUint256(a);
if(mapVotes.count(hash2))
@ -524,7 +524,7 @@ bool CGovernanceManager::AddOrUpdateVote(CBudgetVote& vote, std::string& strErro
LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError);
return false;
}
if(vote.nTime - mapVotes[hash2].nTime < BUDGET_VOTE_UPDATE_MIN){
if(vote.nTime - mapVotes[hash2].nTime < GOVERNANCE_UPDATE_MIN){
strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotes[hash2].nTime);
LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError);
return false;
@ -554,7 +554,6 @@ CGovernanceObject::CGovernanceObject()
fCachedReleaseBounty2 = false;
fCachedReleaseBounty3 = false;
nHash = uint256();
}
CGovernanceObject::CGovernanceObject(uint256 nHashParentIn, int nRevisionIn, std::string strNameIn, int64_t nTime, uint256 nFeeTXHashIn)
@ -585,7 +584,7 @@ CGovernanceObject::CGovernanceObject(const CGovernanceObject& other)
bool CGovernanceObject::IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral)
{
if(GetNoCount(VOTE_ACTION_VALID) - GetYesCount(VOTE_ACTION_VALID) > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10){
if(GetNoCount(VOTE_SIGNAL_VALID) - GetYesCount(VOTE_SIGNAL_VALID) > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10){
strError = "Automated removal";
return false;
}
@ -653,7 +652,7 @@ void CGovernanceManager::CleanAndRemove(bool fSignatureCheck)
*
*/
// std::map<uint256, CBudgetVote>::iterator it2 = mapVotes.begin();
// std::map<uint256, CGovernanceVote>::iterator it2 = mapVotes.begin();
// while(it2 != mapVotes.end()){
// if(!(*it2).second.IsValid(fSignatureCheck))
// {
@ -670,24 +669,24 @@ void CGovernanceManager::CleanAndRemove(bool fSignatureCheck)
* Get specific vote counts for each outcome (funding, validity, etc)
*/
int CGovernanceObject::GetAbsoluteYesCount(int nVoteOutcomeIn)
int CGovernanceObject::GetAbsoluteYesCount(int nVoteSignalIn)
{
return governance.CountMatchingAbsoluteVotes(nVoteOutcomeIn, VOTE_OUTCOME_YES) - governance.CountMatchingAbsoluteVotes(nVoteOutcomeIn, VOTE_OUTCOME_NO);
return governance.CountMatchingVotes(nVoteSignalIn, VOTE_OUTCOME_YES) - governance.CountMatchingVotes(nVoteSignalIn, VOTE_OUTCOME_NO);
}
int CGovernanceObject::GetYesCount(int nVoteOutcomeIn)
int CGovernanceObject::GetYesCount(int nVoteSignalIn)
{
return governance.CountMatchingAbsoluteVotes(nVoteOutcomeIn, VOTE_OUTCOME_YES);
return governance.CountMatchingVotes(nVoteSignalIn, VOTE_OUTCOME_YES);
}
int CGovernanceObject::GetNoCount(int nVoteOutcomeIn)
int CGovernanceObject::GetNoCount(int nVoteSignalIn)
{
return governance.CountMatchingAbsoluteVotes(nVoteOutcomeIn, VOTE_OUTCOME_NO);
return governance.CountMatchingVotes(nVoteSignalIn, VOTE_OUTCOME_NO);
}
int CGovernanceObject::GetAbstainCount(int nVoteOutcomeIn)
int CGovernanceObject::GetAbstainCount(int nVoteSignalIn)
{
return governance.CountMatchingAbsoluteVotes(nVoteOutcomeIn, VOTE_OUTCOME_ABSTAIN);
return governance.CountMatchingVotes(nVoteSignalIn, VOTE_OUTCOME_ABSTAIN);
}
void CGovernanceObject::Relay()
@ -701,8 +700,8 @@ std::string CGovernanceManager::ToString() const
std::ostringstream info;
info << "Governance Objects: " << (int)mapObjects.size() <<
", Seen Budgets: " << (int)mapSeenMasternodeBudgetProposals.size() <<
", Seen Budget Votes: " << (int)mapSeenMasternodeBudgetVotes.size() <<
", Seen Budgets: " << (int)mapSeenGovernanceObjects.size() <<
", Seen Budget Votes: " << (int)mapSeenVotes.size() <<
", Vote Count: " << (int)mapVotes.size();
return info.str();
@ -717,7 +716,7 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex *pindex)
NewBlock();
}
int CGovernanceManager::CountMatchingAbsoluteVotes(int nVoteActionIn, int nVoteOutcomeIn)
int CGovernanceManager::CountMatchingVotes(int nVoteSignalIn, int nVoteOutcomeIn)
{
/*
*
@ -727,10 +726,9 @@ int CGovernanceManager::CountMatchingAbsoluteVotes(int nVoteActionIn, int nVoteO
int nCount = 0;
std::map<uint256, CBudgetVote>::iterator it2 = mapVotes.begin();
std::map<uint256, CGovernanceVote>::iterator it2 = mapVotes.begin();
while(it2 != mapVotes.end()){
//if(!(*it2).second.IsValid(true) && (*it2).second.nVoteAction == nVoteActionIn)
if((*it2).second.IsValid(true) && (*it2).second.nVoteAction == nVoteActionIn)
if((*it2).second.fValid && (*it2).second.nVoteSignal == nVoteSignalIn)
{
nCount += ((*it2).second.nVoteOutcome == nVoteOutcomeIn ? 1 : 0);
++it2;

View File

@ -22,26 +22,17 @@
using namespace std;
extern CCriticalSection cs_budget;
// note: is there a reason these are static?
// http://stackoverflow.com/questions/3709207/c-semantics-of-static-const-vs-const
static const CAmount BUDGET_FEE_TX = (5*COIN);
static const int64_t BUDGET_FEE_CONFIRMATIONS = 6;
static const int64_t BUDGET_VOTE_UPDATE_MIN = 60*60;
static const int64_t CONTRACT_ACTIVATION_TIME = 60*60*24*14;
class CGovernanceManager;
class CGovernanceObject;
class CBudgetVote;
class CGovernanceVote;
class CNode;
// todo - 12.1 - change BUDGET_ to GOVERNANCE_ (cherry pick)
static const CAmount GOVERNANCE_FEE_TX = (5*COIN);
static const int64_t GOVERNANCE_FEE_CONFIRMATIONS = 6;
static const int64_t GOVERNANCE_UPDATE_MIN = 60*60;
extern std::vector<CGovernanceObject> vecImmatureBudgetProposals;
extern std::map<uint256, int64_t> askedForSourceProposalOrBudget;
extern std::vector<CGovernanceObject> vecImmatureGovernanceObjects;
extern std::map<uint256, int64_t> mapAskedForGovernanceObject;
extern CGovernanceManager governance;
// FOR SEEN MAP ARRAYS - GOVERNANCE OBJECTS AND VOTES
@ -75,23 +66,23 @@ public:
map<uint256, CGovernanceObject> mapObjects;
// todo - 12.1 - move to private for better encapsulation
std::map<uint256, int> mapSeenMasternodeBudgetProposals;
std::map<uint256, int> mapSeenMasternodeBudgetVotes;
std::map<uint256, CBudgetVote> mapOrphanMasternodeBudgetVotes;
std::map<uint256, CBudgetVote> mapVotes;
std::map<uint256, int> mapSeenGovernanceObjects;
std::map<uint256, int> mapSeenVotes;
std::map<uint256, CGovernanceVote> mapOrphanVotes;
std::map<uint256, CGovernanceVote> mapVotes;
CGovernanceManager() {
mapObjects.clear();
}
void ClearSeen() {
mapSeenMasternodeBudgetProposals.clear();
mapSeenMasternodeBudgetVotes.clear();
mapSeenGovernanceObjects.clear();
mapSeenVotes.clear();
}
int CountProposalInventoryItems()
{
return mapSeenMasternodeBudgetProposals.size() + mapSeenMasternodeBudgetVotes.size();
return mapSeenGovernanceObjects.size() + mapSeenVotes.size();
}
int sizeProposals() {return (int)mapObjects.size();}
@ -111,14 +102,16 @@ public:
std::vector<CGovernanceObject*> GetAllProposals(int64_t nMoreThanTime);
int CountMatchingVotes(int nVoteSignalIn, int nVoteOutcomeIn);
bool IsBudgetPaymentBlock(int nBlockHeight);
bool AddProposal(CGovernanceObject& budgetProposal);
bool UpdateProposal(CBudgetVote& vote, CNode* pfrom, std::string& strError);
bool AddOrUpdateVote(CBudgetVote& vote, std::string& strError);
bool AddGovernanceObject (CGovernanceObject& budgetProposal);
bool UpdateGovernanceObject(CGovernanceVote& vote, CNode* pfrom, std::string& strError);
bool AddOrUpdateVote(CGovernanceVote& vote, std::string& strError);
bool PropExists(uint256 nHash);
std::string GetRequiredPaymentsString(int nBlockHeight);
void CleanAndRemove(bool fSignatureCheck);
int CountMatchingAbsoluteVotes(int nVoteTypeIn, int nVoteOutcomeIn);
void CheckAndRemove();
void CheckOrphanVotes();
void Clear(){
@ -126,20 +119,19 @@ public:
LogPrintf("Budget object cleared\n");
mapObjects.clear();
mapSeenMasternodeBudgetProposals.clear();
mapSeenMasternodeBudgetVotes.clear();
mapOrphanMasternodeBudgetVotes.clear();
mapSeenGovernanceObjects.clear();
mapSeenVotes.clear();
mapOrphanVotes.clear();
}
void CheckAndRemove();
std::string ToString() const;
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(mapSeenMasternodeBudgetProposals);
READWRITE(mapSeenMasternodeBudgetVotes);
READWRITE(mapOrphanMasternodeBudgetVotes);
READWRITE(mapSeenGovernanceObjects);
READWRITE(mapSeenVotes);
READWRITE(mapOrphanVotes);
READWRITE(mapObjects);
READWRITE(mapVotes);
}
@ -149,35 +141,6 @@ public:
void UpdateLastDiffTime(int64_t nTimeIn) {nTimeLastDiff=nTimeIn;}
};
/**
* Governance objects can hold any type of data
* --------------------------------------------
*
*/
class CGovernanceObjectRegister
{
private:
int nType;
std::string strReg;
public:
CGovernanceObjectRegister(int nTypeIn, char* strRegIn)
{
nType = nTypeIn;
strReg = strRegIn;
}
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
//for syncing with other clients
READWRITE(nType);
READWRITE(LIMITED_STRING(strReg, 255));
}
};
/**
* Generic Governance Object
*
@ -198,7 +161,8 @@ public:
std::string strName; //org name, username, prop name, etc.
int64_t nTime; //time this object was created
uint256 nFeeTXHash; //fee-tx
std::string strData; // Data field - can be used for anything
// caching -- one per voting mechanism -- see governance-vote.h for more information
bool fCachedFunding;
bool fCachedValid;
@ -209,11 +173,6 @@ public:
bool fCachedReleaseBounty2;
bool fCachedReleaseBounty3;
uint256 nHash;
// Data field - can be used for anything
std::string strData;
CGovernanceObject();
CGovernanceObject(uint256 nHashParentIn, int nRevisionIn, std::string strNameIn, int64_t nTime, uint256 nFeeTXHashIn);
CGovernanceObject(const CGovernanceObject& other);
@ -231,6 +190,7 @@ public:
swap(first.nRevision, second.nRevision);
swap(first.nTime, second.nTime);
swap(first.nFeeTXHash, second.nFeeTXHash);
swap(first.strData, second.strData);
// swap all cached valid flags
swap(first.fCachedFunding, second.fCachedFunding);
@ -242,8 +202,6 @@ public:
swap(first.fCachedReleaseBounty2, second.fCachedReleaseBounty2);
swap(first.fCachedReleaseBounty3, second.fCachedReleaseBounty3);
swap(first.nHash, second.nHash);
swap(first.strData, second.strData);
}
bool HasMinimumRequiredSupport();
@ -252,10 +210,10 @@ public:
std::string GetName() {return strName; }
// get vote counts on each outcome
int GetAbsoluteYesCount(int nVoteOutcomeIn);
int GetYesCount(int nVoteOutcomeIn);
int GetNoCount(int nVoteOutcomeIn);
int GetAbstainCount(int nVoteOutcomeIn);
int GetAbsoluteYesCount(int nVoteSignalIn);
int GetYesCount(int nVoteSignalIn);
int GetNoCount(int nVoteSignalIn);
int GetAbstainCount(int nVoteSignalIn);
void CleanAndRemove(bool fSignatureCheck);
void Relay();
@ -333,9 +291,7 @@ public:
READWRITE(LIMITED_STRING(strName, 64));
READWRITE(nTime);
READWRITE(nFeeTXHash);
// todo - 12.1 - serialize map
//READWRITE(mapRegister);
READWRITE(strData);
}
};

View File

@ -4356,10 +4356,10 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
return mnpayments.mapMasternodePayeeVotes.count(inv.hash);
case MSG_BUDGET_VOTE:
return governance.mapSeenMasternodeBudgetVotes.count(inv.hash);
return governance.mapSeenVotes.count(inv.hash);
case MSG_BUDGET_PROPOSAL:
return governance.mapSeenMasternodeBudgetProposals.count(inv.hash);
return governance.mapSeenGovernanceObjects.count(inv.hash);
case MSG_MASTERNODE_ANNOUNCE:
return mnodeman.mapSeenMasternodeBroadcast.count(inv.hash);
@ -4527,20 +4527,20 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
}
}
if (!pushed && inv.type == MSG_BUDGET_VOTE) {
if(governance.mapSeenMasternodeBudgetVotes.count(inv.hash)){
if(governance.mapSeenVotes.count(inv.hash)){
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << governance.mapSeenMasternodeBudgetVotes[inv.hash];
ss << governance.mapSeenVotes[inv.hash];
pfrom->PushMessage(NetMsgType::MNGOVERNANCEVOTE, ss);
pushed = true;
}
}
if (!pushed && inv.type == MSG_BUDGET_PROPOSAL) {
if(governance.mapSeenMasternodeBudgetProposals.count(inv.hash)){
if(governance.mapSeenGovernanceObjects.count(inv.hash)){
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << governance.mapSeenMasternodeBudgetProposals[inv.hash];
ss << governance.mapSeenGovernanceObjects[inv.hash];
pfrom->PushMessage(NetMsgType::MNGOVERNANCEPROPOSAL, ss);
pushed = true;
}

View File

@ -57,7 +57,7 @@ struct sortProposalsByVotes {
// if(pfinalizedBudget && pfinalizedBudget->fValid){
// //mark votes
// std::map<uint256, CBudgetVote>::iterator it4 = pfinalizedBudget->mapVotes.begin();
// std::map<uint256, CGovernanceVote>::iterator it4 = pfinalizedBudget->mapVotes.begin();
// while(it4 != pfinalizedBudget->mapVotes.end()){
// if((*it4).second.fValid)
// (*it4).second.fSynced = true;
@ -80,7 +80,7 @@ struct sortProposalsByVotes {
// if(pfinalizedBudget && pfinalizedBudget->fValid){
// //send votes
// std::map<uint256, CBudgetVote>::iterator it4 = pfinalizedBudget->mapVotes.begin();
// std::map<uint256, CGovernanceVote>::iterator it4 = pfinalizedBudget->mapVotes.begin();
// while(it4 != pfinalizedBudget->mapVotes.end()){
// (*it4).second.fSynced = false;
// ++it4;
@ -117,7 +117,7 @@ void CBudgetManager::Sync(CNode* pfrom, uint256 nProp, bool fPartial)
nInvCount++;
//send votes
std::map<uint256, CBudgetVote>::iterator it4 = pfinalizedBudget->mapVotes.begin();
std::map<uint256, CGovernanceVote>::iterator it4 = pfinalizedBudget->mapVotes.begin();
while(it4 != pfinalizedBudget->mapVotes.end()){
if((*it4).second.fValid) {
if((fPartial && !(*it4).second.fSynced) || !fPartial) {
@ -176,7 +176,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
std::string strError = "";
int nConf = 0;
if(!IsCollateralValid(finalizedBudgetBroadcast.nFeeTXHash, finalizedBudgetBroadcast.GetHash(), strError, finalizedBudgetBroadcast.nTime, nConf, BUDGET_FEE_TX)){
if(!IsCollateralValid(finalizedBudgetBroadcast.nFeeTXHash, finalizedBudgetBroadcast.GetHash(), strError, finalizedBudgetBroadcast.nTime, nConf, GOVERNANCE_FEE_TX)){
LogPrintf("Finalized Budget FeeTX is not valid - %s - %s\n", finalizedBudgetBroadcast.nFeeTXHash.ToString(), strError);
if(nConf >= 1) vecImmatureFinalizedBudgets.push_back(finalizedBudgetBroadcast);
@ -201,7 +201,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
}
if (strCommand == NetMsgType::MNGOVERNANCEFINALVOTE) { //Finalized Budget Vote
CBudgetVote vote;
CGovernanceVote vote;
vRecv >> vote;
vote.fValid = true;
@ -266,7 +266,7 @@ void CBudgetManager::NewBlock()
{
std::string strError = "";
int nConf = 0;
if(!IsCollateralValid((*it5).nFeeTXHash, (*it5).GetHash(), strError, (*it5).nTime, nConf, BUDGET_FEE_TX)){
if(!IsCollateralValid((*it5).nFeeTXHash, (*it5).GetHash(), strError, (*it5).nTime, nConf, GOVERNANCE_FEE_TX)){
++it5;
continue;
}
@ -402,7 +402,7 @@ bool CBudgetManager::HasNextFinalizedBudget()
return false;
}
bool CBudgetManager::UpdateFinalizedBudget(CBudgetVote& vote, CNode* pfrom, std::string& strError)
bool CBudgetManager::UpdateFinalizedBudget(CGovernanceVote& vote, CNode* pfrom, std::string& strError)
{
LOCK(cs);
@ -415,9 +415,9 @@ bool CBudgetManager::UpdateFinalizedBudget(CBudgetVote& vote, CNode* pfrom, std:
LogPrintf("CBudgetManager::UpdateFinalizedBudget - Unknown Finalized Proposal %s, asking for source budget\n", vote.nBudgetHash.ToString());
mapOrphanFinalizedBudgetVotes[vote.nBudgetHash] = vote;
if(!askedForSourceProposalOrBudget.count(vote.nBudgetHash)){
if(!mapAskedForGovernanceObject.count(vote.nBudgetHash)){
pfrom->PushMessage(NetMsgType::MNGOVERNANCEVOTESYNC, vote.nBudgetHash);
askedForSourceProposalOrBudget[vote.nBudgetHash] = GetTime();
mapAskedForGovernanceObject[vote.nBudgetHash] = GetTime();
}
}
@ -562,7 +562,7 @@ void CBudgetManager::CheckOrphanVotes()
std::string strError = "";
std::map<uint256, CBudgetVote>::iterator it2 = mapOrphanFinalizedBudgetVotes.begin();
std::map<uint256, CGovernanceVote>::iterator it2 = mapOrphanFinalizedBudgetVotes.begin();
while(it2 != mapOrphanFinalizedBudgetVotes.end()){
if(UpdateFinalizedBudget(((*it2).second),NULL, strError)){
LogPrintf("CBudgetManager::CheckOrphanVotes - Proposal/Budget is known, activating and removing orphan vote\n");
@ -654,7 +654,7 @@ CFinalizedBudget::CFinalizedBudget(const CFinalizedBudget& other)
fAutoChecked = false;
}
bool CFinalizedBudget::AddOrUpdateVote(CBudgetVote& vote, std::string& strError)
bool CFinalizedBudget::AddOrUpdateVote(CGovernanceVote& vote, std::string& strError)
{
LOCK(cs);
@ -665,7 +665,7 @@ bool CFinalizedBudget::AddOrUpdateVote(CBudgetVote& vote, std::string& strError)
LogPrint("mngovernance", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError);
return false;
}
if(vote.nTime - mapVotes[hash].nTime < BUDGET_VOTE_UPDATE_MIN){
if(vote.nTime - mapVotes[hash].nTime < GOVERNANCE_VOTE_UPDATE_MIN){
strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotes[hash].nTime);
LogPrint("mngovernance", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError);
return false;
@ -757,7 +757,7 @@ void CFinalizedBudget::AutoCheck()
// If masternode voted for a proposal, but is now invalid -- remove the vote
void CFinalizedBudget::CleanAndRemove(bool fSignatureCheck)
{
std::map<uint256, CBudgetVote>::iterator it = mapVotes.begin();
std::map<uint256, CGovernanceVote>::iterator it = mapVotes.begin();
while(it != mapVotes.end()) {
(*it).second.fValid = (*it).second.IsValid(fSignatureCheck);
@ -847,7 +847,7 @@ bool CFinalizedBudget::IsValid(const CBlockIndex* pindex, std::string& strError,
std::string strError2 = "";
if(fCheckCollateral){
int nConf = 0;
if(!IsCollateralValid(nFeeTXHash, GetHash(), strError2, nTime, nConf, BUDGET_FEE_TX)){
if(!IsCollateralValid(nFeeTXHash, GetHash(), strError2, nTime, nConf, GOVERNANCE_FEE_TX)){
strError = "Invalid Collateral : " + strError2;
return false;
}
@ -906,7 +906,7 @@ void CFinalizedBudget::SubmitVote()
return;
}
CBudgetVote vote(activeMasternode.vin, GetHash());
CGovernanceVote vote(activeMasternode.vin, GetHash());
if(!vote.Sign(keyMasternode, pubKeyMasternode)){
LogPrintf("CFinalizedBudget::SubmitVote - Failure to sign.");
return;
@ -957,7 +957,7 @@ void CFinalizedBudget::Relay()
RelayInv(inv, MIN_BUDGET_PEER_PROTO_VERSION);
}
CBudgetVote::CBudgetVote()
CGovernanceVote::CGovernanceVote()
{
vin = CTxIn();
nBudgetHash = uint256();
@ -967,7 +967,7 @@ CBudgetVote::CBudgetVote()
fSynced = false;
}
CBudgetVote::CBudgetVote(CTxIn vinIn, uint256 nBudgetHashIn)
CGovernanceVote::CGovernanceVote(CTxIn vinIn, uint256 nBudgetHashIn)
{
vin = vinIn;
nBudgetHash = nBudgetHashIn;
@ -977,13 +977,13 @@ CBudgetVote::CBudgetVote(CTxIn vinIn, uint256 nBudgetHashIn)
fSynced = false;
}
void CBudgetVote::Relay()
void CGovernanceVote::Relay()
{
CInv inv(MSG_BUDGET_FINALIZED_VOTE, GetHash());
RelayInv(inv, MIN_BUDGET_PEER_PROTO_VERSION);
}
bool CBudgetVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
bool CGovernanceVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
{
// Choose coins to use
CPubKey pubKeyCollateralAddress;
@ -993,22 +993,22 @@ bool CBudgetVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
std::string strMessage = vin.prevout.ToStringShort() + nBudgetHash.ToString() + boost::lexical_cast<std::string>(nTime);
if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyMasternode)) {
LogPrintf("CBudgetVote::Sign - Error upon calling SignMessage");
LogPrintf("CGovernanceVote::Sign - Error upon calling SignMessage");
return false;
}
if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage)) {
LogPrintf("CBudgetVote::Sign - Error upon calling VerifyMessage");
LogPrintf("CGovernanceVote::Sign - Error upon calling VerifyMessage");
return false;
}
return true;
}
bool CBudgetVote::IsValid(bool fSignatureCheck)
bool CGovernanceVote::IsValid(bool fSignatureCheck)
{
if(nTime > GetTime() + (60*60)){
LogPrint("mngovernance", "CBudgetVote::IsValid() - vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", GetHash().ToString(), nTime, GetTime() + (60*60));
LogPrint("mngovernance", "CGovernanceVote::IsValid() - vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", GetHash().ToString(), nTime, GetTime() + (60*60));
return false;
}
@ -1016,7 +1016,7 @@ bool CBudgetVote::IsValid(bool fSignatureCheck)
if(pmn == NULL)
{
LogPrint("mngovernance", "CBudgetVote::IsValid() - Unknown Masternode\n");
LogPrint("mngovernance", "CGovernanceVote::IsValid() - Unknown Masternode\n");
return false;
}
@ -1026,7 +1026,7 @@ bool CBudgetVote::IsValid(bool fSignatureCheck)
std::string strMessage = vin.prevout.ToStringShort() + nBudgetHash.ToString() + boost::lexical_cast<std::string>(nTime);
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)) {
LogPrintf("CBudgetVote::IsValid() - Verify message failed\n");
LogPrintf("CGovernanceVote::IsValid() - Verify message failed\n");
return false;
}

View File

@ -22,32 +22,32 @@
using namespace std;
int ConvertVoteOutcome(std::string strVoteAction)
int ConvertVoteOutcome(std::string strVoteOutcome)
{
int nVote = -1;
if(strVoteAction == "yes") nVote = VOTE_OUTCOME_YES;
if(strVoteAction == "no") nVote = VOTE_OUTCOME_NO;
if(strVoteAction == "abstain") nVote = VOTE_OUTCOME_ABSTAIN;
if(strVoteAction == "none") nVote = VOTE_OUTCOME_NONE;
if(strVoteOutcome == "yes") nVote = VOTE_OUTCOME_YES;
if(strVoteOutcome == "no") nVote = VOTE_OUTCOME_NO;
if(strVoteOutcome == "abstain") nVote = VOTE_OUTCOME_ABSTAIN;
if(strVoteOutcome == "none") nVote = VOTE_OUTCOME_NONE;
return nVote;
}
int ConvertVoteAction(std::string strVoteOutcome)
int ConvertVoteSignal(std::string strVoteSignal)
{
if(strVoteOutcome == "none") return 0;
if(strVoteOutcome == "funding") return 1;
if(strVoteOutcome == "valid") return 2;
if(strVoteOutcome == "delete") return 3;
if(strVoteOutcome == "clear_registers") return 4;
if(strVoteOutcome == "endorsed") return 5;
if(strVoteOutcome == "release_bounty1") return 6;
if(strVoteOutcome == "release_bounty2") return 7;
if(strVoteOutcome == "release_bounty3") return 8;
if(strVoteSignal == "none") return 0;
if(strVoteSignal == "funding") return 1;
if(strVoteSignal == "valid") return 2;
if(strVoteSignal == "delete") return 3;
if(strVoteSignal == "clear_registers") return 4;
if(strVoteSignal == "endorsed") return 5;
if(strVoteSignal == "release_bounty1") return 6;
if(strVoteSignal == "release_bounty2") return 7;
if(strVoteSignal == "release_bounty3") return 8;
// convert custom sentinel outcomes to integer and store
try {
int i = boost::lexical_cast<int>(strVoteOutcome);
if(i < VOTE_ACTION_CUSTOM_START || i > VOTE_ACTION_CUSTOM_END) return -1;
int i = boost::lexical_cast<int>(strVoteSignal);
if(i < VOTE_SIGNAL_CUSTOM_START || i > VOTE_SIGNAL_CUSTOM_END) return -1;
return i;
}
catch(std::exception const & e)
@ -117,7 +117,6 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
if (params.size() != 6)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance prepare <parent-hash> <revision> <time> <name> <registers-hex>'");
int nBlockMin = 0;
LOCK(cs_main);
CBlockIndex* pindex = chainActive.Tip();
@ -170,7 +169,6 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Must wait for client to sync with masternode network. Try again in a minute or so.");
}
int nBlockMin = 0;
LOCK(cs_main);
CBlockIndex* pindex = chainActive.Tip();
@ -204,9 +202,9 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
// throw JSONRPCError(RPC_INTERNAL_ERROR, "Proposal FeeTX is not valid - " + hash.ToString() + " - " + strError);
// }
governance.mapSeenMasternodeBudgetProposals.insert(make_pair(budgetProposalBroadcast.GetHash(), SEEN_OBJECT_IS_VALID));
governance.mapSeenGovernanceObjects.insert(make_pair(budgetProposalBroadcast.GetHash(), SEEN_OBJECT_IS_VALID));
budgetProposalBroadcast.Relay();
governance.AddProposal(budgetProposalBroadcast);
governance.AddGovernanceObject(budgetProposalBroadcast);
return budgetProposalBroadcast.GetHash().ToString();
@ -225,13 +223,13 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
std::string strVoteOutcome = params[3].get_str();
std::string strAlias = params[4].get_str();
int nVoteAction = ConvertVoteAction(strVoteAction);
if(nVoteAction == VOTE_OUTCOME_NONE || nVoteAction == -1)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
int nVoteSignal = ConvertVoteSignal(strVoteAction);
if(nVoteSignal == VOTE_SIGNAL_NONE || nVoteSignal == -1)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote signal. Please use one of the following: 'yes', 'no' or 'abstain'");
int nVoteOutcome = ConvertVoteOutcome(strVoteOutcome);
if(nVoteOutcome == VOTE_OUTCOME_NONE || nVoteAction == -1)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote action. Please using one of the following: (funding|valid|delete|clear_registers|endorsed|release_bounty1|release_bounty2|release_bounty3) OR `custom sentinel code` ");
if(nVoteOutcome == VOTE_OUTCOME_NONE || nVoteOutcome == -1)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please using one of the following: (funding|valid|delete|clear_registers|endorsed|release_bounty1|release_bounty2|release_bounty3) OR `custom sentinel code` ");
int success = 0;
int failed = 0;
@ -274,7 +272,7 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
continue;
}
CBudgetVote vote(pmn->vin, hash, nVoteOutcome, nVoteAction);
CGovernanceVote vote(pmn->vin, hash, nVoteOutcome, nVoteSignal);
if(!vote.Sign(keyMasternode, pubKeyMasternode)){
failed++;
statusObj.push_back(Pair("result", "failed"));
@ -285,8 +283,8 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
std::string strError = "";
if(governance.UpdateProposal(vote, NULL, strError)) {
governance.mapSeenMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), SEEN_OBJECT_IS_VALID));
if(governance.UpdateGovernanceObject(vote, NULL, strError)) {
governance.mapSeenVotes.insert(make_pair(vote.GetHash(), SEEN_OBJECT_IS_VALID));
vote.Relay();
success++;
statusObj.push_back(Pair("result", "success"));
@ -337,11 +335,11 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
bObj.push_back(Pair("FeeTXHash", pbudgetProposal->nFeeTXHash.ToString()));
// vote data for funding
bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount(VOTE_ACTION_FUNDING)-(int64_t)pbudgetProposal->GetNoCount(VOTE_ACTION_FUNDING)));
bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount(VOTE_ACTION_FUNDING)));
bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount(VOTE_ACTION_FUNDING)));
bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount(VOTE_ACTION_FUNDING)));
//bObj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished(VOTE_ACTION_FUNDING)));
bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount(VOTE_SIGNAL_FUNDING)-(int64_t)pbudgetProposal->GetNoCount(VOTE_SIGNAL_FUNDING)));
bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount(VOTE_SIGNAL_FUNDING)));
bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount(VOTE_SIGNAL_FUNDING)));
bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount(VOTE_SIGNAL_FUNDING)));
//bObj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished(VOTE_SIGNAL_FUNDING)));
std::string strError = "";
bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError)));
@ -377,10 +375,10 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
obj.push_back(Pair("Name", pbudgetProposal->GetName()));
obj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString()));
obj.push_back(Pair("FeeTXHash", pbudgetProposal->nFeeTXHash.ToString()));
obj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount(VOTE_ACTION_FUNDING)-(int64_t)pbudgetProposal->GetNoCount(VOTE_ACTION_FUNDING)));
obj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount(VOTE_ACTION_FUNDING)));
obj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount(VOTE_ACTION_FUNDING)));
obj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount(VOTE_ACTION_FUNDING)));
obj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount(VOTE_SIGNAL_FUNDING)-(int64_t)pbudgetProposal->GetNoCount(VOTE_SIGNAL_FUNDING)));
obj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount(VOTE_SIGNAL_FUNDING)));
obj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount(VOTE_SIGNAL_FUNDING)));
obj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount(VOTE_SIGNAL_FUNDING)));
std::string strError = "";
obj.push_back(Pair("IsValid", pbudgetProposal->IsValid(chainActive.Tip(), strError)));
@ -397,11 +395,11 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
);
uint256 hash = ParseHashV(params[1], "Governance hash");
std::string strVoteOutcome = params[2].get_str();
int nVoteOutcome = ConvertVoteOutcome(strVoteOutcome);
if(nVoteOutcome == -1)
std::string strVoteSignal = params[2].get_str();
int nVoteSignal = ConvertVoteSignal(strVoteSignal);
if(nVoteSignal == -1)
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please using one of the following: (funding|valid|delete|clear_registers|endorsed|release_bounty1|release_bounty2|release_bounty3) OR `custom sentinel code` ");
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote signal. Please using one of the following: (funding|valid|delete|clear_registers|endorsed|release_bounty1|release_bounty2|release_bounty3) OR `custom sentinel code` ");
}
CGovernanceObject* pbudgetProposal = governance.FindProposal(hash);
@ -410,10 +408,10 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown governance-hash");
UniValue bObj(UniValue::VOBJ);
bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount(nVoteOutcome)-(int64_t)pbudgetProposal->GetNoCount(nVoteOutcome)));
bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount(nVoteOutcome)));
bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount(nVoteOutcome)));
bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount(nVoteOutcome)));
bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount(nVoteSignal)-(int64_t)pbudgetProposal->GetNoCount(nVoteSignal)));
bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount(nVoteSignal)));
bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount(nVoteSignal)));
bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount(nVoteSignal)));
return bObj;
}
@ -434,15 +432,15 @@ UniValue voteraw(const UniValue& params, bool fHelp)
CTxIn vin = CTxIn(hashMnTx, nMnTxIndex);
uint256 hashProposal = ParseHashV(params[2], "Governance hash");
std::string strVoteAction = params[3].get_str();
std::string strVoteOutcome = params[4].get_str();
std::string strVoteOutcome = params[3].get_str();
std::string strVoteSignal = params[4].get_str();
int nVoteAction = ConvertVoteAction(strVoteAction);
if(nVoteAction == VOTE_OUTCOME_NONE || nVoteAction == -1)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
int nVoteSignal = ConvertVoteSignal(strVoteSignal);
if(nVoteSignal == VOTE_OUTCOME_NONE || nVoteSignal == -1)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote signal. Please use one of the following: 'yes', 'no' or 'abstain'");
int nVoteOutcome = ConvertVoteOutcome(strVoteOutcome);
if(nVoteOutcome == VOTE_OUTCOME_NONE || nVoteAction == -1)
if(nVoteOutcome == VOTE_OUTCOME_NONE || nVoteOutcome == -1)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote action. Please using one of the following: (funding|valid|delete|clear_registers|endorsed|release_bounty1|release_bounty2|release_bounty3) OR `custom sentinel code` ");
@ -460,7 +458,7 @@ UniValue voteraw(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Failure to find masternode in list : " + vin.ToString());
}
CBudgetVote vote(vin, hashProposal, nVoteOutcome, VOTE_ACTION_NONE);
CGovernanceVote vote(vin, hashProposal, nVoteOutcome, VOTE_SIGNAL_NONE);
vote.nTime = nTime;
vote.vchSig = vchSig;
@ -469,8 +467,8 @@ UniValue voteraw(const UniValue& params, bool fHelp)
}
std::string strError = "";
if(governance.UpdateProposal(vote, NULL, strError)){
governance.mapSeenMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), SEEN_OBJECT_IS_VALID));
if(governance.UpdateGovernanceObject(vote, NULL, strError)){
governance.mapSeenVotes.insert(make_pair(vote.GetHash(), SEEN_OBJECT_IS_VALID));
vote.Relay();
return "Voted successfully";
} else {

View File

@ -10,7 +10,7 @@
* network protocol versioning
*/
static const int PROTOCOL_VERSION = 70103;
static const int PROTOCOL_VERSION = 70200;
//! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;

View File

@ -2765,7 +2765,7 @@ bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, bool useI
int nChangePosRet = -1;
std::string strFail = "";
vector< CRecipient > vecSend;
vecSend.push_back((CRecipient){scriptChange, BUDGET_FEE_TX, false});
vecSend.push_back((CRecipient){scriptChange, GOVERNANCE_FEE_TX, false});
CCoinControl *coinControl=NULL;
bool success = CreateTransaction(vecSend, tx, reservekey, nFeeRet, nChangePosRet, strFail, coinControl, true, ALL_COINS, useIX);