Skip to content

Commit c6859ce

Browse files
committed
Move+rename GetDustIndexes -> GetDust
Use to replace HasDust and where appropraite
1 parent 62016b3 commit c6859ce

File tree

8 files changed

+17
-33
lines changed

8 files changed

+17
-33
lines changed

src/policy/ephemeral_policy.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@
55
#include <policy/ephemeral_policy.h>
66
#include <policy/policy.h>
77

8-
bool HasDust(const CTransaction& tx, CFeeRate dust_relay_rate)
9-
{
10-
return std::ranges::any_of(tx.vout, [&](const auto& output) { return IsDust(output, dust_relay_rate); });
11-
}
12-
138
bool PreCheckEphemeralTx(const CTransaction& tx, CFeeRate dust_relay_rate, CAmount base_fee, CAmount mod_fee, TxValidationState& state)
149
{
1510
// We never want to give incentives to mine this transaction alone
16-
if ((base_fee != 0 || mod_fee != 0) && HasDust(tx, dust_relay_rate)) {
11+
if ((base_fee != 0 || mod_fee != 0) && !GetDust(tx, dust_relay_rate).empty()) {
1712
return state.Invalid(TxValidationResult::TX_NOT_STANDARD, "dust", "tx with dust output must be 0-fee");
1813
}
1914

src/policy/ephemeral_policy.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
* are the only way to bring fees.
3535
*/
3636

37-
/** Returns true if transaction contains dust */
38-
bool HasDust(const CTransaction& tx, CFeeRate dust_relay_rate);
39-
4037
/* All the following checks are only called if standardness rules are being applied. */
4138

4239
/** Must be called for each transaction once transaction fees are known.

src/policy/policy.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
6767
return (txout.nValue < GetDustThreshold(txout, dustRelayFeeIn));
6868
}
6969

70+
std::vector<uint32_t> GetDust(const CTransaction& tx, CFeeRate dust_relay_rate)
71+
{
72+
std::vector<uint32_t> dust_outputs;
73+
for (uint32_t i{0}; i < tx.vout.size(); ++i) {
74+
if (IsDust(tx.vout[i], dust_relay_rate)) dust_outputs.push_back(i);
75+
}
76+
return dust_outputs;
77+
}
78+
7079
bool IsStandard(const CScript& scriptPubKey, const std::optional<unsigned>& max_datacarrier_bytes, TxoutType& whichType)
7180
{
7281
std::vector<std::vector<unsigned char> > vSolutions;
@@ -129,7 +138,6 @@ bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_dat
129138
}
130139

131140
unsigned int nDataOut = 0;
132-
unsigned int num_dust_outputs{0};
133141
TxoutType whichType;
134142
for (const CTxOut& txout : tx.vout) {
135143
if (!::IsStandard(txout.scriptPubKey, max_datacarrier_bytes, whichType)) {
@@ -142,13 +150,11 @@ bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_dat
142150
else if ((whichType == TxoutType::MULTISIG) && (!permit_bare_multisig)) {
143151
reason = "bare-multisig";
144152
return false;
145-
} else if (IsDust(txout, dust_relay_fee)) {
146-
num_dust_outputs++;
147153
}
148154
}
149155

150156
// Only MAX_DUST_OUTPUTS_PER_TX dust is permitted(on otherwise valid ephemeral dust)
151-
if (num_dust_outputs > MAX_DUST_OUTPUTS_PER_TX) {
157+
if (GetDust(tx, dust_relay_fee).size() > MAX_DUST_OUTPUTS_PER_TX) {
152158
reason = "dust";
153159
return false;
154160
}

src/policy/policy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee);
131131

132132
bool IsStandard(const CScript& scriptPubKey, const std::optional<unsigned>& max_datacarrier_bytes, TxoutType& whichType);
133133

134+
/** Get the vout index numbers of all dust outputs */
135+
std::vector<uint32_t> GetDust(const CTransaction& tx, CFeeRate dust_relay_rate);
134136

135137
// Changing the default transaction version requires a two step process: first
136138
// adapting relay policy by bumping TX_MAX_STANDARD_VERSION, and then later

src/rpc/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ static RPCHelpMan prioritisetransaction()
496496

497497
// Non-0 fee dust transactions are not allowed for entry, and modification not allowed afterwards
498498
const auto& tx = mempool.get(hash);
499-
if (tx && HasDust(*tx, mempool.m_opts.dust_relay_feerate)) {
499+
if (tx && !GetDust(*tx, mempool.m_opts.dust_relay_feerate).empty()) {
500500
throw JSONRPCError(RPC_INVALID_PARAMETER, "Priority is not supported for transactions with dust outputs.");
501501
}
502502

src/test/fuzz/package_eval.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ std::optional<COutPoint> GetChildEvictingPrevout(const CTxMemPool& tx_pool)
167167
LOCK(tx_pool.cs);
168168
for (const auto& tx_info : tx_pool.infoAll()) {
169169
const auto& entry = *Assert(tx_pool.GetEntry(tx_info.tx->GetHash()));
170-
std::vector<uint32_t> dust_indexes{GetDustIndexes(tx_info.tx, tx_pool.m_opts.dust_relay_feerate)};
170+
std::vector<uint32_t> dust_indexes{GetDust(*tx_info.tx, tx_pool.m_opts.dust_relay_feerate)};
171171
if (!dust_indexes.empty()) {
172172
const auto& children = entry.GetMemPoolChildrenConst();
173173
if (!children.empty()) {
@@ -311,7 +311,7 @@ FUZZ_TARGET(ephemeral_package_eval, .init = initialize_tx_pool)
311311
// filter for ephemeral dust GetEntry
312312
if (tx_pool.exists(GenTxid::Txid(txid))) {
313313
const auto tx_info{tx_pool.info(GenTxid::Txid(txid))};
314-
if (GetDustIndexes(tx_info.tx, tx_pool.m_opts.dust_relay_feerate).empty()) {
314+
if (GetDust(*tx_info.tx, tx_pool.m_opts.dust_relay_feerate).empty()) {
315315
tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
316316
}
317317
}

src/test/util/txmempool.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,13 @@ std::optional<std::string> CheckPackageMempoolAcceptResult(const Package& txns,
141141
return std::nullopt;
142142
}
143143

144-
std::vector<uint32_t> GetDustIndexes(const CTransactionRef& tx_ref, CFeeRate dust_relay_rate)
145-
{
146-
std::vector<uint32_t> dust_indexes;
147-
for (size_t i = 0; i < tx_ref->vout.size(); ++i) {
148-
const auto& output = tx_ref->vout[i];
149-
if (IsDust(output, dust_relay_rate)) dust_indexes.push_back(i);
150-
}
151-
152-
return dust_indexes;
153-
}
154-
155144
void CheckMempoolEphemeralInvariants(const CTxMemPool& tx_pool)
156145
{
157146
LOCK(tx_pool.cs);
158147
for (const auto& tx_info : tx_pool.infoAll()) {
159148
const auto& entry = *Assert(tx_pool.GetEntry(tx_info.tx->GetHash()));
160149

161-
std::vector<uint32_t> dust_indexes = GetDustIndexes(tx_info.tx, tx_pool.m_opts.dust_relay_feerate);
150+
std::vector<uint32_t> dust_indexes = GetDust(*tx_info.tx, tx_pool.m_opts.dust_relay_feerate);
162151

163152
Assert(dust_indexes.size() < 2);
164153

src/test/util/txmempool.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ std::optional<std::string> CheckPackageMempoolAcceptResult(const Package& txns,
5454
*/
5555
void CheckMempoolEphemeralInvariants(const CTxMemPool& tx_pool);
5656

57-
/** Return indexes of the transaction's outputs that are considered dust
58-
* at given dust_relay_rate.
59-
*/
60-
std::vector<uint32_t> GetDustIndexes(const CTransactionRef& tx_ref, CFeeRate dust_relay_rate);
61-
6257
/** For every transaction in tx_pool, check TRUC invariants:
6358
* - a TRUC tx's ancestor count must be within TRUC_ANCESTOR_LIMIT
6459
* - a TRUC tx's descendant count must be within TRUC_DESCENDANT_LIMIT

0 commit comments

Comments
 (0)