Skip to content

Commit 51b29dd

Browse files
committed
Implement GetMaxInputsForConsolidationTxn()
This implements a chain parameter function to get the maximum number of inputs allowable for a UTXO consolidation transaction with either the RPC consolidateunspent or the GUI "consolidate" button in coin control. The defalt value for the RPC consolidateunspent function has been changed to be the same as the upper clamp at the value returned by GetMaxInputsForConsolidationTxn(). The help returned for consolidateunspent uses that value as well.
1 parent 2d8f583 commit 51b29dd

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
lines changed

src/chainparams.h

+5
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,8 @@ inline unsigned int GetMinimumConnectionsRequiredForStaking()
150150
{
151151
return fTestNet ? 1 : 3;
152152
}
153+
154+
inline unsigned int GetMaxInputsForConsolidationTxn()
155+
{
156+
return (unsigned int) 600;
157+
}

src/qt/coincontroldialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CCoinControl* CoinControlDialog::coinControl = new CCoinControl();
2929

3030
CoinControlDialog::CoinControlDialog(QWidget *parent) :
3131
QDialog(parent),
32-
m_inputSelectionLimit(600),
32+
m_inputSelectionLimit(GetMaxInputsForConsolidationTxn()),
3333
ui(new Ui::CoinControlDialog),
3434
model(0)
3535
{

src/rpc/rawtransaction.cpp

+40-38
Original file line numberDiff line numberDiff line change
@@ -493,50 +493,51 @@ UniValue listunspent(const UniValue& params, bool fHelp)
493493

494494
UniValue consolidateunspent(const UniValue& params, bool fHelp)
495495
{
496+
std::stringstream error_strm;
497+
498+
error_strm << "consolidateunspent <address> [UTXO size] [maximum number of inputs] [sweep all addresses] [sweep change]\n"
499+
"\n"
500+
"<address>: The Gridcoin address target for consolidation.\n"
501+
"\n"
502+
"[UTXO size]: Optional parameter for target consolidation output size.\n"
503+
"\n"
504+
"[maximum number of inputs]: Defaults and clamped to "
505+
<< std::to_string(GetMaxInputsForConsolidationTxn())
506+
<< " maximum to prevent transaction failures.\n"
507+
"\n"
508+
"[sweep all addresses]: Boolean to indicate whether all addresses should be used for inputs to the\n"
509+
" consolidation. If true, the source of the consolidation is all addresses and\n"
510+
" the output will be to the specified address, otherwise inputs will only be\n"
511+
" sourced from the same address.\n"
512+
"\n"
513+
"[sweep change]: Boolean to indicate whether change associated with the address should be\n"
514+
" consolidated. If [sweep all addresses] is true then this is also forced true.\n"
515+
"\n"
516+
"consolidateunspent performs a single transaction to consolidate UTXOs to/on a given address. The optional\n"
517+
"parameter of UTXO size will result in consolidating UTXOs to generate the largest output possible less\n"
518+
"than that size or the total value of the specified maximum number of smallest inputs, whichever is less.\n"
519+
"\n"
520+
"The script is designed to be run repeatedly and will become a no-op if the UTXO's are consolidated such\n"
521+
"that no more meet the specified criteria. This is ideal for automated periodic scripting.\n"
522+
"\n"
523+
"To consolidate the entire wallet to one address do something like:\n"
524+
"\n"
525+
"consolidateunspent <address> <amount equal or larger than balance> 200 true repeatedly until there are\n"
526+
"no more UTXOs to consolidate.\n"
527+
"\n"
528+
"In all cases the address MUST exist in your wallet beforehand. If doing this for the purpose of creating\n"
529+
"a new smaller wallet, create a new address beforehand to serve as the target of the consolidation.\n";
530+
496531
if (fHelp || params.size() < 1 || params.size() > 5)
497-
throw runtime_error(
498-
"consolidateunspent <address> [UTXO size] [maximum number of inputs] [sweep all addresses] [sweep change]\n"
499-
"\n"
500-
"<address>: The Gridcoin address target for consolidation.\n"
501-
"\n"
502-
"[UTXO size]: Optional parameter for target consolidation output size.\n"
503-
"\n"
504-
"[maximum number of inputs]: Defaults to 50, clamped to 200 maximum to prevent transaction failures.\n"
505-
"\n"
506-
"[sweep all addresses]: Boolean to indicate whether all addresses should be used for inputs to the\n"
507-
" consolidation. If true, the source of the consolidation is all addresses and\n"
508-
" the output will be to the specified address, otherwise inputs will only be\n"
509-
" sourced from the same address.\n"
510-
"\n"
511-
"[sweep change]: Boolean to indicate whether change associated with the address should be\n"
512-
" consolidated. If [sweep all addresses] is true then this is also forced true.\n"
513-
"\n"
514-
"consolidateunspent performs a single transaction to consolidate UTXOs to/on a given address. The optional\n"
515-
"parameter of UTXO size will result in consolidating UTXOs to generate the largest output possible less\n"
516-
"than that size or the total value of the specified maximum number of smallest inputs, whichever is less.\n"
517-
"\n"
518-
"The script is designed to be run repeatedly and will become a no-op if the UTXO's are consolidated such\n"
519-
"that no more meet the specified criteria. This is ideal for automated periodic scripting.\n"
520-
"\n"
521-
"To consolidate the entire wallet to one address do something like:\n"
522-
"\n"
523-
"consolidateunspent <address> <amount equal or larger than balance> 200 true repeatedly until there are\n"
524-
"no more UTXOs to consolidate.\n"
525-
"\n"
526-
"In all cases the address MUST exist in your wallet beforehand. If doing this for the purpose of creating\n"
527-
"a new smaller wallet, create a new address beforehand to serve as the target of the consolidation.\n");
532+
throw runtime_error(error_strm.str());
528533

529534
UniValue result(UniValue::VOBJ);
530535

531536
std::string sAddress = params[0].get_str();
532537
CBitcoinAddress OptimizeAddress(sAddress);
533538

534539
int64_t nConsolidateLimit = 0;
535-
// Set default maximum consolidation to 50 inputs if it is not specified. This is based
536-
// on performance tests on the Pi to ensure the transaction returns within a reasonable time.
537-
// The performance tests on the Pi show about 3 UTXOs/second. Intel machines should do
538-
// about 3x that. The GUI will not be responsive during the transaction due to locking.
539-
unsigned int nInputNumberLimit = 50;
540+
unsigned int nInputNumberLimit = GetMaxInputsForConsolidationTxn();
540541

541542
bool sweep_all_addresses = false;
542543

@@ -551,8 +552,9 @@ UniValue consolidateunspent(const UniValue& params, bool fHelp)
551552

552553
if (params.size() > 4 && !sweep_all_addresses) sweep_change = params[4].get_bool();
553554

554-
// Clamp InputNumberLimit to 200. Above 200 risks an invalid transaction due to the size.
555-
nInputNumberLimit = std::min<unsigned int>(nInputNumberLimit, 200);
555+
// Clamp InputNumberLimit to GetMaxInputsForConsolidationTxn(). Above that number of inputs risks an invalid transaction
556+
// due to the size.
557+
nInputNumberLimit = std::min<unsigned int>(nInputNumberLimit, GetMaxInputsForConsolidationTxn());
556558

557559
if (!OptimizeAddress.IsValid())
558560
{

0 commit comments

Comments
 (0)