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

Method CompareMainTransactions

src/txgraph.cpp:493–524  ·  view source on GitHub ↗

Compare two entries (which must both exist within the main graph). */

Source from the content-addressed store, hash-verified

491
492 /** Compare two entries (which must both exist within the main graph). */
493 std::strong_ordering CompareMainTransactions(GraphIndex a, GraphIndex b) const noexcept
494 {
495 if (a == b) return std::strong_ordering::equal;
496 Assume(a < m_entries.size() && b < m_entries.size());
497 const auto& entry_a = m_entries[a];
498 const auto& entry_b = m_entries[b];
499 // Compare chunk feerates, and return result if it differs.
500 auto feerate_cmp = ByRatio{entry_b.m_main_chunk_feerate} <=> ByRatio{entry_a.m_main_chunk_feerate};
501 if (feerate_cmp != 0) return feerate_cmp;
502 // Compare equal-feerate chunk prefix size for comparing equal chunk feerates. This does two
503 // things: it distinguishes equal-feerate chunks within the same cluster (because later
504 // ones will always have a higher prefix size), and it may distinguish equal-feerate chunks
505 // from distinct clusters.
506 if (entry_a.m_main_equal_feerate_chunk_prefix_size != entry_b.m_main_equal_feerate_chunk_prefix_size) {
507 return entry_a.m_main_equal_feerate_chunk_prefix_size <=> entry_b.m_main_equal_feerate_chunk_prefix_size;
508 }
509 // Compare by maximum m_fallback_order element to order equal-feerate chunks in distinct
510 // clusters, when the equal-feerate-prefix size is also the same.
511 const auto& locator_a = entry_a.m_locator[0];
512 const auto& locator_b = entry_b.m_locator[0];
513 Assume(locator_a.IsPresent() && locator_b.IsPresent());
514 if (locator_a.cluster != locator_b.cluster) {
515 auto fallback_cmp = m_fallback_order(*m_entries[entry_a.m_main_max_chunk_fallback].m_ref,
516 *m_entries[entry_b.m_main_max_chunk_fallback].m_ref);
517 if (fallback_cmp != 0) return fallback_cmp;
518 // This shouldn't be reachable as m_fallback_order defines a strong ordering.
519 Assume(false);
520 return CompareClusters(locator_a.cluster, locator_b.cluster);
521 }
522 // Within a single chunk, sort by position within cluster linearization.
523 return entry_a.m_main_lin_index <=> entry_b.m_main_lin_index;
524 }
525
526 /** Comparator for ChunkData objects in mining order. */
527 class ChunkOrder

Callers 1

operator()Method · 0.80

Calls 2

IsPresentMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected