diff --git a/src/darksend.cpp b/src/darksend.cpp index 3bf9bceaea..0bfc0dfc2e 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -227,10 +227,35 @@ void CDarkSendPool::Check() // until the transaction is either complete or fails. // void CDarkSendPool::ChargeFees(){ - return; if(fMasterNode) { int i = 0; + + BOOST_FOREACH(const CTransaction& txCollateral, vecSessionCollateral) { + bool found = false; + BOOST_FOREACH(const CDarkSendEntry v, entries) { + if(v.collateral == txCollateral) found = false; + } + + // This queue entry didn't send us the promised transaction + if(!found){ + LogPrintf("CDarkSendPool::ChargeFees -- found uncooperative node (didn't send transaction). charging fees. %u\n", i); + + CWalletTx wtxCollateral = CWalletTx(pwalletMain, txCollateral); + + // Broadcast + if (!wtxCollateral.AcceptToMemoryPool(true, false)) + { + // This must not fail. The transaction has already been signed and recorded. + LogPrintf("CDarkSendPool::ChargeFees() : Error: Transaction not valid"); + } + wtxCollateral.RelayWalletTransaction(); + } + i++; + } + + i = 0; + // who didn't sign? BOOST_FOREACH(const CDarkSendEntry v, entries) { BOOST_FOREACH(const CDarkSendEntryVin s, v.sev) { @@ -396,6 +421,12 @@ bool CDarkSendPool::IsCollateralValid(const CTransaction& txCollateral){ if(fDebug) LogPrintf ("CDarkSendPool::IsCollateralValid - not correct amount or addr (0)\n"); return false; } + //collateral transactions are required to have abnormally large fees associated, to make double + //spending very expensive. + if(txCollateral.GetValueOut() < DARKSEND_COLLATERAL*2) { + if(fDebug) LogPrintf ("CDarkSendPool::IsCollateralValid - did not include enough fees in transaction\n"); + return false; + } LogPrintf("CDarkSendPool::IsCollateralValid %s\n", txCollateral.ToString().c_str()); @@ -1743,6 +1774,7 @@ bool CDarkSendPool::IsCompatibleWithSession(int64 nAmount, CTransaction txCollat sessionUsers++; lastTimeChanged = GetTimeMillis(); + vecSessionCollateral.push_back(txCollateral); return true; } diff --git a/src/darksend.h b/src/darksend.h index bd315c7ce2..a77a0ab707 100644 --- a/src/darksend.h +++ b/src/darksend.h @@ -26,7 +26,7 @@ extern std::string strMasterNodePrivKey; extern std::vector vecDarksendQueue; extern std::vector vecMasternodeAskedFor; -static const int64 DARKSEND_COLLATERAL = 0.025*COIN; +static const int64 DARKSEND_COLLATERAL = 0.0125*COIN; static const int64 DARKSEND_FEE = 0.0125*COIN; @@ -312,6 +312,7 @@ public: int sessionUsers; //N Users have said they'll join bool sessionFoundMasternode; //If we've found a compatible masternode int sessionTries; + std::vector vecSessionCollateral; int lastSplitUpBlock; int splitUpInARow; // how many splits we've done since a success? diff --git a/src/wallet.cpp b/src/wallet.cpp index 8932ea137f..00271aa9f2 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1772,7 +1772,12 @@ int64 CWallet::GetTotalValue(std::vector vCoins) { bool CWallet::CreateCollateralTransaction(CTransaction& txCollateral, std::string strReason) { - int64 nFeeRet = 0.001*COIN; ///need to get a better fee calc + /* + To doublespend a collateral transaction, it will require a fee higher than this. So there's + still a significant cost. + */ + int64 nFeeRet = DARKSEND_COLLATERAL; + CReserveKey reservekey(this); int64 nValueIn2 = 0; std::vector vCoinsCollateral;