Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add dustThreshold explain of P2SH & P2TR #30023

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 34 additions & 14 deletions src/policy/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,42 @@
#include <cstddef>
#include <vector>

/**
* Calculate the dust threshold for an output based on the given fee rate.
*
* "Dust" is defined in terms of dustRelayFee, which has units satoshis-per-kilobyte.
* If you'd pay more in fees than the value of the output to spend something, then we consider it dust.
*
* Definitions for different output types:
* - A typical spendable non-segwit P2PKH txout is 34 bytes big, and will
* need a CTxIn of at least 148 bytes to spend:
* so dust is a spendable txout less than 182*dustRelayFee/1000 (in satoshis).
* 546 satoshis at the default rate of 3000 sat/kvB.
* - A typical spendable non-segwit P2SH txout is 32 bytes big, and will
* need a CTxIn of at least 148 bytes to spend:
* so dust is a spendable txout less than 180*dustRelayFee/1000 (in satoshis).
* 540 satoshis at the default rate of 3000 sat/kvB.
* - A typical spendable segwit P2WPKH txout is 31 bytes big, and will
* need a CTxIn of at least 67 bytes to spend:
* so dust is a spendable txout less than
* 98*dustRelayFee/1000 (in satoshis).
* 294 satoshis at the default rate of 3000 sat/kvB.
* - A typical spendable segwit P2TR txout is 43 bytes big, and will
* need a CTxIn of at least 57(used 67, see reason below) bytes to spend:
* so dust is a spendable txout less than
* 110*dustRelayFee/1000 (in satoshis).
* 330 satoshis at the default rate of 3000 sat/kvB.
*
* The actual dust threshold is calculated by determining the cost to
* spend the output at the current fee rate and comparing it to the
* output's value.
*
* @param txout The transaction output to evaluate.
* @param dustRelayFeeIn The fee rate used for calculating dust, in satoshis-per-kilobyte.
* @return The calculated dust threshold in satoshis.
*/
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 in fees than the value of the output
// to spend something, then we consider it dust.
// A typical spendable non-segwit txout is 34 bytes big, and will
// need a CTxIn of at least 148 bytes to spend:
// so dust is a spendable txout less than
// 182*dustRelayFee/1000 (in satoshis).
// 546 satoshis at the default rate of 3000 sat/kvB.
// A typical spendable segwit P2WPKH txout is 31 bytes big, and will
// need a CTxIn of at least 67 bytes to spend:
// so dust is a spendable txout less than
// 98*dustRelayFee/1000 (in satoshis).
// 294 satoshis at the default rate of 3000 sat/kvB.
if (txout.scriptPubKey.IsUnspendable())
return 0;

Expand Down