Skip to content

Commit b138585

Browse files
committed
Remove factor of 3 from definition of dust.
This redefines dust to be the value of an output such that it would cost that value in fees to (create and) spend the output at the dust relay rate. The previous definition was that it would cost 1/3 of the value. The default dust relay rate is correspondingly increased to 3000 sat/kB so the actual default dust output value of 546 satoshis for a non-segwit output remains unchanged. This commit is a refactor only unless a dustrelayfee is passed on the commandline in which case that number now needs to be increased by a factor of 3 to get the same behavior. -dustrelayfee is a hidden command line option. Note: It's not exactly a refactor due to edge case changes in rounding as evidenced by the required change to the unit test.
1 parent 91edda8 commit b138585

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ std::string HelpMessage(HelpMessageMode mode)
479479
if (showDebug) {
480480
strUsage += HelpMessageOpt("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", defaultChainParams->RequireStandard()));
481481
strUsage += HelpMessageOpt("-incrementalrelayfee=<amt>", 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)));
482-
strUsage += HelpMessageOpt("-dustrelayfee=<amt>", 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)));
482+
strUsage += HelpMessageOpt("-dustrelayfee=<amt>", strprintf("Fee rate (in %s/kB) used to defined dust, the value of an output such that it will cost more than its value in fees at this fee rate to spend it. (default: %s)", CURRENCY_UNIT, FormatMoney(DUST_RELAY_TX_FEE)));
483483
}
484484
strUsage += HelpMessageOpt("-bytespersigop", strprintf(_("Equivalent bytes per sigop in transactions for relay and mining (default: %u)"), DEFAULT_BYTES_PER_SIGOP));
485485
strUsage += HelpMessageOpt("-datacarrier", strprintf(_("Relay and mine data carrier transactions (default: %u)"), DEFAULT_ACCEPT_DATACARRIER));

src/policy/policy.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
1919
{
2020
// "Dust" is defined in terms of dustRelayFee,
2121
// which has units satoshis-per-kilobyte.
22-
// If you'd pay more than 1/3 in fees
22+
// If you'd pay more in fees than the value of the output
2323
// to spend something, then we consider it dust.
2424
// A typical spendable non-segwit txout is 34 bytes big, and will
2525
// need a CTxIn of at least 148 bytes to spend:
2626
// so dust is a spendable txout less than
27-
// 546*dustRelayFee/1000 (in satoshis).
27+
// 182*dustRelayFee/1000 (in satoshis).
28+
// 546 satoshis at the default rate of 3000 sat/kB.
2829
// A typical spendable segwit txout is 31 bytes big, and will
2930
// need a CTxIn of at least 67 bytes to spend:
3031
// so dust is a spendable txout less than
31-
// 294*dustRelayFee/1000 (in satoshis).
32+
// 98*dustRelayFee/1000 (in satoshis).
33+
// 294 satoshis at the default rate of 3000 sat/kB.
3234
if (txout.scriptPubKey.IsUnspendable())
3335
return 0;
3436

@@ -44,7 +46,7 @@ CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
4446
nSize += (32 + 4 + 1 + 107 + 4); // the 148 mentioned above
4547
}
4648

47-
return 3 * dustRelayFeeIn.GetFee(nSize);
49+
return dustRelayFeeIn.GetFee(nSize);
4850
}
4951

5052
bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)

src/policy/policy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ static const unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS = 100;
4040
static const unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE = 80;
4141
/** The maximum size of a standard witnessScript */
4242
static const unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE = 3600;
43-
/** Min feerate for defining dust. Historically this has been the same as the
43+
/** Min feerate for defining dust. Historically this has been based on the
4444
* minRelayTxFee, however changing the dust limit changes which transactions are
4545
* standard and should be done with care and ideally rarely. It makes sense to
4646
* only increase the dust limit after prior releases were already not creating
4747
* outputs below the new threshold */
48-
static const unsigned int DUST_RELAY_TX_FEE = 1000;
48+
static const unsigned int DUST_RELAY_TX_FEE = 3000;
4949
/**
5050
* Standard script verification flags that standard transactions will comply
5151
* with. However scripts violating these flags may still be present in valid

src/test/transaction_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
692692
BOOST_CHECK(IsStandardTx(t, reason));
693693

694694
// Check dust with default relay fee:
695-
CAmount nDustThreshold = 182 * dustRelayFee.GetFeePerK()/1000 * 3;
695+
CAmount nDustThreshold = 182 * dustRelayFee.GetFeePerK()/1000;
696696
BOOST_CHECK_EQUAL(nDustThreshold, 546);
697697
// dust:
698698
t.vout[0].nValue = nDustThreshold - 1;
@@ -702,13 +702,13 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
702702
BOOST_CHECK(IsStandardTx(t, reason));
703703

704704
// Check dust with odd relay fee to verify rounding:
705-
// nDustThreshold = 182 * 1234 / 1000 * 3
706-
dustRelayFee = CFeeRate(1234);
705+
// nDustThreshold = 182 * 3702 / 1000
706+
dustRelayFee = CFeeRate(3702);
707707
// dust:
708-
t.vout[0].nValue = 672 - 1;
708+
t.vout[0].nValue = 673 - 1;
709709
BOOST_CHECK(!IsStandardTx(t, reason));
710710
// not dust:
711-
t.vout[0].nValue = 672;
711+
t.vout[0].nValue = 673;
712712
BOOST_CHECK(IsStandardTx(t, reason));
713713
dustRelayFee = CFeeRate(DUST_RELAY_TX_FEE);
714714

0 commit comments

Comments
 (0)