Guest User

Untitled

a guest
Oct 28th, 2025
244
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.84 KB | None | 0 0
  1. // ==========================================================================================================
  2. // *** RELAY POLICY FILTER ***
  3. // Place in /policy/policy.cpp, and call from within IsStandardTx() before returning:
  4. //     if (IsBulkDust(tx, reason))
  5. //         return false;   // reject as nonstandard
  6. // ==========================================================================================================
  7.  
  8. bool IsBulkDust(const CTransaction& tx, std::string& reason)
  9. {
  10.     static constexpr CAmount MIN_OUTPUT_VALUE_SATS = 1000;   // < 1000 sats counts as "tiny"
  11.     static constexpr int     MAX_TINY_OUTPUTS      = 100;    // >= 100 tiny outputs triggers ratio check
  12.     static constexpr double  TINY_RATIO_THRESHOLD  = 0.6;    // >= 60% of all outputs tiny = reject
  13.  
  14.     int tiny = 0;
  15.     const int total = tx.vout.size();
  16.  
  17.     // Sanity check — avoid division by zero
  18.     if (total == 0)
  19.         return false;
  20.  
  21.     // Count any spendable output under 1000 sats as "tiny"
  22.     for (const auto& out : tx.vout) {
  23.         if (out.nValue < MIN_OUTPUT_VALUE_SATS)
  24.             ++tiny;
  25.     }
  26.  
  27.     // Threshold + ratio check
  28.     if (tiny >= MAX_TINY_OUTPUTS && (static_cast<double>(tiny) / total) >= TINY_RATIO_THRESHOLD)
  29.     {
  30.         reason = strprintf("too-many-tiny-outputs(%d of %d, %.2f%%)", tiny, total, 100.0 * tiny / total);
  31.         return true;  // flag as bulk dust
  32.     }
  33.  
  34.     return false;
  35. }
  36.  
  37.  
  38. // ==========================================================================================================
  39. // *** CONSENSUS (soft-fork, hybrid activation) ***
  40. // Helpers in /consensus/tx_check.cpp; activation/enforcement in /validation.cpp
  41. // Also define deployment in: /consensus/params.h, /chainparams.cpp, /versionbits.*
  42. // ==========================================================================================================
  43.  
  44. // -----------------------------------------------------------------------
  45. // --- In /consensus/tx_check.cpp (helper only; no params needed) ---
  46. // -----------------------------------------------------------------------
  47.  
  48. static constexpr CAmount MIN_OUTPUT_VALUE_SATS = 1000;   // < 1000 sats counts as "tiny"
  49. static constexpr int     MAX_TINY_OUTPUTS      = 100;    // >= 100 tiny outputs triggers ratio check
  50. static constexpr double  TINY_RATIO_THRESHOLD  = 0.6;    // >= 60% of all outputs tiny = reject
  51.  
  52. bool IsBulkDust(const CTransaction& tx)    // expose via tx_check.h if needed
  53. {
  54.     int tiny = 0;
  55.     const int total = tx.vout.size();
  56.  
  57.     // Sanity check — avoid division by zero
  58.     if (total == 0)
  59.         return false;
  60.  
  61.     // Count any spendable output under 1000 sats as "tiny"
  62.     for (const auto& out : tx.vout) {
  63.         if (out.nValue < MIN_OUTPUT_VALUE_SATS)
  64.             ++tiny;
  65.     }
  66.  
  67.     // Threshold + ratio check
  68.     if (tiny >= MAX_TINY_OUTPUTS && ((static_cast<double>(tiny) / total) >= TINY_RATIO_THRESHOLD))
  69.         return true;
  70.    
  71.     return false;
  72. }
  73.  
  74.  
  75. // -----------------------------------------------------------------------
  76. // --- In /validation.cpp (enforcement with hybrid activation) ---
  77. // -----------------------------------------------------------------------
  78.  
  79. #include <consensus/tx_check.h>
  80. #include <versionbits.h>
  81.  
  82. // ... inside the appropriate validation path (e.g., after basic tx checks),
  83. // with access to chainparams/params and a tip pointer:
  84.  
  85. const Consensus::Params& params = chainparams.GetConsensus();
  86.  
  87. const bool bulk_dust_active =
  88.     DeploymentActiveAtTip(params, Consensus::DEPLOYMENT_BULK_DUST_LIMIT) ||
  89.     (chainActive.Tip() && chainActive.Tip()->nHeight >= params.BulkDustActivationHeight);
  90.  
  91. if (bulk_dust_active) {
  92.     if (IsBulkDust(tx)) {
  93.         return state.Invalid(TxValidationResult::TX_CONSENSUS, "too-many-tiny-outputs");
  94.     }
  95. }
  96.  
  97.  
  98. // -----------------------------------------------------------------------
  99. // --- In /consensus/params.h ---
  100. // -----------------------------------------------------------------------
  101.  
  102. enum DeploymentPos {
  103.     // ...
  104.     DEPLOYMENT_BULK_DUST_LIMIT,
  105.     MAX_VERSION_BITS_DEPLOYMENTS
  106. };
  107.  
  108. struct Params {
  109.     // ...
  110.     int BulkDustActivationHeight; // height flag-day fallback
  111. };
  112.  
  113.  
  114. // -----------------------------------------------------------------------
  115. // --- In /chainparams.cpp (per-network values; examples only) ---
  116. // -----------------------------------------------------------------------
  117.  
  118. consensus.vDeployments[Consensus::DEPLOYMENT_BULK_DUST_LIMIT].bit = 12;
  119. consensus.vDeployments[Consensus::DEPLOYMENT_BULK_DUST_LIMIT].nStartTime = 1767225600;  // 2026-01-01 UTC
  120. consensus.vDeployments[Consensus::DEPLOYMENT_BULK_DUST_LIMIT].nTimeout   = 1838160000;  // 2028-04-01 UTC
  121. consensus.vDeployments[Consensus::DEPLOYMENT_BULK_DUST_LIMIT].min_activation_height = 969696;
  122.  
  123. consensus.BulkDustActivationHeight = 1021021;  // flag-day fallback
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment