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);
365 for (
size_t i{0}; i < 10; ++i) {
366 auto mtx = CreateValidMempoolTransaction(m_coinbase_txns[i + 25], 0,
368 parent_locking_script,
373 package_unrelated,
false, {});
375 BOOST_CHECK(result_unrelated_submit.m_state.IsInvalid());
377 BOOST_CHECK_EQUAL(result_unrelated_submit.m_state.GetRejectReason(),
"package-not-child-with-parents");
383 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
385 parent_locking_script,
388 package_parent_child.push_back(tx_parent);
389 package_3gen.push_back(tx_parent);
393 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0,
395 child_locking_script,
398 package_parent_child.push_back(tx_child);
399 package_3gen.push_back(tx_child);
403 auto mtx_grandchild = CreateValidMempoolTransaction(tx_child, 0,
405 grandchild_locking_script,
408 package_3gen.push_back(tx_grandchild);
413 package_3gen,
false, {});
414 BOOST_CHECK(result_3gen_submit.m_state.IsInvalid());
416 BOOST_CHECK_EQUAL(result_3gen_submit.m_state.GetRejectReason(),
"package-not-child-with-parents");
424 bad_witness.
stack.emplace_back(1);
426 mtx_parent_invalid.
vin[0].scriptWitness = bad_witness;
428 Package package_invalid_parent{tx_parent_invalid, tx_child};
430 package_invalid_parent,
false, {});
432 BOOST_ERROR(err_parent_invalid.value());
434 auto it_parent = result_quit_early.m_tx_results.find(tx_parent_invalid->GetWitnessHash());
435 auto it_child = result_quit_early.m_tx_results.find(tx_child->GetWitnessHash());
437 BOOST_CHECK_EQUAL(it_parent->second.m_state.GetRejectReason(),
"bad-witness-nonstandard");
439 BOOST_CHECK_EQUAL(it_child->second.m_state.GetRejectReason(),
"bad-txns-inputs-missingorspent");
445 mtx_child.vin.emplace_back(
COutPoint(package_unrelated[0]->GetHash(), 0));
446 Package package_missing_parent;
447 package_missing_parent.push_back(tx_parent);
451 package_missing_parent,
false, {});
452 BOOST_CHECK(result_missing_parent.m_state.IsInvalid());
454 BOOST_CHECK_EQUAL(result_missing_parent.m_state.GetRejectReason(),
"package-not-child-with-unconfirmed-parents");
461 package_parent_child,
false, {});
462 expected_pool_size += 2;
463 BOOST_CHECK_MESSAGE(submit_parent_child.m_state.IsValid(),
464 "Package validation unexpectedly failed: " << submit_parent_child.m_state.GetRejectReason());
465 BOOST_CHECK_EQUAL(submit_parent_child.m_tx_results.size(), package_parent_child.size());
466 auto it_parent = submit_parent_child.m_tx_results.find(tx_parent->GetWitnessHash());
467 auto it_child = submit_parent_child.m_tx_results.find(tx_child->GetWitnessHash());
468 BOOST_CHECK(it_parent != submit_parent_child.m_tx_results.end());
471 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().size(), 1);
472 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().front(), tx_parent->GetWitnessHash());
475 BOOST_CHECK_EQUAL(it_child->second.m_wtxids_fee_calculations.value().front(), tx_child->GetWitnessHash());
483 package_parent_child,
false, {});
485 BOOST_ERROR(err_deduped.value());
487 auto it_parent_deduped = submit_deduped.m_tx_results.find(tx_parent->GetWitnessHash());
488 auto it_child_deduped = submit_deduped.m_tx_results.find(tx_child->GetWitnessHash());
510 auto mtx_single = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
512 single_locking_script,
515 Package package_tx_single{tx_single};
517 package_tx_single,
false, {});
518 expected_pool_size += 1;
519 BOOST_CHECK_MESSAGE(result_single_tx.m_state.IsValid(),
520 "Package validation unexpectedly failed: " << result_single_tx.m_state.ToString());
526 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[1], 0,
528 parent_locking_script,
531 Package package_just_parent{tx_parent};
534 BOOST_ERROR(err_parent_child.value());
536 auto it_parent = result_just_parent.m_tx_results.find(tx_parent->GetWitnessHash());
537 BOOST_CHECK_MESSAGE(it_parent->second.m_state.IsValid(), it_parent->second.m_state.ToString());
539 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().size(), 1);
540 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().front(), tx_parent->GetWitnessHash());
542 expected_pool_size += 1;
547 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0,
549 child_locking_script,
552 Package package_just_child{tx_child};
555 BOOST_ERROR(err_parent_child.value());
557 auto it_child = result_just_child.m_tx_results.find(tx_child->GetWitnessHash());
558 BOOST_CHECK_MESSAGE(it_child->second.m_state.IsValid(), it_child->second.m_state.ToString());
561 BOOST_CHECK_EQUAL(it_child->second.m_wtxids_fee_calculations.value().front(), tx_child->GetWitnessHash());
563 expected_pool_size += 1;
567 auto mtx_single_low_fee = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
569 single_locking_script,
572 Package package_tx_single_low_fee{tx_single_low_fee};
574 package_tx_single_low_fee,
false, {});
578 BOOST_CHECK(!result_single_tx_low_fee.m_state.IsValid());
580 auto it_low_fee = result_single_tx_low_fee.m_tx_results.find(tx_single_low_fee->GetWitnessHash());
583 BOOST_ERROR(err_single.value());
601 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
609 witness1.
stack.emplace_back(1);
610 witness1.
stack.emplace_back(witnessScript.
begin(), witnessScript.
end());
613 witness2.
stack.emplace_back(2);
614 witness2.
stack.emplace_back(witnessScript.
begin(), witnessScript.
end());
620 mtx_child1.
vin.resize(1);
621 mtx_child1.
vin[0].prevout.hash = ptx_parent->GetHash();
622 mtx_child1.
vin[0].prevout.n = 0;
624 mtx_child1.
vin[0].scriptWitness = witness1;
625 mtx_child1.
vout.resize(1);
627 mtx_child1.
vout[0].scriptPubKey = child_locking_script;
630 mtx_child2.
vin[0].scriptWitness = witness2;
638 BOOST_CHECK(ptx_child1->GetWitnessHash() != ptx_child2->GetWitnessHash());
645 Package package_parent_child1{ptx_parent, ptx_child1};
647 package_parent_child1,
false, {});
649 BOOST_ERROR(err_witness1.value());
653 Package package_parent_child2{ptx_parent, ptx_child2};
655 package_parent_child2,
false, {});
657 BOOST_ERROR(err_witness2.value());
659 auto it_parent2_deduped = submit_witness2.m_tx_results.find(ptx_parent->GetWitnessHash());
660 auto it_child2 = submit_witness2.m_tx_results.find(ptx_child2->GetWitnessHash());
663 BOOST_CHECK_EQUAL(ptx_child1->GetWitnessHash(), it_child2->second.m_other_wtxid.value());
669 package_parent_child1,
false, {});
671 BOOST_ERROR(err_segwit_dedup.value());
673 auto it_parent_dup = submit_segwit_dedup.m_tx_results.find(ptx_parent->GetWitnessHash());
674 auto it_child_dup = submit_segwit_dedup.m_tx_results.find(ptx_child1->GetWitnessHash());
689 auto mtx_grandchild = CreateValidMempoolTransaction(ptx_child2, 0,
691 grandchild_locking_script,
698 Package package_child2_grandchild{ptx_child2, ptx_grandchild};
700 package_child2_grandchild,
false, {});
702 BOOST_ERROR(err_spend_ignored.value());
704 auto it_child2_ignored = submit_spend_ignored.m_tx_results.find(ptx_child2->GetWitnessHash());
705 auto it_grandchild = submit_spend_ignored.m_tx_results.find(ptx_grandchild->GetWitnessHash());
719 acs_witness.
stack.emplace_back(acs_script.
begin(), acs_script.
end());
722 auto mtx_parent1 = CreateValidMempoolTransaction(m_coinbase_txns[1], 0,
727 package_mixed.push_back(ptx_parent1);
733 parent2_witness1.
stack.emplace_back(1);
734 parent2_witness1.
stack.emplace_back(grandparent2_script.
begin(), grandparent2_script.
end());
736 parent2_witness2.
stack.emplace_back(2);
737 parent2_witness2.
stack.emplace_back(grandparent2_script.
begin(), grandparent2_script.
end());
740 auto mtx_grandparent2 = CreateValidMempoolTransaction(m_coinbase_txns[2], 0,
748 mtx_parent2_v1.
vin.resize(1);
749 mtx_parent2_v1.
vin[0].prevout.hash = ptx_grandparent2->GetHash();
750 mtx_parent2_v1.
vin[0].prevout.n = 0;
752 mtx_parent2_v1.
vin[0].scriptWitness = parent2_witness1;
753 mtx_parent2_v1.
vout.resize(1);
755 mtx_parent2_v1.
vout[0].scriptPubKey = acs_spk;
758 mtx_parent2_v2.
vin[0].scriptWitness = parent2_witness2;
765 package_mixed.push_back(ptx_parent2_v1);
768 auto mtx_parent3 = CreateValidMempoolTransaction(m_coinbase_txns[3], 0,
773 package_mixed.push_back(ptx_parent3);
782 mtx_mixed_child.
vin.emplace_back(
COutPoint(ptx_parent1->GetHash(), 0));
783 mtx_mixed_child.
vin.emplace_back(
COutPoint(ptx_parent2_v1->GetHash(), 0));
784 mtx_mixed_child.
vin.emplace_back(
COutPoint(ptx_parent3->GetHash(), 0));
785 mtx_mixed_child.
vin[0].scriptWitness = acs_witness;
786 mtx_mixed_child.
vin[1].scriptWitness = acs_witness;
787 mtx_mixed_child.
vin[2].scriptWitness = acs_witness;
788 mtx_mixed_child.
vout.emplace_back((48 + 49 + 50 - 1) *
COIN, mixed_child_spk);
790 package_mixed.push_back(ptx_mixed_child);
800 BOOST_ERROR(err_mixed.value());
802 auto it_parent1 = mixed_result.m_tx_results.find(ptx_parent1->GetWitnessHash());
803 auto it_parent2 = mixed_result.m_tx_results.find(ptx_parent2_v1->GetWitnessHash());
804 auto it_parent3 = mixed_result.m_tx_results.find(ptx_parent3->GetWitnessHash());
805 auto it_child = mixed_result.m_tx_results.find(ptx_mixed_child->GetWitnessHash());
811 BOOST_CHECK_EQUAL(ptx_parent2_v2->GetWitnessHash(), it_parent2->second.m_other_wtxid.value());
815 BOOST_CHECK(it_parent3->second.m_effective_feerate.value() == expected_feerate);
816 BOOST_CHECK(it_child->second.m_effective_feerate.value() == expected_feerate);
817 std::vector<Wtxid> expected_wtxids({ptx_parent3->GetWitnessHash(), ptx_mixed_child->GetWitnessHash()});
818 BOOST_CHECK(it_parent3->second.m_wtxids_fee_calculations.value() == expected_wtxids);
819 BOOST_CHECK(it_child->second.m_wtxids_fee_calculations.value() == expected_wtxids);
841 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
844 parent_value,
false);
846 package_cpfp.push_back(tx_parent);
848 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0,
853 package_cpfp.push_back(tx_child);
858 m_node.
mempool->PrioritiseTransaction(tx_parent->GetHash(), child_value - coinbase_value);
862 package_cpfp,
false, {});
864 BOOST_ERROR(err_cpfp_deprio.value());
867 BOOST_CHECK_EQUAL(submit_cpfp_deprio.m_tx_results.find(tx_parent->GetWitnessHash())->second.m_state.GetResult(),
869 BOOST_CHECK_EQUAL(submit_cpfp_deprio.m_tx_results.find(tx_child->GetWitnessHash())->second.m_state.GetResult(),
871 BOOST_CHECK(submit_cpfp_deprio.m_tx_results.find(tx_parent->GetWitnessHash())->second.m_state.GetRejectReason() ==
"min relay fee not met");
884 package_cpfp,
false, {});
886 BOOST_ERROR(err_cpfp.value());
888 auto it_parent = submit_cpfp.m_tx_results.find(tx_parent->GetWitnessHash());
889 auto it_child = submit_cpfp.m_tx_results.find(tx_child->GetWitnessHash());
891 BOOST_CHECK(it_parent->second.m_base_fees.value() == coinbase_value - parent_value);
895 const CFeeRate expected_feerate(coinbase_value - child_value,
897 BOOST_CHECK(it_parent->second.m_effective_feerate.value() == expected_feerate);
898 BOOST_CHECK(it_child->second.m_effective_feerate.value() == expected_feerate);
899 std::vector<Wtxid> expected_wtxids({tx_parent->GetWitnessHash(), tx_child->GetWitnessHash()});
900 BOOST_CHECK(it_parent->second.m_wtxids_fee_calculations.value() == expected_wtxids);
901 BOOST_CHECK(it_child->second.m_wtxids_fee_calculations.value() == expected_wtxids);
904 expected_pool_size += 2;
914 auto mtx_parent_cheap = CreateValidMempoolTransaction(m_coinbase_txns[1], 0,
917 coinbase_value - parent_fee,
false);
919 package_still_too_low.push_back(tx_parent_cheap);
923 auto mtx_child_cheap = CreateValidMempoolTransaction(tx_parent_cheap, 0,
926 coinbase_value - parent_fee - child_fee,
false);
928 package_still_too_low.push_back(tx_child_cheap);
936 package_still_too_low,
false, {});
938 BOOST_ERROR(err_package_too_low.value());
941 BOOST_CHECK_EQUAL(submit_package_too_low.m_tx_results.at(tx_parent_cheap->GetWitnessHash()).m_state.GetResult(),
943 BOOST_CHECK(submit_package_too_low.m_tx_results.at(tx_parent_cheap->GetWitnessHash()).m_effective_feerate.value() ==
946 BOOST_CHECK_EQUAL(submit_package_too_low.m_tx_results.at(tx_child_cheap->GetWitnessHash()).m_state.GetResult(),
948 BOOST_CHECK(submit_package_too_low.m_tx_results.at(tx_child_cheap->GetWitnessHash()).m_effective_feerate.value() ==
952 BOOST_CHECK_EQUAL(submit_package_too_low.m_state.GetRejectReason(),
"transaction failed");
962 package_still_too_low,
false, {});
964 BOOST_ERROR(err_prioritised.value());
966 const CFeeRate expected_feerate(1 *
COIN + parent_fee + child_fee,
968 BOOST_CHECK_EQUAL(submit_prioritised_package.m_tx_results.size(), package_still_too_low.size());
969 auto it_parent = submit_prioritised_package.m_tx_results.find(tx_parent_cheap->GetWitnessHash());
970 auto it_child = submit_prioritised_package.m_tx_results.find(tx_child_cheap->GetWitnessHash());
972 BOOST_CHECK(it_parent->second.m_base_fees.value() == parent_fee);
973 BOOST_CHECK(it_parent->second.m_effective_feerate.value() == expected_feerate);
975 BOOST_CHECK(it_child->second.m_base_fees.value() == child_fee);
976 BOOST_CHECK(it_child->second.m_effective_feerate.value() == expected_feerate);
977 std::vector<Wtxid> expected_wtxids({tx_parent_cheap->GetWitnessHash(), tx_child_cheap->GetWitnessHash()});
978 BOOST_CHECK(it_parent->second.m_wtxids_fee_calculations.value() == expected_wtxids);
979 BOOST_CHECK(it_child->second.m_wtxids_fee_calculations.value() == expected_wtxids);
981 expected_pool_size += 2;
992 auto mtx_parent_rich = CreateValidMempoolTransaction(m_coinbase_txns[2], 0,
995 coinbase_value - high_parent_fee,
false);
997 package_rich_parent.push_back(tx_parent_rich);
999 auto mtx_child_poor = CreateValidMempoolTransaction(tx_parent_rich, 0,
1002 coinbase_value - high_parent_fee,
false);
1004 package_rich_parent.push_back(tx_child_poor);
1010 package_rich_parent,
false, {});
1012 BOOST_ERROR(err_rich_parent.value());
1016 BOOST_CHECK_EQUAL(submit_rich_parent.m_state.GetRejectReason(),
"transaction failed");
1018 auto it_parent = submit_rich_parent.m_tx_results.find(tx_parent_rich->GetWitnessHash());
1019 auto it_child = submit_rich_parent.m_tx_results.find(tx_child_poor->GetWitnessHash());
1022 BOOST_CHECK(it_parent->second.m_state.GetRejectReason() ==
"");
1023 BOOST_CHECK_MESSAGE(it_parent->second.m_base_fees.value() == high_parent_fee,
1024 strprintf(
"rich parent: expected fee %s, got %s", high_parent_fee, it_parent->second.m_base_fees.value()));
1028 BOOST_CHECK(it_child->second.m_state.GetRejectReason() ==
"min relay fee not met");
1030 expected_pool_size += 1;
1053 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
1058 package1.push_back(tx_parent);
1059 package2.push_back(tx_parent);
1062 package1.push_back(tx_child_1);
1064 package2.push_back(tx_child_2);
1069 BOOST_ERROR(err_1.value());
1073 auto it_parent_1 = submit1.m_tx_results.find(tx_parent->GetWitnessHash());
1074 auto it_child_1 = submit1.m_tx_results.find(tx_child_1->GetWitnessHash());
1077 expected_pool_size += 2;
1082 BOOST_ERROR(err_2.value());
1086 auto it_parent_2 = submit2.m_tx_results.find(tx_parent->GetWitnessHash());
1087 auto it_child_2 = submit2.m_tx_results.find(tx_child_2->GetWitnessHash());
1099 m_coinbase_txns[1], 0, 0,
1100 coinbaseKey, parent_spk, coinbase_value - 200,
false));
1102 tx_parent_1, 0, 101,
1103 child_key, child_spk, coinbase_value - 400,
false));
1106 m_coinbase_txns[1], 0, 0,
1107 coinbaseKey, parent_spk, coinbase_value - 800,
false));
1109 tx_parent_2, 0, 101,
1110 child_key, child_spk, coinbase_value - 800 - 200,
false));
1113 m_coinbase_txns[1], 0, 0,
1114 coinbaseKey, parent_spk, coinbase_value - 199,
false));
1116 tx_parent_3, 0, 101,
1117 child_key, child_spk, coinbase_value - 199 - 1300,
false));
1120 BOOST_CHECK(tx_parent_1->GetHash() != tx_parent_2->GetHash() && tx_parent_2->GetHash() != tx_parent_3->GetHash());
1123 Package package1{tx_parent_1, tx_child_1};
1125 Package package2{tx_parent_2, tx_child_2};
1127 Package package3{tx_parent_3, tx_child_3};
1131 BOOST_ERROR(err_1.value());
1133 auto it_parent_1 = submit1.m_tx_results.find(tx_parent_1->GetWitnessHash());
1134 auto it_child_1 = submit1.m_tx_results.find(tx_child_1->GetWitnessHash());
1137 expected_pool_size += 2;
1144 BOOST_ERROR(err_2.value());
1146 auto it_parent_2 = submit2.m_tx_results.find(tx_parent_2->GetWitnessHash());
1147 auto it_child_2 = submit2.m_tx_results.find(tx_child_2->GetWitnessHash());
1155 BOOST_ERROR(err_3.value());
1157 auto it_parent_3 = submit3.m_tx_results.find(tx_parent_3->GetWitnessHash());
1158 auto it_child_3 = submit3.m_tx_results.find(tx_child_3->GetWitnessHash());
1163 BOOST_CHECK(it_parent_3->second.m_replaced_transactions.size() == 2);
1164 BOOST_CHECK(it_child_3->second.m_replaced_transactions.empty());
1166 std::vector<Wtxid> expected_package3_wtxids({tx_parent_3->GetWitnessHash(), tx_child_3->GetWitnessHash()});
1168 BOOST_CHECK(it_parent_3->second.m_wtxids_fee_calculations.value() == expected_package3_wtxids);
1169 BOOST_CHECK(it_child_3->second.m_wtxids_fee_calculations.value() == expected_package3_wtxids);
1170 BOOST_CHECK_EQUAL(it_parent_3->second.m_effective_feerate.value().GetFee(package3_total_vsize), 199 + 1300);
1171 BOOST_CHECK_EQUAL(it_child_3->second.m_effective_feerate.value().GetFee(package3_total_vsize), 199 + 1300);
1179 BOOST_ERROR(err_4.value());
1181 m_node.
mempool->PrioritiseTransaction(tx_child_1->GetHash(), 1363);
1184 BOOST_ERROR(err_5.value());
1186 it_parent_1 = submit5.m_tx_results.find(tx_parent_1->GetWitnessHash());
1187 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 kilovirtualbyte: CAmount / kvB.
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.
static GenTxid Txid(const uint256 &hash)
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 (...
uint256 GetPackageHash(const std::vector< CTransactionRef > &transactions)
Get the hash of these transactions' wtxids, concatenated in lexicographical order (treating the wtxid...
bool IsTopoSortedPackage(const Package &txns, std::unordered_set< uint256, SaltedTxidHasher > &later_txids)
IsTopoSortedPackage where a set of txids has been pre-populated.
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.