Skip to content
Bitcoin Roots

v31.1-roots.1 · Commit 3: [PATCH 03/17] feat(policy): preserve cluster accounting and repair dynamic dust

src/policy/policy.cpp

Before: src/policy/policy.cpp · After: src/policy/policy.cpp

File metadata
index d0455dd98cedea3adbc884b10ed5a1e58c570eb1..ae484bb292cfa24dec6f10fff5e55cbaa505be19 100644

Download original patch · Release notes

Diff rows 1–38 of 38. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.

src/policy/policy.cpp CHANGED
@@ -26,6 +26,9 @@
26
26
  #include <utility>
27
27
  #include <vector>
28
28
 
29
+ // Standardness also links into standalone wallet tools through bitcoin_common.
30
+ unsigned int g_script_size_policy_limit = DEFAULT_SCRIPT_SIZE_POLICY_LIMIT;
31
+
29
32
  CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
30
33
  {
31
34
  // "Dust" is defined in terms of dustRelayFee,
@@ -692,3 +695,29 @@ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& inputs)
692
695
  std::string reason;
693
696
  return IsWitnessStandard(tx, inputs, "", reason);
694
697
  }
698
+
699
+ int32_t CalculateExtraTxWeight(const CTransaction& tx, const CCoinsViewCache& view, const unsigned int weight_per_data_byte)
700
+ {
701
+ int64_t mod_weight{0};
702
+
703
+ // Add in any extra weight for data bytes
704
+ if (weight_per_data_byte > 1) {
705
+ for (const CTxIn& txin : tx.vin) {
706
+ const CTxOut &utxo = view.AccessCoin(txin.prevout).out;
707
+ auto[script, consensus_weight_per_byte] = GetScriptForTransactionInput(utxo.scriptPubKey, txin);
708
+ if (weight_per_data_byte > consensus_weight_per_byte) {
709
+ const auto dcb = ScriptDatacarrierBytes(script, 0, &txin.scriptWitness);
710
+ mod_weight += int64_t(dcb.first + dcb.second) * (weight_per_data_byte - consensus_weight_per_byte);
711
+ }
712
+ }
713
+ if (weight_per_data_byte > WITNESS_SCALE_FACTOR) {
714
+ for (size_t i{tx.vout.size()}; i; ) {
715
+ const CTxOut& txout = tx.vout[--i];
716
+ const auto dcb = ScriptDatacarrierBytes(txout.scriptPubKey, tx.vout.size() - i);
717
+ mod_weight += int64_t(dcb.first + dcb.second) * (weight_per_data_byte - WITNESS_SCALE_FACTOR);
718
+ }
719
+ }
720
+ }
721
+
722
+ return int32_t(std::min(mod_weight, int64_t{std::numeric_limits<int32_t>::max()}));
723
+ }