From 0f7f3bd17ad9b26fef3822603381666a692d38b1 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Wed, 6 Aug 2014 10:58:24 -0700 Subject: [PATCH] new version --- src/clientversion.h | 2 +- src/main.cpp | 108 ++++++++++++++++---------------- src/main.h | 7 +-- src/qt/forms/sendcoinsdialog.ui | 66 ++++++++++--------- src/qt/sendcoinsdialog.cpp | 16 ++--- src/qt/sendcoinsdialog.h | 2 +- src/script.cpp | 2 +- src/version.h | 2 +- src/wallet.cpp | 26 +++----- 9 files changed, 114 insertions(+), 117 deletions(-) diff --git a/src/clientversion.h b/src/clientversion.h index 0cfd40faf9..4d7c527805 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -9,7 +9,7 @@ #define CLIENT_VERSION_MAJOR 0 #define CLIENT_VERSION_MINOR 10 #define CLIENT_VERSION_REVISION 12 -#define CLIENT_VERSION_BUILD 14 +#define CLIENT_VERSION_BUILD 15 // Set to true for release, false for prerelease or test build #define CLIENT_VERSION_IS_RELEASE true diff --git a/src/main.cpp b/src/main.cpp index f00074bd55..08ba126f7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3941,13 +3941,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if(!darkSendPool.IsCompatibleWithSession(nAmount)) { - printf("dsi -- not compatible with existing transactions! \n"); + printf("dsa -- not compatible with existing transactions! \n"); accepted = 0; error = "not compatible with existing transactions"; pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), accepted, error); return true; } else { - printf("dsi -- is compatible, please submit! \n"); + printf("dsa -- is compatible, please submit! \n"); accepted = 1; pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), accepted, error); return true; @@ -3967,7 +3967,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) int accepted = 0; std::string error = ""; - if(darkSendPool.IsCompatibleWithEntries(out)) + if(!darkSendPool.IsCompatibleWithEntries(out)) { printf("dsi -- not compatible with existing transactions! \n"); accepted = 0; @@ -4093,14 +4093,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) std::string error; vRecv >> sessionID >> state >> entriesCount >> accepted >> error; - if(accepted != 1 && darkSendPool.sessionID != sessionID){ + if((accepted != 1 && accepted != 0) && darkSendPool.sessionID != sessionID){ printf("dssu - message doesn't match current darksend session\n"); return false; } - + darkSendPool.StatusUpdate(state, entriesCount, accepted, error, sessionID); - printf("DarkSendStatusUpdate - state: %i entriesCount: %i accepted: %i error: %s \n", state, entriesCount, accepted, error.c_str()); } else if (strCommand == "dss") { //DarkSend Sign Final Tx @@ -6018,13 +6017,15 @@ void CDarkSendPool::SetNull(bool clearEverything){ lastEntryAccepted = 0; countEntriesAccepted = 0; - sessionUsers = 0; - sessionAmount = 0; if(clearEverything){ myEntries.clear(); sessionID = 1 + (rand() % 999999); + sessionUsers = 0; + sessionAmount = 0; + sessionFoundMasternode = false; + sessionTries = 0; } } @@ -6149,10 +6150,12 @@ void CDarkSendPool::Check() } if((state == POOL_STATUS_ERROR || state == POOL_STATUS_SUCCESS) && GetTimeMillis()-lastTimeChanged >= 10000) { + //bool runAgain = state == POOL_STATUS_SUCCESS; printf("CDarkSendPool::Check() -- RESETTING MESSAGE \n"); SetNull(true); if(fMasterNode) RelayDarkSendStatus(darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), -1); UnlockCoins(); + //if(runAgain) DoAutomaticDenominating(); } } @@ -6387,7 +6390,7 @@ bool CDarkSendPool::SignaturesComplete(){ return true; } -void CDarkSendPool::SendMoney(const CTransaction& collateral, std::vector& vin, std::vector& vout, int64& fee, int64 amount, std::vector reservedKeysIn){ +void CDarkSendPool::SendMoney(const CTransaction& collateral, std::vector& vin, std::vector& vout, int64& fee, int64 amount){ BOOST_FOREACH(CTxIn in, collateral.vin) lockedCoins.push_back(in); @@ -6395,11 +6398,6 @@ void CDarkSendPool::SendMoney(const CTransaction& collateral, std::vector BOOST_FOREACH(CTxIn in, vin) lockedCoins.push_back(in); - BOOST_FOREACH(int64 index, reservedKeysIn){ - printf(" reserved key -- %"PRI64d"\n", index); - keypoolIndexes.push_back(index); - } - int i = darkSendPool.GetCurrentMasterNode(1); if(i < 0) return; @@ -6414,31 +6412,20 @@ void CDarkSendPool::SendMoney(const CTransaction& collateral, std::vector } printf("CDarkSendPool::SendMoney() - Added transaction to pool.\n"); - if(fDebug){ - printf("CDarkSendPool::SendMoney() -- NEW INPUT -- adding %s\n", vin[0].ToString().c_str()); - } ClearLastMessage(); - printf("CDarkSendPool::SendMoney() - Is connected to masternode?.\n"); - if(!IsConnectedToMasterNode()){ if(!ConnectToBestMasterNode()){ - printf("CDarkSendPool::SendMoney() - Couldn't connect to masternode.\n"); return; } } - printf("CDarkSendPool::SendMoney() - connected to masternode.\n"); - // store our entry for later use CDarkSendEntry e; e.Add(vin, amount, collateral, vout); myEntries.push_back(e); - BOOST_FOREACH(const CTxIn& i, vin) - printf(" -- new input %s\n", i.ToString().c_str()); - // relay our entry to the master node RelayDarkSendIn(vin, amount, collateral, vout); Check(); @@ -6451,16 +6438,18 @@ bool CDarkSendPool::StatusUpdate(int newState, int newEntriesCount, int newAccep UpdateState(newState); entriesCount = newEntriesCount; + printf("DarkSendStatusUpdate - state: %i entriesCount: %i accepted: %i error: %s \n", newState, newEntriesCount, newAccepted, error.c_str()); + if(newState == POOL_STATUS_ACCEPTING_ENTRIES){ if(newAccepted == 1){ - sessionID = newSessionID; - printf("CDarkSendPool::StatusUpdate - set sessionID to %d\n", sessionID); printf("CDarkSendPool::StatusUpdate - entry accepted! \n"); sessionFoundMasternode = true; - } else { + DoAutomaticDenominating(); + } else if (newAccepted == 0 && sessionID == 0 && !sessionFoundMasternode) { printf("CDarkSendPool::StatusUpdate - entry not accepted by masternode \n"); + DoAutomaticDenominating(); } - DoAutomaticDenominating(); + if(sessionFoundMasternode) return true; } if(newAccepted != -1) { @@ -6470,6 +6459,12 @@ bool CDarkSendPool::StatusUpdate(int newState, int newEntriesCount, int newAccep UpdateState(POOL_STATUS_ERROR); lastMessage = error; } + + if(newAccepted == 1) { + sessionID = newSessionID; + printf("CDarkSendPool::StatusUpdate - set sessionID to %d\n", sessionID); + sessionFoundMasternode = true; + } } return true; @@ -6951,14 +6946,7 @@ void CDarkSendPool::CompletedTransaction(bool error, std::string lastMessageNew) if(fDebug) printf("CompletedTransaction -- success \n"); UpdateState(POOL_STATUS_SUCCESS); - BOOST_FOREACH(const int64 index, keypoolIndexes) { - CReserveKey reservekey(pwalletMain); - reservekey.SetIndex(index); - reservekey.KeepKey(); - } - myEntries.clear(); - DoAutomaticDenominating(); } lastMessage = lastMessageNew; @@ -7061,18 +7049,21 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun) return false; } - int64 balanceNeedsAnonymized = pwalletMain->GetBalance() - pwalletMain->GetAnonymizedBalance(); - if(balanceNeedsAnonymized < COIN*1.1){ - printf("DoAutomaticDenominating : No funds detected in need of denominating \n"); - return false; - } - // ** find the coins we'll use std::vector vCoins; int64 nValueMin = 0.01*COIN; int64 nValueMax = 999*COIN; int64 nValueIn = 0; + int64 balanceNeedsAnonymized = pwalletMain->GetBalance() - pwalletMain->GetAnonymizedBalance(); + if(balanceNeedsAnonymized < COIN*1.1){ + printf("DoAutomaticDenominating : No funds detected in need of denominating \n"); + return false; + } + if(balanceNeedsAnonymized > nValueMax){ + balanceNeedsAnonymized = nValueMax; + } + if (!pwalletMain->SelectCoinsDark(nValueMin, nValueMax, vCoins, nValueIn, -2, nDarksendRounds)) { nValueIn = 0; @@ -7107,20 +7098,26 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun) // initial phase, find a masternode if(!sessionFoundMasternode){ if(sessionTries++ < 10){ - int i = GetMasternodeByRank(rand() % 20); - if(i != -1) { - if(ConnectNode((CAddress)darkSendMasterNodes[i].addr, NULL, true)){ - submittedToMasternode = darkSendMasterNodes[i].addr; - LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodes) - { - if(darkSendMasterNodes[i].addr != pnode->addr) continue; - pnode->PushMessage("dsa", balanceNeedsAnonymized); - return true; - } - } else { - return DoAutomaticDenominating(); + int i = GetMasternodeByRank(rand() % 1+(std::min(20, (int)darkSendMasterNodes.size()))); + if(i == -1) { + printf("DoAutomaticDenominating : Error finding a masternode\n"); + return false; + } + + lastTimeChanged = GetTimeMillis(); + printf("DoAutomaticDenominating -- attempt connection to masternode %s\n", darkSendMasterNodes[i].addr.ToString().c_str()); + if(ConnectNode((CAddress)darkSendMasterNodes[i].addr, NULL, true)){ + submittedToMasternode = darkSendMasterNodes[i].addr; + LOCK(cs_vNodes); + BOOST_FOREACH(CNode* pnode, vNodes) + { + if(darkSendMasterNodes[i].addr != pnode->addr) continue; + pnode->PushMessage("dsa", balanceNeedsAnonymized); + printf(" --- connected, sending dsa for %"PRI64d"\n", balanceNeedsAnonymized); + return true; } + } else { + return DoAutomaticDenominating(); } } } @@ -7228,6 +7225,7 @@ int CDarkSendPool::GetMasternodeByRank(int findRank) memcpy(&n2, &n, sizeof(n2)); vecMasternodeScores.push_back(make_pair(n2, i)); + i++; } sort(vecMasternodeScores.rbegin(), vecMasternodeScores.rend(), CompareValueOnly2()); diff --git a/src/main.h b/src/main.h index b8d6caede9..e1c6918657 100644 --- a/src/main.h +++ b/src/main.h @@ -2583,7 +2583,7 @@ static const int64 DARKSEND_FEE = 0.001*COIN; class CDarkSendPool { public: - static const int MIN_PEER_PROTO_VERSION = 70026; + static const int MIN_PEER_PROTO_VERSION = 70027; std::vector myEntries; std::vector entries; @@ -2599,8 +2599,7 @@ public: CScript collateralPubKey; std::vector lockedCoins; - std::vector keypoolIndexes; - + CTxIn vinMasterNode; CPubKey pubkeyMasterNode; CPubKey pubkeyMasterNode2; @@ -2729,7 +2728,7 @@ public: bool AddEntry(const std::vector& newInput, const int64& nAmount, const CTransaction& txCollateral, const std::vector& newOutput, std::string& error); bool AddScriptSig(const CTxIn& newVin); bool SignaturesComplete(); - void SendMoney(const CTransaction& collateral, std::vector& vin, std::vector& vout, int64& fee, int64 amount, std::vector reservedKeysIn); + void SendMoney(const CTransaction& collateral, std::vector& vin, std::vector& vout, int64& fee, int64 amount); bool StatusUpdate(int newState, int newEntriesCount, int newAccepted, std::string& error, int newSessionID=0); bool SignFinalTransaction(CTransaction& finalTransactionNew, CNode* node); diff --git a/src/qt/forms/sendcoinsdialog.ui b/src/qt/forms/sendcoinsdialog.ui index 95cef08d79..dc8e9676c7 100644 --- a/src/qt/forms/sendcoinsdialog.ui +++ b/src/qt/forms/sendcoinsdialog.ui @@ -6,8 +6,8 @@ 0 0 - 920 - 410 + 1024 + 457 @@ -625,8 +625,8 @@ 0 0 - 900 - 162 + 1004 + 209 @@ -702,32 +702,6 @@ - - - - - 0 - 0 - - - - Create inputs compatible with DarkSend - - - DarkSendStatus - - - - :/icons/denominate:/icons/denominate - - - 300 - - - false - - - @@ -758,6 +732,38 @@ 3 + + + + + 200 + 0 + + + + + 75 + true + + + + Darksend Status + + + + + + + + 75 + true + + + + Qt::Vertical + + + diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 0c9275cbed..df2a222433 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -29,7 +29,7 @@ SendCoinsDialog::SendCoinsDialog(QWidget *parent) : #ifdef Q_OS_MAC // Icons on push buttons are very uncommon on Mac ui->addButton->setIcon(QIcon()); ui->clearButton->setIcon(QIcon()); - ui->darkSendStatusButton->setIcon(QIcon()); + ui->darkSendStatus->setIcon(QIcon()); ui->sendButton->setIcon(QIcon()); #endif #if QT_VERSION >= 0x040700 @@ -41,7 +41,6 @@ SendCoinsDialog::SendCoinsDialog(QWidget *parent) : connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addEntry())); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); - connect(ui->darkSendStatusButton, SIGNAL(clicked()), this, SLOT(darkSendStatusButton())); // Coin Control ui->lineEditCoinControlChange->setFont(GUIUtil::bitcoinAddressFont()); @@ -50,7 +49,7 @@ SendCoinsDialog::SendCoinsDialog(QWidget *parent) : connect(ui->lineEditCoinControlChange, SIGNAL(textEdited(const QString &)), this, SLOT(coinControlChangeEdited(const QString &))); timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(darkSendStatusButton())); + connect(timer, SIGNAL(timeout()), this, SLOT(darkSendStatus())); timer->start(333); // Coin Control: clipboard actions @@ -260,7 +259,7 @@ void SendCoinsDialog::clear() ui->sendButton->setDefault(true); } -void SendCoinsDialog::darkSendStatusButton() +void SendCoinsDialog::darkSendStatus() { // check darksend status and unlock if needed if(darksendActionCheck % 30 == 0){ @@ -325,10 +324,13 @@ void SendCoinsDialog::darkSendStatusButton() if(state == POOL_STATUS_ERROR || state == POOL_STATUS_SUCCESS) darkSendPool.Check(); - printf("%s\n", convert.str().c_str()); QString s(convert.str().c_str()); - ui->darkSendStatusButton->setText(s); + + if(s != ui->darkSendStatus->text()) + printf("%s\n", convert.str().c_str()); + + ui->darkSendStatus->setText(s); showingDarkSendMessage++; darksendActionCheck++; @@ -481,7 +483,7 @@ void SendCoinsDialog::setState(int state, int entries, int accepted) if(!model || !model->getOptionsModel()) return; - ui->darkSendStatusButton->setText("Status Updated"); + ui->darkSendStatus->setText("Status Updated"); } void SendCoinsDialog::updateDisplayUnit() diff --git a/src/qt/sendcoinsdialog.h b/src/qt/sendcoinsdialog.h index 30d79dc27d..10189ec04e 100644 --- a/src/qt/sendcoinsdialog.h +++ b/src/qt/sendcoinsdialog.h @@ -37,7 +37,7 @@ public: public slots: void clear(); - void darkSendStatusButton(); + void darkSendStatus(); void reject(); void accept(); SendCoinsEntry *addEntry(); diff --git a/src/script.cpp b/src/script.cpp index 2fadb74de5..b62b5935e6 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -237,7 +237,7 @@ bool IsCanonicalPubKey(const valtype &vchPubKey) { if (vchPubKey.size() != 33) return error("Non-canonical public key: invalid length for compressed key"); } else { - return error("Non-canonical public key: compressed nor uncompressed : size %d", vchPubKey.size()); + return error("Non-canonical public key: compressed nor uncompressed : size %d", (int)vchPubKey.size()); } return true; } diff --git a/src/version.h b/src/version.h index ce3a2be27f..48b2525f94 100644 --- a/src/version.h +++ b/src/version.h @@ -25,7 +25,7 @@ extern const std::string CLIENT_DATE; // network protocol versioning // -static const int PROTOCOL_VERSION = 70026; +static const int PROTOCOL_VERSION = 70027; // intial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209; diff --git a/src/wallet.cpp b/src/wallet.cpp index 2b93234544..8d79a11071 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1321,13 +1321,13 @@ bool CWallet::SelectCoinsDark(int64 nValueMin, int64 nValueMax, std::vector vCoins; AvailableCoins(vCoins, false, coinControl, ALL_COINS); - printf("found coins %d\n", (int)vCoins.size()); + //printf("found coins %d\n", (int)vCoins.size()); set > setCoinsRet2; BOOST_FOREACH(const COutput& out, vCoins) { - printf(" vin nValue %"PRI64d" \n", out.tx->vout[out.i].nValue); + //printf(" vin nValue %"PRI64d" \n", out.tx->vout[out.i].nValue); if(out.tx->vout[out.i].nValue <= DARKSEND_COLLATERAL*5) continue; //these are made for collateral/fees/etc if(fMasterNode && out.tx->vout[out.i].nValue == 1000*COIN) continue; //masternode input @@ -1335,17 +1335,17 @@ bool CWallet::SelectCoinsDark(int64 nValueMin, int64 nValueMax, std::vectorGetHash(),out.i); int rounds = darkSendPool.GetInputDarksendRounds(vin); - printf(" -- rounds %d\n", rounds); + //printf(" -- rounds %d\n", rounds); if(rounds >= nDarksendRoundsMax) continue; - printf(" -- rounds less than max\n"); + //printf(" -- rounds less than max\n"); if(rounds < nDarksendRoundsMin) continue; vin.prevPubKey = out.tx->vout[out.i].scriptPubKey; // the inputs PubKey nValueRet += out.tx->vout[out.i].nValue; setCoinsRet.push_back(vin); setCoinsRet2.insert(make_pair(out.tx, out.i)); - printf(" -- nValueRet %"PRI64d"\n", nValueRet/COIN); + //printf(" -- nValueRet %"PRI64d"\n", nValueRet/COIN); if(nValueRet >= nValueMax) return true; } } @@ -1743,7 +1743,6 @@ string CWallet::DarkSendDenominate() // calculate total value out int64 nTotalValue = 0; - std::vector reservedKeys; CWalletTx wtx; BOOST_FOREACH(CTxIn i, vCoins){ if (mapWallet.count(i.prevout.hash)) @@ -1779,9 +1778,7 @@ string CWallet::DarkSendDenominate() CPubKey vchPubKey; assert(reservekey.GetReservedKey(vchPubKey)); // should never fail, as we just unlocked scriptChange.SetDestination(vchPubKey.GetID()); - reservekey.ReserveKey(); - reservedKeys.push_back(reservekey.GetIndex()); - reservekey.Reset(); + reservekey.KeepKey(); CTxOut vout2 = CTxOut(DARKSEND_COLLATERAL, darkSendPool.collateralPubKey); @@ -1824,9 +1821,7 @@ string CWallet::DarkSendDenominate() CPubKey vchPubKey; assert(reservekey.GetReservedKey(vchPubKey)); // should never fail, as we just unlocked scriptChange.SetDestination(vchPubKey.GetID()); - reservekey.ReserveKey(); - reservedKeys.push_back(reservekey.GetIndex()); - reservekey.Reset(); + reservekey.KeepKey(); CTxOut o(v, scriptChange); vOut.push_back(o); @@ -1846,10 +1841,7 @@ string CWallet::DarkSendDenominate() CPubKey vchPubKey; assert(reservekey.GetReservedKey(vchPubKey)); // should never fail, as we just unlocked scriptChange.SetDestination(vchPubKey.GetID()); - reservekey.ReserveKey(); - reservedKeys.push_back(reservekey.GetIndex()); - reservekey.Reset(); - + reservekey.KeepKey(); CTxOut o(nValueLeft, scriptChange); vOut.push_back(o); @@ -1857,7 +1849,7 @@ string CWallet::DarkSendDenominate() nOutputs++; } - darkSendPool.SendMoney(txCollateral, vCoins, vOut, nFeeRet, nValueIn, reservedKeys); + darkSendPool.SendMoney(txCollateral, vCoins, vOut, nFeeRet, nValueIn); return ""; }