diff --git a/src/drafted/governance.new.h b/src/drafted/governance.new.h index 5651e6116..1d2a188f3 100644 --- a/src/drafted/governance.new.h +++ b/src/drafted/governance.new.h @@ -267,7 +267,6 @@ public: int GetTotalPaymentCount(); int64_t GetValidEndTimestamp(); int64_t GetValidStartTimestamp(); - std::pair GetVotes(); int GetYesCount(); bool IsCategoryValid(); diff --git a/src/governance.cpp b/src/governance.cpp index a62d0e7e2..49879cd76 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -87,7 +87,6 @@ void CGovernanceManager::CheckOrphanVotes() { LOCK(cs); - std::string strError = ""; std::map::iterator it1 = mapOrphanMasternodeBudgetVotes.begin(); while(it1 != mapOrphanMasternodeBudgetVotes.end()){ @@ -496,15 +495,19 @@ bool CGovernanceManager::UpdateProposal(CBudgetVote& vote, CNode* pfrom, std::st } - return mapProposals[vote.nProposalHash].AddOrUpdateVote(vote, strError); + return AddOrUpdateVote(vote, strError); } -bool CBudgetProposal::AddOrUpdateVote(CBudgetVote& vote, std::string& strError) +bool CGovernanceManager::AddOrUpdateVote(CBudgetVote& vote, std::string& strError) { LOCK(cs); uint256 hash = vote.vin.prevout.GetHash(); + // todo - need to rewrite + // check for first vote, create structure + // clear out votes if the budgets are invalid + if(mapVotes.count(hash)){ if(mapVotes[hash].nTime > vote.nTime){ strError = strprintf("new vote older than existing vote - %s", vote.GetHash().ToString()); @@ -626,17 +629,20 @@ bool CBudgetProposal::IsValid(const CBlockIndex* pindex, std::string& strError, return false; } - found = false - if strProposalName[:10] = "proposal="; found = true; - if strProposalName[:10] = "contract="; found = true; - if strProposalName[:10] = "project="; found = true; - if strProposalName[:10] = "employee="; found = true; - if strProposalName[:10] = "project-milestone="; found = true; - if strProposalName[:10] = "project-report="; found = true; + // 12.1 - add valid predicates + // this can be handled by configuration + // found = false + // if strProposalName[:10] = "proposal="; found = true; + // if strProposalName[:10] = "contract="; found = true; + // if strProposalName[:10] = "project="; found = true; + // if strProposalName[:10] = "employee="; found = true; + // if strProposalName[:10] = "project-milestone="; found = true; + // if strProposalName[:10] = "project-report="; found = true; - if not found: return false + // if not found: return false - if(GetTime() > nExpirationTime) return false; + // automatically expire + // if(GetTime() > nExpirationTime) return false; if(fCheckCollateral){ int nConf = 0; @@ -666,11 +672,12 @@ bool CBudgetProposal::IsValid(const CBlockIndex* pindex, std::string& strError, return false; } - nAmount can be - and +, allows increasing budget dynamically. This is R&D mode + //* + //nAmount can be - and +, allows increasing budget dynamically. This is R&D mode + //* if(GetBlockEnd() + Params().GetConsensus().nBudgetPaymentsWindowBlocks < pindex->nHeight) return false; - return true; } diff --git a/src/governance.h b/src/governance.h index 4e5547de5..d62cb8479 100644 --- a/src/governance.h +++ b/src/governance.h @@ -22,7 +22,6 @@ extern CCriticalSection cs_budget; class CGovernanceManager; class CBudgetProposal; -class CBudgetProposalBroadcast; class CBudgetVote; // todo - 12.1 - change BUDGET_ to GOVERNANCE_ (cherry pick) @@ -30,7 +29,7 @@ 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 vecImmatureBudgetProposals; +extern std::vector vecImmatureBudgetProposals; extern std::map askedForSourceProposalOrBudget; extern CGovernanceManager governance; @@ -50,9 +49,6 @@ private: // Keep track of current block index const CBlockIndex *pCurrentBlockIndex; - // parent hash vote hash vote - std::map > mapVotes; - public: // critical section to protect the inner data structures mutable CCriticalSection cs; @@ -60,12 +56,12 @@ public: // keep track of the scanning errors I've seen map mapProposals; -// #----------- voting sweep ---------- - // todo - 12.1 - move to private for better encapsulation - std::map mapSeenMasternodeBudgetProposals; + std::map mapSeenMasternodeBudgetProposals; std::map mapSeenMasternodeBudgetVotes; std::map mapOrphanMasternodeBudgetVotes; + // parent hash vote hash vote + std::map > mapVotes; CGovernanceManager() { mapProposals.clear(); @@ -103,6 +99,7 @@ public: bool AddProposal(CBudgetProposal& budgetProposal); bool UpdateProposal(CBudgetVote& vote, CNode* pfrom, std::string& strError); + bool AddOrUpdateVote(CBudgetVote& vote, std::string& strError); bool PropExists(uint256 nHash); std::string GetRequiredPaymentsString(int nBlockHeight); @@ -127,11 +124,45 @@ public: READWRITE(mapSeenMasternodeBudgetVotes); READWRITE(mapOrphanMasternodeBudgetVotes); READWRITE(mapProposals); + READWRITE(mapVotes); } void UpdatedBlockTip(const CBlockIndex *pindex); }; +/** +* Governance objects can hold any time of data +* -------------------------------------------- +* +* +*/ + +// todo - 12.1 - add payload obj to CGovernanceObj +// union GovernanceObjectPayload +// { +// CAmount nAmount; +// int nValue; +// bool bIsActive; +// std::string strPayload; +// double fValue; +// } + +/** +* Governance object payload types +* -------------------------------------------- +* +* +*/ + +// todo - 12.1 - add payload obj to CGovernanceObj +// enum class GovernanceObjectPayloadType { +// CAmount, +// Int, +// Bool, +// String, +// Double +// }; + // // Budget Proposal : Contains the masternode votes for each budget // @@ -153,23 +184,24 @@ public: */ std::string strURL; int nBlockStart; - int nExpirationTime; - CAmount nAmount; - CScript address; + int nBlockEnd; //int nExpirationTime; + int nBlockStart; + CAmount nValue; // 12.1 - remove + // int nPriority; //budget is sorted by this integer before funding votecount + // GovernanceObjectPayloadType payloadType; + // GovernanceObjectPayload payload; + CScript address; //todo rename to addressOwner; int64_t nTime; uint256 nFeeTXHash; - uint256 nHashParent; + uint256 nHashParent; // 12.1 - remove - map > mapVotes; //cache object CBudgetProposal(); CBudgetProposal(const CBudgetProposal& other); CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn); - bool AddOrUpdateVote(CBudgetVote& vote, std::string& strError); bool HasMinimumRequiredSupport(); - std::pair GetVotes(); bool IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral=true); bool IsEstablished(); @@ -223,63 +255,9 @@ public: READWRITE(*(CScriptBase*)(&address)); READWRITE(nTime); READWRITE(nFeeTXHash); - - //for saving to the serialized db - READWRITE(mapVotes); } }; -// Proposals are cast then sent to peers with this object, which leaves the votes out -class CBudgetProposalBroadcast : public CBudgetProposal -{ -public: - CBudgetProposalBroadcast() : CBudgetProposal(){} - CBudgetProposalBroadcast(const CBudgetProposal& other) : CBudgetProposal(other){} - CBudgetProposalBroadcast(const CBudgetProposalBroadcast& other) : CBudgetProposal(other){} - CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn) {} - - void swap(CBudgetProposalBroadcast& first, CBudgetProposalBroadcast& second) // nothrow - { - // enable ADL (not necessary in our case, but good practice) - using std::swap; - - // by swapping the members of two classes, - // the two classes are effectively swapped - swap(first.strProposalName, second.strProposalName); - swap(first.nBlockStart, second.nBlockStart); - swap(first.strURL, second.strURL); - swap(first.nBlockEnd, second.nBlockEnd); - swap(first.nAmount, second.nAmount); - swap(first.address, second.address); - swap(first.nTime, second.nTime); - swap(first.nFeeTXHash, second.nFeeTXHash); - first.mapVotes.swap(second.mapVotes); - } - - CBudgetProposalBroadcast& operator=(CBudgetProposalBroadcast from) - { - swap(*this, from); - return *this; - } - - void Relay(); - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - //for syncing with other clients - - READWRITE(LIMITED_STRING(strProposalName, 20)); - READWRITE(LIMITED_STRING(strURL, 64)); - READWRITE(nTime); - READWRITE(nBlockStart); - READWRITE(nBlockEnd); - READWRITE(nAmount); - READWRITE(*(CScriptBase*)(&address)); - READWRITE(nFeeTXHash); - } -}; // // CBudgetVote - Allow a masternode node to vote and broadcast throughout the network @@ -293,6 +271,7 @@ public: CTxIn vin; uint256 nProposalHash; int nVote; + //int nVoteType; //12.1 - mapped to config values int64_t nTime; std::vector vchSig; @@ -330,8 +309,6 @@ public: READWRITE(vchSig); } - - }; #endif