21#include <boost/test/unit_test.hpp>
34 mtx.
vin.resize(num_inputs);
35 mtx.
vout.resize(num_outputs);
37 for (
size_t i{0}; i < num_inputs; ++i) {
39 mtx.
vin[i].prevout.n = 0;
40 mtx.
vin[i].scriptSig = random_script;
42 for (
size_t o{0}; o < num_outputs; ++o) {
44 mtx.
vout[o].scriptPubKey = random_script;
56 "02000000000101964b8aa63509579ca6086e6012eeaa4c2f4dd1e283da29b67c8eea38b3c6fd220000000000fdffffff0294c618000000000017a9145afbbb42f4e83312666d0697f9e66259912ecde38768fa2c0000000000160014897388a0889390fd0e153a22bb2cf9d8f019faf50247304402200547406380719f84d68cf4e96cc3e4a1688309ef475b150be2b471c70ea562aa02206d255f5acc40fd95981874d77201d2eb07883657ce1c796513f32b6079545cdf0121023ae77335cefcb5ab4c1dc1fb0d2acfece184e593727d7d5906c78e564c7c11d125cf0c00"_hex,
63 "01000000010b26e9b7735eb6aabdf358bab62f9816a21ba9ebdb719d5299e88607d722c190000000008b4830450220070aca44506c5cef3a16ed519d7c3c39f8aab192c4e1c90d065f37b8a4af6141022100a8e160b856c2d43d27d8fba71e5aef6405b8643ac4cb7cb3c462aced7f14711a0141046d11fee51b0e60666d5049a9101a72741df480b96ee26488a4d3466b95c9a40ac5eeef87e10a5cd336c19a84565f80fa6c547957b7700ff4dfbdefe76036c339ffffffff021bff3d11000000001976a91404943fdd508053c75000106d3bc6e2754dbcff1988ac2f15de00000000001976a914a266436d2965547608b9e15d9032a7b9d64fa43188ac00000000"_hex,
70 "0200000000010177862801f77c2c068a70372b4c435ef8dd621291c36a64eb4dd491f02218f5324600000000fdffffff014a0100000000000022512035ea312034cfac01e956a269f3bf147f569c2fbb00180677421262da042290d803402be713325ff285e66b0380f53f2fae0d0fb4e16f378a440fed51ce835061437566729d4883bc917632f3cff474d6384bc8b989961a1d730d4a87ed38ad28bd337b20f1d658c6c138b1c312e072b4446f50f01ae0da03a42e6274f8788aae53416a7fac0063036f7264010118746578742f706c61696e3b636861727365743d7574662d3800357b2270223a226272632d3230222c226f70223a226d696e74222c227469636b223a224342414c222c22616d74223a2236393639227d6821c1f1d658c6c138b1c312e072b4446f50f01ae0da03a42e6274f8788aae53416a7f00000000"_hex,
76 Wtxid wtxid_1{
Wtxid::FromHex(
"85cd1a31eb38f74ed5742ec9cb546712ab5aaf747de28a9168b53e846cbda17f").value()};
77 Wtxid wtxid_2{
Wtxid::FromHex(
"b4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b").value()};
78 Wtxid wtxid_3{
Wtxid::FromHex(
"e065bac15f62bb4e761d761db928ddee65a47296b2b776785abb912cdec474e3").value()};
87 Txid txid_1{
Txid::FromHex(
"bd0f71c1d5e50589063e134fad22053cdae5ab2320db5bf5e540198b0b5a4e69").value()};
88 Txid txid_2{
Txid::FromHex(
"b4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b").value()};
89 Txid txid_3{
Txid::FromHex(
"ee707be5201160e32c4fc715bec227d1aeea5940fb4295605e7373edce3b1a93").value()};
96 BOOST_CHECK(txid_1.ToUint256() != wtxid_1.ToUint256());
97 BOOST_CHECK(txid_2.ToUint256() == wtxid_2.ToUint256());
98 BOOST_CHECK(txid_3.ToUint256() != wtxid_3.ToUint256());
107 std::vector<CTransactionRef> package_123{ptx_1, ptx_2, ptx_3};
108 std::vector<CTransactionRef> package_132{ptx_1, ptx_3, ptx_2};
109 std::vector<CTransactionRef> package_231{ptx_2, ptx_3, ptx_1};
110 std::vector<CTransactionRef> package_213{ptx_2, ptx_1, ptx_3};
111 std::vector<CTransactionRef> package_312{ptx_3, ptx_1, ptx_2};
112 std::vector<CTransactionRef> package_321{ptx_3, ptx_2, ptx_1};
114 uint256 calculated_hash_123 = (
HashWriter() << wtxid_1 << wtxid_2 << wtxid_3).GetSHA256();
116 uint256 hash_if_by_txid = (
HashWriter() << wtxid_2 << wtxid_1 << wtxid_3).GetSHA256();
117 BOOST_CHECK(hash_if_by_txid != calculated_hash_123);
119 uint256 hash_if_use_txid = (
HashWriter() << txid_2 << txid_1 << txid_3).GetSHA256();
120 BOOST_CHECK(hash_if_use_txid != calculated_hash_123);
122 uint256 hash_if_use_int_order = (
HashWriter() << wtxid_2 << wtxid_1 << wtxid_3).GetSHA256();
123 BOOST_CHECK(hash_if_use_int_order != calculated_hash_123);
139 package_too_many.emplace_back(create_placeholder_tx(1, 1));
150 size_t total_weight{0};
152 package_too_large.push_back(large_ptx);
153 total_weight += size_large;
162 Package package_duplicate_txids_empty;
163 for (
auto i{0}; i < 3; ++i) {
177 tx_zero_1.
vin.emplace_back(same_prevout);
178 tx_zero_2.
vin.emplace_back(same_prevout);
195 dup_tx.
vin.emplace_back(rand_prevout);
196 dup_tx.
vin.emplace_back(rand_prevout);
199 package_with_dup_tx.emplace_back(create_placeholder_tx(1, 1));
211 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
213 parent_locking_script,
219 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0,
221 child_locking_script,
224 Package package_parent_child{tx_parent, tx_child};
227 BOOST_ERROR(err_parent_child.value());
229 auto it_parent = result_parent_child.m_tx_results.find(tx_parent->GetWitnessHash());
230 auto it_child = result_parent_child.m_tx_results.find(tx_child->GetWitnessHash());
233 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().size(), 1);
234 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().front(), tx_parent->GetWitnessHash());
238 BOOST_CHECK_EQUAL(it_child->second.m_wtxids_fee_calculations.value().front(), tx_child->GetWitnessHash());
243 Package package_single_giant{giant_ptx};
246 BOOST_ERROR(err_single_large.value());
249 BOOST_CHECK_EQUAL(result_single_large.m_state.GetRejectReason(),
"transaction failed");
250 auto it_giant_tx = result_single_large.m_tx_results.find(giant_ptx->GetWitnessHash());
268 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0, 0, coinbaseKey, spk,
272 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0, 101, placeholder_key, spk2,
294 for (
int i{0}; i < 24; ++i) {
295 auto parent =
MakeTransactionRef(CreateValidMempoolTransaction(m_coinbase_txns[i + 1],
296 0, 0, coinbaseKey, spk,
CAmount(48 *
COIN),
false));
297 package.emplace_back(parent);
298 child.
vin.emplace_back(
COutPoint(parent->GetHash(), 0));
300 child.
vout.emplace_back(47 *
COIN, spk2);
307 std::shuffle(package.begin(), package.end(), rng);
315 package.erase(package.begin());
319 package.insert(package.begin(), m_coinbase_txns[0]);
326 mtx_parent.
vin.emplace_back(
COutPoint(m_coinbase_txns[0]->GetHash(), 0));
327 mtx_parent.
vout.emplace_back(20 *
COIN, spk);
328 mtx_parent.
vout.emplace_back(20 *
COIN, spk2);
332 mtx_parent_also_child.
vin.emplace_back(
COutPoint(tx_parent->GetHash(), 0));
333 mtx_parent_also_child.
vout.emplace_back(20 *
COIN, spk);
337 mtx_child.
vin.emplace_back(
COutPoint(tx_parent->GetHash(), 1));
338 mtx_child.
vin.emplace_back(
COutPoint(tx_parent_also_child->GetHash(), 0));
339 mtx_child.
vout.emplace_back(39 *
COIN, spk);
368 for (
size_t i{0}; i < 10; ++i) {
369 auto mtx = CreateValidMempoolTransaction(m_coinbase_txns[i + 25], 0,
371 parent_locking_script,
376 package_unrelated,
false, {});
378 BOOST_CHECK(result_unrelated_submit.m_state.IsInvalid());
380 BOOST_CHECK_EQUAL(result_unrelated_submit.m_state.GetRejectReason(),
"package-not-child-with-parents");
386 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
388 parent_locking_script,
391 package_parent_child.push_back(tx_parent);
392 package_3gen.push_back(tx_parent);
396 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0,
398 child_locking_script,
401 package_parent_child.push_back(tx_child);
402 package_3gen.push_back(tx_child);
406 auto mtx_grandchild = CreateValidMempoolTransaction(tx_child, 0,
408 grandchild_locking_script,
411 package_3gen.push_back(tx_grandchild);
416 package_3gen,
false, {});
417 BOOST_CHECK(result_3gen_submit.m_state.IsInvalid());
419 BOOST_CHECK_EQUAL(result_3gen_submit.m_state.GetRejectReason(),
"package-not-child-with-parents");
427 bad_witness.
stack.emplace_back(1);
429 mtx_parent_invalid.
vin[0].scriptWitness = bad_witness;
431 Package package_invalid_parent{tx_parent_invalid, tx_child};
433 package_invalid_parent,
false, {});
435 BOOST_ERROR(err_parent_invalid.value());
437 auto it_parent = result_quit_early.m_tx_results.find(tx_parent_invalid->GetWitnessHash());
438 auto it_child = result_quit_early.m_tx_results.find(tx_child->GetWitnessHash());
440 BOOST_CHECK_EQUAL(it_parent->second.m_state.GetRejectReason(),
"bad-witness-nonstandard");
442 BOOST_CHECK_EQUAL(it_child->second.m_state.GetRejectReason(),
"bad-txns-inputs-missingorspent");
450 package_parent_child,
false, {});
451 expected_pool_size += 2;
452 BOOST_CHECK_MESSAGE(submit_parent_child.m_state.IsValid(),
453 "Package validation unexpectedly failed: " << submit_parent_child.m_state.GetRejectReason());
454 BOOST_CHECK_EQUAL(submit_parent_child.m_tx_results.size(), package_parent_child.size());
455 auto it_parent = submit_parent_child.m_tx_results.find(tx_parent->GetWitnessHash());
456 auto it_child = submit_parent_child.m_tx_results.find(tx_child->GetWitnessHash());
457 BOOST_CHECK(it_parent != submit_parent_child.m_tx_results.end());
460 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().size(), 1);
461 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().front(), tx_parent->GetWitnessHash());
464 BOOST_CHECK_EQUAL(it_child->second.m_wtxids_fee_calculations.value().front(), tx_child->GetWitnessHash());
472 package_parent_child,
false, {});
474 BOOST_ERROR(err_deduped.value());
476 auto it_parent_deduped = submit_deduped.m_tx_results.find(tx_parent->GetWitnessHash());
477 auto it_child_deduped = submit_deduped.m_tx_results.find(tx_child->GetWitnessHash());
487 auto tx_parent_1 =
MakeTransactionRef(CreateValidMempoolTransaction(m_coinbase_txns[1], 0,
489 parent_locking_script,
491 auto tx_parent_2 =
MakeTransactionRef(CreateValidMempoolTransaction(m_coinbase_txns[2], 0,
493 parent_locking_script,
496 auto tx_child_missing_parent =
MakeTransactionRef(CreateValidMempoolTransaction({tx_parent_1, tx_parent_2},
497 {{tx_parent_1->GetHash(), 0}, {tx_parent_2->GetHash(), 0}},
499 {{49 *
COIN, child_locking_script}},
false));
501 Package package_missing_parent{tx_parent_1, tx_child_missing_parent};
504 package_missing_parent,
false, {});
506 BOOST_ERROR(err_missing_parent.value());
508 auto it_parent = result_missing_parent.m_tx_results.find(tx_parent_1->GetWitnessHash());
509 auto it_child = result_missing_parent.m_tx_results.find(tx_child_missing_parent->GetWitnessHash());
512 BOOST_CHECK_EQUAL(result_missing_parent.m_state.GetRejectReason(),
"transaction failed");
516 BOOST_CHECK_EQUAL(it_child->second.m_state.GetRejectReason(),
"bad-txns-inputs-missingorspent");
521 Package package_just_parent2{tx_parent_2};
522 expected_pool_size += 1;
524 package_just_parent2,
false, {});
526 BOOST_ERROR(err_parent2.value());
531 package_missing_parent,
false, {});
532 expected_pool_size += 2;
534 BOOST_ERROR(err_parent_already_in.value());
553 auto mtx_single = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
555 single_locking_script,
558 Package package_tx_single{tx_single};
560 package_tx_single,
false, {});
561 expected_pool_size += 1;
562 BOOST_CHECK_MESSAGE(result_single_tx.m_state.IsValid(),
563 "Package validation unexpectedly failed: " << result_single_tx.m_state.ToString());
569 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[1], 0,
571 parent_locking_script,
574 Package package_just_parent{tx_parent};
577 BOOST_ERROR(err_parent_child.value());
579 auto it_parent = result_just_parent.m_tx_results.find(tx_parent->GetWitnessHash());
580 BOOST_CHECK_MESSAGE(it_parent->second.m_state.IsValid(), it_parent->second.m_state.ToString());
582 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().size(), 1);
583 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().front(), tx_parent->GetWitnessHash());
585 expected_pool_size += 1;
590 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0,
592 child_locking_script,
595 Package package_just_child{tx_child};
598 BOOST_ERROR(err_parent_child.value());
600 auto it_child = result_just_child.m_tx_results.find(tx_child->GetWitnessHash());
601 BOOST_CHECK_MESSAGE(it_child->second.m_state.IsValid(), it_child->second.m_state.ToString());
604 BOOST_CHECK_EQUAL(it_child->second.m_wtxids_fee_calculations.value().front(), tx_child->GetWitnessHash());
606 expected_pool_size += 1;
610 auto mtx_single_low_fee = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
612 single_locking_script,
615 Package package_tx_single_low_fee{tx_single_low_fee};
617 package_tx_single_low_fee,
false, {});
621 BOOST_CHECK(!result_single_tx_low_fee.m_state.IsValid());
623 auto it_low_fee = result_single_tx_low_fee.m_tx_results.find(tx_single_low_fee->GetWitnessHash());
626 BOOST_ERROR(err_single.value());
644 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
652 witness1.
stack.emplace_back(1);
653 witness1.
stack.emplace_back(witnessScript.
begin(), witnessScript.
end());
656 witness2.
stack.emplace_back(2);
657 witness2.
stack.emplace_back(witnessScript.
begin(), witnessScript.
end());
663 mtx_child1.
vin.resize(1);
664 mtx_child1.
vin[0].prevout.hash = ptx_parent->GetHash();
665 mtx_child1.
vin[0].prevout.n = 0;
667 mtx_child1.
vin[0].scriptWitness = witness1;
668 mtx_child1.
vout.resize(1);
670 mtx_child1.
vout[0].scriptPubKey = child_locking_script;
673 mtx_child2.
vin[0].scriptWitness = witness2;
681 BOOST_CHECK(ptx_child1->GetWitnessHash() != ptx_child2->GetWitnessHash());
688 Package package_parent_child1{ptx_parent, ptx_child1};
690 package_parent_child1,
false, {});
692 BOOST_ERROR(err_witness1.value());
696 Package package_parent_child2{ptx_parent, ptx_child2};
698 package_parent_child2,
false, {});
700 BOOST_ERROR(err_witness2.value());
702 auto it_parent2_deduped = submit_witness2.m_tx_results.find(ptx_parent->GetWitnessHash());
703 auto it_child2 = submit_witness2.m_tx_results.find(ptx_child2->GetWitnessHash());
706 BOOST_CHECK_EQUAL(ptx_child1->GetWitnessHash(), it_child2->second.m_other_wtxid.value());
712 package_parent_child1,
false, {});
714 BOOST_ERROR(err_segwit_dedup.value());
716 auto it_parent_dup = submit_segwit_dedup.m_tx_results.find(ptx_parent->GetWitnessHash());
717 auto it_child_dup = submit_segwit_dedup.m_tx_results.find(ptx_child1->GetWitnessHash());
732 auto mtx_grandchild = CreateValidMempoolTransaction(ptx_child2, 0,
734 grandchild_locking_script,
741 Package package_child2_grandchild{ptx_child2, ptx_grandchild};
743 package_child2_grandchild,
false, {});
745 BOOST_ERROR(err_spend_ignored.value());
747 auto it_child2_ignored = submit_spend_ignored.m_tx_results.find(ptx_child2->GetWitnessHash());
748 auto it_grandchild = submit_spend_ignored.m_tx_results.find(ptx_grandchild->GetWitnessHash());
762 acs_witness.
stack.emplace_back(acs_script.
begin(), acs_script.
end());
765 auto mtx_parent1 = CreateValidMempoolTransaction(m_coinbase_txns[1], 0,
770 package_mixed.push_back(ptx_parent1);
776 parent2_witness1.
stack.emplace_back(1);
777 parent2_witness1.
stack.emplace_back(grandparent2_script.
begin(), grandparent2_script.
end());
779 parent2_witness2.
stack.emplace_back(2);
780 parent2_witness2.
stack.emplace_back(grandparent2_script.
begin(), grandparent2_script.
end());
783 auto mtx_grandparent2 = CreateValidMempoolTransaction(m_coinbase_txns[2], 0,
791 mtx_parent2_v1.
vin.resize(1);
792 mtx_parent2_v1.
vin[0].prevout.hash = ptx_grandparent2->GetHash();
793 mtx_parent2_v1.
vin[0].prevout.n = 0;
795 mtx_parent2_v1.
vin[0].scriptWitness = parent2_witness1;
796 mtx_parent2_v1.
vout.resize(1);
798 mtx_parent2_v1.
vout[0].scriptPubKey = acs_spk;
801 mtx_parent2_v2.
vin[0].scriptWitness = parent2_witness2;
808 package_mixed.push_back(ptx_parent2_v1);
811 auto mtx_parent3 = CreateValidMempoolTransaction(m_coinbase_txns[3], 0,
816 package_mixed.push_back(ptx_parent3);
825 mtx_mixed_child.
vin.emplace_back(
COutPoint(ptx_parent1->GetHash(), 0));
826 mtx_mixed_child.
vin.emplace_back(
COutPoint(ptx_parent2_v1->GetHash(), 0));
827 mtx_mixed_child.
vin.emplace_back(
COutPoint(ptx_parent3->GetHash(), 0));
828 mtx_mixed_child.
vin[0].scriptWitness = acs_witness;
829 mtx_mixed_child.
vin[1].scriptWitness = acs_witness;
830 mtx_mixed_child.
vin[2].scriptWitness = acs_witness;
831 mtx_mixed_child.
vout.emplace_back((48 + 49 + 50 - 1) *
COIN, mixed_child_spk);
833 package_mixed.push_back(ptx_mixed_child);
843 BOOST_ERROR(err_mixed.value());
845 auto it_parent1 = mixed_result.m_tx_results.find(ptx_parent1->GetWitnessHash());
846 auto it_parent2 = mixed_result.m_tx_results.find(ptx_parent2_v1->GetWitnessHash());
847 auto it_parent3 = mixed_result.m_tx_results.find(ptx_parent3->GetWitnessHash());
848 auto it_child = mixed_result.m_tx_results.find(ptx_mixed_child->GetWitnessHash());
854 BOOST_CHECK_EQUAL(ptx_parent2_v2->GetWitnessHash(), it_parent2->second.m_other_wtxid.value());
858 BOOST_CHECK(it_parent3->second.m_effective_feerate.value() == expected_feerate);
859 BOOST_CHECK(it_child->second.m_effective_feerate.value() == expected_feerate);
860 std::vector<Wtxid> expected_wtxids({ptx_parent3->GetWitnessHash(), ptx_mixed_child->GetWitnessHash()});
861 BOOST_CHECK(it_parent3->second.m_wtxids_fee_calculations.value() == expected_wtxids);
862 BOOST_CHECK(it_child->second.m_wtxids_fee_calculations.value() == expected_wtxids);
884 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
887 parent_value,
false);
889 package_cpfp.push_back(tx_parent);
891 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0,
896 package_cpfp.push_back(tx_child);
901 m_node.
mempool->PrioritiseTransaction(tx_parent->GetHash(), child_value - coinbase_value);
905 package_cpfp,
false, {});
907 BOOST_ERROR(err_cpfp_deprio.value());
910 BOOST_CHECK_EQUAL(submit_cpfp_deprio.m_tx_results.find(tx_parent->GetWitnessHash())->second.m_state.GetResult(),
912 BOOST_CHECK_EQUAL(submit_cpfp_deprio.m_tx_results.find(tx_child->GetWitnessHash())->second.m_state.GetResult(),
914 BOOST_CHECK(submit_cpfp_deprio.m_tx_results.find(tx_parent->GetWitnessHash())->second.m_state.GetRejectReason() ==
"min relay fee not met");
927 package_cpfp,
false, {});
929 BOOST_ERROR(err_cpfp.value());
931 auto it_parent = submit_cpfp.m_tx_results.find(tx_parent->GetWitnessHash());
932 auto it_child = submit_cpfp.m_tx_results.find(tx_child->GetWitnessHash());
934 BOOST_CHECK(it_parent->second.m_base_fees.value() == coinbase_value - parent_value);
938 const CFeeRate expected_feerate(coinbase_value - child_value,
940 BOOST_CHECK(it_parent->second.m_effective_feerate.value() == expected_feerate);
941 BOOST_CHECK(it_child->second.m_effective_feerate.value() == expected_feerate);
942 std::vector<Wtxid> expected_wtxids({tx_parent->GetWitnessHash(), tx_child->GetWitnessHash()});
943 BOOST_CHECK(it_parent->second.m_wtxids_fee_calculations.value() == expected_wtxids);
944 BOOST_CHECK(it_child->second.m_wtxids_fee_calculations.value() == expected_wtxids);
947 expected_pool_size += 2;
957 auto mtx_parent_cheap = CreateValidMempoolTransaction(m_coinbase_txns[1], 0,
960 coinbase_value - parent_fee,
false);
962 package_still_too_low.push_back(tx_parent_cheap);
966 auto mtx_child_cheap = CreateValidMempoolTransaction(tx_parent_cheap, 0,
969 coinbase_value - parent_fee - child_fee,
false);
971 package_still_too_low.push_back(tx_child_cheap);
979 package_still_too_low,
false, {});
981 BOOST_ERROR(err_package_too_low.value());
984 BOOST_CHECK_EQUAL(submit_package_too_low.m_tx_results.at(tx_parent_cheap->GetWitnessHash()).m_state.GetResult(),
986 BOOST_CHECK(submit_package_too_low.m_tx_results.at(tx_parent_cheap->GetWitnessHash()).m_effective_feerate.value() ==
989 BOOST_CHECK_EQUAL(submit_package_too_low.m_tx_results.at(tx_child_cheap->GetWitnessHash()).m_state.GetResult(),
991 BOOST_CHECK(submit_package_too_low.m_tx_results.at(tx_child_cheap->GetWitnessHash()).m_effective_feerate.value() ==
995 BOOST_CHECK_EQUAL(submit_package_too_low.m_state.GetRejectReason(),
"transaction failed");
1005 package_still_too_low,
false, {});
1007 BOOST_ERROR(err_prioritised.value());
1009 const CFeeRate expected_feerate(1 *
COIN + parent_fee + child_fee,
1011 BOOST_CHECK_EQUAL(submit_prioritised_package.m_tx_results.size(), package_still_too_low.size());
1012 auto it_parent = submit_prioritised_package.m_tx_results.find(tx_parent_cheap->GetWitnessHash());
1013 auto it_child = submit_prioritised_package.m_tx_results.find(tx_child_cheap->GetWitnessHash());
1015 BOOST_CHECK(it_parent->second.m_base_fees.value() == parent_fee);
1016 BOOST_CHECK(it_parent->second.m_effective_feerate.value() == expected_feerate);
1018 BOOST_CHECK(it_child->second.m_base_fees.value() == child_fee);
1019 BOOST_CHECK(it_child->second.m_effective_feerate.value() == expected_feerate);
1020 std::vector<Wtxid> expected_wtxids({tx_parent_cheap->GetWitnessHash(), tx_child_cheap->GetWitnessHash()});
1021 BOOST_CHECK(it_parent->second.m_wtxids_fee_calculations.value() == expected_wtxids);
1022 BOOST_CHECK(it_child->second.m_wtxids_fee_calculations.value() == expected_wtxids);
1024 expected_pool_size += 2;
1035 auto mtx_parent_rich = CreateValidMempoolTransaction(m_coinbase_txns[2], 0,
1038 coinbase_value - high_parent_fee,
false);
1040 package_rich_parent.push_back(tx_parent_rich);
1042 auto mtx_child_poor = CreateValidMempoolTransaction(tx_parent_rich, 0,
1045 coinbase_value - high_parent_fee,
false);
1047 package_rich_parent.push_back(tx_child_poor);
1053 package_rich_parent,
false, {});
1055 BOOST_ERROR(err_rich_parent.value());
1059 BOOST_CHECK_EQUAL(submit_rich_parent.m_state.GetRejectReason(),
"transaction failed");
1061 auto it_parent = submit_rich_parent.m_tx_results.find(tx_parent_rich->GetWitnessHash());
1062 auto it_child = submit_rich_parent.m_tx_results.find(tx_child_poor->GetWitnessHash());
1065 BOOST_CHECK(it_parent->second.m_state.GetRejectReason() ==
"");
1066 BOOST_CHECK_MESSAGE(it_parent->second.m_base_fees.value() == high_parent_fee,
1067 strprintf(
"rich parent: expected fee %s, got %s", high_parent_fee, it_parent->second.m_base_fees.value()));
1071 BOOST_CHECK(it_child->second.m_state.GetRejectReason() ==
"min relay fee not met");
1073 expected_pool_size += 1;
1096 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
1101 package1.push_back(tx_parent);
1102 package2.push_back(tx_parent);
1105 package1.push_back(tx_child_1);
1107 package2.push_back(tx_child_2);
1112 BOOST_ERROR(err_1.value());
1116 auto it_parent_1 = submit1.m_tx_results.find(tx_parent->GetWitnessHash());
1117 auto it_child_1 = submit1.m_tx_results.find(tx_child_1->GetWitnessHash());
1120 expected_pool_size += 2;
1125 BOOST_ERROR(err_2.value());
1129 auto it_parent_2 = submit2.m_tx_results.find(tx_parent->GetWitnessHash());
1130 auto it_child_2 = submit2.m_tx_results.find(tx_child_2->GetWitnessHash());
1142 m_coinbase_txns[1], 0, 0,
1143 coinbaseKey, parent_spk, coinbase_value - 200,
false));
1145 tx_parent_1, 0, 101,
1146 child_key, child_spk, coinbase_value - 400,
false));
1149 m_coinbase_txns[1], 0, 0,
1150 coinbaseKey, parent_spk, coinbase_value - 800,
false));
1152 tx_parent_2, 0, 101,
1153 child_key, child_spk, coinbase_value - 800 - 200,
false));
1156 m_coinbase_txns[1], 0, 0,
1157 coinbaseKey, parent_spk, coinbase_value - 199,
false));
1159 tx_parent_3, 0, 101,
1160 child_key, child_spk, coinbase_value - 199 - 1300,
false));
1163 BOOST_CHECK(tx_parent_1->GetHash() != tx_parent_2->GetHash() && tx_parent_2->GetHash() != tx_parent_3->GetHash());
1166 Package package1{tx_parent_1, tx_child_1};
1168 Package package2{tx_parent_2, tx_child_2};
1170 Package package3{tx_parent_3, tx_child_3};
1174 BOOST_ERROR(err_1.value());
1176 auto it_parent_1 = submit1.m_tx_results.find(tx_parent_1->GetWitnessHash());
1177 auto it_child_1 = submit1.m_tx_results.find(tx_child_1->GetWitnessHash());
1180 expected_pool_size += 2;
1187 BOOST_ERROR(err_2.value());
1189 auto it_parent_2 = submit2.m_tx_results.find(tx_parent_2->GetWitnessHash());
1190 auto it_child_2 = submit2.m_tx_results.find(tx_child_2->GetWitnessHash());
1198 BOOST_ERROR(err_3.value());
1200 auto it_parent_3 = submit3.m_tx_results.find(tx_parent_3->GetWitnessHash());
1201 auto it_child_3 = submit3.m_tx_results.find(tx_child_3->GetWitnessHash());
1206 BOOST_CHECK(it_parent_3->second.m_replaced_transactions.size() == 2);
1207 BOOST_CHECK(it_child_3->second.m_replaced_transactions.empty());
1209 std::vector<Wtxid> expected_package3_wtxids({tx_parent_3->GetWitnessHash(), tx_child_3->GetWitnessHash()});
1211 BOOST_CHECK(it_parent_3->second.m_wtxids_fee_calculations.value() == expected_package3_wtxids);
1212 BOOST_CHECK(it_child_3->second.m_wtxids_fee_calculations.value() == expected_package3_wtxids);
1213 BOOST_CHECK_EQUAL(it_parent_3->second.m_effective_feerate.value().GetFee(package3_total_vsize), 199 + 1300);
1214 BOOST_CHECK_EQUAL(it_child_3->second.m_effective_feerate.value().GetFee(package3_total_vsize), 199 + 1300);
1222 BOOST_ERROR(err_4.value());
1224 m_node.
mempool->PrioritiseTransaction(tx_child_1->GetHash(), 1363);
1227 BOOST_ERROR(err_5.value());
1229 it_parent_1 = submit5.m_tx_results.find(tx_parent_1->GetWitnessHash());
1230 it_child_1 = submit5.m_tx_results.find(tx_child_1->GetWitnessHash());
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
An encapsulated private key.
CPubKey GetPubKey() const
Compute the public key from a private key.
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
const Wtxid & GetWitnessHash() const LIFETIMEBOUND
const Txid & GetHash() const LIFETIMEBOUND
Double ended buffer combining vector and stream-like interfaces.
A writer stream (for serialization) that computes a 256-bit hash.
uint256 rand256() noexcept
generate a random uint256.
std::string GetRejectReason() const
transaction_identifier represents the two canonical transaction identifier types (txid,...
static transaction_identifier FromUint256(const uint256 &id)
static std::optional< transaction_identifier > FromHex(std::string_view hex)
static int32_t GetTransactionWeight(const CTransaction &tx)
@ TX_MISSING_INPUTS
transaction was missing some of its inputs
@ TX_MEMPOOL_POLICY
violated mempool's fee/size/descendant/RBF/etc limits
@ TX_WITNESS_MUTATED
Transaction might have a witness prior to SegWit activation, or witness may have been malleated (whic...
@ TX_RECONSIDERABLE
fails some policy, but might be acceptable if submitted in a (different) package
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
CKey GenerateRandomKey(bool compressed) noexcept
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
bool IsChildWithParents(const Package &package)
Context-free check that a package is exactly one child and its parents; not all parents need to be pr...
bool IsConsistentPackage(const Package &txns)
Checks that these transactions don't conflict, i.e., spend the same prevout.
bool IsWellFormedPackage(const Package &txns, PackageValidationState &state, bool require_sorted)
Context-free package policy checks:
bool IsChildWithParentsTree(const Package &package)
Context-free check that a package IsChildWithParents() and none of the parents depend on each other (...
bool IsTopoSortedPackage(const Package &txns, std::unordered_set< Txid, SaltedTxidHasher > &later_txids)
IsTopoSortedPackage where a set of txids has been pre-populated.
uint256 GetPackageHash(const std::vector< CTransactionRef > &transactions)
Get the hash of the concatenated wtxids of transactions, with wtxids treated as a little-endian numbe...
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
static constexpr uint32_t MAX_PACKAGE_WEIGHT
Default maximum total weight of transactions in a package in weight to allow for context-less checks.
static constexpr uint32_t MAX_PACKAGE_COUNT
Default maximum number of transactions in a package.
@ PCKG_POLICY
The package itself is invalid (e.g. too many transactions).
@ PCKG_TX
At least one tx is invalid.
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
static constexpr unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT_KVB
Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors.
static constexpr TransactionSerParams TX_WITH_WITNESS
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
std::vector< unsigned char > ToByteVector(const T &in)
constexpr deserialize_type deserialize
static constexpr CAmount CENT
A mutable version of CTransaction.
std::vector< CTxOut > vout
std::vector< std::vector< unsigned char > > stack
Validation result for a transaction evaluated by MemPoolAccept (single or package).
const ResultType m_result_type
Result type.
@ DIFFERENT_WITNESS
Valid, transaction was already in the mempool.
@ INVALID
Fully validated, valid.
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
CTransactionRef create_placeholder_tx(size_t num_inputs, size_t num_outputs)
std::unique_ptr< CTxMemPool > mempool
std::unique_ptr< ChainstateManager > chainman
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
static const CScript P2WSH_OP_TRUE
std::optional< std::string > CheckPackageMempoolAcceptResult(const Package &txns, const PackageMempoolAcceptResult &result, bool expect_valid, const CTxMemPool *mempool)
Check expected properties for every PackageMempoolAcceptResult, regardless of value.
static const CAmount low_fee_amt
BOOST_AUTO_TEST_CASE(package_hash_tests)
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &package, bool test_accept, const std::optional< CFeeRate > &client_maxfeerate)
Validate (and maybe submit) a package to the mempool.