diff --git a/src/darksend.cpp b/src/darksend.cpp index fe8a76ff4..80c5aa8d9 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -45,7 +45,7 @@ CActiveMasternode activeMasternode; udjinm6 - udjinm6@dash.org */ -void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) +void CDarksendPool::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) { if(fLiteMode) return; //disable all Darksend/Masternode related functionality if(!masternodeSync.IsBlockchainSynced()) return; diff --git a/src/darksend.h b/src/darksend.h index e2ce3bbbd..1dbce0416 100644 --- a/src/darksend.h +++ b/src/darksend.h @@ -360,7 +360,7 @@ public: * dssub | Darksend Subscribe To * \param vRecv */ - void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); + void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); void InitCollateralAddress(){ SetCollateralAddress(Params().DarksendPoolDummyAddress()); diff --git a/src/governance-vote.h b/src/governance-vote.h index be4b4e0ee..2318a421b 100644 --- a/src/governance-vote.h +++ b/src/governance-vote.h @@ -27,20 +27,20 @@ class CGovernanceVote; #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_VALID 2 // -- this object checks out in sentinel engine #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_ENDORSED 4 // -- officially endorsed by the network somehow (delegation) +#define VOTE_SIGNAL_NOOP1 5 // FOR FURTHER EXPANSION +#define VOTE_SIGNAL_NOOP2 6 // +#define VOTE_SIGNAL_NOOP3 7 // +#define VOTE_SIGNAL_NOOP4 8 // +#define VOTE_SIGNAL_NOOP5 9 // +#define VOTE_SIGNAL_NOOP6 10 // +#define VOTE_SIGNAL_NOOP7 11 // +#define VOTE_SIGNAL_NOOP8 12 // +#define VOTE_SIGNAL_NOOP9 13 // +#define VOTE_SIGNAL_NOOP10 14 // +#define VOTE_SIGNAL_NOOP11 15 // #define VOTE_SIGNAL_CUSTOM_START 16 // SENTINEL CUSTOM ACTIONS #define VOTE_SIGNAL_CUSTOM_END 35 // 16-35 diff --git a/src/governance.cpp b/src/governance.cpp index a07aa0d02..5ba5b4efa 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -127,8 +127,20 @@ void CGovernanceManager::CheckAndRemove() { LogPrintf("CGovernanceManager::CheckAndRemove \n"); - // 12.1 -- disabled -- use "delete" voting mechanism - + // DELETE OBJECTS WHICH MASTERNODE HAS FLAGGED DELETE=TRUE + + std::map::iterator it = mapObjects.begin(); + while(it != mapObjects.end()) + { + CGovernanceObject* pObj = &((*it).second); + + pObj->UpdateLocalValidity(pCurrentBlockIndex); + pObj->UpdateSentinelVariables(pCurrentBlockIndex); + ++it; + } + + // UPDATE CACHING MECHANISMS FOR GOVERNANCE OBJECTS + if(!pCurrentBlockIndex) return; std::string strError = ""; @@ -136,14 +148,18 @@ void CGovernanceManager::CheckAndRemove() std::map::iterator it2 = mapObjects.begin(); while(it2 != mapObjects.end()) { - CGovernanceObject* pbudgetProposal = &((*it2).second); + CGovernanceObject* pObj = &((*it2).second); - pbudgetProposal->UpdateLocalValidity(pCurrentBlockIndex); + // UPDATE LOCAL VALIDITY AGAINST CRYPTO DATA + pObj->UpdateLocalValidity(pCurrentBlockIndex); + + // UPDATE SENTINEL SIGNALING VARIABLES + pObj->UpdateSentinelVariables(pCurrentBlockIndex); ++it2; } } -CGovernanceObject *CGovernanceManager::FindProposal(const std::string &strName) +CGovernanceObject *CGovernanceManager::FindGovernanceObject(const std::string &strName) { //find the prop with the highest yes count @@ -164,7 +180,7 @@ CGovernanceObject *CGovernanceManager::FindProposal(const std::string &strName) return pbudgetProposal; } -CGovernanceObject *CGovernanceManager::FindProposal(uint256 nHash) +CGovernanceObject *CGovernanceManager::FindGovernanceObject(uint256 nHash) { LOCK(cs); @@ -396,13 +412,6 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C } -//todo - 12.1 - terrible name - maybe DoesObjectExist? -bool CGovernanceManager::PropExists(uint256 nHash) -{ - if(mapObjects.count(nHash)) return true; - return false; -} - // description: incremental sync with our peers // note: incremental syncing seems excessive, well just have clients ask for specific objects and their votes // note: 12.1 - remove @@ -458,10 +467,11 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp) int nInvCount = 0; - // sync gov objects + // SYNC GOVERNANCE OBJECTS WITH OTHER CLIENT + std::map::iterator it1 = mapSeenGovernanceObjects.begin(); while(it1 != mapSeenGovernanceObjects.end()){ - CGovernanceObject* pbudgetProposal = FindProposal((*it1).first); + CGovernanceObject* pbudgetProposal = FindGovernanceObject((*it1).first); if(pbudgetProposal && pbudgetProposal->fCachedValid && ((nProp == uint256() || ((*it1).first == nProp)))){ // Push the inventory budget proposal message over to the other client pfrom->PushInventory(CInv(MSG_BUDGET_PROPOSAL, (*it1).first)); @@ -470,7 +480,8 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp) ++it1; } - // sync votes + // SYNC OUR GOVERNANCE OBJECT VOTES WITH THEIR GOVERNANCE OBJECT VOTES + std::map::iterator it2 = mapVotes.begin(); while(it2 != mapVotes.end()){ pfrom->PushInventory(CInv(MSG_BUDGET_VOTE, (*it2).first)); @@ -549,11 +560,7 @@ CGovernanceObject::CGovernanceObject() fCachedFunding = false; fCachedValid = true; fCachedDelete = false; - fCachedClearRegisters = false; fCachedEndorsed = false; - fCachedReleaseBounty1 = false; - fCachedReleaseBounty2 = false; - fCachedReleaseBounty3 = false; } diff --git a/src/governance.h b/src/governance.h index 8acd919ab..9951a56be 100644 --- a/src/governance.h +++ b/src/governance.h @@ -13,6 +13,7 @@ #include "base58.h" #include "masternode.h" #include "governance-vote.h" +#include "masternodeman.h" #include #include "init.h" @@ -97,8 +98,8 @@ public: void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); void NewBlock(); - CGovernanceObject *FindProposal(const std::string &strName); - CGovernanceObject *FindProposal(uint256 nHash); + CGovernanceObject *FindGovernanceObject(const std::string &strName); + CGovernanceObject *FindGovernanceObject(uint256 nHash); std::vector GetAllProposals(int64_t nMoreThanTime); @@ -108,7 +109,6 @@ public: 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); void CheckAndRemove(); @@ -172,11 +172,7 @@ public: bool fCachedFunding; bool fCachedValid; bool fCachedDelete; - bool fCachedClearRegisters; bool fCachedEndorsed; - bool fCachedReleaseBounty1; - bool fCachedReleaseBounty2; - bool fCachedReleaseBounty3; CGovernanceObject(); CGovernanceObject(uint256 nHashParentIn, int nRevisionIn, std::string strNameIn, int64_t nTime, uint256 nFeeTXHashIn); @@ -184,6 +180,29 @@ public: // Update local validity : store the values in memory void UpdateLocalValidity(const CBlockIndex *pCurrentBlockIndex) {fCachedLocalValidity = IsValid(pCurrentBlockIndex, strLocalValidityError);}; + void UpdateSentinelVariables(const CBlockIndex *pCurrentBlockIndex) + { + /* + #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_ENDORSED 5 // -- officially endorsed by the network somehow (delegation) + */ + + int nMnCount = mnodeman.CountEnabled(); + int nAbsYesVoteReq = nMnCount / 10; + + // set all flags to false + fCachedFunding = false; + fCachedValid = false; + fCachedDelete = false; + fCachedEndorsed = false; + + if(GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING) >= nAbsYesVoteReq) fCachedFunding = true; + if(GetAbsoluteYesCount(VOTE_SIGNAL_VALID) >= nAbsYesVoteReq) fCachedValid = true; + if(GetAbsoluteYesCount(VOTE_SIGNAL_DELETE) >= nAbsYesVoteReq) fCachedDelete = true; + if(GetAbsoluteYesCount(VOTE_SIGNAL_ENDORSED) >= nAbsYesVoteReq) fCachedEndorsed = true; + } void swap(CGovernanceObject& first, CGovernanceObject& second) // nothrow { @@ -203,12 +222,7 @@ public: swap(first.fCachedFunding, second.fCachedFunding); swap(first.fCachedValid, second.fCachedValid); swap(first.fCachedDelete, second.fCachedDelete); - swap(first.fCachedClearRegisters, second.fCachedClearRegisters); swap(first.fCachedEndorsed, second.fCachedEndorsed); - swap(first.fCachedReleaseBounty1, second.fCachedReleaseBounty1); - swap(first.fCachedReleaseBounty2, second.fCachedReleaseBounty2); - swap(first.fCachedReleaseBounty3, second.fCachedReleaseBounty3); - } bool HasMinimumRequiredSupport(); @@ -225,6 +239,7 @@ public: void CleanAndRemove(bool fSignatureCheck); void Relay(); + uint256 GetHash(){ /* @@ -236,7 +251,10 @@ public: */ CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); + ss << nHashParent; + ss << nRevision; ss << strName; + ss << nTime; ss << strData; uint256 h1 = ss.GetHash(); @@ -256,6 +274,7 @@ public: bool SetData(std::string& strError, std::string strDataIn) { + // (assumption) this is equal to pythons len(strData) > 512*4, I think if(strDataIn.size() > 512*4) { strError = "Too big."; diff --git a/src/init.cpp b/src/init.cpp index 86dac58cc..2027562e7 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -221,7 +221,8 @@ void PrepareShutdown() GenerateBitcoins(false, 0, Params()); StopNode(); - // todo - 12.1 - magic strings as const + // STORE DATA CACHES INTO SERIALIZED DAT FILES + CFlatDB flatdb1("mncache.dat", "magicMasternodeCache"); flatdb1.Dump(mnodeman); CFlatDB flatdb2("mnpayments.dat", "magicMasternodePaymentsCache"); @@ -1824,7 +1825,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // ********************************************************* Step 10: Load cache data - // todo - 12.1 - magic strings as const + // LOAD SERIALIZED DAT FILES INTO DATA CACHES FOR INTERNAL USE + uiInterface.InitMessage(_("Loading masternode cache...")); CFlatDB flatdb1("mncache.dat", "magicMasternodeCache"); flatdb1.Load(mnodeman); diff --git a/src/main.cpp b/src/main.cpp index 59b06b4d1..88dd94c20 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1499,7 +1499,6 @@ CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params& // LogPrintf("height %u diff %4.2f reward %i \n", nPrevHeight, dDiff, nSubsidy); nSubsidy *= COIN; - // updated - 12.1 - unified logic // yearly decline of production by 7.1% per year, projected 21.3M coins max by year 2050. for(int i = consensusParams.nSubsidyHalvingInterval; i <= nPrevHeight; i += consensusParams.nSubsidyHalvingInterval) nSubsidy -= nSubsidy/14; @@ -5605,9 +5604,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (found) { //probably one the extensions - darkSendPool.ProcessMessageDarksend(pfrom, strCommand, vRecv); + darkSendPool.ProcessMessage(pfrom, strCommand, vRecv); mnodeman.ProcessMessage(pfrom, strCommand, vRecv); - mnpayments.ProcessMessageMasternodePayments(pfrom, strCommand, vRecv); + mnpayments.ProcessMessage(pfrom, strCommand, vRecv); ProcessMessageInstantX(pfrom, strCommand, vRecv); ProcessSpork(pfrom, strCommand, vRecv); masternodeSync.ProcessMessage(pfrom, strCommand, vRecv); diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index de06dbaea..de4ca0816 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -6,18 +6,6 @@ #include "main.h" #include "init.h" -// todo 12.1 - remove the unused -#include "governance.h" -#include "masternode.h" -#include "darksend.h" -#include "governance.h" -#include "masternodeman.h" -#include "masternode-sync.h" -#include "util.h" -//#include "addrman.h" -//#include -//#include - CBudgetManager budget; CCriticalSection cs_budget; @@ -783,7 +771,7 @@ std::string CFinalizedBudget::GetProposals() std::string ret = ""; BOOST_FOREACH(CTxBudgetPayment& budgetPayment, vecBudgetPayments){ - CGovernanceObject* pbudgetProposal = governance.FindProposal(budgetPayment.nProposalHash); + CGovernanceObject* pbudgetProposal = governance.FindGovernanceObject(budgetPayment.nProposalHash); std::string token = budgetPayment.nProposalHash.ToString(); @@ -807,7 +795,7 @@ std::string CFinalizedBudget::GetStatus() continue; } - CGovernanceObject* pbudgetProposal = governance.FindProposal(budgetPayment.nProposalHash); + CGovernanceObject* pbudgetProposal = governance.FindGovernanceObject(budgetPayment.nProposalHash); if(!pbudgetProposal){ if(retBadHashes == ""){ retBadHashes = "Unknown proposal hash! Check this proposal before voting" + budgetPayment.nProposalHash.ToString(); diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 2f33579ed..8f35b5050 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -288,12 +288,15 @@ void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees) std::string GetRequiredPaymentsString(int nBlockHeight) { - // 12.1 + // 12.1 -- added triggered payments + // if(IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) && budget.IsBudgetPaymentBlock(nBlockHeight)){ // return budget.GetRequiredPaymentsString(nBlockHeight); // } else { // return mnpayments.GetRequiredPaymentsString(nBlockHeight); // } + + return mnpayments.GetRequiredPaymentsString(nBlockHeight); } void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, CAmount nFees) @@ -343,7 +346,7 @@ int CMasternodePayments::GetMinMasternodePaymentsProto() { : MIN_MASTERNODE_PAYMENT_PROTO_VERSION_1; } -void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) +void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) { if(!masternodeSync.IsBlockchainSynced()) return; @@ -500,9 +503,7 @@ bool CMasternodePayments::AddWinningMasternode(CMasternodePaymentWinner& winnerI } } - int n = 1; - if(IsReferenceNode(winnerIn.vinMasternode)) n = 100; - mapMasternodeBlocks[winnerIn.nBlockHeight].AddPayee(winnerIn.payee, n); + mapMasternodeBlocks[winnerIn.nBlockHeight].AddPayee(winnerIn.payee, 1); return true; } @@ -622,20 +623,8 @@ void CMasternodePayments::CheckAndRemove() } } -bool IsReferenceNode(CTxIn& vin) -{ - //reference node - hybrid mode - if(vin.prevout.ToStringShort() == "099c01bea63abd1692f60806bb646fa1d288e2d049281225f17e499024084e28-0") return true; // mainnet - if(vin.prevout.ToStringShort() == "fbc16ae5229d6d99181802fd76a4feee5e7640164dcebc7f8feb04a7bea026f8-0") return true; // testnet - if(vin.prevout.ToStringShort() == "e466f5d8beb4c2d22a314310dc58e0ea89505c95409754d0d68fb874952608cc-1") return true; // regtest - - return false; -} - bool CMasternodePaymentWinner::IsValid(CNode* pnode, std::string& strError) { - if(IsReferenceNode(vinMasternode)) return true; - CMasternode* pmn = mnodeman.Find(vinMasternode); if(!pmn) @@ -673,59 +662,55 @@ bool CMasternodePaymentWinner::IsValid(CNode* pnode, std::string& strError) bool CMasternodePayments::ProcessBlock(int nBlockHeight) { + // DETERMINE IF WE SHOULD BE VOTING FOR THE NEXT PAYEE + if(!fMasterNode) return false; + + int n = mnodeman.GetMasternodeRank(activeMasternode.vin, nBlockHeight-100, MIN_MNW_PEER_PROTO_VERSION); + + if(n == -1) + { + LogPrint("mnpayments", "CMasternodePayments::ProcessBlock - Unknown Masternode\n"); + return false; + } - //reference node - hybrid mode + if(n > MNPAYMENTS_SIGNATURES_TOTAL) + { + LogPrint("mnpayments", "CMasternodePayments::ProcessBlock - Masternode not in the top %d (%d)\n", MNPAYMENTS_SIGNATURES_TOTAL, n); + return false; + } - if(!IsReferenceNode(activeMasternode.vin)){ - int n = mnodeman.GetMasternodeRank(activeMasternode.vin, nBlockHeight-100, MIN_MNW_PEER_PROTO_VERSION); - if(n == -1) + // LOCATE THE NEXT MASTERNODE WHICH SHOULD BE PAID + + CMasternodePaymentWinner newWinner(activeMasternode.vin); + { + LogPrintf("CMasternodePayments::ProcessBlock() Start nHeight %d - vin %s. \n", nBlockHeight, activeMasternode.vin.ToString()); + + // pay to the oldest MN that still had no payment but its input is old enough and it was active long enough + int nCount = 0; + CMasternode *pmn = mnodeman.GetNextMasternodeInQueueForPayment(nBlockHeight, true, nCount); + + if(pmn != NULL) { - LogPrint("mnpayments", "CMasternodePayments::ProcessBlock - Unknown Masternode\n"); - return false; - } + LogPrintf("CMasternodePayments::ProcessBlock() Found by FindOldestNotInVec \n"); - if(n > MNPAYMENTS_SIGNATURES_TOTAL) - { - LogPrint("mnpayments", "CMasternodePayments::ProcessBlock - Masternode not in the top %d (%d)\n", MNPAYMENTS_SIGNATURES_TOTAL, n); - return false; + newWinner.nBlockHeight = nBlockHeight; + + CScript payee = GetScriptForDestination(pmn->pubkey.GetID()); + newWinner.AddPayee(payee); + + CTxDestination address1; + ExtractDestination(payee, address1); + CBitcoinAddress address2(address1); + + LogPrintf("CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d. \n", address2.ToString(), newWinner.nBlockHeight); + } else { + LogPrintf("CMasternodePayments::ProcessBlock() Failed to find masternode to pay\n"); } } - if(nBlockHeight <= nLastBlockHeight) return false; - - CMasternodePaymentWinner newWinner(activeMasternode.vin); - - // 12.1 - // if(budget.IsBudgetPaymentBlock(nBlockHeight)){ - // //is budget payment block -- handled by the budgeting software - // } else { - // LogPrintf("CMasternodePayments::ProcessBlock() Start nHeight %d - vin %s. \n", nBlockHeight, activeMasternode.vin.ToString()); - - // // pay to the oldest MN that still had no payment but its input is old enough and it was active long enough - // int nCount = 0; - // CMasternode *pmn = mnodeman.GetNextMasternodeInQueueForPayment(nBlockHeight, true, nCount); - - // if(pmn != NULL) - // { - // LogPrintf("CMasternodePayments::ProcessBlock() Found by FindOldestNotInVec \n"); - - // newWinner.nBlockHeight = nBlockHeight; - - // CScript payee = GetScriptForDestination(pmn->pubkey.GetID()); - // newWinner.AddPayee(payee); - - // CTxDestination address1; - // ExtractDestination(payee, address1); - // CBitcoinAddress address2(address1); - - // LogPrintf("CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d. \n", address2.ToString(), newWinner.nBlockHeight); - // } else { - // LogPrintf("CMasternodePayments::ProcessBlock() Failed to find masternode to pay\n"); - // } - - // } + // SIGN MESSAGE TO NETWORK WITH OUR MASTERNODE KEYS std::string errorMessage; CPubKey pubKeyMasternode; @@ -745,7 +730,6 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) if(AddWinningMasternode(newWinner)) { newWinner.Relay(); - nLastBlockHeight = nBlockHeight; return true; } } diff --git a/src/masternode-payments.h b/src/masternode-payments.h index b0a89009a..d40cbfa9a 100644 --- a/src/masternode-payments.h +++ b/src/masternode-payments.h @@ -29,7 +29,7 @@ extern CMasternodePayments mnpayments; #define MNPAYMENTS_SIGNATURES_REQUIRED 6 #define MNPAYMENTS_SIGNATURES_TOTAL 10 -void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); +void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); bool IsReferenceNode(CTxIn& vin); bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight); std::string GetRequiredPaymentsString(int nBlockHeight); @@ -225,7 +225,6 @@ class CMasternodePayments { private: int nSyncedFromPeer; - int nLastBlockHeight; // Keep track of current block index const CBlockIndex *pCurrentBlockIndex; @@ -236,7 +235,6 @@ public: CMasternodePayments() { nSyncedFromPeer = 0; - nLastBlockHeight = 0; } void Clear() { @@ -271,7 +269,7 @@ public: } int GetMinMasternodePaymentsProto(); - void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); + void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); std::string GetRequiredPaymentsString(int nBlockHeight); void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees); std::string ToString() const; diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index 8babca6ac..f1c2319ac 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -195,10 +195,10 @@ void CMasternodeSync::ClearFulfilledRequest() BOOST_FOREACH(CNode* pnode, vNodes) { - pnode->ClearFulfilledRequest("getspork"); - pnode->ClearFulfilledRequest("mnsync"); - pnode->ClearFulfilledRequest("mnwsync"); - pnode->ClearFulfilledRequest("busync"); + pnode->ClearFulfilledRequest("spork-sync"); + pnode->ClearFulfilledRequest("masternode-winner-sync"); + pnode->ClearFulfilledRequest("governance-sync"); + pnode->ClearFulfilledRequest("masternode-sync"); } } @@ -213,6 +213,7 @@ void CMasternodeSync::Process() int nMnCount = mnodeman.CountEnabled(); // RESET SYNCING INCASE OF FAILURE + { if(IsSynced()) { /* @@ -272,9 +273,9 @@ void CMasternodeSync::Process() */ // ALWAYS ASK FOR SPORKS AS WE SYNC (we skip this mode now) - if(!pnode->HasFulfilledRequest("getspork")) + if(!pnode->HasFulfilledRequest("spork-sync")) { - pnode->FulfilledRequest("getspork"); + pnode->FulfilledRequest("spork-sync"); pnode->PushMessage(NetMsgType::GETSPORKS); //get current network sporks } @@ -286,7 +287,8 @@ void CMasternodeSync::Process() if (pnode->nVersion >= mnpayments.GetMinMasternodePaymentsProto()) { - // MODE : MASTERNODE_SYNC_LIST + // SYNC MASTERNODE LIST FROM OTHER CONNECTED CLIENTS + if(RequestedMasternodeAssets == MASTERNODE_SYNC_LIST) { // shall we move onto the next asset? @@ -303,8 +305,8 @@ void CMasternodeSync::Process() // requesting is the last thing we do (incase we needed to move to the next asset and we've requested from each peer already) - if(pnode->HasFulfilledRequest("mnsync")) continue; - pnode->FulfilledRequest("mnsync"); + if(pnode->HasFulfilledRequest("masternode-sync")) continue; + pnode->FulfilledRequest("masternode-sync"); //see if we've synced the masternode list /* note: Is this activing up? It's probably related to int CMasternodeMan::GetEstimatedMasternodes(int nBlock) */ @@ -315,7 +317,8 @@ void CMasternodeSync::Process() return; //this will cause each peer to get one request each six seconds for the various assets we need } - // MODE : MASTERNODE_SYNC_MNW + // SYNC MASTERNODE WINNERS FROM OTHER CONNECTED CLIENTS + if(RequestedMasternodeAssets == MASTERNODE_SYNC_MNW) { // Shall we move onto the next asset? @@ -340,14 +343,52 @@ void CMasternodeSync::Process() // requesting is the last thing we do (incase we needed to move to the next asset and we've requested from each peer already) - if(pnode->HasFulfilledRequest("mnwsync")) continue; - pnode->FulfilledRequest("mnwsync"); + if(pnode->HasFulfilledRequest("masternode-winner-sync")) continue; + pnode->FulfilledRequest("masternode-winner-sync"); int nMnCount = mnodeman.CountEnabled(); pnode->PushMessage(NetMsgType::MNWINNERSSYNC, nMnCount); //sync payees RequestedMasternodeAttempt++; + return; //this will cause each peer to get one request each six seconds for the various assets we need + } + } + + if (pnode->nVersion >= MIN_BUDGET_PEER_PROTO_VERSION) { + // MODE : MASTERNODE_SYNC_BUDGET + if(RequestedMasternodeAssets == MASTERNODE_SYNC_BUDGET){ + // shall we move onto the next asset + // if(countBudgetItemProp > 0 && countBudgetItemFin) + // { + // if(governance.CountProposalInventoryItems() >= (sumBudgetItemProp / countBudgetItemProp)*0.9) + // { + // if(governance.CountFinalizedInventoryItems() >= (sumBudgetItemFin / countBudgetItemFin)*0.9) + // { + // GetNextAsset(); + // return; + // } + // } + // } + + //we'll start rejecting votes if we accidentally get set as synced too soon, this allows plenty of time + if(lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT){ + GetNextAsset(); + + //try to activate our masternode if possible + activeMasternode.ManageStatus(); + return; + } + + // requesting is the last thing we do, incase we needed to move to the next asset and we've requested from each peer already + + if(pnode->HasFulfilledRequest("governance-sync")) continue; + pnode->FulfilledRequest("governance-sync"); + + uint256 n = uint256(); + pnode->PushMessage(NetMsgType::MNGOVERNANCEVOTESYNC, n); //sync masternode votes + RequestedMasternodeAttempt++; + return; //this will cause each peer to get one request each six seconds for the various assets we need } diff --git a/src/protocol.cpp b/src/protocol.cpp index c3aa6143f..6476d3b6c 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -42,13 +42,11 @@ const char *SPORK="spork"; const char *GETSPORKS="getsporks"; const char *MNWINNER="mnw"; const char *MNWINNERSSYNC="mnget"; -const char *MNSCANERROR="mn scan error"; // TODO ??? 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"; const char *DSACCEPT="dsa"; @@ -74,12 +72,10 @@ static const char* ppszTypeName[] = NetMsgType::IXLOCKVOTE, NetMsgType::SPORK, NetMsgType::MNWINNER, - NetMsgType::MNSCANERROR, NetMsgType::MNGOVERNANCEVOTE, NetMsgType::MNGOVERNANCEPROPOSAL, NetMsgType::MNGOVERNANCEFINAL, NetMsgType::MNGOVERNANCEFINALVOTE, - NetMsgType::MNQUORUM, NetMsgType::MNANNOUNCE, NetMsgType::MNPING, NetMsgType::DSTX @@ -118,13 +114,11 @@ const static std::string allNetMessageTypes[] = { NetMsgType::GETSPORKS, NetMsgType::MNWINNER, NetMsgType::MNWINNERSSYNC, - NetMsgType::MNSCANERROR, NetMsgType::MNGOVERNANCEVOTESYNC, NetMsgType::MNGOVERNANCEVOTE, NetMsgType::MNGOVERNANCEPROPOSAL, NetMsgType::MNGOVERNANCEFINAL, NetMsgType::MNGOVERNANCEFINALVOTE, - NetMsgType::MNQUORUM, NetMsgType::MNANNOUNCE, NetMsgType::MNPING, NetMsgType::DSACCEPT, diff --git a/src/protocol.h b/src/protocol.h index de6f0b72e..5dcbe3615 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -227,13 +227,11 @@ extern const char *SPORK; extern const char *GETSPORKS; extern const char *MNWINNER; extern const char *MNWINNERSSYNC; -extern const char *MNSCANERROR; 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; extern const char *DSACCEPT; diff --git a/src/rpcmasternode-budget.cpp b/src/rpcmasternode-budget.cpp index 1efafc56f..1367535be 100644 --- a/src/rpcmasternode-budget.cpp +++ b/src/rpcmasternode-budget.cpp @@ -38,11 +38,9 @@ int ConvertVoteSignal(std::string strVoteSignal) 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; + if(strVoteSignal == "endorsed") return 4; + + // ID FIVE THROUGH CUSTOM_START ARE TO BE USED BY GOVERNANCE ENGINE / TRIGGER SYSTEM // convert custom sentinel outcomes to integer and store try { @@ -59,35 +57,7 @@ int ConvertVoteSignal(std::string strVoteSignal) } /** -* NOTE: 12.1 - code needs to be rewritten, much of it's in the incorrect context -* -* Governance Object Creation and Voting -* ------------------------------------------------------- -* -* This code allows users to create new types of objects. To correctly use the system -* please see the governance wiki and code-as-law implementation. Any conflicting entries will be -* automatically downvoted and deleted, requiring resubmission to correct. -* -* command structure: -* -* 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, 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 +* MN GOVERNANCE RPC COMMAND * */ @@ -359,7 +329,7 @@ UniValue mngovernance(const UniValue& params, bool fHelp) uint256 hash = ParseHashV(params[1], "Proposal hash"); - CGovernanceObject* pbudgetProposal = governance.FindProposal(hash); + CGovernanceObject* pbudgetProposal = governance.FindGovernanceObject(hash); if(pbudgetProposal == NULL) throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proposal"); @@ -402,7 +372,7 @@ UniValue mngovernance(const UniValue& params, bool fHelp) 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); + CGovernanceObject* pbudgetProposal = governance.FindGovernanceObject(hash); if(pbudgetProposal == NULL) throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown governance-hash"); diff --git a/src/rpcmasternode.cpp b/src/rpcmasternode.cpp index 4b13c608c..ae76489ee 100644 --- a/src/rpcmasternode.cpp +++ b/src/rpcmasternode.cpp @@ -467,45 +467,46 @@ UniValue masternode(const UniValue& params, bool fHelp) return obj; } - /* - Shows which masternode wins by score each block - */ - if (strCommand == "calcscore") - { + // 12.1 -- remove? + // /* + // Shows which masternode wins by score each block + // */ + // if (strCommand == "calcscore") + // { - int nHeight; - { - LOCK(cs_main); - CBlockIndex* pindex = chainActive.Tip(); - if(!pindex) return NullUniValue; + // int nHeight; + // { + // LOCK(cs_main); + // CBlockIndex* pindex = chainActive.Tip(); + // if(!pindex) return NullUniValue; - nHeight = pindex->nHeight; - } + // nHeight = pindex->nHeight; + // } - int nLast = 10; + // int nLast = 10; - if (params.size() >= 2){ - nLast = atoi(params[1].get_str()); - } - UniValue obj(UniValue::VOBJ); + // if (params.size() >= 2){ + // nLast = atoi(params[1].get_str()); + // } + // UniValue obj(UniValue::VOBJ); - std::vector vMasternodes = mnodeman.GetFullMasternodeVector(); - for(int i = nHeight - nLast; i < nHeight + 20; i++){ - arith_uint256 nHigh = 0; - CMasternode *pBestMasternode = NULL; - BOOST_FOREACH(CMasternode& mn, vMasternodes) { - arith_uint256 n = UintToArith256(mn.CalculateScore(1, i - 100)); - if(n > nHigh){ - nHigh = n; - pBestMasternode = &mn; - } - } - if(pBestMasternode) - obj.push_back(Pair(strprintf("%d", i), pBestMasternode->vin.prevout.ToStringShort().c_str())); - } + // std::vector vMasternodes = mnodeman.GetFullMasternodeVector(); + // for(int i = nHeight - nLast; i < nHeight + 20; i++){ + // arith_uint256 nHigh = 0; + // CMasternode *pBestMasternode = NULL; + // BOOST_FOREACH(CMasternode& mn, vMasternodes) { + // arith_uint256 n = UintToArith256(mn.CalculateScore(1, i - 100)); + // if(n > nHigh){ + // nHigh = n; + // pBestMasternode = &mn; + // } + // } + // if(pBestMasternode) + // obj.push_back(Pair(strprintf("%d", i), pBestMasternode->vin.prevout.ToStringShort().c_str())); + // } - return obj; - } + // return obj; + // } return NullUniValue; }