Browse Source

Litecoin: Add mininput to deal with dust spam. By default, mininput is set to 0.0001. This means that create transaction will ignore any transactions with an output value less than 0.0001. You can override the default by passing in -mininput on startup or by calling setmininput.

Historically this patch allowed wallets to perform without delay after the dust spam attack during November 2011.
0.8
coblee 12 years ago committed by Warren Togami
parent
commit
2db43142bc
  1. 2
      src/bitcoinrpc.cpp
  2. 1
      src/bitcoinrpc.h
  3. 7
      src/init.cpp
  4. 2
      src/main.cpp
  5. 1
      src/main.h
  6. 19
      src/rpcwallet.cpp
  7. 2
      src/wallet.cpp
  8. 2
      src/wallet.h

2
src/bitcoinrpc.cpp

@ -249,6 +249,7 @@ static const CRPCCommand vRPCCommands[] =
{ "settxfee", &settxfee, false, false }, { "settxfee", &settxfee, false, false },
{ "getblocktemplate", &getblocktemplate, true, false }, { "getblocktemplate", &getblocktemplate, true, false },
{ "submitblock", &submitblock, false, false }, { "submitblock", &submitblock, false, false },
{ "setmininput", &setmininput, false, false },
{ "listsinceblock", &listsinceblock, false, false }, { "listsinceblock", &listsinceblock, false, false },
{ "dumpprivkey", &dumpprivkey, true, false }, { "dumpprivkey", &dumpprivkey, true, false },
{ "importprivkey", &importprivkey, false, false }, { "importprivkey", &importprivkey, false, false },
@ -1149,6 +1150,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "getnetworkhashps" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "getnetworkhashps" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]); if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]);
if (strMethod == "settxfee" && n > 0) ConvertTo<double>(params[0]); if (strMethod == "settxfee" && n > 0) ConvertTo<double>(params[0]);
if (strMethod == "setmininput" && n > 0) ConvertTo<double>(params[0]);
if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]);

1
src/bitcoinrpc.h

@ -193,6 +193,7 @@ extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, b
extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp
extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value settxfee(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value settxfee(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value setmininput(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp);

7
src/init.cpp

@ -324,6 +324,7 @@ std::string HelpMessage()
#endif #endif
#endif #endif
" -paytxfee=<amt> " + _("Fee per KB to add to transactions you send") + "\n" + " -paytxfee=<amt> " + _("Fee per KB to add to transactions you send") + "\n" +
" -mininput=<amt> " + _("When creating transactions, ignore inputs with value less than this (default: 0.0001)") + "\n" +
#ifdef QT_GUI #ifdef QT_GUI
" -server " + _("Accept command line and JSON-RPC commands") + "\n" + " -server " + _("Accept command line and JSON-RPC commands") + "\n" +
#endif #endif
@ -615,6 +616,12 @@ bool AppInit2(boost::thread_group& threadGroup)
InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction.")); InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction."));
} }
if (mapArgs.count("-mininput"))
{
if (!ParseMoney(mapArgs["-mininput"], nMinimumInputValue))
return InitError(strprintf(_("Invalid amount for -mininput=<amount>: '%s'"), mapArgs["-mininput"].c_str()));
}
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log // ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
std::string strDataDir = GetDataDir().string(); std::string strDataDir = GetDataDir().string();

2
src/main.cpp

@ -71,7 +71,7 @@ int64 nHPSTimerStart = 0;
// Settings // Settings
int64 nTransactionFee = 0; int64 nTransactionFee = 0;
int64 nMinimumInputValue = CENT / 100;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

1
src/main.h

@ -97,6 +97,7 @@ extern unsigned int nCoinCacheSize;
// Settings // Settings
extern int64 nTransactionFee; extern int64 nTransactionFee;
extern int64 nMinimumInputValue;
// Minimum disk space required - used in CheckDiskSpace() // Minimum disk space required - used in CheckDiskSpace()
static const uint64 nMinDiskSpace = 52428800; static const uint64 nMinDiskSpace = 52428800;

19
src/rpcwallet.cpp

@ -83,6 +83,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize())); obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee))); obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
obj.push_back(Pair("mininput", ValueFromAmount(nMinimumInputValue)));
if (pwalletMain->IsCrypted()) if (pwalletMain->IsCrypted())
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime / 1000)); obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime / 1000));
obj.push_back(Pair("errors", GetWarnings("statusbar"))); obj.push_back(Pair("errors", GetWarnings("statusbar")));
@ -247,6 +248,24 @@ Value getaddressesbyaccount(const Array& params, bool fHelp)
return ret; return ret;
} }
Value setmininput(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 1)
throw runtime_error(
"setmininput <amount>\n"
"<amount> is a real and is rounded to the nearest 0.00000001");
// Amount
int64 nAmount = 0;
if (params[0].get_real() != 0.0)
nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts
nMinimumInputValue = nAmount;
return true;
}
Value sendtoaddress(const Array& params, bool fHelp) Value sendtoaddress(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() < 2 || params.size() > 4) if (fHelp || params.size() < 2 || params.size() > 4)

2
src/wallet.cpp

@ -976,7 +976,7 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed) const
for (unsigned int i = 0; i < pcoin->vout.size(); i++) { for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
if (!(pcoin->IsSpent(i)) && IsMine(pcoin->vout[i]) && if (!(pcoin->IsSpent(i)) && IsMine(pcoin->vout[i]) &&
!IsLockedCoin((*it).first, i) && pcoin->vout[i].nValue > 0) !IsLockedCoin((*it).first, i) && pcoin->vout[i].nValue >= nMinimumInputValue)
vCoins.push_back(COutput(pcoin, i, pcoin->GetDepthInMainChain())); vCoins.push_back(COutput(pcoin, i, pcoin->GetDepthInMainChain()));
} }
} }

2
src/wallet.h

@ -221,7 +221,7 @@ public:
bool IsMine(const CTransaction& tx) const bool IsMine(const CTransaction& tx) const
{ {
BOOST_FOREACH(const CTxOut& txout, tx.vout) BOOST_FOREACH(const CTxOut& txout, tx.vout)
if (IsMine(txout)) if (IsMine(txout) && txout.nValue >= nMinimumInputValue)
return true; return true;
return false; return false;
} }

Loading…
Cancel
Save