@@ -749,6 +749,43 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
749
749
pool.GetTransactionAncestry (ty6->GetHash (), ancestors, descendants);
750
750
BOOST_CHECK_EQUAL (ancestors, 9ULL );
751
751
BOOST_CHECK_EQUAL (descendants, 6ULL );
752
+
753
+ /* Ancestors represented more than once ("diamond") */
754
+ //
755
+ // [ta].0 <- [tb].0 -----<------- [td].0
756
+ // | |
757
+ // \---1 <- [tc].0 --<--/
758
+ //
759
+ CTransactionRef ta, tb, tc, td;
760
+ ta = make_tx (/* output_values */ {10 * COIN});
761
+ tb = make_tx (/* output_values */ {5 * COIN, 3 * COIN}, /* inputs */ {ta});
762
+ tc = make_tx (/* output_values */ {2 * COIN}, /* inputs */ {tb}, /* input_indices */ {1 });
763
+ td = make_tx (/* output_values */ {6 * COIN}, /* inputs */ {tb, tc}, /* input_indices */ {0 , 0 });
764
+ pool.clear ();
765
+ pool.addUnchecked (entry.Fee (10000LL ).FromTx (ta));
766
+ pool.addUnchecked (entry.Fee (10000LL ).FromTx (tb));
767
+ pool.addUnchecked (entry.Fee (10000LL ).FromTx (tc));
768
+ pool.addUnchecked (entry.Fee (10000LL ).FromTx (td));
769
+
770
+ // Ancestors / descendants should be:
771
+ // transaction ancestors descendants
772
+ // ============ =================== ===========
773
+ // ta 1 (ta 4 (ta,tb,tc,td)
774
+ // tb 2 (ta,tb) 4 (ta,tb,tc,td)
775
+ // tc 3 (ta,tb,tc) 4 (ta,tb,tc,td)
776
+ // td 4 (ta,tb,tc,td) 4 (ta,tb,tc,td)
777
+ pool.GetTransactionAncestry (ta->GetHash (), ancestors, descendants);
778
+ BOOST_CHECK_EQUAL (ancestors, 1ULL );
779
+ BOOST_CHECK_EQUAL (descendants, 4ULL );
780
+ pool.GetTransactionAncestry (tb->GetHash (), ancestors, descendants);
781
+ BOOST_CHECK_EQUAL (ancestors, 2ULL );
782
+ BOOST_CHECK_EQUAL (descendants, 4ULL );
783
+ pool.GetTransactionAncestry (tc->GetHash (), ancestors, descendants);
784
+ BOOST_CHECK_EQUAL (ancestors, 3ULL );
785
+ BOOST_CHECK_EQUAL (descendants, 4ULL );
786
+ pool.GetTransactionAncestry (td->GetHash (), ancestors, descendants);
787
+ BOOST_CHECK_EQUAL (ancestors, 4ULL );
788
+ BOOST_CHECK_EQUAL (descendants, 4ULL );
752
789
}
753
790
754
791
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments