Skip to content
Bitcoin Roots

v30.3-roots.1 · Commit 3: [PATCH 03/68] feat(policy): preserve Roots relay and network controls on Core 30.3

src/test/transaction_tests.cpp

Before: src/test/transaction_tests.cpp · After: src/test/transaction_tests.cpp

File metadata
index c0443f3a0a45ef611448379d8d4f026bc83a91a3..c54c13bdbb74ea5e8e1ecfed47aee776714d4047 100644

Download original patch · Release notes

Diff rows 1–235 of 235. 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/test/transaction_tests.cpp CHANGED
@@ -13,6 +13,7 @@
13
13
  #include <consensus/tx_verify.h>
14
14
  #include <consensus/validation.h>
15
15
  #include <core_io.h>
16
+ #include <kernel/mempool_options.h>
16
17
  #include <key.h>
17
18
  #include <policy/policy.h>
18
19
  #include <policy/settings.h>
@@ -46,8 +47,7 @@ using util::ToString;
46
47
 
47
48
  typedef std::vector<unsigned char> valtype;
48
49
 
49
- static CFeeRate g_dust{DUST_RELAY_TX_FEE};
50
- static bool g_bare_multi{DEFAULT_PERMIT_BAREMULTISIG};
50
+ static kernel::MemPoolOptions g_mempool_opts;
51
51
 
