MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / IsConsistentPackage

Function IsConsistentPackage

src/policy/packages.cpp:52–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52bool IsConsistentPackage(const Package& txns)
53{
54 // Don't allow any conflicting transactions, i.e. spending the same inputs, in a package.
55 std::unordered_set<COutPoint, SaltedOutpointHasher> inputs_seen;
56 for (const auto& tx : txns) {
57 if (tx->vin.empty()) {
58 // This function checks consistency based on inputs, and we can't do that if there are
59 // no inputs. Duplicate empty transactions are also not consistent with one another.
60 // This doesn't create false negatives, as unconfirmed transactions are not allowed to
61 // have no inputs.
62 return false;
63 }
64 for (const auto& input : tx->vin) {
65 if (inputs_seen.contains(input.prevout)) {
66 // This input is also present in another tx in the package.
67 return false;
68 }
69 }
70 // Batch-add all the inputs for a tx at a time. If we added them 1 at a time, we could
71 // catch duplicate inputs within a single tx. This is a more severe, consensus error,
72 // and we want to report that from CheckTransaction instead.
73 std::transform(tx->vin.cbegin(), tx->vin.cend(), std::inserter(inputs_seen, inputs_seen.end()),
74 [](const auto& input) { return input.prevout; });
75 }
76 return true;
77}
78
79bool IsWellFormedPackage(const Package& txns, PackageValidationState& state)
80{

Callers 2

IsWellFormedPackageFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 5

emptyMethod · 0.45
containsMethod · 0.45
cbeginMethod · 0.45
cendMethod · 0.45
endMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68