From fe5c4dd811ba0ddefbf4fa6deb3572915f43f1a5 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Tue, 19 Apr 2016 09:51:15 -0700 Subject: [PATCH] Converting governance system - Generic usage of governance objects - Added different voting types of signaling - Removed budget commands (projection, mesc -- see sentinel https://github.com/evan82/sentinel/blob/master/docs/example4.md) - Added various voting signaling mechanisms (origin funding, remove, valid, endorsed, milestones, outerstorage) --- doc/masternode-budget.md | 22 +++++------ src/drafted/governance-classes.h | 26 ------------- src/governance-misc.h | 54 +++++++++++++++++++++++++ src/governance-settings.h | 16 -------- src/governance-vote.cpp | 4 +- src/governance.cpp | 58 ++++++++++----------------- src/governance.h | 40 ++++++++++++++----- src/init.cpp | 2 +- src/main.cpp | 4 +- src/masternode-budget.cpp | 24 ++++++------ src/masternode-sync.cpp | 2 +- src/protocol.cpp | 28 ++++++------- src/protocol.h | 10 ++--- src/rpcclient.cpp | 4 +- src/rpcmasternode-budget.cpp | 67 ++++++++++++++++---------------- src/rpcmisc.cpp | 2 +- src/rpcserver.cpp | 4 +- src/rpcserver.h | 4 +- src/util.cpp | 2 +- 19 files changed, 194 insertions(+), 179 deletions(-) create mode 100644 src/governance-misc.h delete mode 100644 src/governance-settings.h diff --git a/doc/masternode-budget.md b/doc/masternode-budget.md index 432ff35be..28feee007 100644 --- a/doc/masternode-budget.md +++ b/doc/masternode-budget.md @@ -23,9 +23,9 @@ In this transaction we prepare collateral for "_cool-project_". This proposal wi **Warning: if you change any fields within this command, the collateral transaction will become invalid.** -Format: ```mnbudget prepare proposal-name url payment-count block-start dash-address monthly-payment-dash``` +Format: ```mngovernance prepare proposal-name url payment-count block-start dash-address monthly-payment-dash``` -Example: ```mnbudget prepare cool-project http://www.cool-project/one.json 12 100000 y6R9oN12KnB9zydzTLc3LikD9cCjjQzYG7 1200 true``` +Example: ```mngovernance prepare cool-project http://www.cool-project/one.json 12 100000 y6R9oN12KnB9zydzTLc3LikD9cCjjQzYG7 1200 true``` Output: ```464a0eb70ea91c94295214df48c47baa72b3876cfb658744aaf863c7b5bf1ff0``` @@ -36,9 +36,9 @@ This is the collateral hash, copy this output for the next step. Now we can submit our proposal to the network. -Format: ```mnbudget submit proposal-name url payment-count block-start dash-address monthly-payment-dash fee-tx``` +Format: ```mngovernance submit proposal-name url payment-count block-start dash-address monthly-payment-dash fee-tx``` -Example: ```mnbudget submit cool-project http://www.cool-project/one.json 12 100000 y6R9oN12KnB9zydzTLc3LikD9cCjjQzYG7 1200 464a0eb70ea91c94295214df48c47baa72b3876cfb658744aaf863c7b5bf1ff0``` +Example: ```mngovernance submit cool-project http://www.cool-project/one.json 12 100000 y6R9oN12KnB9zydzTLc3LikD9cCjjQzYG7 1200 464a0eb70ea91c94295214df48c47baa72b3876cfb658744aaf863c7b5bf1ff0``` Output : ```a2b29778ae82e45a973a94309ffa6aa2e2388b8f95b39ab3739f0078835f0491``` @@ -49,9 +49,9 @@ This is your proposal hash, which other nodes will use to vote on it. Double check your information. -Format: ```mnbudget getproposal proposal-hash``` +Format: ```mngovernance getproposal proposal-hash``` -Example: ```mnbudget getproposal a2b29778ae82e45a973a94309ffa6aa2e2388b8f95b39ab3739f0078835f0491``` +Example: ```mngovernance getproposal a2b29778ae82e45a973a94309ffa6aa2e2388b8f95b39ab3739f0078835f0491```  ``` { @@ -77,16 +77,16 @@ Example: ```mnbudget getproposal a2b29778ae82e45a973a94309ffa6aa2e2388b8f95b39ab If everything looks correct, you can ask for votes from other masternodes. To vote on a proposal, load a wallet with _masternode.conf_ file. You do not need to access your cold wallet to vote for proposals. -Format: ```mnbudget vote proposal-hash [yes|no]``` +Format: ```mngovernance vote proposal-hash [yes|no]``` -Example: ```mnbudget vote a2b29778ae82e45a973a94309ffa6aa2e2388b8f95b39ab3739f0078835f0491 yes``` +Example: ```mngovernance vote a2b29778ae82e45a973a94309ffa6aa2e2388b8f95b39ab3739f0078835f0491 yes``` 4. Make it into the budget -- -After you get enough votes, execute ```mnbudget projection``` to see if you made it into the budget. If you the budget was finalized at this moment which proposals would be in it. Note: Proposals must be active at least 1 day on the network and receive 10% of the masternode network in yes votes in order to qualify (E.g. if there is 3500 masternodes, you will need 350 yes votes.) +After you get enough votes, execute ```mngovernance projection``` to see if you made it into the budget. If you the budget was finalized at this moment which proposals would be in it. Note: Proposals must be active at least 1 day on the network and receive 10% of the masternode network in yes votes in order to qualify (E.g. if there is 3500 masternodes, you will need 350 yes votes.) -```mnbudget projection```: +```mngovernance projection```: ``` { "cool-project" : { @@ -135,7 +135,7 @@ When block ```1000000``` is reached you'll receive a payment for ```1200``` DASH The following RPC commands are supported: - - mnbudget "command"... ( "passphrase" ) + - mngovernance "command"... ( "passphrase" ) - check - Scan proposals and remove invalid from proposals list - prepare - Prepare proposal by signing and creating tx - submit - Submit proposal to network diff --git a/src/drafted/governance-classes.h b/src/drafted/governance-classes.h index c145d4d0c..a56986a93 100644 --- a/src/drafted/governance-classes.h +++ b/src/drafted/governance-classes.h @@ -64,18 +64,6 @@ * CValueOverride lvl, vo-type, status, status-error */ -class CDashNetwork; -class CDashNetworkVariable; -class CCategory; -class CGroup; -class CUser; -class CCompany; -class CProject; -class CProjectReport; -class CProjectMilestone; -class CProposal; -class CContract; -class CValueOverride; /* @@ -87,20 +75,6 @@ class CValueOverride; * -- Most of the values in these classes can be overriden * * CGovernanceNode (base) - * -> CGovernanceObject (unimplementable) - * -> CDashNetwork - * -> CDashNetworkVariable - * -> CValueOverride - * -> CCategory - * -> CGovernanceActor - * -> CGroup - * -> CUser - * -> CCompany - * -> DAO/DO/LLC/501c6/etc - * -> CProject - * -> CProjectReport - * -> CProjectMilestone - * * * TREE STRUCTURE * =========================================== diff --git a/src/governance-misc.h b/src/governance-misc.h new file mode 100644 index 000000000..a64c4caf2 --- /dev/null +++ b/src/governance-misc.h @@ -0,0 +1,54 @@ +// Copyright (c) 2014-2016 The Dash Core developers + +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. +#ifndef GOVERANCE_MISC_H +#define GOVERANCE_MISC_H + +#include "main.h" +#include "governance.h" +#include "init.h" + +using namespace std; + +class CBudgetVote; + +/** +* Triggers and Settings - 12.2 +* ----------------------------------- +* +* This allows the network fine grained control of the p2p side, including but not limited to: +* - Which blocks are valid +* - What it costs to do various things on the network +* +*/ + + +// class CGovernanceTrigger +// { +// static &T IsBlockBanned(int n) +// { + +// } +// }; + +// /* + + +// */ + +// class CGovernanceSettings +// { +// template +// // strName=trigger, strParamater=ban-block ... obj= tigger.ban-block(args) +// static &T GetSetting(std::string strName, &T networkDefault) +// { +// /* +// - get setting from masternode network +// */ + +// return networkDefault; +// } +// }; + +#endif \ No newline at end of file diff --git a/src/governance-settings.h b/src/governance-settings.h deleted file mode 100644 index 0e43422d8..000000000 --- a/src/governance-settings.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2014-2016 The Dash Core developers - -/* - - -*/ - -class CGovernanceSettings -{ - template - // strName=trigger, strParamater=ban-block ... obj= tigger.ban-block(args) - static &T GetSetting(std::string strName) - { - - } -} \ No newline at end of file diff --git a/src/governance-vote.cpp b/src/governance-vote.cpp index fdff4adbe..6285d3d09 100644 --- a/src/governance-vote.cpp +++ b/src/governance-vote.cpp @@ -69,7 +69,7 @@ bool CBudgetVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) bool CBudgetVote::IsValid(bool fSignatureCheck) { if(nTime > GetTime() + (60*60)){ - LogPrint("mnbudget", "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", "CBudgetVote::IsValid() - vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", GetHash().ToString(), nTime, GetTime() + (60*60)); return false; } @@ -77,7 +77,7 @@ bool CBudgetVote::IsValid(bool fSignatureCheck) if(pmn == NULL) { - LogPrint("mnbudget", "CBudgetVote::IsValid() - Unknown Masternode - %s\n", vin.ToString()); + LogPrint("mngovernance", "CBudgetVote::IsValid() - Unknown Masternode - %s\n", vin.ToString()); return false; } diff --git a/src/governance.cpp b/src/governance.cpp index 20585593b..acda93b60 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -166,7 +166,7 @@ CGovernanceObject *CGovernanceManager::FindProposal(uint256 nHash) return NULL; } -std::vector CGovernanceManager::GetAllProposals() +std::vector CGovernanceManager::GetAllProposals(int64_t nTimeIn) { LOCK(cs); @@ -175,6 +175,10 @@ std::vector CGovernanceManager::GetAllProposals() std::map::iterator it = mapProposals.begin(); while(it != mapProposals.end()) { + if((*it).second.nTime < nTimeIn) { + ++it; + continue; + } (*it).second.CleanAndRemove(false); CGovernanceObject* pbudgetProposal = &((*it).second); @@ -291,18 +295,18 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C LOCK(cs_budget); // todo - 12.1 - change to MNGOVERNANCEVOTESYNC - if (strCommand == NetMsgType::MNBUDGETVOTESYNC) { //Masternode vote sync + if (strCommand == NetMsgType::mngovernanceVOTESYNC) { //Masternode vote sync uint256 nProp; vRecv >> nProp; if(Params().NetworkIDString() == CBaseChainParams::MAIN){ if(nProp == uint256()) { - if(pfrom->HasFulfilledRequest(NetMsgType::MNBUDGETVOTESYNC)) { + if(pfrom->HasFulfilledRequest(NetMsgType::mngovernanceVOTESYNC)) { LogPrintf("mnvs - peer already asked me for the list\n"); Misbehaving(pfrom->GetId(), 20); return; } - pfrom->FulfilledRequest(NetMsgType::MNBUDGETVOTESYNC); + pfrom->FulfilledRequest(NetMsgType::mngovernanceVOTESYNC); } } @@ -312,7 +316,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C } // todo - 12.1 - change to MNGOVERNANCEPROPOSAL - if (strCommand == NetMsgType::MNBUDGETPROPOSAL) { //Masternode Proposal + if (strCommand == NetMsgType::mngovernancePROPOSAL) { //Masternode Proposal CGovernanceObject budgetProposalBroadcast; vRecv >> budgetProposalBroadcast; @@ -347,7 +351,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C } // todo - 12.1 - change to MNGOVERNANCEVOTE - if (strCommand == NetMsgType::MNBUDGETVOTE) { //Masternode Vote + if (strCommand == NetMsgType::mngovernanceVOTE) { //Masternode Vote CBudgetVote vote; vRecv >> vote; vote.fValid = true; @@ -359,7 +363,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C CMasternode* pmn = mnodeman.Find(vote.vinMasternode); if(pmn == NULL) { - LogPrint("mnbudget", "mvote - unknown masternode - vin: %s\n", vote.vinMasternode.ToString()); + LogPrint("mngovernance", "mvote - unknown masternode - vin: %s\n", vote.vinMasternode.ToString()); mnodeman.AskForMN(pfrom, vote.vinMasternode); return; } @@ -490,7 +494,7 @@ bool CGovernanceManager::UpdateProposal(CBudgetVote& vote, CNode* pfrom, std::st mapOrphanMasternodeBudgetVotes[vote.nParentHash] = vote; if(!askedForSourceProposalOrBudget.count(vote.nParentHash)){ - pfrom->PushMessage(NetMsgType::MNBUDGETVOTESYNC, vote.nParentHash); + pfrom->PushMessage(NetMsgType::mngovernanceVOTESYNC, vote.nParentHash); askedForSourceProposalOrBudget[vote.nParentHash] = GetTime(); } } @@ -513,12 +517,12 @@ bool CGovernanceManager::AddOrUpdateVote(CBudgetVote& vote, std::string& strErro if(mapVotes[hash2].count(hash)){ if(mapVotes[hash2][hash].nTime > vote.nTime){ strError = strprintf("new vote older than existing vote - %s", vote.GetHash().ToString()); - LogPrint("mnbudget", "CGovernanceObject::AddOrUpdateVote - %s\n", strError); + LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError); return false; } if(vote.nTime - mapVotes[hash2][hash].nTime < BUDGET_VOTE_UPDATE_MIN){ strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotes[hash2][hash].nTime); - LogPrint("mnbudget", "CGovernanceObject::AddOrUpdateVote - %s\n", strError); + LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError); return false; } } @@ -532,29 +536,17 @@ CGovernanceObject::CGovernanceObject() strName = "unknown"; nStartTime = 0; nEndTime = 0; - nAmount = 0; nTime = 0; fValid = true; } -CGovernanceObject::CGovernanceObject(const CGovernanceObject& other) -{ - strName = other.strName; - strURL = other.strURL; - nStartTime = other.nStartTime; - nEndTime = other.nEndTime; - address = other.address; - nAmount = other.nAmount; - nTime = other.nTime; - nFeeTXHash = other.nFeeTXHash; - fValid = true; -} - -CGovernanceObject::CGovernanceObject(std::string strNameIn, std::string strURLIn, int64_t nStartTimeIn, - int64_t nEndTimeIn, uint256 nFeeTXHashIn) +CGovernanceObject::CGovernanceObject(uint256 nHashParentIn, int nPriorityIn, int nRevisionIn, int nTypeVersionIn, std::string strNameIn, int64_t nStartTimeIn, int64_t nEndTimeIn, uint256 nFeeTXHashIn) { + nHashParent = nHashParentIn + nPriority = nPriorityIn; + nRevision = nRevisionIn; + nTypeVersion = nTypeVersionIn; strName = strNameIn; - strURL = strURLIn; nStartTime = nStartTimeIn; nEndTime = nEndTimeIn; nFeeTXHash = nFeeTXHashIn; @@ -592,16 +584,6 @@ bool CGovernanceObject::IsValid(const CBlockIndex* pindex, std::string& strError return false; } - if(strURL.size() > 100) { - strError = "Invalid proposal url, limit of 64 characters."; - return false; - } - - if(strURL != SanitizeString(strURL)) { - strError = "Invalid proposal url, unsafe characters found."; - return false; - } - if(address == CScript()) { strError = "Invalid proposal Payment Address"; return false; @@ -741,7 +723,7 @@ std::string CGovernanceManager::ToString() const void CGovernanceManager::UpdatedBlockTip(const CBlockIndex *pindex) { pCurrentBlockIndex = pindex; - LogPrint("mnbudget", "pCurrentBlockIndex->nHeight: %d\n", pCurrentBlockIndex->nHeight); + LogPrint("mngovernance", "pCurrentBlockIndex->nHeight: %d\n", pCurrentBlockIndex->nHeight); if(!fLiteMode && masternodeSync.RequestedMasternodeAssets > MASTERNODE_SYNC_LIST) NewBlock(); diff --git a/src/governance.h b/src/governance.h index baec9023d..f2bcb22a7 100644 --- a/src/governance.h +++ b/src/governance.h @@ -60,6 +60,8 @@ private: // Keep track of current block index const CBlockIndex *pCurrentBlockIndex; + int64_t nTimeLastDiff; + public: // critical section to protect the inner data structures mutable CCriticalSection cs; @@ -139,6 +141,8 @@ public: } void UpdatedBlockTip(const CBlockIndex *pindex); + int64_t GetLastDiffTime() {return nTimeLastDiff;} + void UpdateLastDiffTime(int64_t nTimeIn) {nTimeLastDiff=nTimeIn;} }; /** @@ -166,7 +170,7 @@ public: inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { //for syncing with other clients READWRITE(nType); - READWRITE(LIMITED_STRING(strReg, 64)); + READWRITE(LIMITED_STRING(strReg, 255)); } }; @@ -184,25 +188,29 @@ private: CAmount nAlloted; public: - bool fValid; + + uint256 nHashParent; //parent object, 0 is root + int nPriority; //budget is sorted by this integer before funding votecount + int nRevision; //object revision in the system + int64_t nTime; //time this object was created + std::string strName; //org name, username, prop name, etc. int nStartTime; int nEndTime; - CAmount nAmount; // 12.1 - remove - int nPriority; //budget is sorted by this integer before funding votecount - CScript address; //todo rename to addressOwner; - int64_t nTime; + CScript ownerAddress; //todo rename to addressOwner; uint256 nFeeTXHash; - uint256 nHashParent; // 12.1 - remove + // caching + bool fValid; + uint256 nHash; + // Registers, these can be used for anything // -- check governance wiki for correct usage std::map mapRegister; CGovernanceObject(); - CGovernanceObject(const CGovernanceObject& other); - CGovernanceObject(std::string strNameIn, int64_t nStartTimeIn, int64_t nEndTimeIn, uint256 nFeeTXHashIn); + CGovernanceObject(uint256 nHashParentIn, int nPriorityIn, int nRevisionIn, int nTypeVersionIn, std::string strNameIn, int64_t nStartTimeIn, int64_t nEndTimeIn, uint256 nFeeTXHashIn); bool HasMinimumRequiredSupport(); bool IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral=true); @@ -210,7 +218,6 @@ public: bool NetworkWillPay(); std::string GetName() {return strName; } - std::string GetURL() {return strURL; } int GetStartTime() {return nStartTime;} int GetEndTime() {return nEndTime;} int IsActive(int64_t nTime) {return nTime > nStartTime && nTime < nEndTime;} @@ -276,6 +283,19 @@ public: template inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + /* + + uint256 nHashParent; //parent object, 0 is root + int nPriority; //budget is sorted by this integer before funding votecount + int nRevision; //object revision in the system + int64_t nTime; //time this object was created + + std::string strName; //org name, username, prop name, etc. + int nStartTime; + int nEndTime; + CScript ownerAddress; //todo rename to addressOwner; + uint256 nFeeTXHash; + */ READWRITE(LIMITED_STRING(strName, 20)); READWRITE(nTime); READWRITE(nStartTime); diff --git a/src/init.cpp b/src/init.cpp index 5ea98aa05..0d55cacc4 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -511,7 +511,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-limitdescendantsize=", strprintf("Do not accept transactions if any ancestor would have more than kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT)); } string debugCategories = "addrman, alert, bench, coindb, db, lock, rand, rpc, selectcoins, mempool, mempoolrej, net, proxy, prune, http, libevent, tor, zmq, " - "dash (or specifically: darksend, instantx, masternode, keepass, mnpayments, mnbudget)"; // Don't translate these and qt below + "dash (or specifically: darksend, instantx, masternode, keepass, mnpayments, mngovernance)"; // Don't translate these and qt below if (mode == HMM_BITCOIN_QT) debugCategories += ", qt"; strUsage += HelpMessageOpt("-debug=", strprintf(_("Output debugging information (default: %u, supplying is optional)"), 0) + ". " + diff --git a/src/main.cpp b/src/main.cpp index f753aef3b..3b61433b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4580,7 +4580,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); ss.reserve(1000); ss << governance.mapSeenMasternodeBudgetVotes[inv.hash]; - pfrom->PushMessage(NetMsgType::MNBUDGETVOTE, ss); + pfrom->PushMessage(NetMsgType::mngovernanceVOTE, ss); pushed = true; } } @@ -4590,7 +4590,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); ss.reserve(1000); ss << governance.mapSeenMasternodeBudgetProposals[inv.hash]; - pfrom->PushMessage(NetMsgType::MNBUDGETPROPOSAL, ss); + pfrom->PushMessage(NetMsgType::mngovernancePROPOSAL, ss); pushed = true; } } diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index 737e2338f..06a5bb398 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -146,18 +146,18 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData // todo : 12.1 - split out into two messages // --- one for finalized budgets and one for gov objs - if (strCommand == NetMsgType::MNBUDGETVOTESYNC) { //Masternode vote sync + if (strCommand == NetMsgType::mngovernanceVOTESYNC) { //Masternode vote sync uint256 nProp; vRecv >> nProp; if(Params().NetworkIDString() == CBaseChainParams::MAIN){ if(nProp == uint256()) { - if(pfrom->HasFulfilledRequest(NetMsgType::MNBUDGETVOTESYNC)) { + if(pfrom->HasFulfilledRequest(NetMsgType::mngovernanceVOTESYNC)) { LogPrintf("mnvs - peer already asked me for the list\n"); Misbehaving(pfrom->GetId(), 20); return; } - pfrom->FulfilledRequest(NetMsgType::MNBUDGETVOTESYNC); + pfrom->FulfilledRequest(NetMsgType::mngovernanceVOTESYNC); } } @@ -165,7 +165,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData LogPrintf("mnvs - Sent Masternode votes to %s\n", pfrom->addr.ToString()); } - if (strCommand == NetMsgType::MNBUDGETFINAL) { //Finalized Budget Suggestion + if (strCommand == NetMsgType::mngovernanceFINAL) { //Finalized Budget Suggestion CFinalizedBudget finalizedBudgetBroadcast; vRecv >> finalizedBudgetBroadcast; @@ -200,7 +200,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData CheckOrphanVotes(); } - if (strCommand == NetMsgType::MNBUDGETFINALVOTE) { //Finalized Budget Vote + if (strCommand == NetMsgType::mngovernanceFINALVOTE) { //Finalized Budget Vote CBudgetVote vote; vRecv >> vote; vote.fValid = true; @@ -212,7 +212,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData CMasternode* pmn = mnodeman.Find(vote.vin); if(pmn == NULL) { - LogPrint("mnbudget", "fbvote - unknown masternode - vin: %s\n", vote.vin.ToString()); + LogPrint("mngovernance", "fbvote - unknown masternode - vin: %s\n", vote.vin.ToString()); mnodeman.AskForMN(pfrom, vote.vin); return; } @@ -416,7 +416,7 @@ bool CBudgetManager::UpdateFinalizedBudget(CBudgetVote& vote, CNode* pfrom, std: mapOrphanFinalizedBudgetVotes[vote.nBudgetHash] = vote; if(!askedForSourceProposalOrBudget.count(vote.nBudgetHash)){ - pfrom->PushMessage(NetMsgType::MNBUDGETVOTESYNC, vote.nBudgetHash); + pfrom->PushMessage(NetMsgType::mngovernanceVOTESYNC, vote.nBudgetHash); askedForSourceProposalOrBudget[vote.nBudgetHash] = GetTime(); } @@ -616,7 +616,7 @@ std::string CBudgetManager::ToString() const void CBudgetManager::UpdatedBlockTip(const CBlockIndex *pindex) { pCurrentBlockIndex = pindex; - LogPrint("mnbudget", "pCurrentBlockIndex->nHeight: %d\n", pCurrentBlockIndex->nHeight); + LogPrint("mngovernance", "pCurrentBlockIndex->nHeight: %d\n", pCurrentBlockIndex->nHeight); if(!fLiteMode && masternodeSync.RequestedMasternodeAssets > MASTERNODE_SYNC_LIST) NewBlock(); @@ -662,12 +662,12 @@ bool CFinalizedBudget::AddOrUpdateVote(CBudgetVote& vote, std::string& strError) if(mapVotes.count(hash)){ if(mapVotes[hash].nTime > vote.nTime){ strError = strprintf("new vote older than existing vote - %s", vote.GetHash().ToString()); - LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); + LogPrint("mngovernance", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); return false; } if(vote.nTime - mapVotes[hash].nTime < BUDGET_VOTE_UPDATE_MIN){ strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotes[hash].nTime); - LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); + LogPrint("mngovernance", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); return false; } } @@ -1008,7 +1008,7 @@ bool CBudgetVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) bool CBudgetVote::IsValid(bool fSignatureCheck) { if(nTime > GetTime() + (60*60)){ - LogPrint("mnbudget", "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", "CBudgetVote::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("mnbudget", "CBudgetVote::IsValid() - Unknown Masternode\n"); + LogPrint("mngovernance", "CBudgetVote::IsValid() - Unknown Masternode\n"); return false; } diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index a3774a622..144ff6964 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -259,7 +259,7 @@ void CMasternodeSync::Process() int nMnCount = mnodeman.CountEnabled(); pnode->PushMessage(NetMsgType::MNWINNERSSYNC, nMnCount); //sync payees uint256 n = uint256(); - pnode->PushMessage(NetMsgType::MNBUDGETVOTESYNC, n); //sync masternode votes + pnode->PushMessage(NetMsgType::mngovernanceVOTESYNC, n); //sync masternode votes } else { RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED; } diff --git a/src/protocol.cpp b/src/protocol.cpp index 637efbcc2..e67a3e3ff 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -43,11 +43,11 @@ const char *GETSPORKS="getsporks"; const char *MNWINNER="mnw"; const char *MNWINNERSSYNC="mnget"; const char *MNSCANERROR="mn scan error"; // TODO ??? -const char *MNBUDGETVOTESYNC="mnvs"; -const char *MNBUDGETVOTE="mvote"; -const char *MNBUDGETPROPOSAL="mprop"; -const char *MNBUDGETFINAL="fbs"; -const char *MNBUDGETFINALVOTE="fbvote"; +const char *mngovernanceVOTESYNC="mnvs"; +const char *mngovernanceVOTE="mvote"; +const char *mngovernancePROPOSAL="mprop"; +const char *mngovernanceFINAL="fbs"; +const char *mngovernanceFINALVOTE="fbvote"; const char *MNQUORUM="mn quorum"; // TODO ??? const char *MNANNOUNCE="mnb"; const char *MNPING="mnp"; @@ -75,10 +75,10 @@ static const char* ppszTypeName[] = NetMsgType::SPORK, NetMsgType::MNWINNER, NetMsgType::MNSCANERROR, - NetMsgType::MNBUDGETVOTE, - NetMsgType::MNBUDGETPROPOSAL, - NetMsgType::MNBUDGETFINAL, - NetMsgType::MNBUDGETFINALVOTE, + NetMsgType::mngovernanceVOTE, + NetMsgType::mngovernancePROPOSAL, + NetMsgType::mngovernanceFINAL, + NetMsgType::mngovernanceFINALVOTE, NetMsgType::MNQUORUM, NetMsgType::MNANNOUNCE, NetMsgType::MNPING, @@ -119,11 +119,11 @@ const static std::string allNetMessageTypes[] = { NetMsgType::MNWINNER, NetMsgType::MNWINNERSSYNC, NetMsgType::MNSCANERROR, - NetMsgType::MNBUDGETVOTESYNC, - NetMsgType::MNBUDGETVOTE, - NetMsgType::MNBUDGETPROPOSAL, - NetMsgType::MNBUDGETFINAL, - NetMsgType::MNBUDGETFINALVOTE, + NetMsgType::mngovernanceVOTESYNC, + NetMsgType::mngovernanceVOTE, + NetMsgType::mngovernancePROPOSAL, + NetMsgType::mngovernanceFINAL, + NetMsgType::mngovernanceFINALVOTE, NetMsgType::MNQUORUM, NetMsgType::MNANNOUNCE, NetMsgType::MNPING, diff --git a/src/protocol.h b/src/protocol.h index f7d73f9d4..b251e3fb5 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -228,11 +228,11 @@ extern const char *GETSPORKS; extern const char *MNWINNER; extern const char *MNWINNERSSYNC; extern const char *MNSCANERROR; -extern const char *MNBUDGETVOTESYNC; -extern const char *MNBUDGETVOTE; -extern const char *MNBUDGETPROPOSAL; -extern const char *MNBUDGETFINAL; -extern const char *MNBUDGETFINALVOTE; +extern const char *mngovernanceVOTESYNC; +extern const char *mngovernanceVOTE; +extern const char *mngovernancePROPOSAL; +extern const char *mngovernanceFINAL; +extern const char *mngovernanceFINALVOTE; extern const char *MNQUORUM; extern const char *MNANNOUNCE; extern const char *MNPING; diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index f7aec227e..a2d46ec5d 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -111,8 +111,8 @@ static const CRPCConvertParam vRPCConvertParams[] = { "setban", 2 }, { "setban", 3 }, { "spork", 1 }, - { "mnbudgetvoteraw", 1 }, - { "mnbudgetvoteraw", 4 }, + { "mngovernancevoteraw", 1 }, + { "mngovernancevoteraw", 4 }, }; class CRPCConvertTable diff --git a/src/rpcmasternode-budget.cpp b/src/rpcmasternode-budget.cpp index 012fcfbd6..a961eea77 100644 --- a/src/rpcmasternode-budget.cpp +++ b/src/rpcmasternode-budget.cpp @@ -34,16 +34,28 @@ using namespace std; * * command structure: * -* governance prepare new nTypeIn nParentID "name" epoch-start epoch-end parameter1 parameter2 parameter3 +* For instructions on creating registers, see dashbrain +* +* +* governance prepare new nTypeIn nParentID "name" epoch-start epoch-end register1 register2 register3 * >> fee transaction hash * -* governance submit fee-hash nTypeIn nParentID, "name", epoch-start, epoch-end, fee-hash, parameter1, parameter2, parameter3 +* governance submit fee-hash nTypeIn nParentID, "name", epoch-start, epoch-end, fee-hash, register1, register2, register3 * >> governance object hash +* +* governance vote(-alias|many) type hash yes|no|abstain +* >> success|failure +* +* governance list +* >> flat data representation of the governance system +* >> NOTE: this shouldn't be altered, we'll analyze the system outside of this project * +* governance get hash +* >> show one proposal * */ -UniValue mnbudget(const UniValue& params, bool fHelp) +UniValue mngovernance(const UniValue& params, bool fHelp) { string strCommand; if (params.size() >= 1) @@ -51,20 +63,16 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if (fHelp || (strCommand != "vote-many" && strCommand != "vote-alias" && strCommand != "prepare" && strCommand != "submit" && - strCommand != "vote" && strCommand != "getvotes" && strCommand != "getproposal" && - strCommand != "list" && strCommand != "projection" && strCommand != "check")) + strCommand != "vote" && strCommand != "get" && strCommand != "list" && strCommand != "diff")) throw runtime_error( - "mnbudget \"command\"...\n" + "mngovernance \"command\"...\n" "Manage proposals\n" "\nAvailable commands:\n" - " check - Scan proposals and remove invalid from proposals list\n" " prepare - Prepare proposal by signing and creating tx\n" " submit - Submit proposal to network\n" - " getproposalhash - Get proposal hash(es) by proposal name\n" - " getproposal - Show proposal\n" - " getvotes - Show detailed votes list for proposal\n" + " get - Get proposal hash(es) by proposal name\n" " list - List all proposals\n" - " projection - Show the projection of which proposals will be paid the next cycle\n" + " diff - List differences since last diff\n" " vote - Vote on a proposal by single masternode (using dash.conf setup)\n" " vote-many - Vote on a proposal by all masternodes (using masternode.conf setup)\n" " vote-alias - Vote on a proposal by alias\n" @@ -73,7 +81,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "prepare") { if (params.size() != 7) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget prepare '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance prepare '"); int nBlockMin = 0; LOCK(cs_main); @@ -83,15 +91,10 @@ UniValue mnbudget(const UniValue& params, bool fHelp) mnEntries = masternodeConfig.getEntries(); std::string strName = SanitizeString(params[1].get_str()); - std::string strURL = SanitizeString(params[2].get_str()); - int nBlockStart = params[4].get_int(); //set block min if(pindex != NULL) nBlockMin = pindex->nHeight; - if(nBlockStart < nBlockMin) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block start, must be more than current height."); - CBitcoinAddress address(params[5].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address"); @@ -99,7 +102,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) //************************************************************************* // create transaction 15 minutes into the future, to allow for confirmation time - CGovernanceObject budgetProposalBroadcast(strName, strURL, GetTime(), 253370764800, uint256()); + CGovernanceObject budgetProposalBroadcast(strName, GetTime(), 253370764800, uint256()); std::string strError = ""; if(!budgetProposalBroadcast.IsValid(pindex, strError, false)) @@ -121,7 +124,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "submit") { if (params.size() != 8) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget submit '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance submit '"); if(!masternodeSync.IsBlockchainSynced()){ throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Must wait for client to sync with masternode network. Try again in a minute or so."); @@ -135,7 +138,6 @@ UniValue mnbudget(const UniValue& params, bool fHelp) mnEntries = masternodeConfig.getEntries(); std::string strName = SanitizeString(params[1].get_str()); - std::string strURL = SanitizeString(params[2].get_str()); //set block min if(pindex != NULL) nBlockMin = pindex->nHeight; @@ -143,7 +145,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) // create new governance object uint256 hash = ParseHashV(params[7], "Proposal hash"); - CGovernanceObject budgetProposalBroadcast(strName, strURL, GetTime(), 253370764800, uint256()); + CGovernanceObject budgetProposalBroadcast(strName, GetTime(), 253370764800, uint256()); std::string strError = ""; @@ -167,7 +169,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "vote-many") { if(params.size() != 3) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget vote-many [yes|no]'"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance vote-many [yes|no]'"); uint256 hash; std::string strVote; @@ -254,7 +256,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "vote-alias") { if(params.size() != 4) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget vote-alias [yes|no] '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance vote-alias [yes|no] '"); uint256 hash; std::string strVote; @@ -345,7 +347,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "vote") { if (params.size() != 3) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget vote [yes|no]'"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance vote [yes|no]'"); uint256 hash = ParseHashV(params[1], "Proposal hash"); std::string strVote = params[2].get_str(); @@ -385,10 +387,10 @@ UniValue mnbudget(const UniValue& params, bool fHelp) } } - if(strCommand == "list") + if(strCommand == "list" || strCommand == "diff") { if (params.size() > 2) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget list [valid]'"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance list [valid]'"); std::string strShow = "valid"; if (params.size() == 2) strShow = params[1].get_str(); @@ -401,14 +403,14 @@ UniValue mnbudget(const UniValue& params, bool fHelp) pindex = chainActive.Tip(); } - std::vector winningProps = governance.GetAllProposals(); + std::vector winningProps = governance.GetAllProposals(governance.GetLastDiffTime()); + governance.UpdateLastDiffTime(GetTime()); BOOST_FOREACH(CGovernanceObject* pbudgetProposal, winningProps) { if(strShow == "valid" && !pbudgetProposal->fValid) continue; UniValue bObj(UniValue::VOBJ); bObj.push_back(Pair("Name", pbudgetProposal->GetName())); - bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); bObj.push_back(Pair("FeeTXHash", pbudgetProposal->nFeeTXHash.ToString())); bObj.push_back(Pair("StartTime", (int64_t)pbudgetProposal->GetStartTime())); @@ -433,7 +435,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "getproposal") { if (params.size() != 2) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget getproposal '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance getproposal '"); uint256 hash = ParseHashV(params[1], "Proposal hash"); @@ -453,7 +455,6 @@ UniValue mnbudget(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("URL", pbudgetProposal->GetURL())); obj.push_back(Pair("StartTime", (int64_t)pbudgetProposal->GetStartTime())); obj.push_back(Pair("EndTime", (int64_t)pbudgetProposal->GetEndTime())); obj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); @@ -472,7 +473,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "getvotes") { if (params.size() != 2) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget getvotes '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance getvotes '"); uint256 hash = ParseHashV(params[1], "Proposal hash"); @@ -505,11 +506,11 @@ UniValue mnbudget(const UniValue& params, bool fHelp) return NullUniValue; } -UniValue mnbudgetvoteraw(const UniValue& params, bool fHelp) +UniValue mngovernancevoteraw(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 6) throw runtime_error( - "mnbudgetvoteraw [yes|no]