Skip to content

Commit fc44792

Browse files
authored
Merge pull request #2119 from jamescowens/update_consolidateunspent_max_inputs
util, rpc, gui: Implement GetMaxInputsForConsolidationTxn()
2 parents cc44a68 + 385b8ef commit fc44792

File tree

6 files changed

+70
-44
lines changed

6 files changed

+70
-44
lines changed

src/chainparams.h

-5
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,3 @@ inline int GetNewbieSnapshotFixHeight()
145145
{
146146
return fTestNet ? 1480000 : 2197000;
147147
}
148-
149-
inline unsigned int GetMinimumConnectionsRequiredForStaking()
150-
{
151-
return fTestNet ? 1 : 3;
152-
}

src/miner.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "gridcoin/staking/reward.h"
2020
#include "gridcoin/staking/status.h"
2121
#include "gridcoin/tally.h"
22+
#include "policy/policy.h"
2223
#include "policy/fees.h"
2324
#include "util.h"
2425
#include "validation.h"

src/policy/policy.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,14 @@ bool AreInputsStandard(const CTransaction& tx, const MapPrevTx& mapInputs)
175175

176176
return true;
177177
}
178+
179+
unsigned int GetMinimumConnectionsRequiredForStaking()
180+
{
181+
return fTestNet ? 1 : 3;
182+
}
183+
184+
unsigned int GetMaxInputsForConsolidationTxn()
185+
{
186+
return (unsigned int) 600;
187+
}
188+

src/policy/policy.h

+15
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,19 @@ bool IsStandardTx(const CTransaction& tx);
2323
*/
2424
bool AreInputsStandard(const CTransaction& tx, const MapPrevTx& mapInputs);
2525

26+
//!
27+
//! \brief Gets the minimum number of connections required for a wallet to stake.
28+
//!
29+
//! \return unsigned int minimum number of connections to stake
30+
//!
31+
unsigned int GetMinimumConnectionsRequiredForStaking();
32+
33+
//!
34+
//! \brief Gets the maximum number of inputs supported for a UTXO consolidation transaction to ensure
35+
//! the transaction does not exceed the maximum size and fail as a result.
36+
//!
37+
//! \return unsigned int maximum number of consolidation inputs.
38+
//!
39+
unsigned int GetMaxInputsForConsolidationTxn();
40+
2641
#endif // BITCOIN_POLICY_POLICY_H

src/qt/coincontroldialog.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "bitcoinunits.h"
66
#include "addresstablemodel.h"
77
#include "optionsmodel.h"
8+
#include "policy/policy.h"
89
#include "policy/fees.h"
910
#include "validation.h"
1011
#include "wallet/coincontrol.h"
@@ -29,7 +30,7 @@ CCoinControl* CoinControlDialog::coinControl = new CCoinControl();
2930

3031
CoinControlDialog::CoinControlDialog(QWidget *parent) :
3132
QDialog(parent),
32-
m_inputSelectionLimit(600),
33+
m_inputSelectionLimit(GetMaxInputsForConsolidationTxn()),
3334
ui(new Ui::CoinControlDialog),
3435
model(0)
3536
{

src/rpc/rawtransaction.cpp

+41-38
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "gridcoin/support/block_finder.h"
1515
#include "gridcoin/tx_message.h"
1616
#include "gridcoin/voting/payloads.h"
17+
#include "policy/policy.h"
1718
#include "policy/fees.h"
1819
#include "primitives/transaction.h"
1920
#include "protocol.h"
@@ -493,50 +494,51 @@ UniValue listunspent(const UniValue& params, bool fHelp)
493494

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

529535
UniValue result(UniValue::VOBJ);
530536

531537
std::string sAddress = params[0].get_str();
532538
CBitcoinAddress OptimizeAddress(sAddress);
533539

534540
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;
541+
unsigned int nInputNumberLimit = GetMaxInputsForConsolidationTxn();
540542

541543
bool sweep_all_addresses = false;
542544

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

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

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

557560
if (!OptimizeAddress.IsValid())
558561
{

0 commit comments

Comments
 (0)