Skip to content

Commit

Permalink
Remove factor of 3 from definition of dust.
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Jun 2, 2021
1 parent a1c56fd commit cf4a90b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-minrelaytxfee=<amt>", strprintf(_("Fees (in %s/Kb) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s)"), CURRENCY_UNIT, FormatMoney(::minRelayTxFee.GetFeePerK())));
strUsage += HelpMessageOpt("-printtoconsole", strprintf(_("Send trace/debug info to console instead of debug.log file (default: %u)"), 0));
if (showDebug) {
strUsage += HelpMessageOpt("-dustrelayfee=<amt>", strprintf("Fee rate (in %s/kB) used to define 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("-dustrelayfee=<amt>", strprintf("Fee rate (in %s/kB) used to define 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)));
strUsage += HelpMessageOpt("-printpriority", strprintf(_("Log transaction priority and fee per kB when mining blocks (default: %u)"), DEFAULT_PRINTPRIORITY));
}
strUsage += HelpMessageOpt("-shrinkdebugfile", _("Shrink debug.log file on client startup (default: 1 when no -debug)"));
Expand Down
12 changes: 6 additions & 6 deletions src/policy/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
{
// "Dust" is defined in terms of dustRelayFee,
// which has units satoshis-per-kilobyte.
// If you'd pay more than 1/3 in fees
// If you'd pay more in fees than the value of the output
// to spend something, then we consider it dust.
// A typical spendable txout is 34 bytes big, and will
// need a CTxIn of at least 148 bytes to spend:
Expand All @@ -33,13 +33,13 @@ CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)

size_t nSize = GetSerializeSize(txout, SER_DISK, 0);
nSize += (32 + 4 + 1 + 107 + 4); // the 148 mentioned above
return 3 * dustRelayFeeIn.GetFee(nSize);
return dustRelayFeeIn.GetFee(nSize);
}

CAmount GetDustThreshold(const CFeeRate& dustRelayFeeIn)
{
// return the dust threshold for a typical 34 bytes output
return 3 * dustRelayFeeIn.GetFee(182);
return dustRelayFeeIn.GetFee(182);
}

bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
Expand All @@ -50,9 +50,9 @@ bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
CAmount GetShieldedDustThreshold(const CFeeRate& dustRelayFeeIn)
{
unsigned int K = DEFAULT_SHIELDEDTXFEE_K; // Fixed (100) for now
return 3 * K * dustRelayFeeIn.GetFee(SPENDDESCRIPTION_SIZE +
CTXOUT_REGULAR_SIZE +
BINDINGSIG_SIZE);
return K * dustRelayFeeIn.GetFee(SPENDDESCRIPTION_SIZE +
CTXOUT_REGULAR_SIZE +
BINDINGSIG_SIZE);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300;
/** Default for -permitbaremultisig */
static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
extern bool fIsBareMultisigStd;
/** Min feerate for defining dust. Historically this has been the same as the
/** Min feerate for defining dust. Historically this has been based on the
* minRelayTxFee, however changing the dust limit changes which transactions are
* 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 = 10000;
static const unsigned int DUST_RELAY_TX_FEE = 30000;

/**
* Standard script verification flags that standard transactions will comply
Expand Down
19 changes: 17 additions & 2 deletions src/test/transaction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,26 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
std::string reason;
BOOST_CHECK(IsStandardTx(t, 0, reason));

t.vout[0].nValue = 5011; // dust
// Check dust with default relay fee:
CAmount nDustThreshold = GetDustThreshold(dustRelayFee);
BOOST_CHECK_EQUAL(nDustThreshold, 5460);
// dust:
t.vout[0].nValue = nDustThreshold - 1;
BOOST_CHECK(!IsStandardTx(t, 0, reason));
// not dust:
t.vout[0].nValue = nDustThreshold;
BOOST_CHECK(IsStandardTx(t, 0, reason));

t.vout[0].nValue = 6011; // not dust
// Check dust with odd relay fee to verify rounding:
// nDustThreshold = 182 * 3702 / 1000
dustRelayFee = CFeeRate(3702);
// dust:
t.vout[0].nValue = 673 - 1;
BOOST_CHECK(!IsStandardTx(t, 0, reason));
// not dust:
t.vout[0].nValue = 673;
BOOST_CHECK(IsStandardTx(t, 0, reason));
dustRelayFee = CFeeRate(DUST_RELAY_TX_FEE);

t.vout[0].scriptPubKey = CScript() << OP_1;
BOOST_CHECK(!IsStandardTx(t, 0, reason));
Expand Down

0 comments on commit cf4a90b

Please sign in to comment.