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

Function IsTopoSortedPackage

src/policy/packages.cpp:19–41  ·  view source on GitHub ↗

IsTopoSortedPackage where a set of txids has been pre-populated. The set is assumed to be correct and * is mutated within this function (even if return value is false). */

Source from the content-addressed store, hash-verified

17/** IsTopoSortedPackage where a set of txids has been pre-populated. The set is assumed to be correct and
18 * is mutated within this function (even if return value is false). */
19bool IsTopoSortedPackage(const Package& txns, std::unordered_set<Txid, SaltedTxidHasher>& later_txids)
20{
21 // Avoid misusing this function: later_txids should contain the txids of txns.
22 Assume(txns.size() == later_txids.size());
23
24 // later_txids always contains the txids of this transaction and the ones that come later in
25 // txns. If any transaction's input spends a tx in that set, we've found a parent placed later
26 // than its child.
27 for (const auto& tx : txns) {
28 for (const auto& input : tx->vin) {
29 if (later_txids.contains(input.prevout.hash)) {
30 // The parent is a subsequent transaction in the package.
31 return false;
32 }
33 }
34 // Avoid misusing this function: later_txids must contain every tx.
35 Assume(later_txids.erase(tx->GetHash()) == 1);
36 }
37
38 // Avoid misusing this function: later_txids should have contained the txids of txns.
39 Assume(later_txids.empty());
40 return true;
41}
42
43bool IsTopoSortedPackage(const Package& txns)
44{

Callers 2

IsWellFormedPackageFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 8

sizeMethod · 0.45
containsMethod · 0.45
eraseMethod · 0.45
GetHashMethod · 0.45
emptyMethod · 0.45
cbeginMethod · 0.45
cendMethod · 0.45
endMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68