diff options
author | Greg Sanders <gsanders87@gmail.com> | 2024-11-12 12:14:32 -0500 |
---|---|---|
committer | Greg Sanders <gsanders87@gmail.com> | 2024-11-20 12:48:03 -0500 |
commit | c6859ce2de7531e42fc304b69d74ca0d8e99ea29 (patch) | |
tree | bfffc8568a220f66caee4a49ddff0f86befad294 /src/policy | |
parent | 62016b32300123a44599e649b4f35a3a0f32565f (diff) |
Move+rename GetDustIndexes -> GetDust
Use to replace HasDust and where appropraite
Diffstat (limited to 'src/policy')
-rw-r--r-- | src/policy/ephemeral_policy.cpp | 7 | ||||
-rw-r--r-- | src/policy/ephemeral_policy.h | 3 | ||||
-rw-r--r-- | src/policy/policy.cpp | 14 | ||||
-rw-r--r-- | src/policy/policy.h | 2 |
4 files changed, 13 insertions, 13 deletions
diff --git a/src/policy/ephemeral_policy.cpp b/src/policy/ephemeral_policy.cpp index 08fb262609..c1e184c81f 100644 --- a/src/policy/ephemeral_policy.cpp +++ b/src/policy/ephemeral_policy.cpp @@ -5,15 +5,10 @@ #include <policy/ephemeral_policy.h> #include <policy/policy.h> -bool HasDust(const CTransaction& tx, CFeeRate dust_relay_rate) -{ - return std::ranges::any_of(tx.vout, [&](const auto& output) { return IsDust(output, dust_relay_rate); }); -} - bool PreCheckEphemeralTx(const CTransaction& tx, CFeeRate dust_relay_rate, CAmount base_fee, CAmount mod_fee, TxValidationState& state) { // We never want to give incentives to mine this transaction alone - if ((base_fee != 0 || mod_fee != 0) && HasDust(tx, dust_relay_rate)) { + if ((base_fee != 0 || mod_fee != 0) && !GetDust(tx, dust_relay_rate).empty()) { return state.Invalid(TxValidationResult::TX_NOT_STANDARD, "dust", "tx with dust output must be 0-fee"); } diff --git a/src/policy/ephemeral_policy.h b/src/policy/ephemeral_policy.h index 0ed4a54eb7..ac889e8234 100644 --- a/src/policy/ephemeral_policy.h +++ b/src/policy/ephemeral_policy.h @@ -34,9 +34,6 @@ * are the only way to bring fees. */ -/** Returns true if transaction contains dust */ -bool HasDust(const CTransaction& tx, CFeeRate dust_relay_rate); - /* All the following checks are only called if standardness rules are being applied. */ /** Must be called for each transaction once transaction fees are known. diff --git a/src/policy/policy.cpp b/src/policy/policy.cpp index 21c35af5cc..ed33692823 100644 --- a/src/policy/policy.cpp +++ b/src/policy/policy.cpp @@ -67,6 +67,15 @@ bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFeeIn) return (txout.nValue < GetDustThreshold(txout, dustRelayFeeIn)); } +std::vector<uint32_t> GetDust(const CTransaction& tx, CFeeRate dust_relay_rate) +{ + std::vector<uint32_t> dust_outputs; + for (uint32_t i{0}; i < tx.vout.size(); ++i) { + if (IsDust(tx.vout[i], dust_relay_rate)) dust_outputs.push_back(i); + } + return dust_outputs; +} + bool IsStandard(const CScript& scriptPubKey, const std::optional<unsigned>& max_datacarrier_bytes, TxoutType& whichType) { std::vector<std::vector<unsigned char> > vSolutions; @@ -129,7 +138,6 @@ bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_dat } unsigned int nDataOut = 0; - unsigned int num_dust_outputs{0}; TxoutType whichType; for (const CTxOut& txout : tx.vout) { if (!::IsStandard(txout.scriptPubKey, max_datacarrier_bytes, whichType)) { @@ -142,13 +150,11 @@ bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_dat else if ((whichType == TxoutType::MULTISIG) && (!permit_bare_multisig)) { reason = "bare-multisig"; return false; - } else if (IsDust(txout, dust_relay_fee)) { - num_dust_outputs++; } } // Only MAX_DUST_OUTPUTS_PER_TX dust is permitted(on otherwise valid ephemeral dust) - if (num_dust_outputs > MAX_DUST_OUTPUTS_PER_TX) { + if (GetDust(tx, dust_relay_fee).size() > MAX_DUST_OUTPUTS_PER_TX) { reason = "dust"; return false; } diff --git a/src/policy/policy.h b/src/policy/policy.h index 0488f8dbee..4412f2db87 100644 --- a/src/policy/policy.h +++ b/src/policy/policy.h @@ -131,6 +131,8 @@ bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee); bool IsStandard(const CScript& scriptPubKey, const std::optional<unsigned>& max_datacarrier_bytes, TxoutType& whichType); +/** Get the vout index numbers of all dust outputs */ +std::vector<uint32_t> GetDust(const CTransaction& tx, CFeeRate dust_relay_rate); // Changing the default transaction version requires a two step process: first // adapting relay policy by bumping TX_MAX_STANDARD_VERSION, and then later |