fixed collateral issue, debug messages, no fees, changed function names, progress bar

This commit is contained in:
Evan Duffield 2014-09-04 13:21:47 -07:00
parent 0099670008
commit 6eb5ba6419
7 changed files with 67 additions and 60 deletions

View File

@ -222,6 +222,8 @@ void CDarkSendPool::Check()
// until the transaction is either complete or fails.
//
void CDarkSendPool::ChargeFees(){
return;
if(fMasterNode) {
int i = 0;
// who didn't sign?
@ -253,7 +255,7 @@ void CDarkSendPool::CheckTimeout(){
// catching hanging sessions
if(!fMasterNode) {
if(state == POOL_STATUS_TRANSMISSION) {
if(fDebug) LogPrintf("CDarkSendPool::CheckTimeout() -- SESSION COMPLETED -- CHECKING\n");
if(fDebug) LogPrintf("CDarkSendPool::CheckTimeout() -- Session complete -- Running Check()\n");
Check();
}
}
@ -263,7 +265,7 @@ void CDarkSendPool::CheckTimeout(){
vector<CDarksendQueue>::iterator it;
for(it=vecDarksendQueue.begin();it<vecDarksendQueue.end();it++){
if((*it).IsExpired()){
LogPrintf("CDarkSendPool::CheckTimeout() : REMOVING EXPIRED QUEUE ENTRY - %d\n", c);
if(fDebug) LogPrintf("CDarkSendPool::CheckTimeout() : Removing expired queue entry - %d\n", c);
vecDarksendQueue.erase(it);
break;
}
@ -281,7 +283,7 @@ void CDarkSendPool::CheckTimeout(){
vector<CDarkSendEntry>::iterator it2;
for(it2=vec->begin();it2<vec->end();it2++){
if((*it2).IsExpired()){
LogPrintf("CDarkSendPool::CheckTimeout() : REMOVING EXPIRED ENTRY - %d\n", c);
if(fDebug) LogPrintf("CDarkSendPool::CheckTimeout() : Removing expired entry - %d\n", c);
vec->erase(it2);
if(entries.size() == 0 && myEntries.size() == 0){
SetNull(true);
@ -306,7 +308,7 @@ void CDarkSendPool::CheckTimeout(){
}
} else if(GetTimeMillis()-lastTimeChanged >= 30000){
if(fDebug) LogPrintf("CDarkSendPool::CheckTimeout() -- SESSION TIMED OUT (30) -- RESETTING\n");
if(fDebug) LogPrintf("CDarkSendPool::CheckTimeout() -- Session timed out (30s) -- resetting\n");
SetNull();
UnlockCoins();
@ -316,7 +318,7 @@ void CDarkSendPool::CheckTimeout(){
if(state == POOL_STATUS_SIGNING && GetTimeMillis()-lastTimeChanged >= 10000 ) {
if(fDebug) LogPrintf("CDarkSendPool::CheckTimeout() -- SESSION TIMED OUT -- RESETTING\n");
if(fDebug) LogPrintf("CDarkSendPool::CheckTimeout() -- Session timed out -- restting\n");
ChargeFees();
SetNull();
UnlockCoins();
@ -357,7 +359,7 @@ bool CDarkSendPool::SignatureValid(const CScript& newSig, const CTxIn& newVin){
txNew.vin[n].scriptSig = newSig;
if(fDebug) LogPrintf("CDarkSendPool::SignatureValid() - Sign with sig %s\n", newSig.ToString().substr(0,24).c_str());
if (!VerifyScript(txNew.vin[n].scriptSig, sigPubKey, txNew, n, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, 0)){
if(fDebug) LogPrintf("CDarkSendPool::SignatureValid() - Signing - ERROR signing input %u\n", n);
if(fDebug) LogPrintf("CDarkSendPool::SignatureValid() - Signing - Error signing input %u\n", n);
return false;
}
}
@ -509,7 +511,7 @@ bool CDarkSendPool::SignaturesComplete(){
// Execute a darksend denomination via a masternode.
// This is only ran from clients
//
void CDarkSendPool::SendMoney(const CTransaction& collateral, std::vector<CTxIn>& vin, std::vector<CTxOut>& vout, int64& fee, int64 amount){
void CDarkSendPool::SendDarksendDenominate(const CTransaction& collateral, std::vector<CTxIn>& vin, std::vector<CTxOut>& vout, int64& fee, int64 amount){
// lock the funds we're going to use
BOOST_FOREACH(CTxIn in, collateral.vin)
lockedCoins.push_back(in);
@ -519,7 +521,7 @@ void CDarkSendPool::SendMoney(const CTransaction& collateral, std::vector<CTxIn>
// we should already be connected to a masternode
if(!sessionFoundMasternode){
LogPrintf("CDarkSendPool::SendMoney() - No masternode has been selected yet.\n");
LogPrintf("CDarkSendPool::SendDarksendDenominate() - No masternode has been selected yet.\n");
UnlockCoins();
SetNull(true);
return;
@ -529,11 +531,11 @@ void CDarkSendPool::SendMoney(const CTransaction& collateral, std::vector<CTxIn>
return;
if(fMasterNode) {
LogPrintf("CDarkSendPool::SendMoney() - DarkSend from a masternode is not supported currently.\n");
LogPrintf("CDarkSendPool::SendDarksendDenominate() - DarkSend from a masternode is not supported currently.\n");
return;
}
LogPrintf("CDarkSendPool::SendMoney() - Added transaction to pool.\n");
LogPrintf("CDarkSendPool::SendDarksendDenominate() - Added transaction to pool.\n");
ClearLastMessage();
@ -581,8 +583,6 @@ bool CDarkSendPool::StatusUpdate(int newState, int newEntriesCount, int newAccep
UpdateState(newState);
entriesCount = newEntriesCount;
LogPrintf("DarkSendStatusUpdate - state: %i entriesCount: %i accepted: %i error: %s \n", newState, newEntriesCount, newAccepted, error.c_str());
if(newAccepted != -1) {
lastEntryAccepted = newAccepted;
countEntriesAccepted += newAccepted;
@ -1232,7 +1232,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun)
}
// Submit transaction to the pool if we get here
std::string strError = pwalletMain->DarkSendDenominate(minRounds, maxAmount);
std::string strError = pwalletMain->PrepareDarksendDenominate(minRounds, maxAmount);
LogPrintf("DoAutomaticDenominating : Running darksend denominate. Return '%s'\n", strError.c_str());
if(strError == "") return true;

View File

@ -396,7 +396,7 @@ public:
// are all inputs signed?
bool SignaturesComplete();
// as a client, send a transaction to a masternode to start the denomination process
void SendMoney(const CTransaction& collateral, std::vector<CTxIn>& vin, std::vector<CTxOut>& vout, int64& fee, int64 amount);
void SendDarksendDenominate(const CTransaction& collateral, std::vector<CTxIn>& vin, std::vector<CTxOut>& vout, int64& fee, int64 amount);
// get masternode updates about the progress of darksend
bool StatusUpdate(int newState, int newEntriesCount, int newAccepted, std::string& error, int newSessionID=0);

View File

@ -3830,8 +3830,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
else if (strCommand == "dsf") { //DarkSend Final tx
LogPrintf("got RelayDarkSendFinalTransaction\n");
if (pfrom->nVersion != darkSendPool.MIN_PEER_PROTO_VERSION) {
return true;
}
@ -3846,7 +3844,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
vRecv >> sessionID >> txNew;
if(darkSendPool.sessionID != sessionID){
LogPrintf("dsc - message doesn't match current darksend session %d %d\n", darkSendPool.sessionID, sessionID);
if (fDebug) LogPrintf("dsf - message doesn't match current darksend session %d %d\n", darkSendPool.sessionID, sessionID);
return true;
}
@ -3870,7 +3868,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
vRecv >> sessionID >> error >> lastMessage;
if(darkSendPool.sessionID != sessionID){
LogPrintf("dsc - message doesn't match current darksend session %d %d\n", darkSendPool.sessionID, sessionID);
if (fDebug) LogPrintf("dsc - message doesn't match current darksend session %d %d\n", darkSendPool.sessionID, sessionID);
return true;
}
@ -3878,6 +3876,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
else if (strCommand == "dsa") { //DarkSend Acceptable
if (pfrom->nVersion != darkSendPool.MIN_PEER_PROTO_VERSION) {
return true;
}
int64 nAmount;
vRecv >> nAmount;
@ -3898,6 +3900,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
return true;
}
} else if (strCommand == "dsq") { //DarkSend Queue
if (pfrom->nVersion != darkSendPool.MIN_PEER_PROTO_VERSION) {
return true;
}
CDarksendQueue dsq;
vRecv >> dsq;
@ -3910,7 +3916,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
if(dsq.IsExpired()) return true;
LogPrintf("new darksend queue object - %s\n", addr.ToString().c_str());
if (fDebug) LogPrintf("new darksend queue object - %s\n", addr.ToString().c_str());
vecDarksendQueue.push_back(dsq);
dsq.Relay();
dsq.time = GetTime();
@ -4067,8 +4073,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
std::string error;
vRecv >> sessionID >> state >> entriesCount >> accepted >> error;
LogPrintf("dssu - state: %i entriesCount: %i accepted: %i error: %s \n", state, entriesCount, accepted, error.c_str());
if((accepted != 1 && accepted != 0) && darkSendPool.sessionID != sessionID){
LogPrintf("dsc - message doesn't match current darksend session %d %d\n", darkSendPool.sessionID, sessionID);
LogPrintf("dssu - message doesn't match current darksend session %d %d\n", darkSendPool.sessionID, sessionID);
return true;
}
@ -4724,7 +4732,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
// Relay
pfrom->hashCheckpointKnown = checkpoint.hashCheckpoint;
LogPrintf("!!! ENFORCING PAYMENTS %"PRI64u"\n", checkpoint.enforcingPaymentsTime);
enforceMasternodePaymentsTime = checkpoint.enforcingPaymentsTime;
LOCK(cs_vNodes);

View File

@ -251,14 +251,7 @@
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Avg Rounds</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="darksendAvgRounds">
<property name="text">
<string>X/X2</string>
<string>Completion</string>
</property>
</widget>
</item>
@ -269,6 +262,19 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QProgressBar" name="darksendProgress">
<property name="maximumSize">
<size>
<width>154</width>
<height>16777215</height>
</size>
</property>
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="labelAnonymized">
<property name="font">
@ -288,9 +294,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>130</y>
<y>140</y>
<width>251</width>
<height>61</height>
<height>51</height>
</rect>
</property>
<property name="text">

View File

@ -241,9 +241,10 @@ void OverviewPage::darkSendStatus()
ui->darksendStatus->setText("");
std::ostringstream convert;
convert << pwalletMain->GetAverageAnonymizedRounds() << "/" << nDarksendRounds;
ui->darksendProgress->setValue(((double)pwalletMain->GetAverageAnonymizedRounds() / (double)nDarksendRounds)*100);
convert << "Inputs have an average of " << pwalletMain->GetAverageAnonymizedRounds() << " of " << nDarksendRounds << " rounds";
QString s(convert.str().c_str());
ui->darksendAvgRounds->setText(s);
ui->darksendProgress->setToolTip(s);
}
return;
@ -287,9 +288,10 @@ void OverviewPage::darkSendStatus()
ui->darksendEnabled->setText("Enabled");
std::ostringstream convert;
convert << pwalletMain->GetAverageAnonymizedRounds() << "/" << nDarksendRounds;
ui->darksendProgress->setValue(((double)pwalletMain->GetAverageAnonymizedRounds() / (double)nDarksendRounds)*100);
convert << "Inputs have an average of " << pwalletMain->GetAverageAnonymizedRounds() << " of " << nDarksendRounds << " rounds";
QString s(convert.str().c_str());
ui->darksendAvgRounds->setText(s);
ui->darksendProgress->setToolTip(s);
}
@ -304,7 +306,7 @@ void OverviewPage::darkSendStatus()
if(state == POOL_STATUS_ACCEPTING_ENTRIES) {
if(entries == 0) {
convert << "Idle";
convert << "Darksend is idle";
showingDarkSendMessage = 0;
} else if (accepted == 1) {
convert << "Your transaction was accepted into the pool!";
@ -324,17 +326,17 @@ void OverviewPage::darkSendStatus()
else if(showingDarkSendMessage % 70 <= 30) convert << "Found enough users => SIGNING ( waiting.. )";
else if(showingDarkSendMessage % 70 <= 40) convert << "Found enough users => SIGNING ( waiting... )";
} else if(state == POOL_STATUS_TRANSMISSION) {
convert << "Found enough users => TRANSMISSION";
convert << "Status => TRANSMISSION";
} else if (state == POOL_STATUS_IDLE) {
convert << "Found enough users => POOL_STATUS_IDLE";
convert << "Status => POOL_STATUS_IDLE";
} else if (state == POOL_STATUS_FINALIZE_TRANSACTION) {
convert << "Found enough users => POOL_STATUS_FINALIZE_TRANSACTION";
convert << "Status => POOL_STATUS_FINALIZE_TRANSACTION";
} else if(state == POOL_STATUS_ERROR) {
convert << "Found enough users => ERROR : " << darkSendPool.lastMessage;
convert << "Status => ERROR : " << darkSendPool.lastMessage;
} else if(state == POOL_STATUS_SUCCESS) {
convert << "Found enough users => SUCCESS : " << darkSendPool.lastMessage;
convert << "Status => SUCCESS : " << darkSendPool.lastMessage;
} else {
convert << "Found enough users => UNKNOWN STATE : ID=" << state;
convert << "Status => UNKNOWN STATE : ID=" << state;
}
if(state == POOL_STATUS_ERROR || state == POOL_STATUS_SUCCESS) darkSendPool.Check();

View File

@ -1669,9 +1669,6 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
return true;
}
string CWallet::SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee, AvailableCoinsType coin_type)
{
CReserveKey reservekey(this);
@ -1737,13 +1734,10 @@ int64 CWallet::GetTotalValue(std::vector<CTxIn> vCoins) {
return nTotalValue;
}
string CWallet::DarkSendDenominate(int minRounds, int maxAmount)
string CWallet::PrepareDarksendDenominate(int minRounds, int maxAmount)
{
if (IsLocked())
{
return _("Error: Wallet locked, unable to create transaction!");
}
if(darkSendPool.GetState() != POOL_STATUS_ERROR && darkSendPool.GetState() != POOL_STATUS_SUCCESS){
if(darkSendPool.GetMyTransactionCount() > 0){
@ -1751,8 +1745,7 @@ string CWallet::DarkSendDenominate(int minRounds, int maxAmount)
}
}
CTransaction txCollateral;
CTransaction txCollateral;
int64 nFeeRet = 0.0125*COIN; ///need to get a better fee calc
// ** find the coins we'll use
@ -1830,18 +1823,19 @@ string CWallet::DarkSendDenominate(int minRounds, int maxAmount)
LockCoin(v.prevout);
}
//** denominate our funds ** //
// denominate our funds
int64 nValueLeft = nTotalValue;
std::vector<CTxOut> vOut;
int nOutputs = 0;
//LogPrintf("nValueLeft %"PRI64d"\n", nValueLeft/COIN);
// Make outputs by looping through denominations, from large to small
BOOST_FOREACH(int64 v, darkSendDenominations){
nOutputs = 0;
// add each output up to 10 times until it can't be added again
while(nValueLeft - v >= 0 && nOutputs <= 10) {
CScript scriptChange;
CPubKey vchPubKey;
//use a unique change address
assert(reservekey.GetReservedKey(vchPubKey)); // should never fail, as we just unlocked
scriptChange.SetDestination(vchPubKey.GetID());
reservekey.KeepKey();
@ -1849,16 +1843,15 @@ string CWallet::DarkSendDenominate(int minRounds, int maxAmount)
CTxOut o(v, scriptChange);
vOut.push_back(o);
//increment outputs and subtract denomination amount
nOutputs++;
nValueLeft -= v;
//LogPrintf(" -- denom %"PRI64d"\n", v/COIN);
//LogPrintf("nValueLeft %"PRI64d"\n", nValueLeft/COIN);
}
if(nValueLeft == 0) break;
}
// if we have anything left over, send it back as change
if(nValueLeft > 0){
CScript scriptChange;
CPubKey vchPubKey;
@ -1872,7 +1865,7 @@ string CWallet::DarkSendDenominate(int minRounds, int maxAmount)
nOutputs++;
}
darkSendPool.SendMoney(txCollateral, vCoins, vOut, nFeeRet, nValueIn);
darkSendPool.SendDarksendDenominate(txCollateral, vCoins, vOut, nFeeRet, nValueIn);
return "";
}

View File

@ -205,8 +205,7 @@ public:
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false, AvailableCoinsType coin_type=ALL_COINS);
std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false, AvailableCoinsType coin_type=ALL_COINS);
std::string DarkSendMoney(const CTxDestination &address, int64 nValue);
std::string DarkSendDenominate(int minRounds, int maxAmount);
std::string PrepareDarksendDenominate(int minRounds, int maxAmount);
bool NewKeyPool();
bool TopUpKeyPool();