From 0b3ef3c9fef278c59a098e265e09cef7d544c4e4 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Sun, 12 Jul 2015 10:34:21 -0700 Subject: [PATCH] Various fixes - Proposal submitting now works properly - Syncing proposals now works properly - Finalized budgets are now created correctly --- src/darksend.cpp | 13 ++++++++----- src/masternode-budget.cpp | 31 ++++++++++++++++++------------- src/masternode-payments.cpp | 11 +++++++---- src/rpcmasternode-budget.cpp | 2 ++ src/wallet.cpp | 10 ++++++++++ src/wallet.h | 1 + 6 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index 1e65c3c332..0ba914370b 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -2360,6 +2360,7 @@ void ThreadCheckDarkSendPool() if(c % 5 == 0 && RequestedMasternodeAssets <= 5){ bool fIsInitialDownload = IsInitialBlockDownload(); if(!fIsInitialDownload) { + CBlockIndex* pindexPrev = chainActive.Tip(); if(pindexPrev != NULL) { if(pindexPrev->nTime > GetAdjustedTime() - 60) @@ -2368,11 +2369,13 @@ void ThreadCheckDarkSendPool() LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { - if (pnode->nVersion >= MIN_POOL_PEER_PROTO_VERSION) { - - //keep track of who we've asked for the list - if(pnode->HasFulfilledRequest("mnsync")) continue; - pnode->FulfilledRequest("mnsync"); + if (pnode->nVersion >= MIN_POOL_PEER_PROTO_VERSION) { + bool IsLocal = pnode->addr.IsRFC1918() || pnode->addr.IsLocal(); + if(!IsLocal) { + //keep track of who we've asked for the list + if(pnode->HasFulfilledRequest("mnsync")) continue; + pnode->FulfilledRequest("mnsync"); + } //request full mn list only if Masternodes.dat was updated quite a long time ago diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index 8e60686457..0d20130146 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -126,6 +126,7 @@ void CBudgetManager::SubmitFinalBudget() CBlockIndex* pindexPrev = chainActive.Tip(); if(!pindexPrev) return; + int nBlockStart = pindexPrev->nHeight-(pindexPrev->nHeight % GetBudgetPaymentCycleBlocks())+GetBudgetPaymentCycleBlocks(); if(nSubmittedFinalBudget >= nBlockStart) return; if(nBlockStart - pindexPrev->nHeight > 100) return; @@ -155,26 +156,34 @@ void CBudgetManager::SubmitFinalBudget() if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)){ LogPrintf("SubmitFinalBudget - Error upon calling SetKey\n"); + return; } + CFinalizedBudgetBroadcast tempBudget(strBudgetName, nBlockStart, vecTxBudgetPayments, 0); + //create fee tx - uint256 hash = 0; + CTransaction tx; + if(!pwalletMain->GetBudgetSystemCollateralTX(tx, tempBudget.GetHash(), true)){ + LogPrintf("SubmitFinalBudget - Can't make collateral transaction\n"); + return; + } //create the proposal incase we're the first to make it - CFinalizedBudgetBroadcast finalizedBudgetBroadcast(strBudgetName, nBlockStart, vecTxBudgetPayments, hash); + CFinalizedBudgetBroadcast finalizedBudgetBroadcast(strBudgetName, nBlockStart, vecTxBudgetPayments, tx.GetHash()); if(!finalizedBudgetBroadcast.IsValid()){ LogPrintf("SubmitFinalBudget - Invalid finalized budget broadcast (are all the hashes correct?)\n"); + return; } mapSeenFinalizedBudgets.insert(make_pair(finalizedBudgetBroadcast.GetHash(), finalizedBudgetBroadcast)); finalizedBudgetBroadcast.Relay(); budget.AddFinalizedBudget(finalizedBudgetBroadcast); - CFinalizedBudgetVote vote(activeMasternode.vin, finalizedBudgetBroadcast.GetHash()); if(!vote.Sign(keyMasternode, pubKeyMasternode)){ LogPrintf("SubmitFinalBudget - Failure to sign.\n"); + return; } mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote)); @@ -696,19 +705,19 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData LOCK(cs_budget); if (strCommand == "mnvs") { //Masternode vote sync + uint256 nProp; + vRecv >> nProp; + bool IsLocal = pfrom->addr.IsRFC1918() || pfrom->addr.IsLocal(); - if(!IsLocal){ + if(!IsLocal && nProp == 0){ if(pfrom->HasFulfilledRequest("mnvs")) { LogPrintf("mnvs - peer already asked me for the list\n"); Misbehaving(pfrom->GetId(), 20); return; } + pfrom->FulfilledRequest("mnvs"); } - uint256 nProp; - vRecv >> nProp; - - pfrom->FulfilledRequest("mnvs"); budget.Sync(pfrom, nProp); LogPrintf("mnvs - Sent Masternode votes to %s\n", pfrom->addr.ToString()); } @@ -735,8 +744,6 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData return; } - //delete if it exists and insert the new object - if(mapSeenMasternodeBudgetProposals.count(budgetProposalBroadcast.GetHash())) mapSeenMasternodeBudgetProposals.erase(budgetProposalBroadcast.GetHash()); mapSeenMasternodeBudgetProposals.insert(make_pair(budgetProposalBroadcast.GetHash(), budgetProposalBroadcast)); CBudgetProposal budgetProposal(budgetProposalBroadcast); @@ -797,8 +804,6 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData return; } - //delete if it exists and insert the new object - if(mapSeenFinalizedBudgets.count(finalizedBudgetBroadcast.GetHash())) mapSeenFinalizedBudgets.erase(finalizedBudgetBroadcast.GetHash()); mapSeenFinalizedBudgets.insert(make_pair(finalizedBudgetBroadcast.GetHash(), finalizedBudgetBroadcast)); CFinalizedBudget finalizedBudget(finalizedBudgetBroadcast); @@ -1398,7 +1403,7 @@ bool CFinalizedBudget::IsValid() if(vecProposals.size() > 100) return false; if(strBudgetName == "") return false; if(nBlockStart == 0) return false; - + if(nFeeTXHash == 0) return false; //can only pay out 10% of the possible coins (min value of coins) if(GetTotalPayout() > budget.GetTotalBudget(nBlockStart)) return false; diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 73f957aa5d..31e9f5a6d7 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -166,10 +166,13 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st if (strCommand == "mnget") { //Masternode Payments Request Sync if(fLiteMode) return; //disable all Darksend/Masternode related functionality - if(pfrom->HasFulfilledRequest("mnget")) { - LogPrintf("mnget - peer already asked me for the list\n"); - Misbehaving(pfrom->GetId(), 20); - return; + bool IsLocal = pfrom->addr.IsRFC1918() || pfrom->addr.IsLocal(); + if(!IsLocal){ + if(pfrom->HasFulfilledRequest("mnget")) { + LogPrintf("mnget - peer already asked me for the list\n"); + Misbehaving(pfrom->GetId(), 20); + return; + } } pfrom->FulfilledRequest("mnget"); diff --git a/src/rpcmasternode-budget.cpp b/src/rpcmasternode-budget.cpp index 04b1fc8a78..c748b849fb 100644 --- a/src/rpcmasternode-budget.cpp +++ b/src/rpcmasternode-budget.cpp @@ -198,6 +198,7 @@ Value mnbudget(const Array& params, bool fHelp) mapSeenMasternodeBudgetProposals.insert(make_pair(budgetProposalBroadcast.GetHash(), budgetProposalBroadcast)); budgetProposalBroadcast.Relay(); + budget.AddProposal(budgetProposalBroadcast); return budgetProposalBroadcast.GetHash().ToString().c_str(); @@ -255,6 +256,7 @@ Value mnbudget(const Array& params, bool fHelp) mapSeenMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), vote)); vote.Relay(); + budget.UpdateProposal(vote, NULL); success++; } diff --git a/src/wallet.cpp b/src/wallet.cpp index 881c1a5ff6..3a51f3fae1 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1980,6 +1980,16 @@ bool CWallet::CreateCollateralTransaction(CMutableTransaction& txCollateral, std return true; } +bool CWallet::GetBudgetSystemCollateralTX(CTransaction& tx, uint256 hash, bool useIX) +{ + CWalletTx wtx; + if(GetBudgetSystemCollateralTX(wtx, hash, useIX)){ + tx = (CTransaction)wtx; + return true; + } + return false; +} + bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, bool useIX) { // make our change address diff --git a/src/wallet.h b/src/wallet.h index 473a7f4f91..fcd74c3700 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -345,6 +345,7 @@ public: std::set GetAccountAddresses(std::string strAccount) const; + bool GetBudgetSystemCollateralTX(CTransaction& tx, uint256 hash, bool useIX); bool GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, bool useIX); bool IsDenominated(const CTxIn &txin) const;