From 4c46af04830cec3da6ecfbf677ef3d826a5892e6 Mon Sep 17 00:00:00 2001 From: Patrick Lodder Date: Sun, 27 Jun 2021 00:37:10 +0200 Subject: [fees] introduce configurable hard dust limit Co-authored-by: Ross Nicoll --- src/init.cpp | 9 +++++++++ src/policy/policy.cpp | 1 + src/policy/policy.h | 8 ++++++++ src/primitives/transaction.h | 4 +++- src/wallet/test/wallet_tests.cpp | 14 ++++++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/init.cpp b/src/init.cpp index 22dc45929..dd1942133 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -475,6 +475,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-incrementalrelayfee=", strprintf("Fee rate (in %s/kB) used to define cost of relay, used for mempool limiting and BIP 125 replacement. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_INCREMENTAL_RELAY_FEE))); strUsage += HelpMessageOpt("-dustrelayfee=", strprintf("Fee rate (in %s/kB) used to defined dust, the value of an output such that it will cost about 1/3 of its value in fees at this fee rate to spend it. (default: %s)", CURRENCY_UNIT, FormatMoney(DUST_RELAY_TX_FEE))); } + strUsage += HelpMessageOpt("-dustlimit=", strprintf(_("Amount under which a transaction output is considered dust, in %s (default: %s)"), CURRENCY_UNIT, FormatMoney(DEFAULT_DUST_LIMIT))); strUsage += HelpMessageOpt("-bytespersigop", strprintf(_("Equivalent bytes per sigop in transactions for relay and mining (default: %u)"), DEFAULT_BYTES_PER_SIGOP)); strUsage += HelpMessageOpt("-datacarrier", strprintf(_("Relay and mine data carrier transactions (default: %u)"), DEFAULT_ACCEPT_DATACARRIER)); strUsage += HelpMessageOpt("-datacarriersize", strprintf(_("Maximum size of data in data carrier transactions we relay and mine (default: %u)"), MAX_OP_RETURN_RELAY)); @@ -1043,6 +1044,14 @@ bool AppInitParameterInteraction() return InitError(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.NetworkIDString())); nBytesPerSigOp = GetArg("-bytespersigop", nBytesPerSigOp); + if (IsArgSet("-dustlimit")) + { + CAmount n = nDustLimit; + if (!ParseMoney(GetArg("-dustlimit", ""), n)) + return InitError(AmountErrMsg("dustlimit", GetArg("-dustlimit", ""))); + nDustLimit = n; + } + #ifdef ENABLE_WALLET if (!CWallet::ParameterInteraction()) return false; diff --git a/src/policy/policy.cpp b/src/policy/policy.cpp index ec398f662..7b2b23964 100644 --- a/src/policy/policy.cpp +++ b/src/policy/policy.cpp @@ -209,6 +209,7 @@ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs) CFeeRate incrementalRelayFee = CFeeRate(DEFAULT_INCREMENTAL_RELAY_FEE); CFeeRate dustRelayFee = CFeeRate(DUST_RELAY_TX_FEE); unsigned int nBytesPerSigOp = DEFAULT_BYTES_PER_SIGOP; +unsigned int nDustLimit = DEFAULT_DUST_LIMIT; int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost) { diff --git a/src/policy/policy.h b/src/policy/policy.h index a7fc8b78e..be34b9156 100644 --- a/src/policy/policy.h +++ b/src/policy/policy.h @@ -46,6 +46,13 @@ static const unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE = 3600; * only increase the dust limit after prior releases were already not creating * outputs below the new threshold */ static const unsigned int DUST_RELAY_TX_FEE = 1000; +/** + * Dogecoin: Default dust limit that is evaluated when considering whether a + * transaction output is required to pay additional fee for relay and inclusion + * in blocks. Overridden by -dustlimit + */ +static const unsigned int DEFAULT_DUST_LIMIT = 100000000; + /** * Standard script verification flags that standard transactions will comply * with. However scripts violating these flags may still be present in valid @@ -96,6 +103,7 @@ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs) extern CFeeRate incrementalRelayFee; extern CFeeRate dustRelayFee; extern unsigned int nBytesPerSigOp; +extern unsigned int nDustLimit; /** Compute the virtual transaction size (weight reinterpreted as bytes). */ int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost); diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 16a92bf2e..0d0ceda54 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -15,6 +15,8 @@ static const int SERIALIZE_TRANSACTION_NO_WITNESS = 0x40000000; static const int WITNESS_SCALE_FACTOR = 4; +extern unsigned int nDustLimit; + /** An outpoint - a combination of a transaction hash and an index n into its vout */ class COutPoint { @@ -195,7 +197,7 @@ public: */ // Dogecoin: Anything below 1 DOGE is always dust - return COIN; + return nDustLimit; } bool IsDust(const CFeeRate &minRelayTxFeeRate) const diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 4e84bb688..79a994bf6 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -36,6 +36,8 @@ std::vector> wtxn; typedef set > CoinSet; +extern unsigned int nDustLimit; + BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup) static const CWallet wallet; @@ -524,6 +526,18 @@ BOOST_AUTO_TEST_CASE(GetMinimumFee_dust_test) BOOST_CHECK_EQUAL(CWallet::GetMinimumFee(tx, 963, 0, pool), 2 * nMinTxFee); BOOST_CHECK_EQUAL(CWallet::GetMinimumFee(tx, 1000, 0, pool), 2 * nMinTxFee); BOOST_CHECK_EQUAL(CWallet::GetMinimumFee(tx, 1999, 0, pool), 3 * nMinTxFee); + + // change the hard dust limit + + nDustLimit = COIN / 10; + + // Confirm dust penalty fees are not added + + BOOST_CHECK_EQUAL(CWallet::GetMinimumFee(tx, 963, 0, pool), 1 * nMinTxFee); + BOOST_CHECK_EQUAL(CWallet::GetMinimumFee(tx, 1000, 0, pool), 1 * nMinTxFee); + BOOST_CHECK_EQUAL(CWallet::GetMinimumFee(tx, 1999, 0, pool), 2 * nMinTxFee); + + nDustLimit = COIN; } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 2dc1adb7fe849f0be47b6e23b6b45702d8440893 Mon Sep 17 00:00:00 2001 From: Patrick Lodder Date: Fri, 16 Jul 2021 21:17:52 +0200 Subject: [fees] Express policies in COIN instead of Koinu --- src/policy/policy.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/policy/policy.h b/src/policy/policy.h index be34b9156..5380f7b5b 100644 --- a/src/policy/policy.h +++ b/src/policy/policy.h @@ -45,13 +45,13 @@ static const unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE = 3600; * standard and should be done with care and ideally rarely. It makes sense to * only increase the dust limit after prior releases were already not creating * outputs below the new threshold */ -static const unsigned int DUST_RELAY_TX_FEE = 1000; +static const unsigned int DUST_RELAY_TX_FEE = COIN / 100000; /** * Dogecoin: Default dust limit that is evaluated when considering whether a * transaction output is required to pay additional fee for relay and inclusion * in blocks. Overridden by -dustlimit */ -static const unsigned int DEFAULT_DUST_LIMIT = 100000000; +static const unsigned int DEFAULT_DUST_LIMIT = COIN / 1; /** * Standard script verification flags that standard transactions will comply -- cgit v1.2.3