21 #include <boost/test/unit_test.hpp>
32 mtx.
vin.resize(num_inputs);
33 mtx.
vout.resize(num_outputs);
35 for (
size_t i{0}; i < num_inputs; ++i) {
37 mtx.
vin[i].prevout.n = 0;
38 mtx.
vin[i].scriptSig = random_script;
40 for (
size_t o{0}; o < num_outputs; ++o) {
42 mtx.
vout[o].scriptPubKey = random_script;
57 ParseHex(
"02000000000101964b8aa63509579ca6086e6012eeaa4c2f4dd1e283da29b67c8eea38b3c6fd220000000000fdffffff0294c618000000000017a9145afbbb42f4e83312666d0697f9e66259912ecde38768fa2c0000000000160014897388a0889390fd0e153a22bb2cf9d8f019faf50247304402200547406380719f84d68cf4e96cc3e4a1688309ef475b150be2b471c70ea562aa02206d255f5acc40fd95981874d77201d2eb07883657ce1c796513f32b6079545cdf0121023ae77335cefcb5ab4c1dc1fb0d2acfece184e593727d7d5906c78e564c7c11d125cf0c00"),
64 ParseHex(
"01000000010b26e9b7735eb6aabdf358bab62f9816a21ba9ebdb719d5299e88607d722c190000000008b4830450220070aca44506c5cef3a16ed519d7c3c39f8aab192c4e1c90d065f37b8a4af6141022100a8e160b856c2d43d27d8fba71e5aef6405b8643ac4cb7cb3c462aced7f14711a0141046d11fee51b0e60666d5049a9101a72741df480b96ee26488a4d3466b95c9a40ac5eeef87e10a5cd336c19a84565f80fa6c547957b7700ff4dfbdefe76036c339ffffffff021bff3d11000000001976a91404943fdd508053c75000106d3bc6e2754dbcff1988ac2f15de00000000001976a914a266436d2965547608b9e15d9032a7b9d64fa43188ac00000000"),
71 ParseHex(
"0200000000010177862801f77c2c068a70372b4c435ef8dd621291c36a64eb4dd491f02218f5324600000000fdffffff014a0100000000000022512035ea312034cfac01e956a269f3bf147f569c2fbb00180677421262da042290d803402be713325ff285e66b0380f53f2fae0d0fb4e16f378a440fed51ce835061437566729d4883bc917632f3cff474d6384bc8b989961a1d730d4a87ed38ad28bd337b20f1d658c6c138b1c312e072b4446f50f01ae0da03a42e6274f8788aae53416a7fac0063036f7264010118746578742f706c61696e3b636861727365743d7574662d3800357b2270223a226272632d3230222c226f70223a226d696e74222c227469636b223a224342414c222c22616d74223a2236393639227d6821c1f1d658c6c138b1c312e072b4446f50f01ae0da03a42e6274f8788aae53416a7f00000000"),
77 Wtxid wtxid_1{
WtxidFromString(
"0x85cd1a31eb38f74ed5742ec9cb546712ab5aaf747de28a9168b53e846cbda17f")};
78 Wtxid wtxid_2{
WtxidFromString(
"0xb4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b")};
79 Wtxid wtxid_3{
WtxidFromString(
"0xe065bac15f62bb4e761d761db928ddee65a47296b2b776785abb912cdec474e3")};
88 Txid txid_1{
TxidFromString(
"0xbd0f71c1d5e50589063e134fad22053cdae5ab2320db5bf5e540198b0b5a4e69")};
89 Txid txid_2{
TxidFromString(
"0xb4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b")};
90 Txid txid_3{
TxidFromString(
"0xee707be5201160e32c4fc715bec227d1aeea5940fb4295605e7373edce3b1a93")};
97 BOOST_CHECK(txid_1.ToUint256() != wtxid_1.ToUint256());
98 BOOST_CHECK(txid_2.ToUint256() == wtxid_2.ToUint256());
99 BOOST_CHECK(txid_3.ToUint256() != wtxid_3.ToUint256());
108 std::vector<CTransactionRef> package_123{ptx_1, ptx_2, ptx_3};
109 std::vector<CTransactionRef> package_132{ptx_1, ptx_3, ptx_2};
110 std::vector<CTransactionRef> package_231{ptx_2, ptx_3, ptx_1};
111 std::vector<CTransactionRef> package_213{ptx_2, ptx_1, ptx_3};
112 std::vector<CTransactionRef> package_312{ptx_3, ptx_1, ptx_2};
113 std::vector<CTransactionRef> package_321{ptx_3, ptx_2, ptx_1};
115 uint256 calculated_hash_123 = (
HashWriter() << wtxid_1 << wtxid_2 << wtxid_3).GetSHA256();
117 uint256 hash_if_by_txid = (
HashWriter() << wtxid_2 << wtxid_1 << wtxid_3).GetSHA256();
118 BOOST_CHECK(hash_if_by_txid != calculated_hash_123);
120 uint256 hash_if_use_txid = (
HashWriter() << txid_2 << txid_1 << txid_3).GetSHA256();
121 BOOST_CHECK(hash_if_use_txid != calculated_hash_123);
123 uint256 hash_if_use_int_order = (
HashWriter() << wtxid_2 << wtxid_1 << wtxid_3).GetSHA256();
124 BOOST_CHECK(hash_if_use_int_order != calculated_hash_123);
151 size_t total_weight{0};
153 package_too_large.push_back(large_ptx);
154 total_weight += size_large;
163 Package package_duplicate_txids_empty;
164 for (
auto i{0}; i < 3; ++i) {
178 tx_zero_1.
vin.emplace_back(same_prevout);
179 tx_zero_2.
vin.emplace_back(same_prevout);
196 dup_tx.
vin.emplace_back(rand_prevout);
197 dup_tx.
vin.emplace_back(rand_prevout);
212 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
214 parent_locking_script,
220 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0,
222 child_locking_script,
225 Package package_parent_child{tx_parent, tx_child};
228 BOOST_ERROR(err_parent_child.value());
230 auto it_parent = result_parent_child.m_tx_results.find(tx_parent->GetWitnessHash());
231 auto it_child = result_parent_child.m_tx_results.find(tx_child->GetWitnessHash());
234 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().size(), 1);
235 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().front(), tx_parent->GetWitnessHash());
239 BOOST_CHECK_EQUAL(it_child->second.m_wtxids_fee_calculations.value().front(), tx_child->GetWitnessHash());
244 Package package_single_giant{giant_ptx};
247 BOOST_ERROR(err_single_large.value());
250 BOOST_CHECK_EQUAL(result_single_large.m_state.GetRejectReason(),
"transaction failed");
251 auto it_giant_tx = result_single_large.m_tx_results.find(giant_ptx->GetWitnessHash());
269 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0, 0, coinbaseKey, spk,
273 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0, 101, placeholder_key, spk2,
293 for (
int i{0}; i < 24; ++i) {
294 auto parent =
MakeTransactionRef(CreateValidMempoolTransaction(m_coinbase_txns[i + 1],
295 0, 0, coinbaseKey, spk,
CAmount(48 *
COIN),
false));
296 package.emplace_back(parent);
297 child.
vin.emplace_back(
COutPoint(parent->GetHash(), 0));
299 child.
vout.emplace_back(47 *
COIN, spk2);
306 std::shuffle(package.begin(), package.end(), rng);
314 package.erase(package.begin());
318 package.insert(package.begin(), m_coinbase_txns[0]);
325 mtx_parent.
vin.emplace_back(
COutPoint(m_coinbase_txns[0]->GetHash(), 0));
326 mtx_parent.
vout.emplace_back(20 *
COIN, spk);
327 mtx_parent.
vout.emplace_back(20 *
COIN, spk2);
331 mtx_parent_also_child.
vin.emplace_back(
COutPoint(tx_parent->GetHash(), 0));
332 mtx_parent_also_child.
vout.emplace_back(20 *
COIN, spk);
336 mtx_child.
vin.emplace_back(
COutPoint(tx_parent->GetHash(), 1));
337 mtx_child.
vin.emplace_back(
COutPoint(tx_parent_also_child->GetHash(), 0));
338 mtx_child.
vout.emplace_back(39 *
COIN, spk);
364 for (
size_t i{0}; i < 10; ++i) {
365 auto mtx = CreateValidMempoolTransaction(m_coinbase_txns[i + 25], 0,
367 parent_locking_script,
372 package_unrelated,
false, {});
374 BOOST_CHECK(result_unrelated_submit.m_state.IsInvalid());
376 BOOST_CHECK_EQUAL(result_unrelated_submit.m_state.GetRejectReason(),
"package-not-child-with-parents");
382 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
384 parent_locking_script,
387 package_parent_child.push_back(tx_parent);
388 package_3gen.push_back(tx_parent);
392 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0,
394 child_locking_script,
397 package_parent_child.push_back(tx_child);
398 package_3gen.push_back(tx_child);
402 auto mtx_grandchild = CreateValidMempoolTransaction(tx_child, 0,
404 grandchild_locking_script,
407 package_3gen.push_back(tx_grandchild);
412 package_3gen,
false, {});
413 BOOST_CHECK(result_3gen_submit.m_state.IsInvalid());
415 BOOST_CHECK_EQUAL(result_3gen_submit.m_state.GetRejectReason(),
"package-not-child-with-parents");
423 bad_witness.
stack.emplace_back(1);
425 mtx_parent_invalid.
vin[0].scriptWitness = bad_witness;
427 Package package_invalid_parent{tx_parent_invalid, tx_child};
429 package_invalid_parent,
false, {});
431 BOOST_ERROR(err_parent_invalid.value());
433 auto it_parent = result_quit_early.m_tx_results.find(tx_parent_invalid->GetWitnessHash());
434 auto it_child = result_quit_early.m_tx_results.find(tx_child->GetWitnessHash());
436 BOOST_CHECK_EQUAL(it_parent->second.m_state.GetRejectReason(),
"bad-witness-nonstandard");
438 BOOST_CHECK_EQUAL(it_child->second.m_state.GetRejectReason(),
"bad-txns-inputs-missingorspent");
444 mtx_child.vin.emplace_back(
COutPoint(package_unrelated[0]->GetHash(), 0));
445 Package package_missing_parent;
446 package_missing_parent.push_back(tx_parent);
450 package_missing_parent,
false, {});
451 BOOST_CHECK(result_missing_parent.m_state.IsInvalid());
453 BOOST_CHECK_EQUAL(result_missing_parent.m_state.GetRejectReason(),
"package-not-child-with-unconfirmed-parents");
460 package_parent_child,
false, {});
461 expected_pool_size += 2;
462 BOOST_CHECK_MESSAGE(submit_parent_child.m_state.IsValid(),
463 "Package validation unexpectedly failed: " << submit_parent_child.m_state.GetRejectReason());
464 BOOST_CHECK_EQUAL(submit_parent_child.m_tx_results.size(), package_parent_child.size());
465 auto it_parent = submit_parent_child.m_tx_results.find(tx_parent->GetWitnessHash());
466 auto it_child = submit_parent_child.m_tx_results.find(tx_child->GetWitnessHash());
467 BOOST_CHECK(it_parent != submit_parent_child.m_tx_results.end());
470 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().size(), 1);
471 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().front(), tx_parent->GetWitnessHash());
474 BOOST_CHECK_EQUAL(it_child->second.m_wtxids_fee_calculations.value().front(), tx_child->GetWitnessHash());
482 package_parent_child,
false, {});
484 BOOST_ERROR(err_deduped.value());
486 auto it_parent_deduped = submit_deduped.m_tx_results.find(tx_parent->GetWitnessHash());
487 auto it_child_deduped = submit_deduped.m_tx_results.find(tx_child->GetWitnessHash());
509 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
517 witness1.
stack.emplace_back(1);
518 witness1.
stack.emplace_back(witnessScript.
begin(), witnessScript.
end());
521 witness2.
stack.emplace_back(2);
522 witness2.
stack.emplace_back(witnessScript.
begin(), witnessScript.
end());
528 mtx_child1.
vin.resize(1);
529 mtx_child1.
vin[0].prevout.hash = ptx_parent->GetHash();
530 mtx_child1.
vin[0].prevout.n = 0;
532 mtx_child1.
vin[0].scriptWitness = witness1;
533 mtx_child1.
vout.resize(1);
535 mtx_child1.
vout[0].scriptPubKey = child_locking_script;
538 mtx_child2.
vin[0].scriptWitness = witness2;
546 BOOST_CHECK(ptx_child1->GetWitnessHash() != ptx_child2->GetWitnessHash());
553 Package package_parent_child1{ptx_parent, ptx_child1};
555 package_parent_child1,
false, {});
557 BOOST_ERROR(err_witness1.value());
561 Package package_parent_child2{ptx_parent, ptx_child2};
563 package_parent_child2,
false, {});
565 BOOST_ERROR(err_witness2.value());
567 auto it_parent2_deduped = submit_witness2.m_tx_results.find(ptx_parent->GetWitnessHash());
568 auto it_child2 = submit_witness2.m_tx_results.find(ptx_child2->GetWitnessHash());
571 BOOST_CHECK_EQUAL(ptx_child1->GetWitnessHash(), it_child2->second.m_other_wtxid.value());
577 package_parent_child1,
false, {});
579 BOOST_ERROR(err_segwit_dedup.value());
581 auto it_parent_dup = submit_segwit_dedup.m_tx_results.find(ptx_parent->GetWitnessHash());
582 auto it_child_dup = submit_segwit_dedup.m_tx_results.find(ptx_child1->GetWitnessHash());
597 auto mtx_grandchild = CreateValidMempoolTransaction(ptx_child2, 0,
599 grandchild_locking_script,
606 Package package_child2_grandchild{ptx_child2, ptx_grandchild};
608 package_child2_grandchild,
false, {});
610 BOOST_ERROR(err_spend_ignored.value());
612 auto it_child2_ignored = submit_spend_ignored.m_tx_results.find(ptx_child2->GetWitnessHash());
613 auto it_grandchild = submit_spend_ignored.m_tx_results.find(ptx_grandchild->GetWitnessHash());
627 acs_witness.
stack.emplace_back(acs_script.
begin(), acs_script.
end());
630 auto mtx_parent1 = CreateValidMempoolTransaction(m_coinbase_txns[1], 0,
635 package_mixed.push_back(ptx_parent1);
641 parent2_witness1.
stack.emplace_back(1);
642 parent2_witness1.
stack.emplace_back(grandparent2_script.
begin(), grandparent2_script.
end());
644 parent2_witness2.
stack.emplace_back(2);
645 parent2_witness2.
stack.emplace_back(grandparent2_script.
begin(), grandparent2_script.
end());
648 auto mtx_grandparent2 = CreateValidMempoolTransaction(m_coinbase_txns[2], 0,
656 mtx_parent2_v1.
vin.resize(1);
657 mtx_parent2_v1.
vin[0].prevout.hash = ptx_grandparent2->GetHash();
658 mtx_parent2_v1.
vin[0].prevout.n = 0;
660 mtx_parent2_v1.
vin[0].scriptWitness = parent2_witness1;
661 mtx_parent2_v1.
vout.resize(1);
663 mtx_parent2_v1.
vout[0].scriptPubKey = acs_spk;
666 mtx_parent2_v2.
vin[0].scriptWitness = parent2_witness2;
673 package_mixed.push_back(ptx_parent2_v1);
676 auto mtx_parent3 = CreateValidMempoolTransaction(m_coinbase_txns[3], 0,
681 package_mixed.push_back(ptx_parent3);
690 mtx_mixed_child.
vin.emplace_back(
COutPoint(ptx_parent1->GetHash(), 0));
691 mtx_mixed_child.
vin.emplace_back(
COutPoint(ptx_parent2_v1->GetHash(), 0));
692 mtx_mixed_child.
vin.emplace_back(
COutPoint(ptx_parent3->GetHash(), 0));
693 mtx_mixed_child.
vin[0].scriptWitness = acs_witness;
694 mtx_mixed_child.
vin[1].scriptWitness = acs_witness;
695 mtx_mixed_child.
vin[2].scriptWitness = acs_witness;
696 mtx_mixed_child.
vout.emplace_back((48 + 49 + 50 - 1) *
COIN, mixed_child_spk);
698 package_mixed.push_back(ptx_mixed_child);
708 BOOST_ERROR(err_mixed.value());
710 auto it_parent1 = mixed_result.m_tx_results.find(ptx_parent1->GetWitnessHash());
711 auto it_parent2 = mixed_result.m_tx_results.find(ptx_parent2_v1->GetWitnessHash());
712 auto it_parent3 = mixed_result.m_tx_results.find(ptx_parent3->GetWitnessHash());
713 auto it_child = mixed_result.m_tx_results.find(ptx_mixed_child->GetWitnessHash());
719 BOOST_CHECK_EQUAL(ptx_parent2_v2->GetWitnessHash(), it_parent2->second.m_other_wtxid.value());
723 BOOST_CHECK(it_parent3->second.m_effective_feerate.value() == expected_feerate);
724 BOOST_CHECK(it_child->second.m_effective_feerate.value() == expected_feerate);
725 std::vector<Wtxid> expected_wtxids({ptx_parent3->GetWitnessHash(), ptx_mixed_child->GetWitnessHash()});
726 BOOST_CHECK(it_parent3->second.m_wtxids_fee_calculations.value() == expected_wtxids);
727 BOOST_CHECK(it_child->second.m_wtxids_fee_calculations.value() == expected_wtxids);
749 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
752 parent_value,
false);
754 package_cpfp.push_back(tx_parent);
756 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0,
761 package_cpfp.push_back(tx_child);
766 m_node.
mempool->PrioritiseTransaction(tx_parent->GetHash(), child_value - coinbase_value);
770 package_cpfp,
false, {});
772 BOOST_ERROR(err_cpfp_deprio.value());
775 BOOST_CHECK_EQUAL(submit_cpfp_deprio.m_tx_results.find(tx_parent->GetWitnessHash())->second.m_state.GetResult(),
777 BOOST_CHECK_EQUAL(submit_cpfp_deprio.m_tx_results.find(tx_child->GetWitnessHash())->second.m_state.GetResult(),
779 BOOST_CHECK(submit_cpfp_deprio.m_tx_results.find(tx_parent->GetWitnessHash())->second.m_state.GetRejectReason() ==
"min relay fee not met");
792 package_cpfp,
false, {});
794 BOOST_ERROR(err_cpfp.value());
796 auto it_parent = submit_cpfp.m_tx_results.find(tx_parent->GetWitnessHash());
797 auto it_child = submit_cpfp.m_tx_results.find(tx_child->GetWitnessHash());
799 BOOST_CHECK(it_parent->second.m_base_fees.value() == coinbase_value - parent_value);
803 const CFeeRate expected_feerate(coinbase_value - child_value,
805 BOOST_CHECK(it_parent->second.m_effective_feerate.value() == expected_feerate);
806 BOOST_CHECK(it_child->second.m_effective_feerate.value() == expected_feerate);
807 std::vector<Wtxid> expected_wtxids({tx_parent->GetWitnessHash(), tx_child->GetWitnessHash()});
808 BOOST_CHECK(it_parent->second.m_wtxids_fee_calculations.value() == expected_wtxids);
809 BOOST_CHECK(it_child->second.m_wtxids_fee_calculations.value() == expected_wtxids);
812 expected_pool_size += 2;
822 auto mtx_parent_cheap = CreateValidMempoolTransaction(m_coinbase_txns[1], 0,
825 coinbase_value - parent_fee,
false);
827 package_still_too_low.push_back(tx_parent_cheap);
831 auto mtx_child_cheap = CreateValidMempoolTransaction(tx_parent_cheap, 0,
834 coinbase_value - parent_fee - child_fee,
false);
836 package_still_too_low.push_back(tx_child_cheap);
844 package_still_too_low,
false, {});
846 BOOST_ERROR(err_package_too_low.value());
849 BOOST_CHECK_EQUAL(submit_package_too_low.m_tx_results.at(tx_parent_cheap->GetWitnessHash()).m_state.GetResult(),
851 BOOST_CHECK(submit_package_too_low.m_tx_results.at(tx_parent_cheap->GetWitnessHash()).m_effective_feerate.value() ==
854 BOOST_CHECK_EQUAL(submit_package_too_low.m_tx_results.at(tx_child_cheap->GetWitnessHash()).m_state.GetResult(),
856 BOOST_CHECK(submit_package_too_low.m_tx_results.at(tx_child_cheap->GetWitnessHash()).m_effective_feerate.value() ==
860 BOOST_CHECK_EQUAL(submit_package_too_low.m_state.GetRejectReason(),
"transaction failed");
870 package_still_too_low,
false, {});
872 BOOST_ERROR(err_prioritised.value());
874 const CFeeRate expected_feerate(1 *
COIN + parent_fee + child_fee,
876 BOOST_CHECK_EQUAL(submit_prioritised_package.m_tx_results.size(), package_still_too_low.size());
877 auto it_parent = submit_prioritised_package.m_tx_results.find(tx_parent_cheap->GetWitnessHash());
878 auto it_child = submit_prioritised_package.m_tx_results.find(tx_child_cheap->GetWitnessHash());
880 BOOST_CHECK(it_parent->second.m_base_fees.value() == parent_fee);
881 BOOST_CHECK(it_parent->second.m_effective_feerate.value() == expected_feerate);
883 BOOST_CHECK(it_child->second.m_base_fees.value() == child_fee);
884 BOOST_CHECK(it_child->second.m_effective_feerate.value() == expected_feerate);
885 std::vector<Wtxid> expected_wtxids({tx_parent_cheap->GetWitnessHash(), tx_child_cheap->GetWitnessHash()});
886 BOOST_CHECK(it_parent->second.m_wtxids_fee_calculations.value() == expected_wtxids);
887 BOOST_CHECK(it_child->second.m_wtxids_fee_calculations.value() == expected_wtxids);
889 expected_pool_size += 2;
900 auto mtx_parent_rich = CreateValidMempoolTransaction(m_coinbase_txns[2], 0,
903 coinbase_value - high_parent_fee,
false);
905 package_rich_parent.push_back(tx_parent_rich);
907 auto mtx_child_poor = CreateValidMempoolTransaction(tx_parent_rich, 0,
910 coinbase_value - high_parent_fee,
false);
912 package_rich_parent.push_back(tx_child_poor);
918 package_rich_parent,
false, {});
920 BOOST_ERROR(err_rich_parent.value());
924 BOOST_CHECK_EQUAL(submit_rich_parent.m_state.GetRejectReason(),
"transaction failed");
926 auto it_parent = submit_rich_parent.m_tx_results.find(tx_parent_rich->GetWitnessHash());
927 auto it_child = submit_rich_parent.m_tx_results.find(tx_child_poor->GetWitnessHash());
930 BOOST_CHECK(it_parent->second.m_state.GetRejectReason() ==
"");
931 BOOST_CHECK_MESSAGE(it_parent->second.m_base_fees.value() == high_parent_fee,
932 strprintf(
"rich parent: expected fee %s, got %s", high_parent_fee, it_parent->second.m_base_fees.value()));
936 BOOST_CHECK(it_child->second.m_state.GetRejectReason() ==
"min relay fee not met");
938 expected_pool_size += 1;
961 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
966 package1.push_back(tx_parent);
967 package2.push_back(tx_parent);
970 package1.push_back(tx_child_1);
972 package2.push_back(tx_child_2);
977 BOOST_ERROR(err_1.value());
981 auto it_parent_1 = submit1.m_tx_results.find(tx_parent->GetWitnessHash());
982 auto it_child_1 = submit1.m_tx_results.find(tx_child_1->GetWitnessHash());
985 expected_pool_size += 2;
990 BOOST_ERROR(err_2.value());
994 auto it_parent_2 = submit2.m_tx_results.find(tx_parent->GetWitnessHash());
995 auto it_child_2 = submit2.m_tx_results.find(tx_child_2->GetWitnessHash());
1007 m_coinbase_txns[1], 0, 0,
1008 coinbaseKey, parent_spk, coinbase_value - 200,
false));
1010 tx_parent_1, 0, 101,
1011 child_key, child_spk, coinbase_value - 400,
false));
1014 m_coinbase_txns[1], 0, 0,
1015 coinbaseKey, parent_spk, coinbase_value - 800,
false));
1017 tx_parent_2, 0, 101,
1018 child_key, child_spk, coinbase_value - 800 - 200,
false));
1021 m_coinbase_txns[1], 0, 0,
1022 coinbaseKey, parent_spk, coinbase_value - 199,
false));
1024 tx_parent_3, 0, 101,
1025 child_key, child_spk, coinbase_value - 199 - 1300,
false));
1028 BOOST_CHECK(tx_parent_1->GetHash() != tx_parent_2->GetHash() && tx_parent_2->GetHash() != tx_parent_3->GetHash());
1031 Package package1{tx_parent_1, tx_child_1};
1033 Package package2{tx_parent_2, tx_child_2};
1035 Package package3{tx_parent_3, tx_child_3};
1039 BOOST_ERROR(err_1.value());
1041 auto it_parent_1 = submit1.m_tx_results.find(tx_parent_1->GetWitnessHash());
1042 auto it_child_1 = submit1.m_tx_results.find(tx_child_1->GetWitnessHash());
1045 expected_pool_size += 2;
1052 BOOST_ERROR(err_2.value());
1054 auto it_parent_2 = submit2.m_tx_results.find(tx_parent_2->GetWitnessHash());
1055 auto it_child_2 = submit2.m_tx_results.find(tx_child_2->GetWitnessHash());
1063 BOOST_ERROR(err_3.value());
1065 auto it_parent_3 = submit3.m_tx_results.find(tx_parent_3->GetWitnessHash());
1066 auto it_child_3 = submit3.m_tx_results.find(tx_child_3->GetWitnessHash());
1071 BOOST_CHECK(it_parent_3->second.m_replaced_transactions.size() == 2);
1072 BOOST_CHECK(it_child_3->second.m_replaced_transactions.empty());
1074 std::vector<Wtxid> expected_package3_wtxids({tx_parent_3->GetWitnessHash(), tx_child_3->GetWitnessHash()});
1076 BOOST_CHECK(it_parent_3->second.m_wtxids_fee_calculations.value() == expected_package3_wtxids);
1077 BOOST_CHECK(it_child_3->second.m_wtxids_fee_calculations.value() == expected_package3_wtxids);
1078 BOOST_CHECK_EQUAL(it_parent_3->second.m_effective_feerate.value().GetFee(package3_total_vsize), 199 + 1300);
1079 BOOST_CHECK_EQUAL(it_child_3->second.m_effective_feerate.value().GetFee(package3_total_vsize), 199 + 1300);
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 Txid & GetHash() const LIFETIMEBOUND
const Wtxid & GetWitnessHash() 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.
std::string GetRejectReason() const
transaction_identifier represents the two canonical transaction identifier types (txid,...
static transaction_identifier FromUint256(const uint256 &id)
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_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
CKey GenerateRandomKey(bool compressed) noexcept
#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
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
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.
std::unique_ptr< CTxMemPool > mempool
std::unique_ptr< ChainstateManager > chainman
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
static uint256 InsecureRand256()
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.
Txid TxidFromString(std::string_view str)
DEPRECATED due to missing length-check and hex-check, please use the safer FromHex,...
static const CAmount low_fee_amt
Wtxid WtxidFromString(std::string_view str)
BOOST_FIXTURE_TEST_CASE(package_hash_tests, TestChain100Setup)
CTransactionRef create_placeholder_tx(size_t num_inputs, size_t num_outputs)
uint256 uint256S(std::string_view str)
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.