52
52
  static std::map<std::string, unsigned int> mapFlagNames = {
53
53
  {std::string("P2SH"), (unsigned int)SCRIPT_VERIFY_P2SH},
@@ -798,21 +798,30 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
798
798
  CKey key = GenerateRandomKey();
799
799
  t.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
800
800
 
801
- constexpr auto CheckIsStandard = [](const auto& t, const unsigned int max_op_return_relay = MAX_OP_RETURN_RELAY) {
801
+ constexpr auto CheckIsStandard = [](const auto& t, const unsigned int max_op_return_relay = MAX_OP_RETURN_RELAY, const ignore_rejects_type& ignore_rejects = empty_ignore_rejects) {
802
802
  std::string reason;
803
- BOOST_CHECK(IsStandardTx(CTransaction{t}, max_op_return_relay, g_bare_multi, g_dust, reason));
803
+ auto opts = g_mempool_opts;
804
+ opts.max_datacarrier_bytes = max_op_return_relay;
805
+ BOOST_CHECK(IsStandardTx(CTransaction{t}, opts, reason, ignore_rejects));
804
806
  BOOST_CHECK(reason.empty());
805
807
  };
806
- constexpr auto CheckIsNotStandard = [](const auto& t, const std::string& reason_in, const unsigned int max_op_return_relay = MAX_OP_RETURN_RELAY) {
808
+ constexpr auto CheckIsNotStandard = [](const auto& t, const std::string& reason_in, const unsigned int max_op_return_relay = MAX_OP_RETURN_RELAY, const ignore_rejects_type& ignore_rejects = empty_ignore_rejects) {
807
809
  std::string reason;
808
- BOOST_CHECK(!IsStandardTx(CTransaction{t}, max_op_return_relay, g_bare_multi, g_dust, reason));
810
+ auto opts = g_mempool_opts;
811
+ opts.max_datacarrier_bytes = max_op_return_relay;
812
+ BOOST_CHECK(!IsStandardTx(CTransaction{t}, opts, reason, ignore_rejects));
809
813
  BOOST_CHECK_EQUAL(reason_in, reason);
810
814
  };
811
815
 
816
+ g_mempool_opts.permit_bare_pubkey = true;
812
817
  CheckIsStandard(t);
813
818
 
819
+ g_mempool_opts.permitephemeral_anchor = true;
820
+ g_mempool_opts.permitephemeral_dust = true;
821
+ g_mempool_opts.permitephemeral_send = true;
822
+
814
823
  // Check dust with default relay fee:
815
- CAmount nDustThreshold = 182 * g_dust.GetFeePerK() / 1000;
824
+ CAmount nDustThreshold = 182 * g_mempool_opts.dust_relay_feerate.GetFeePerK() / 1000;
816
825
  BOOST_CHECK_EQUAL(nDustThreshold, 546);
817
826
 
818
827
  // Add dust outputs up to allowed maximum, still standard!
@@ -847,25 +856,66 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
847
856
 
848
857
  // Check dust with odd relay fee to verify rounding:
849
858
  // nDustThreshold = 182 * 3702 / 1000
850
- g_dust = CFeeRate(3702);
859
+ g_mempool_opts.dust_relay_feerate = CFeeRate(3702);
851
860
  // dust:
852
861
  t.vout[0].nValue = 674 - 1;
853
862
  CheckIsNotStandard(t, "dust");
854
863
  // not dust:
855
864
  t.vout[0].nValue = 674;
856
865
  CheckIsStandard(t);
857
- g_dust = CFeeRate{DUST_RELAY_TX_FEE};
866
+ g_mempool_opts.dust_relay_feerate = CFeeRate{DUST_RELAY_TX_FEE};
858
867
 
859
868
  t.vout[0].scriptPubKey = CScript() << OP_1;
860
869
  CheckIsNotStandard(t, "scriptpubkey");
861
870
 
862
- // Custom 83-byte TxoutType::NULL_DATA (standard with max_op_return_relay of 83)
863
- t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
864
- BOOST_CHECK_EQUAL(83, t.vout[0].scriptPubKey.size());
865
- CheckIsStandard(t, /*max_op_return_relay=*/83);
871
+ // Test rejectparasites
872
+ t.vout[0].scriptPubKey = CScript() << OP_RETURN;
873
+ t.vout.emplace_back(674, GetScriptForDestination(PKHash(key.GetPubKey())));
874
+ t.nLockTime = 21;
875
+ g_mempool_opts.reject_parasites = false;
876
+ CheckIsStandard(t);
877
+ g_mempool_opts.reject_parasites = true;
878
+ CheckIsNotStandard(t, "parasite-cat21");
879
+ t.nLockTime = 0;
880
+ CheckIsStandard(t);
881
+ g_mempool_opts.reject_parasites = false;
866
882
 
867
- // Non-standard if max_op_return_relay datacarrier arg is one less
868
- CheckIsNotStandard(t, "datacarrier", /*max_op_return_relay=*/82);
883
+ // Test rejecttokens
884
+ t.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_13 << OP_FALSE;
885
+ g_mempool_opts.reject_tokens = false;
886
+ CheckIsStandard(t);
887
+ g_mempool_opts.reject_tokens = true;
888
+ CheckIsNotStandard(t, "tokens-runes");
889
+ // At least one data push is needed after OP_13 to match
890
+ t.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_13;
891
+ CheckIsStandard(t);
892
+ // Test rejecttokens applying to OLGA
893
+ const auto olga_header = CScript() << OP_0 << "003e7374616d703a000000000000000000000000000000000000000000000000"_hex;
894
+ t.vout[0].scriptPubKey = olga_header;
895
+ t.vout.resize(1);
896
+ // Missing a second output, so not OLGA
897
+ CheckIsStandard(t);
898
+ t.vout.emplace_back(1000, olga_header);
899
+ CheckIsNotStandard(t, "tokens-olga");
900
+ t.vout.emplace_back(1000, olga_header);
901
+ CheckIsNotStandard(t, "tokens-olga");
902
+ g_mempool_opts.reject_tokens = false;
903
+ CheckIsStandard(t);
904
+ t.vout.resize(1);
905
+
906
+ // MAX_OP_RETURN_RELAY-byte TxoutType::NULL_DATA (standard)
907
+ g_mempool_opts.permitbaredatacarrier = true;
908
+ t.vout[0].scriptPubKey = CScript() << OP_RETURN;
909
+ while (t.vout[0].scriptPubKey.size() < MAX_OP_RETURN_RELAY) {
910
+ t.vout[0].scriptPubKey << OP_0;
911
+ }
912
+ BOOST_CHECK_EQUAL(MAX_OP_RETURN_RELAY, t.vout[0].scriptPubKey.size());
913
+ CheckIsStandard(t);
914
+
915
+ // MAX_OP_RETURN_RELAY+1-byte TxoutType::NULL_DATA (non-standard)
916
+ t.vout[0].scriptPubKey << OP_0;
917
+ BOOST_CHECK_EQUAL(MAX_OP_RETURN_RELAY + 1, t.vout[0].scriptPubKey.size());
918
+ CheckIsNotStandard(t, "datacarrier");
869
919
 
870
920
  // Data payload can be encoded in any way...
871
921
  t.vout[0].scriptPubKey = CScript() << OP_RETURN << ""_hex;
@@ -887,28 +937,40 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
887
937
  t.vout[0].scriptPubKey = CScript() << OP_RETURN;
888
938
  CheckIsStandard(t);
889
939
 
890
- // Multiple TxoutType::NULL_DATA are permitted
940
+ // Multiple carriers require an explicit local policy relaxation
891
941
  t.vout.resize(2);
892
942
  t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
893
943
  t.vout[0].nValue = 0;
894
944
  t.vout[1].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
895
945
  t.vout[1].nValue = 0;
896
- CheckIsStandard(t);
946
+ CheckIsNotStandard(t, "multi-op-return", MAX_STANDARD_TX_WEIGHT / WITNESS_SCALE_FACTOR);
947
+ CheckIsStandard(t, MAX_STANDARD_TX_WEIGHT / WITNESS_SCALE_FACTOR, {"multi-op-return"});
897
948
 
898
949
  t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
899
950
  t.vout[1].scriptPubKey = CScript() << OP_RETURN;
900
- CheckIsStandard(t);
951
+ CheckIsNotStandard(t, "multi-op-return", MAX_STANDARD_TX_WEIGHT / WITNESS_SCALE_FACTOR);
952
+ CheckIsStandard(t, MAX_STANDARD_TX_WEIGHT / WITNESS_SCALE_FACTOR, {"multi-op-return"});
901
953
 
902
954
  t.vout[0].scriptPubKey = CScript() << OP_RETURN;
903
955
  t.vout[1].scriptPubKey = CScript() << OP_RETURN;
904
- CheckIsStandard(t);
956
+ CheckIsNotStandard(t, "multi-op-return", MAX_STANDARD_TX_WEIGHT / WITNESS_SCALE_FACTOR);
957
+ CheckIsStandard(t, MAX_STANDARD_TX_WEIGHT / WITNESS_SCALE_FACTOR, {"multi-op-return"});
905
958
 
906
959
  t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
907
960
  t.vout[1].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
908
961
  const auto datacarrier_size = t.vout[0].scriptPubKey.size() + t.vout[1].scriptPubKey.size();
909
- CheckIsStandard(t); // Default max relay should never trigger
910
- CheckIsStandard(t, /*max_op_return_relay=*/datacarrier_size);
911
- CheckIsNotStandard(t, "datacarrier", /*max_op_return_relay=*/datacarrier_size-1);
962
+ CheckIsNotStandard(t, "datacarrier");
963
+ CheckIsStandard(t, MAX_STANDARD_TX_WEIGHT / WITNESS_SCALE_FACTOR, {"multi-op-return"}); // Explicit generous aggregate limit
964
+ CheckIsStandard(t, /*max_op_return_relay=*/datacarrier_size, {"multi-op-return"});
965
+ CheckIsNotStandard(t, "datacarrier", /*max_op_return_relay=*/datacarrier_size-1, {"multi-op-return"});
966
+
967
+ // Bare carrier transactions still require explicit permission.
968
+ t.vout.resize(1);
969
+ t.vout[0].scriptPubKey = CScript() << OP_RETURN;
970
+ g_mempool_opts.permitbaredatacarrier = false;
971
+ CheckIsNotStandard(t, "bare-datacarrier");
972
+ g_mempool_opts.permitbaredatacarrier = true;
973
+ CheckIsStandard(t);
912
974
 
913
975
  // Check large scriptSig (non-standard if size is >1650 bytes)
914
976
  t.vout.resize(1);
@@ -971,16 +1033,16 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
971
1033
  BOOST_CHECK_EQUAL(GetTransactionWeight(CTransaction(t)), 400004);
972
1034
  CheckIsNotStandard(t, "tx-size");
973
1035
 
974
- // Check bare multisig (standard if policy flag g_bare_multi is set)
975
- g_bare_multi = true;
1036
+ // Check bare multisig (standard if the policy flag is set)
1037
+ g_mempool_opts.permit_bare_multisig = true;
976
1038
  t.vout[0].scriptPubKey = GetScriptForMultisig(1, {key.GetPubKey()}); // simple 1-of-1
977
1039
  t.vin.resize(1);
978
1040
  t.vin[0].scriptSig = CScript() << std::vector<unsigned char>(65, 0);
979
1041
  CheckIsStandard(t);
980
1042
 
981
- g_bare_multi = false;
1043
+ g_mempool_opts.permit_bare_multisig = false;
982
1044
  CheckIsNotStandard(t, "bare-multisig");
983
- g_bare_multi = DEFAULT_PERMIT_BAREMULTISIG;
1045
+ g_mempool_opts.permit_bare_multisig = true;
984
1046
 
985
1047
  // Add dust outputs up to allowed maximum
986
1048
  assert(t.vout.size() == 1);
@@ -1039,6 +1101,9 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
1039
1101
  for (int op = OP_1; op <= OP_16; op += 1) {
1040
1102
  t.vout[0].scriptPubKey = CScript() << (opcodetype)op << std::vector<unsigned char>(2, 0);
1041
1103
  t.vout[0].nValue = 240;
1104
+ g_mempool_opts.acceptunknownwitness = false;
1105
+ CheckIsNotStandard(t, "scriptpubkey-unknown-witnessversion");
1106
+ g_mempool_opts.acceptunknownwitness = true;
1042
1107
  CheckIsStandard(t);
1043
1108
 
1044
1109
  t.vout[0].nValue = 239;
@@ -1052,6 +1117,34 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
1052
1117
  CheckIsStandard(t);
1053
1118
  t.vout[0].nValue = 239;
1054
1119
  CheckIsNotStandard(t, "dust");
1120
+
1121
+ // Test permitbareanchor
1122
+ g_mempool_opts.permitbareanchor = false;
1123
+ t.vout[1].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
1124
+ t.vout[1].nValue = COIN;
1125
+ CheckIsStandard(t);
1126
+ t.vout.resize(1);
1127
+ CheckIsNotStandard(t, "bare-anchor");
1128
+ g_mempool_opts.permitbareanchor = true;
1129
+ CheckIsStandard(t);
1130
+
1131
+ // Test permitephemeral
1132
+ g_mempool_opts.permitephemeral_anchor = false;
1133
+ CheckIsNotStandard(t, "anchor");
1134
+ t.vout[0].nValue = 0;
1135
+ CheckIsNotStandard(t, "anchor");
1136
+ g_mempool_opts.permitephemeral_anchor = true;
1137
+ g_mempool_opts.permitephemeral_dust = false;
1138
+ CheckIsStandard(t);
1139
+ t.vout[0].nValue = 1;
1140
+ CheckIsNotStandard(t, "dust-nonzero");
1141
+ g_mempool_opts.permitephemeral_dust = true;
1142
+ g_mempool_opts.permitephemeral_send = false;
1143
+ CheckIsStandard(t);
1144
+ t.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
1145
+ CheckIsNotStandard(t, "dust-nonanchor");
1146
+ g_mempool_opts.permitephemeral_send = true;
1147
+ CheckIsStandard(t);
1055
1148
  }
1056
1149
 
1057
1150
  BOOST_AUTO_TEST_CASE(max_standard_legacy_sigops)