Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==========================================================================================================
- // *** RELAY POLICY FILTER ***
- // Place in /policy/policy.cpp, and call from within IsStandardTx() before returning:
- // if (IsBulkDust(tx, reason))
- // return false; // reject as nonstandard
- // ==========================================================================================================
- bool IsBulkDust(const CTransaction& tx, std::string& reason)
- {
- static constexpr CAmount MIN_OUTPUT_VALUE_SATS = 1000; // < 1000 sats counts as "tiny"
- static constexpr int MAX_TINY_OUTPUTS = 100; // >= 100 tiny outputs triggers ratio check
- static constexpr double TINY_RATIO_THRESHOLD = 0.6; // >= 60% of all outputs tiny = reject
- int tiny = 0;
- const int total = tx.vout.size();
- // Sanity check — avoid division by zero
- if (total == 0)
- return false;
- // Count any spendable output under 1000 sats as "tiny"
- for (const auto& out : tx.vout) {
- if (out.nValue < MIN_OUTPUT_VALUE_SATS)
- ++tiny;
- }
- // Threshold + ratio check
- if (tiny >= MAX_TINY_OUTPUTS && (static_cast<double>(tiny) / total) >= TINY_RATIO_THRESHOLD)
- {
- reason = strprintf("too-many-tiny-outputs(%d of %d, %.2f%%)", tiny, total, 100.0 * tiny / total);
- return true; // flag as bulk dust
- }
- return false;
- }
- // ==========================================================================================================
- // *** CONSENSUS (soft-fork, hybrid activation) ***
- // Helpers in /consensus/tx_check.cpp; activation/enforcement in /validation.cpp
- // Also define deployment in: /consensus/params.h, /chainparams.cpp, /versionbits.*
- // ==========================================================================================================
- // -----------------------------------------------------------------------
- // --- In /consensus/tx_check.cpp (helper only; no params needed) ---
- // -----------------------------------------------------------------------
- static constexpr CAmount MIN_OUTPUT_VALUE_SATS = 1000; // < 1000 sats counts as "tiny"
- static constexpr int MAX_TINY_OUTPUTS = 100; // >= 100 tiny outputs triggers ratio check
- static constexpr double TINY_RATIO_THRESHOLD = 0.6; // >= 60% of all outputs tiny = reject
- bool IsBulkDust(const CTransaction& tx) // expose via tx_check.h if needed
- {
- int tiny = 0;
- const int total = tx.vout.size();
- // Sanity check — avoid division by zero
- if (total == 0)
- return false;
- // Count any spendable output under 1000 sats as "tiny"
- for (const auto& out : tx.vout) {
- if (out.nValue < MIN_OUTPUT_VALUE_SATS)
- ++tiny;
- }
- // Threshold + ratio check
- if (tiny >= MAX_TINY_OUTPUTS && ((static_cast<double>(tiny) / total) >= TINY_RATIO_THRESHOLD))
- return true;
- return false;
- }
- // -----------------------------------------------------------------------
- // --- In /validation.cpp (enforcement with hybrid activation) ---
- // -----------------------------------------------------------------------
- #include <consensus/tx_check.h>
- #include <versionbits.h>
- // ... inside the appropriate validation path (e.g., after basic tx checks),
- // with access to chainparams/params and a tip pointer:
- const Consensus::Params& params = chainparams.GetConsensus();
- const bool bulk_dust_active =
- DeploymentActiveAtTip(params, Consensus::DEPLOYMENT_BULK_DUST_LIMIT) ||
- (chainActive.Tip() && chainActive.Tip()->nHeight >= params.BulkDustActivationHeight);
- if (bulk_dust_active) {
- if (IsBulkDust(tx)) {
- return state.Invalid(TxValidationResult::TX_CONSENSUS, "too-many-tiny-outputs");
- }
- }
- // -----------------------------------------------------------------------
- // --- In /consensus/params.h ---
- // -----------------------------------------------------------------------
- enum DeploymentPos {
- // ...
- DEPLOYMENT_BULK_DUST_LIMIT,
- MAX_VERSION_BITS_DEPLOYMENTS
- };
- struct Params {
- // ...
- int BulkDustActivationHeight; // height flag-day fallback
- };
- // -----------------------------------------------------------------------
- // --- In /chainparams.cpp (per-network values; examples only) ---
- // -----------------------------------------------------------------------
- consensus.vDeployments[Consensus::DEPLOYMENT_BULK_DUST_LIMIT].bit = 12;
- consensus.vDeployments[Consensus::DEPLOYMENT_BULK_DUST_LIMIT].nStartTime = 1767225600; // 2026-01-01 UTC
- consensus.vDeployments[Consensus::DEPLOYMENT_BULK_DUST_LIMIT].nTimeout = 1838160000; // 2028-04-01 UTC
- consensus.vDeployments[Consensus::DEPLOYMENT_BULK_DUST_LIMIT].min_activation_height = 969696;
- consensus.BulkDustActivationHeight = 1021021; // flag-day fallback
Advertisement