From f69ff36c779d2b464a93cb75f8c51dbe2c5ed843 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Tue, 12 Aug 2014 10:28:30 -0700 Subject: [PATCH] fixed some bugs --- src/main.cpp | 52 ++++++++++++++++++++++++++++---------------------- src/main.h | 3 +++ src/wallet.cpp | 39 +++++++++++++++++++++++++------------ 3 files changed, 59 insertions(+), 35 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9d9aa1546e..212d210fee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3885,7 +3885,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) } if(darkSendPool.submittedToMasternode != pfrom->addr){ - LogPrintf("dsc - message doesn't match current masternode - %s != %s\n", darkSendPool.submittedToMasternode.ToString().c_str(), pfrom->addr.ToString().c_str()); + //LogPrintf("dsc - message doesn't match current masternode - %s != %s\n", darkSendPool.submittedToMasternode.ToString().c_str(), pfrom->addr.ToString().c_str()); return true; } @@ -3908,7 +3908,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) } if(darkSendPool.submittedToMasternode != pfrom->addr){ - LogPrintf("dsc - message doesn't match current masternode - %s != %s\n", darkSendPool.submittedToMasternode.ToString().c_str(), pfrom->addr.ToString().c_str()); + //LogPrintf("dsc - message doesn't match current masternode - %s != %s\n", darkSendPool.submittedToMasternode.ToString().c_str(), pfrom->addr.ToString().c_str()); return true; } @@ -4090,7 +4090,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) } if(darkSendPool.submittedToMasternode != pfrom->addr){ - LogPrintf("dssu - message doesn't match current masternode - %s != %s\n", darkSendPool.submittedToMasternode.ToString().c_str(), pfrom->addr.ToString().c_str()); + //LogPrintf("dssu - message doesn't match current masternode - %s != %s\n", darkSendPool.submittedToMasternode.ToString().c_str(), pfrom->addr.ToString().c_str()); return true; } @@ -6100,6 +6100,19 @@ void CDarkSendPool::Check() LOCK2(cs_main, pwalletMain->cs_wallet); { if (fMasterNode) { //only the main node is master atm + LogPrintf("Transaction 2: %s\n", txNew.ToString().c_str()); + + // Broadcast + if (!txNew.AcceptToMemoryPool(true, false)) + { + LogPrintf("CDarkSendPool::Check() - CommitTransaction : Error: Transaction not valid\n"); + SetNull(); + pwalletMain->Lock(); + UpdateState(POOL_STATUS_ACCEPTING_ENTRIES); + RelayDarkSendCompletedTransaction(sessionID, true, "Transaction not valid, please try again"); + return; + } + int i = 0; BOOST_FOREACH(const CTxIn& txin, txNew.vin) { @@ -6120,19 +6133,6 @@ void CDarkSendPool::Check() i++; } - LogPrintf("Transaction 2: %s\n", txNew.ToString().c_str()); - - // Broadcast - if (!txNew.AcceptToMemoryPool(true, false)) - { - LogPrintf("CDarkSendPool::Check() - CommitTransaction : Error: Transaction not valid\n"); - SetNull(); - pwalletMain->Lock(); - UpdateState(POOL_STATUS_ACCEPTING_ENTRIES); - RelayDarkSendCompletedTransaction(sessionID, true, "Transaction not valid, please try again"); - return; - } - if(myEntries.size() > 0) { // add to my wallet if it's mine pwalletMain->AddToWallet(txNew); @@ -7110,7 +7110,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun) } if(fDryRun) return true; - +/* // initial phase, find a masternode if(!sessionFoundMasternode){ int64 nTotalValue = pwalletMain->GetTotalValue(vCoins) - DARKSEND_FEE; @@ -7171,9 +7171,10 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun) return false; } } - +*/ std::string strError = pwalletMain->DarkSendDenominate(minRounds, maxAmount); LogPrintf("DoAutomaticDenominating : Running darksend denominate. Return '%s'\n", strError.c_str()); + return true; if(strError == "") return true; @@ -7191,9 +7192,15 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun) bool CDarkSendPool::SplitUpMoney(bool justCollateral) { + if((nBestHeight - lastSplitUpBlock) < 10){ + LogPrintf("SplitUpMoney - Too soon to split up again\n"); + return false; + } + int64 nTotalBalance = pwalletMain->GetDenominatedBalance(false); if(justCollateral && nTotalBalance > 1*COIN) nTotalBalance = 1*COIN; int64 nTotalOut = 0; + lastSplitUpBlock = nBestHeight; LogPrintf("DoAutomaticDenominating: Split up large input (justCollateral %d):\n", justCollateral); LogPrintf(" auto -- nTotalBalance %"PRI64d"\n", nTotalBalance); @@ -7221,8 +7228,7 @@ bool CDarkSendPool::SplitUpMoney(bool justCollateral) if(!justCollateral) addingEachRound += (a) + (a/5); bool addedFees = false; - - while(nTotalOut + addingEachRound < nTotalBalance-DARKSEND_FEE){ + while(nTotalOut + addingEachRound < nTotalBalance-DARKSEND_FEE && (!justCollateral || !addedFees)){ LogPrintf(" nTotalOut %"PRI64d"\n", nTotalOut); LogPrintf(" nTotalOut + ((nTotalBalance/5) + (nTotalBalance/5/5) + 0.01*COIN) %"PRI64d"\n", nTotalOut + ((a) + (a/5) + ((DARKSEND_FEE*4)))); LogPrintf(" nTotalBalance-(DARKSEND_COLLATERAL) %"PRI64d"\n", (nTotalBalance-DARKSEND_COLLATERAL)); @@ -7231,7 +7237,8 @@ bool CDarkSendPool::SplitUpMoney(bool justCollateral) vecSend.push_back(make_pair(scriptChange, a/5)); nTotalOut += (a) + (a/5); } - if(!addedFees || justCollateral){ + if(!addedFees){ + vecSend.push_back(make_pair(scriptChange, DARKSEND_COLLATERAL*5)); vecSend.push_back(make_pair(scriptChange, DARKSEND_COLLATERAL*5)); vecSend.push_back(make_pair(scriptChange, DARKSEND_FEE)); vecSend.push_back(make_pair(scriptChange, DARKSEND_FEE)); @@ -7239,9 +7246,8 @@ bool CDarkSendPool::SplitUpMoney(bool justCollateral) vecSend.push_back(make_pair(scriptChange, DARKSEND_FEE)); vecSend.push_back(make_pair(scriptChange, DARKSEND_FEE)); addedFees = true; + nTotalOut += (DARKSEND_COLLATERAL*5)+(DARKSEND_FEE*nDarksendRounds); } - - nTotalOut += (DARKSEND_COLLATERAL*5)+(DARKSEND_FEE*nDarksendRounds); } if(!justCollateral){ diff --git a/src/main.h b/src/main.h index 6b0e53c4a0..53a5c481ab 100644 --- a/src/main.h +++ b/src/main.h @@ -2670,6 +2670,8 @@ public: bool sessionFoundMasternode; //If we've found a compatible masternode int sessionTries; + int lastSplitUpBlock; + CDarkSendPool() { //LogPrintf("CDarkSendPool::INIT()\n"); @@ -2685,6 +2687,7 @@ public: isCapableMasterNode = MASTERNODE_NOT_PROCESSED; masternodePortOpen = 0; + lastSplitUpBlock = 0; unitTest = false; SetCollateralAddress(strAddress); diff --git a/src/wallet.cpp b/src/wallet.cpp index 0ca061b9ab..cc1eaf0168 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1078,10 +1078,15 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const } if(!found) continue; + //printf(" nValue %"PRI64d"\n", pcoin->vout[i].nValue); + //printf(" --- %d %d %d %d\n", !(pcoin->IsSpent(i)), IsMine(pcoin->vout[i]), !IsLockedCoin((*it).first, i), pcoin->vout[i].nValue >= nMinimumInputValue); + if (!(pcoin->IsSpent(i)) && IsMine(pcoin->vout[i]) && !IsLockedCoin((*it).first, i) && pcoin->vout[i].nValue >= nMinimumInputValue && - (!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i))) + (!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i))) { + //printf(" -- added\n"); vCoins.push_back(COutput(pcoin, i, pcoin->GetDepthInMainChain())); + } } } } @@ -1299,34 +1304,40 @@ bool CWallet::SelectCoinsDark(int64 nValueMin, int64 nValueMax, std::vector vCoins; AvailableCoins(vCoins, false, coinControl, ALL_COINS); - //LogPrintf("found coins %d\n", (int)vCoins.size()); + //printf("found coins %d\n", (int)vCoins.size()); set > setCoinsRet2; + //order the array so fees are first, then denominated money, then the rest. sort(vCoins.rbegin(), vCoins.rend(), CompareByDenominated()); + //the first thing we get is a fee input, then we'll use as many denominated as possible. then the rest BOOST_FOREACH(const COutput& out, vCoins) { - //LogPrintf(" vin nValue %"PRI64d" \n", out.tx->vout[out.i].nValue); - if(!allowCollateral && out.tx->vout[out.i].nValue <= DARKSEND_COLLATERAL*5) continue; //these are made for fees + //printf(" vin nValue %"PRI64d" \n", out.tx->vout[out.i].nValue); + if(!allowFees && out.tx->vout[out.i].nValue == DARKSEND_FEE) continue; //these are made for fees + if(out.tx->vout[out.i].nValue == DARKSEND_COLLATERAL || out.tx->vout[out.i].nValue == DARKSEND_COLLATERAL*2 || + out.tx->vout[out.i].nValue == DARKSEND_COLLATERAL*3 || out.tx->vout[out.i].nValue == DARKSEND_COLLATERAL*5 || + out.tx->vout[out.i].nValue == DARKSEND_COLLATERAL*5 + ) continue; //these are made for collateral if(fMasterNode && out.tx->vout[out.i].nValue == 1000*COIN) continue; //masternode input if(nOnlyDenominationAmount != 0 && out.tx->vout[out.i].nValue != nOnlyDenominationAmount && - out.tx->vout[out.i].nValue > DARKSEND_COLLATERAL*5) continue; //only get one type of denom + out.tx->vout[out.i].nValue > DARKSEND_FEE) continue; //only get one type of denom - //LogPrintf(" ---- ret %"PRI64d", nValue %"PRI64d", max %"PRI64d" -- %d\n", nValueRet, out.tx->vout[out.i].nValue, nValueMax, nValueRet + out.tx->vout[out.i].nValue <= nValueMax); + //printf(" ---- ret %"PRI64d", nValue %"PRI64d", max %"PRI64d" -- %d\n", nValueRet, out.tx->vout[out.i].nValue, nValueMax, nValueRet + out.tx->vout[out.i].nValue <= nValueMax); if(nValueRet + out.tx->vout[out.i].nValue <= nValueMax){ CTxIn vin = CTxIn(out.tx->GetHash(),out.i); if(out.tx->vout[out.i].nValue == DARKSEND_FEE) { - allowCollateral = false; //these are made for fees + allowFees = false; //these are made for fees } else { int rounds = darkSendPool.GetInputDarksendRounds(vin); - //LogPrintf(" -- rounds %d\n", rounds); + //printf(" -- rounds %d\n", rounds); if(rounds >= nDarksendRoundsMax) continue; - //LogPrintf(" -- rounds less than max\n"); + //printf(" -- rounds less than max\n"); if(rounds < nDarksendRoundsMin) continue; } @@ -1335,11 +1346,11 @@ bool CWallet::SelectCoinsDark(int64 nValueMin, int64 nValueMax, std::vector= nValueMax) return true; + //printf(" -- nValueRet %"PRI64d"\n", nValueRet/COIN); } } + // if it's more than min, we're good to return if(nValueRet >= nValueMin) return true; return false; @@ -1350,6 +1361,8 @@ bool CWallet::SelectCoinsCollateral(std::vector& setCoinsRet, int64& nVal CCoinControl *coinControl=NULL; vector vCoins; + + //printf(" selecting coins for collateral\n"); AvailableCoins(vCoins, false, coinControl, ALL_COINS); //printf("found coins %d\n", (int)vCoins.size()); @@ -1359,6 +1372,8 @@ bool CWallet::SelectCoinsCollateral(std::vector& setCoinsRet, int64& nVal BOOST_FOREACH(const COutput& out, vCoins) { //printf(" vin nValue %"PRI64d"\n", out.tx->vout[out.i].nValue); + + // collateral inputs will always be a multiple of DARSEND_COLLATERAL, up to five if( out.tx->vout[out.i].nValue == DARKSEND_COLLATERAL || out.tx->vout[out.i].nValue == DARKSEND_COLLATERAL * 2 ||