20 #include <boost/test/unit_test.hpp>
31 mtx.
vin.resize(num_inputs);
32 mtx.
vout.resize(num_outputs);
34 for (
size_t i{0}; i < num_inputs; ++i) {
36 mtx.
vin[i].prevout.n = 0;
37 mtx.
vin[i].scriptSig = random_script;
39 for (
size_t o{0}; o < num_outputs; ++o) {
41 mtx.
vout[o].scriptPubKey = random_script;
56 ParseHex(
"02000000000101964b8aa63509579ca6086e6012eeaa4c2f4dd1e283da29b67c8eea38b3c6fd220000000000fdffffff0294c618000000000017a9145afbbb42f4e83312666d0697f9e66259912ecde38768fa2c0000000000160014897388a0889390fd0e153a22bb2cf9d8f019faf50247304402200547406380719f84d68cf4e96cc3e4a1688309ef475b150be2b471c70ea562aa02206d255f5acc40fd95981874d77201d2eb07883657ce1c796513f32b6079545cdf0121023ae77335cefcb5ab4c1dc1fb0d2acfece184e593727d7d5906c78e564c7c11d125cf0c00"),
63 ParseHex(
"01000000010b26e9b7735eb6aabdf358bab62f9816a21ba9ebdb719d5299e88607d722c190000000008b4830450220070aca44506c5cef3a16ed519d7c3c39f8aab192c4e1c90d065f37b8a4af6141022100a8e160b856c2d43d27d8fba71e5aef6405b8643ac4cb7cb3c462aced7f14711a0141046d11fee51b0e60666d5049a9101a72741df480b96ee26488a4d3466b95c9a40ac5eeef87e10a5cd336c19a84565f80fa6c547957b7700ff4dfbdefe76036c339ffffffff021bff3d11000000001976a91404943fdd508053c75000106d3bc6e2754dbcff1988ac2f15de00000000001976a914a266436d2965547608b9e15d9032a7b9d64fa43188ac00000000"),
70 ParseHex(
"0200000000010177862801f77c2c068a70372b4c435ef8dd621291c36a64eb4dd491f02218f5324600000000fdffffff014a0100000000000022512035ea312034cfac01e956a269f3bf147f569c2fbb00180677421262da042290d803402be713325ff285e66b0380f53f2fae0d0fb4e16f378a440fed51ce835061437566729d4883bc917632f3cff474d6384bc8b989961a1d730d4a87ed38ad28bd337b20f1d658c6c138b1c312e072b4446f50f01ae0da03a42e6274f8788aae53416a7fac0063036f7264010118746578742f706c61696e3b636861727365743d7574662d3800357b2270223a226272632d3230222c226f70223a226d696e74222c227469636b223a224342414c222c22616d74223a2236393639227d6821c1f1d658c6c138b1c312e072b4446f50f01ae0da03a42e6274f8788aae53416a7f00000000"),
76 Wtxid wtxid_1{
WtxidFromString(
"0x85cd1a31eb38f74ed5742ec9cb546712ab5aaf747de28a9168b53e846cbda17f")};
77 Wtxid wtxid_2{
WtxidFromString(
"0xb4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b")};
78 Wtxid wtxid_3{
WtxidFromString(
"0xe065bac15f62bb4e761d761db928ddee65a47296b2b776785abb912cdec474e3")};
87 Txid txid_1{
TxidFromString(
"0xbd0f71c1d5e50589063e134fad22053cdae5ab2320db5bf5e540198b0b5a4e69")};
88 Txid txid_2{
TxidFromString(
"0xb4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b")};
89 Txid txid_3{
TxidFromString(
"0xee707be5201160e32c4fc715bec227d1aeea5940fb4295605e7373edce3b1a93")};
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);
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);
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,
292 for (
int i{0}; i < 24; ++i) {
293 auto parent =
MakeTransactionRef(CreateValidMempoolTransaction(m_coinbase_txns[i + 1],
294 0, 0, coinbaseKey, spk,
CAmount(48 *
COIN),
false));
295 package.emplace_back(parent);
296 child.
vin.emplace_back(
COutPoint(parent->GetHash(), 0));
298 child.
vout.emplace_back(47 *
COIN, spk2);
305 Shuffle(package.begin(), package.end(), rng);
313 package.erase(package.begin());
317 package.insert(package.begin(), m_coinbase_txns[0]);
324 mtx_parent.
vin.emplace_back(
COutPoint(m_coinbase_txns[0]->GetHash(), 0));
325 mtx_parent.
vout.emplace_back(20 *
COIN, spk);
326 mtx_parent.
vout.emplace_back(20 *
COIN, spk2);
330 mtx_parent_also_child.
vin.emplace_back(
COutPoint(tx_parent->GetHash(), 0));
331 mtx_parent_also_child.
vout.emplace_back(20 *
COIN, spk);
335 mtx_child.
vin.emplace_back(
COutPoint(tx_parent->GetHash(), 1));
336 mtx_child.
vin.emplace_back(
COutPoint(tx_parent_also_child->GetHash(), 0));
337 mtx_child.
vout.emplace_back(39 *
COIN, spk);
363 for (
size_t i{0}; i < 10; ++i) {
364 auto mtx = CreateValidMempoolTransaction(m_coinbase_txns[i + 25], 0,
366 parent_locking_script,
371 package_unrelated,
false, {});
373 BOOST_CHECK(result_unrelated_submit.m_state.IsInvalid());
375 BOOST_CHECK_EQUAL(result_unrelated_submit.m_state.GetRejectReason(),
"package-not-child-with-parents");
381 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
383 parent_locking_script,
386 package_parent_child.push_back(tx_parent);
387 package_3gen.push_back(tx_parent);
391 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0,
393 child_locking_script,
396 package_parent_child.push_back(tx_child);
397 package_3gen.push_back(tx_child);
401 auto mtx_grandchild = CreateValidMempoolTransaction(tx_child, 0,
403 grandchild_locking_script,
406 package_3gen.push_back(tx_grandchild);
411 package_3gen,
false, {});
412 BOOST_CHECK(result_3gen_submit.m_state.IsInvalid());
414 BOOST_CHECK_EQUAL(result_3gen_submit.m_state.GetRejectReason(),
"package-not-child-with-parents");
422 bad_witness.
stack.emplace_back(1);
424 mtx_parent_invalid.
vin[0].scriptWitness = bad_witness;
426 Package package_invalid_parent{tx_parent_invalid, tx_child};
428 package_invalid_parent,
false, {});
430 BOOST_ERROR(err_parent_invalid.value());
432 auto it_parent = result_quit_early.m_tx_results.find(tx_parent_invalid->GetWitnessHash());
433 auto it_child = result_quit_early.m_tx_results.find(tx_child->GetWitnessHash());
435 BOOST_CHECK_EQUAL(it_parent->second.m_state.GetRejectReason(),
"bad-witness-nonstandard");
437 BOOST_CHECK_EQUAL(it_child->second.m_state.GetRejectReason(),
"bad-txns-inputs-missingorspent");
443 mtx_child.vin.emplace_back(
COutPoint(package_unrelated[0]->GetHash(), 0));
444 Package package_missing_parent;
445 package_missing_parent.push_back(tx_parent);
449 package_missing_parent,
false, {});
450 BOOST_CHECK(result_missing_parent.m_state.IsInvalid());
452 BOOST_CHECK_EQUAL(result_missing_parent.m_state.GetRejectReason(),
"package-not-child-with-unconfirmed-parents");
459 package_parent_child,
false, {});
460 expected_pool_size += 2;
461 BOOST_CHECK_MESSAGE(submit_parent_child.m_state.IsValid(),
462 "Package validation unexpectedly failed: " << submit_parent_child.m_state.GetRejectReason());
463 BOOST_CHECK_EQUAL(submit_parent_child.m_tx_results.size(), package_parent_child.size());
464 auto it_parent = submit_parent_child.m_tx_results.find(tx_parent->GetWitnessHash());
465 auto it_child = submit_parent_child.m_tx_results.find(tx_child->GetWitnessHash());
466 BOOST_CHECK(it_parent != submit_parent_child.m_tx_results.end());
469 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().size(), 1);
470 BOOST_CHECK_EQUAL(it_parent->second.m_wtxids_fee_calculations.value().front(), tx_parent->GetWitnessHash());
473 BOOST_CHECK_EQUAL(it_child->second.m_wtxids_fee_calculations.value().front(), tx_child->GetWitnessHash());
481 package_parent_child,
false, {});
483 BOOST_ERROR(err_deduped.value());
485 auto it_parent_deduped = submit_deduped.m_tx_results.find(tx_parent->GetWitnessHash());
486 auto it_child_deduped = submit_deduped.m_tx_results.find(tx_child->GetWitnessHash());
508 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
516 witness1.
stack.emplace_back(1);
517 witness1.
stack.emplace_back(witnessScript.
begin(), witnessScript.
end());
520 witness2.
stack.emplace_back(2);
521 witness2.
stack.emplace_back(witnessScript.
begin(), witnessScript.
end());
527 mtx_child1.
vin.resize(1);
528 mtx_child1.
vin[0].prevout.hash = ptx_parent->GetHash();
529 mtx_child1.
vin[0].prevout.n = 0;
531 mtx_child1.
vin[0].scriptWitness = witness1;
532 mtx_child1.
vout.resize(1);
534 mtx_child1.
vout[0].scriptPubKey = child_locking_script;
537 mtx_child2.
vin[0].scriptWitness = witness2;
545 BOOST_CHECK(ptx_child1->GetWitnessHash() != ptx_child2->GetWitnessHash());
552 Package package_parent_child1{ptx_parent, ptx_child1};
554 package_parent_child1,
false, {});
556 BOOST_ERROR(err_witness1.value());
560 Package package_parent_child2{ptx_parent, ptx_child2};
562 package_parent_child2,
false, {});
564 BOOST_ERROR(err_witness2.value());
566 auto it_parent2_deduped = submit_witness2.m_tx_results.find(ptx_parent->GetWitnessHash());
567 auto it_child2 = submit_witness2.m_tx_results.find(ptx_child2->GetWitnessHash());
570 BOOST_CHECK_EQUAL(ptx_child1->GetWitnessHash(), it_child2->second.m_other_wtxid.value());
576 package_parent_child1,
false, {});
578 BOOST_ERROR(err_segwit_dedup.value());
580 auto it_parent_dup = submit_segwit_dedup.m_tx_results.find(ptx_parent->GetWitnessHash());
581 auto it_child_dup = submit_segwit_dedup.m_tx_results.find(ptx_child1->GetWitnessHash());
596 auto mtx_grandchild = CreateValidMempoolTransaction(ptx_child2, 0,
598 grandchild_locking_script,
605 Package package_child2_grandchild{ptx_child2, ptx_grandchild};
607 package_child2_grandchild,
false, {});
609 BOOST_ERROR(err_spend_ignored.value());
611 auto it_child2_ignored = submit_spend_ignored.m_tx_results.find(ptx_child2->GetWitnessHash());
612 auto it_grandchild = submit_spend_ignored.m_tx_results.find(ptx_grandchild->GetWitnessHash());
626 acs_witness.
stack.emplace_back(acs_script.
begin(), acs_script.
end());
629 auto mtx_parent1 = CreateValidMempoolTransaction(m_coinbase_txns[1], 0,
634 package_mixed.push_back(ptx_parent1);
640 parent2_witness1.
stack.emplace_back(1);
641 parent2_witness1.
stack.emplace_back(grandparent2_script.
begin(), grandparent2_script.
end());
643 parent2_witness2.
stack.emplace_back(2);
644 parent2_witness2.
stack.emplace_back(grandparent2_script.
begin(), grandparent2_script.
end());
647 auto mtx_grandparent2 = CreateValidMempoolTransaction(m_coinbase_txns[2], 0,
655 mtx_parent2_v1.
vin.resize(1);
656 mtx_parent2_v1.
vin[0].prevout.hash = ptx_grandparent2->GetHash();
657 mtx_parent2_v1.
vin[0].prevout.n = 0;
659 mtx_parent2_v1.
vin[0].scriptWitness = parent2_witness1;
660 mtx_parent2_v1.
vout.resize(1);
662 mtx_parent2_v1.
vout[0].scriptPubKey = acs_spk;
665 mtx_parent2_v2.
vin[0].scriptWitness = parent2_witness2;
672 package_mixed.push_back(ptx_parent2_v1);
675 auto mtx_parent3 = CreateValidMempoolTransaction(m_coinbase_txns[3], 0,
680 package_mixed.push_back(ptx_parent3);
689 mtx_mixed_child.
vin.emplace_back(
COutPoint(ptx_parent1->GetHash(), 0));
690 mtx_mixed_child.
vin.emplace_back(
COutPoint(ptx_parent2_v1->GetHash(), 0));
691 mtx_mixed_child.
vin.emplace_back(
COutPoint(ptx_parent3->GetHash(), 0));
692 mtx_mixed_child.
vin[0].scriptWitness = acs_witness;
693 mtx_mixed_child.
vin[1].scriptWitness = acs_witness;
694 mtx_mixed_child.
vin[2].scriptWitness = acs_witness;
695 mtx_mixed_child.
vout.emplace_back((48 + 49 + 50 - 1) *
COIN, mixed_child_spk);
697 package_mixed.push_back(ptx_mixed_child);
707 BOOST_ERROR(err_mixed.value());
709 auto it_parent1 = mixed_result.m_tx_results.find(ptx_parent1->GetWitnessHash());
710 auto it_parent2 = mixed_result.m_tx_results.find(ptx_parent2_v1->GetWitnessHash());
711 auto it_parent3 = mixed_result.m_tx_results.find(ptx_parent3->GetWitnessHash());
712 auto it_child = mixed_result.m_tx_results.find(ptx_mixed_child->GetWitnessHash());
718 BOOST_CHECK_EQUAL(ptx_parent2_v2->GetWitnessHash(), it_parent2->second.m_other_wtxid.value());
722 BOOST_CHECK(it_parent3->second.m_effective_feerate.value() == expected_feerate);
723 BOOST_CHECK(it_child->second.m_effective_feerate.value() == expected_feerate);
724 std::vector<Wtxid> expected_wtxids({ptx_parent3->GetWitnessHash(), ptx_mixed_child->GetWitnessHash()});
725 BOOST_CHECK(it_parent3->second.m_wtxids_fee_calculations.value() == expected_wtxids);
726 BOOST_CHECK(it_child->second.m_wtxids_fee_calculations.value() == expected_wtxids);
748 auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[0], 0,
751 parent_value,
false);
753 package_cpfp.push_back(tx_parent);
755 auto mtx_child = CreateValidMempoolTransaction(tx_parent, 0,
760 package_cpfp.push_back(tx_child);
765 m_node.
mempool->PrioritiseTransaction(tx_parent->GetHash(), child_value - coinbase_value);
769 package_cpfp,
false, {});
771 BOOST_ERROR(err_cpfp_deprio.value());
774 BOOST_CHECK_EQUAL(submit_cpfp_deprio.m_tx_results.find(tx_parent->GetWitnessHash())->second.m_state.GetResult(),
776 BOOST_CHECK_EQUAL(submit_cpfp_deprio.m_tx_results.find(tx_child->GetWitnessHash())->second.m_state.GetResult(),
778 BOOST_CHECK(submit_cpfp_deprio.m_tx_results.find(tx_parent->GetWitnessHash())->second.m_state.GetRejectReason() ==
"min relay fee not met");
791 package_cpfp,
false, {});
793 BOOST_ERROR(err_cpfp.value());
795 auto it_parent = submit_cpfp.m_tx_results.find(tx_parent->GetWitnessHash());
796 auto it_child = submit_cpfp.m_tx_results.find(tx_child->GetWitnessHash());
798 BOOST_CHECK(it_parent->second.m_base_fees.value() == coinbase_value - parent_value);
802 const CFeeRate expected_feerate(coinbase_value - child_value,
804 BOOST_CHECK(it_parent->second.m_effective_feerate.value() == expected_feerate);
805 BOOST_CHECK(it_child->second.m_effective_feerate.value() == expected_feerate);
806 std::vector<Wtxid> expected_wtxids({tx_parent->GetWitnessHash(), tx_child->GetWitnessHash()});
807 BOOST_CHECK(it_parent->second.m_wtxids_fee_calculations.value() == expected_wtxids);
808 BOOST_CHECK(it_child->second.m_wtxids_fee_calculations.value() == expected_wtxids);
811 expected_pool_size += 2;
821 auto mtx_parent_cheap = CreateValidMempoolTransaction(m_coinbase_txns[1], 0,
824 coinbase_value - parent_fee,
false);
826 package_still_too_low.push_back(tx_parent_cheap);
830 auto mtx_child_cheap = CreateValidMempoolTransaction(tx_parent_cheap, 0,
833 coinbase_value - parent_fee - child_fee,
false);
835 package_still_too_low.push_back(tx_child_cheap);
843 package_still_too_low,
false, {});
845 BOOST_ERROR(err_package_too_low.value());
848 BOOST_CHECK_EQUAL(submit_package_too_low.m_tx_results.at(tx_parent_cheap->GetWitnessHash()).m_state.GetResult(),
850 BOOST_CHECK(submit_package_too_low.m_tx_results.at(tx_parent_cheap->GetWitnessHash()).m_effective_feerate.value() ==
853 BOOST_CHECK_EQUAL(submit_package_too_low.m_tx_results.at(tx_child_cheap->GetWitnessHash()).m_state.GetResult(),
855 BOOST_CHECK(submit_package_too_low.m_tx_results.at(tx_child_cheap->GetWitnessHash()).m_effective_feerate.value() ==
859 BOOST_CHECK_EQUAL(submit_package_too_low.m_state.GetRejectReason(),
"transaction failed");
869 package_still_too_low,
false, {});
871 BOOST_ERROR(err_prioritised.value());
873 const CFeeRate expected_feerate(1 *
COIN + parent_fee + child_fee,
875 BOOST_CHECK_EQUAL(submit_prioritised_package.m_tx_results.size(), package_still_too_low.size());
876 auto it_parent = submit_prioritised_package.m_tx_results.find(tx_parent_cheap->GetWitnessHash());
877 auto it_child = submit_prioritised_package.m_tx_results.find(tx_child_cheap->GetWitnessHash());
879 BOOST_CHECK(it_parent->second.m_base_fees.value() == parent_fee);
880 BOOST_CHECK(it_parent->second.m_effective_feerate.value() == expected_feerate);
882 BOOST_CHECK(it_child->second.m_base_fees.value() == child_fee);
883 BOOST_CHECK(it_child->second.m_effective_feerate.value() == expected_feerate);
884 std::vector<Wtxid> expected_wtxids({tx_parent_cheap->GetWitnessHash(), tx_child_cheap->GetWitnessHash()});
885 BOOST_CHECK(it_parent->second.m_wtxids_fee_calculations.value() == expected_wtxids);
886 BOOST_CHECK(it_child->second.m_wtxids_fee_calculations.value() == expected_wtxids);
888 expected_pool_size += 2;
899 auto mtx_parent_rich = CreateValidMempoolTransaction(m_coinbase_txns[2], 0,
902 coinbase_value - high_parent_fee,
false);
904 package_rich_parent.push_back(tx_parent_rich);
906 auto mtx_child_poor = CreateValidMempoolTransaction(tx_parent_rich, 0,
909 coinbase_value - high_parent_fee,
false);
911 package_rich_parent.push_back(tx_child_poor);
917 package_rich_parent,
false, {});
919 BOOST_ERROR(err_rich_parent.value());
923 BOOST_CHECK_EQUAL(submit_rich_parent.m_state.GetRejectReason(),
"transaction failed");
925 auto it_parent = submit_rich_parent.m_tx_results.find(tx_parent_rich->GetWitnessHash());
926 auto it_child = submit_rich_parent.m_tx_results.find(tx_child_poor->GetWitnessHash());
929 BOOST_CHECK(it_parent->second.m_state.GetRejectReason() ==
"");
930 BOOST_CHECK_MESSAGE(it_parent->second.m_base_fees.value() == high_parent_fee,
931 strprintf(
"rich parent: expected fee %s, got %s", high_parent_fee, it_parent->second.m_base_fees.value()));
935 BOOST_CHECK(it_child->second.m_state.GetRejectReason() ==
"min relay fee not met");
937 expected_pool_size += 1;
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.
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
void Shuffle(I first, I last, R &&rng)
More efficient than using std::shuffle on a FastRandomContext.
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)
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(const char *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.