1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150
crate::ix!();
//-------------------------------------------[.cpp/bitcoin/src/txmempool.h]
//-------------------------------------------[.cpp/bitcoin/src/txmempool.cpp]
/**
| Fake height value used in Coin to signify
| they are only in the memory pool (since
| 0.8)
|
*/
pub const MEMPOOL_HEIGHT: u32 = 0x7FFFFFFF;
/**
| Multi_index tag names
|
*/
pub struct DescendantScore {}
pub struct EntryTime {}
pub struct AncestorScore {}
pub struct IndexByWTxid {}
pub struct TxIdIndex {}
pub struct InsertionOrder {}
/**
| TxMemPool stores
| valid-according-to-the-current-best-chain
| transactions that may be included in the next
| block.
|
| Transactions are added when they are seen on
| the network (or created by the local node), but
| not all transactions seen are added to the
| pool. For example, the following new
| transactions will not be added to the mempool:
|
| - a transaction which doesn't meet the minimum
| fee requirements.
|
| - a new transaction that double-spends an input
| of a transaction already in the pool where the
| new transaction does not meet the
| Replace-By-Fee requirements as defined in BIP
| 125.
|
| - a non-standard transaction.
|
| TxMemPool::mapTx, and TxMemPoolEntry
| bookkeeping:
|
| mapTx is a boost::multi_index that sorts the
| mempool on 5 criteria:
|
| - transaction hash (txid)
|
| - witness-transaction hash (wtxid)
|
| - descendant feerate [we use max(feerate of tx,
| feerate of tx with all descendants)]
|
| - time in mempool
|
| - ancestor feerate [we use min(feerate of tx,
| feerate of tx with all unconfirmed ancestors)]
|
| Note: the term "descendant" refers to
| in-mempool transactions that depend on this
| one, while "ancestor" refers to in-mempool
| transactions that a given transaction depends
| on.
|
| In order for the feerate sort to remain
| correct, we must update transactions in the
| mempool when new descendants arrive. To
| facilitate this, we track the set of in-mempool
| direct parents and direct children in mapLinks.
| Within each TxMemPoolEntry, we track the size
| and fees of all descendants.
|
| Usually when a new transaction is added to the
| mempool, it has no in-mempool children (because
| any such children would be an orphan). So in
| addUnchecked(), we:
|
| - update a new entry's setMemPoolParents to
| include all in-mempool parents
|
| - update the new entry's direct parents to
| include the new tx as a child
|
| - update all ancestors of the transaction to
| include the new tx's size/fee
|
| When a transaction is removed from the mempool,
| we must:
|
| - update all in-mempool parents to not track
| the tx in setMemPoolChildren
|
| - update all ancestors to not include the tx's
| size/fees in descendant state
|
| - update all in-mempool children to not include
| it as a parent
|
| These happen in UpdateForRemoveFromMempool().
| (Note that when removing a transaction along
| with its descendants, we must calculate
| that set of transactions to be removed
| before doing the removal, or else the
| mempool can be in an inconsistent state
| where it's impossible to walk the ancestors
| of a transaction.)
|
| In the event of a reorg, the assumption that
| a newly added tx has no in-mempool children is
| false.
|
| In particular, the mempool is in an
| inconsistent state while new transactions are
| being added, because there may be descendant
| transactions of a tx coming from a disconnected
| block that are unreachable from just looking at
| transactions in the mempool (the linking
| transactions may also be in the
| disconnected block, waiting to be added).
|
| Because of this, there's not much benefit in
| trying to search for in-mempool children in
| addUnchecked().
|
| Instead, in the special case of transactions
| being added from a disconnected block, we
| require the caller to clean up the state, to
| account for in-mempool, out-of-block
| descendants for all the in-block transactions
| by calling UpdateTransactionsFromBlock().
|
| Note that until this is called, the mempool
| state is not consistent, and in particular
| mapLinks may not be correct (and therefore
| functions like CalculateMemPoolAncestors()
| and CalculateDescendants() that rely on
| them to walk the mempool are not generally safe
| to use).
|
| Computational limits:
|
| Updating all in-mempool ancestors of a newly
| added transaction can be slow, if no bound
| exists on how many in-mempool ancestors there
| may be.
|
| CalculateMemPoolAncestors() takes configurable
| limits that are designed to prevent these
| calculations from being too CPU intensive.
|
*/
pub struct TxMemPool {
/**
| Value n means that 1 times in n we check.
|
*/
pub check_ratio: i32,
/**
| Used by getblocktemplate to trigger
| CreateNewBlock() invocation
|
*/
pub n_transactions_updated: AtomicU32, // default = { 0 }
pub miner_policy_estimator: Arc<BlockPolicyEstimator>,
/**
| This mutex needs to be locked when
| accessing `mapTx` or other members that are
| guarded by it.
|
| @par Consistency guarantees
|
| By design, it is guaranteed that:
|
| 1. Locking both `cs_main` and
| `mempool.cs` will give a view of mempool
| that is consistent with current chain
| tip (`ActiveChain()` and `CoinsTip()`)
| and is fully populated. Fully populated
| means that if the current active chain
| is missing transactions that were
| present in a previously active chain,
| all the missing transactions will have
| been re-added to the mempool and should
| be present if they meet size and
| consistency constraints.
|
| 2. Locking `mempool.cs` without `cs_main`
| will give a view of a mempool consistent
| with some chain that was active since
| `cs_main` was last locked, and that is
| fully populated as described
| above. It is ok for code that only needs
| to query or remove transactions from the
| mempool to lock just `mempool.cs`
| without `cs_main`.
|
| To provide these guarantees, it is
| necessary to lock both `cs_main` and
| `mempool.cs` whenever adding transactions
| to the mempool and whenever changing the
| chain tip. It's necessary to keep both
| mutexes locked until the mempool is
| consistent with the new chain tip and fully
| populated.
*/
pub cs: Arc<Mutex<TxMemPoolInner>>,
}
pub struct TxMemPoolInner {
/**
| sum of all mempool tx's virtual sizes.
| Differs from serialized tx size since
| witness data is discounted. Defined
| in BIP 141.
|
*/
pub total_tx_size: u64,
/**
| sum of all mempool tx's fees (NOT modified
| fee)
|
*/
pub total_fee: Amount,
/**
| sum of dynamic memory usage of all the
| map elements (NOT the maps themselves)
|
*/
pub cached_inner_usage: u64,
pub last_rolling_fee_update: Arc<Mutex<i64>>,
pub block_since_last_rolling_fee_bump: AtomicBool,
/**
| minimum fee to get into the pool, decreases
| exponentially
|
*/
pub rolling_minimum_fee_rate: AtomicF64,
pub epoch: Arc<Mutex<Epoch>>,
/**
| In-memory counter for external mempool
| tracking purposes.
|
| This number is incremented once every time
| a transaction is added or removed from the
| mempool for any reason.
*/
pub sequence_number: RefCell<u64>, // default = { 1 }
pub is_loaded: bool, // default = { false }
pub map_tx: TxMemPoolIndexedTransactionSet,
/**
| All tx witness hashes/entries in mapTx,
| in random order
|
*/
pub tx_hashes: Vec<(u256,TxMemPoolTxIter)>,
/**
| Track locally submitted transactions
| to periodically retry initial broadcast.
|
*/
pub unbroadcast_txids: HashSet<u256>,
pub map_next_tx: IndirectMap<OutPoint,Arc<Transaction>>,
pub map_deltas: HashMap<u256,Amount>,
}
pub type TxMemPoolSetEntries = HashSet<TxMemPoolTxIter,CompareIteratorByHash>;
//pub type TxIter = IndexedTransactionSet::NthIndex<0>::ConstIterator;
pub type TxMemPoolIndexedTransactionSetNthIndex0ConstIterator = Broken;
pub type TxMemPoolTxIter = TxMemPoolIndexedTransactionSetNthIndex0ConstIterator;
pub type TxMemPoolCacheMap = HashMap<TxMemPoolTxIter,TxMemPoolSetEntries,CompareIteratorByHash>;
pub const ROLLING_FEE_HALFLIFE: i32 = 60 * 60 * 12; // public only for testing
pub type TxMemPoolIndexedTransactionSet = Broken;//TODO
pub type TxMemPoolIndexedTransactionSetConstIterator = Broken;
pub type TxMemPoolIndexedTransactionSetIterator = Broken;
/*
| typedef boost::multi_index_container<
| TxMemPoolEntry,
| boost::multi_index::indexed_by<
|
| // sorted by txid
| boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>,
|
| // sorted by wtxid
| boost::multi_index::hashed_unique<
| boost::multi_index::tag<index_by_wtxid>,
| mempoolentry_wtxid,
| SaltedTxidHasher
| >,
|
| // sorted by fee rate
| boost::multi_index::ordered_non_unique<
| boost::multi_index::tag<descendant_score>,
| boost::multi_index::identity<TxMemPoolEntry>,
| CompareTxMemPoolEntryByDescendantScore
| >,
|
| // sorted by entry time
| boost::multi_index::ordered_non_unique<
| boost::multi_index::tag<entry_time>,
| boost::multi_index::identity<TxMemPoolEntry>,
| CompareTxMemPoolEntryByEntryTime
| >,
|
| // sorted by fee rate with ancestors
| boost::multi_index::ordered_non_unique<
| boost::multi_index::tag<ancestor_score>,
| boost::multi_index::identity<TxMemPoolEntry>,
| CompareTxMemPoolEntryByAncestorFee
| >
| >
| > indexed_transaction_set;
*/
multidex!{
name => TxMemPoolIndexedTransactionSet,
item => TxMemPoolEntry,
hashed_unique => [
// sorted by txid
(IndexByTxid, MempoolEntryTxId, SaltedTxidHasher),
// sorted by wtxid
(IndexByWtxId, MempoolEntryWTxId, SaltedTxidHasher)
]
ordered_nonunique => [
// sorted by fee rate
(DescendantScore, TxMemPoolEntry, CompareTxMemPoolEntryByDescendantScore),
// sorted by entry time
(EntryTime, TxMemPoolEntry, CompareTxMemPoolEntryByEntryTime),
// sorted by fee rate with ancestors
(AncestorScore, TxMemPoolEntry, CompareTxMemPoolEntryByAncestorFee)
]
}
/**
| we will need to see which interfaces
| we need upon uncommenting
|
*/
pub trait ITxMemPool {}
impl ITxMemPool for TxMemPool {}
impl TxMemPool {
pub fn size(&self) -> u64 {
todo!();
/*
LOCK(cs);
return mapTx.size();
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn get_total_tx_size(&self) -> u64 {
todo!();
/*
AssertLockHeld(cs);
return totalTxSize;
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn get_total_fee(&self) -> Amount {
todo!();
/*
AssertLockHeld(cs);
return m_total_fee;
*/
}
pub fn exists(&self, gtxid: &GenTxId) -> bool {
todo!();
/*
LOCK(cs);
if (gtxid.IsWtxid()) {
return (mapTx.get<index_by_wtxid>().count(gtxid.GetHash()) != 0);
}
return (mapTx.count(gtxid.GetHash()) != 0);
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn get_iter_from_wtxid(&self, wtxid: &u256) -> TxMemPoolTxIter {
todo!();
/*
AssertLockHeld(cs);
return mapTx.project<0>(mapTx.get<index_by_wtxid>().find(wtxid));
*/
}
/**
| Adds a transaction to the unbroadcast
| set
|
*/
pub fn add_unbroadcast_tx(&mut self, txid: &u256) {
todo!();
/*
LOCK(cs);
// Sanity check the transaction is in the mempool & insert into
// unbroadcast set.
if (exists(GenTxId::Txid(txid))) m_unbroadcast_txids.insert(txid);
}{
*/
}
/**
| Returns transactions in unbroadcast
| set
|
*/
pub fn get_unbroadcast_txs(&self) -> HashSet<u256> {
todo!();
/*
LOCK(cs);
return m_unbroadcast_txids;
*/
}
/**
| Returns whether a txid is in the unbroadcast
| set
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn is_unbroadcast_tx(&self, txid: &u256) -> bool {
todo!();
/*
AssertLockHeld(cs);
return m_unbroadcast_txids.count(txid) != 0;
*/
}
/**
| Guards this internal counter for external
| reporting
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn get_and_increment_sequence(&self) -> u64 {
todo!();
/*
return m_sequence_number++;
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn get_sequence(&self) -> u64 {
todo!();
/*
return m_sequence_number;
*/
}
/**
| visited marks a TxMemPoolEntry as
| having been traversed during the lifetime
| of the most recently created Epoch::Guard
| and returns false if we are the first
| visitor, true otherwise.
|
| An Epoch::Guard must be held when visited
| is called or an assert will be triggered.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs, m_epoch)]
fn visited_impl(&self, it: TxMemPoolTxIter) -> bool {
todo!();
/*
return m_epoch.visited(it->m_epoch_marker);
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs, m_epoch)]
pub fn visited(&self, it: Option<TxMemPoolTxIter>) -> bool {
todo!();
/*
assert(m_epoch.guarded()); // verify guard even when it==nullopt
return !it || visited(*it);
*/
}
/**
| Update the given tx for any in-mempool
| descendants.
|
| Assumes that TxMemPool::m_children is correct
| for the given tx and all descendants.
|
| UpdateForDescendants is used by
| UpdateTransactionsFromBlock to update the
| descendants for a single transaction that
| has been added to the mempool but may have
| child transactions in the mempool, eg
| during a chain reorg. setExclude is the
| set of descendant transactions in the
| mempool that must not be accounted for
| (because any descendants in setExclude were
| added to the mempool after the transaction
| being updated and hence their state is
| already reflected in the parent state).
|
| cachedDescendants will be updated with the
| descendants of the transaction being
| updated, so that future invocations don't
| need to walk the same transaction again,
| if encountered in another transaction
| chain.
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn update_for_descendants(&mut self,
update_it: TxMemPoolTxIter,
cached_descendants: &mut TxMemPoolCacheMap,
set_exclude: &HashSet<u256>) {
todo!();
/*
TxMemPoolEntry::Children stageEntries, descendants;
stageEntries = updateIt->GetMemPoolChildrenConst();
while (!stageEntries.empty()) {
const TxMemPoolEntry& descendant = *stageEntries.begin();
descendants.insert(descendant);
stageEntries.erase(descendant);
const TxMemPoolEntry::Children& children = descendant.GetMemPoolChildrenConst();
for (const TxMemPoolEntry& childEntry : children) {
cacheMap::iterator cacheIt = cachedDescendants.find(mapTx.iterator_to(childEntry));
if (cacheIt != cachedDescendants.end()) {
// We've already calculated this one, just add the entries for this set
// but don't traverse again.
for (txiter cacheEntry : cacheIt->second) {
descendants.insert(*cacheEntry);
}
} else if (!descendants.count(childEntry)) {
// Schedule for later processing
stageEntries.insert(childEntry);
}
}
}
// descendants now contains all in-mempool descendants of updateIt.
// Update and add to cached descendant map
int64_t modifySize = 0;
CAmount modifyFee = 0;
int64_t modifyCount = 0;
for (const TxMemPoolEntry& descendant : descendants) {
if (!setExclude.count(descendant.GetTx().GetHash())) {
modifySize += descendant.GetTxSize();
modifyFee += descendant.GetModifiedFee();
modifyCount++;
cachedDescendants[updateIt].insert(mapTx.iterator_to(descendant));
// Update ancestor state for each descendant
mapTx.modify(mapTx.iterator_to(descendant), update_ancestor_state(updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost()));
}
}
mapTx.modify(updateIt, update_descendant_state(modifySize, modifyFee, modifyCount));
*/
}
/**
| When adding transactions from a disconnected
| block back to the mempool, new mempool
| entries may have children in the mempool
| (which is generally not the case when
| otherwise adding transactions).
|
| UpdateTransactionsFromBlock() will
| find child transactions and update
| the descendant state for each transaction
| in vHashesToUpdate (excluding any
| child transactions present in vHashesToUpdate,
| which are already accounted for). Note:
| vHashesToUpdate should be the set of
| transactions from the disconnected
| block that have been accepted back into
| the mempool.
|
| vHashesToUpdate is the set of transaction
| hashes from a disconnected block which has been
| re-added to the mempool.
|
| for each entry, look for descendants that are
| outside vHashesToUpdate, and add fee/size
| information for such descendants to the parent.
|
| for each such descendant, also update the
| ancestor state to include the parent.
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main)]
#[LOCKS_EXCLUDED(m_epoch)]
pub fn update_transactions_from_block(&mut self, hashes_to_update: &Vec<u256>) {
todo!();
/*
AssertLockHeld(cs);
// For each entry in vHashesToUpdate, store the set of in-mempool, but not
// in-vHashesToUpdate transactions, so that we don't have to recalculate
// descendants when we come across a previously seen entry.
cacheMap mapMemPoolDescendantsToUpdate;
// Use a set for lookups into vHashesToUpdate (these entries are already
// accounted for in the state of their ancestors)
std::set<uint256> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());
// Iterate in reverse, so that whenever we are looking at a transaction
// we are sure that all in-mempool descendants have already been processed.
// This maximizes the benefit of the descendant cache and guarantees that
// TxMemPool::m_children will be updated, an assumption made in
// UpdateForDescendants.
for (const uint256 &hash : reverse_iterate(vHashesToUpdate)) {
// calculate children from mapNextTx
txiter it = mapTx.find(hash);
if (it == mapTx.end()) {
continue;
}
auto iter = mapNextTx.lower_bound(OutPoint(hash, 0));
// First calculate the children, and update TxMemPool::m_children to
// include them, and update their TxMemPoolEntry::m_parents to include this tx.
// we cache the in-mempool children to avoid duplicate updates
{
WITH_FRESH_EPOCH(m_epoch);
for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
const uint256 &childHash = iter->second->GetHash();
txiter childIter = mapTx.find(childHash);
assert(childIter != mapTx.end());
// We can skip updating entries we've encountered before or that
// are in the block (which are already accounted for).
if (!visited(childIter) && !setAlreadyIncluded.count(childHash)) {
UpdateChild(it, childIter, true);
UpdateParent(childIter, it, true);
}
}
} // release epoch guard for UpdateForDescendants
UpdateForDescendants(it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded);
}
*/
}
/**
| Helper function to calculate all in-mempool
| ancestors of staged_ancestors and
| apply ancestor and descendant limits
| (including staged_ancestors thsemselves,
| entry_size and entry_count).
|
| -----------
| @param[in] entry_size
|
| Virtual size to include in the limits.
| ----------
| @param[in] entry_count
|
| How many entries to include in the limits.
| ----------
| @param[in] staged_ancestors
|
| Should contain entries in the mempool.
| ----------
| @param[out] setAncestors
|
| Will be populated with all mempool ancestors.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn calculate_ancestors_and_check_limits(&self,
entry_size: usize,
entry_count: usize,
set_ancestors: &mut TxMemPoolSetEntries,
staged_ancestors: &mut TxMemPoolEntryParents,
limit_ancestor_count: u64,
limit_ancestor_size: u64,
limit_descendant_count: u64,
limit_descendant_size: u64,
err_string: &mut String) -> bool {
todo!();
/*
size_t totalSizeWithAncestors = entry_size;
while (!staged_ancestors.empty()) {
const TxMemPoolEntry& stage = staged_ancestors.begin()->get();
txiter stageit = mapTx.iterator_to(stage);
setAncestors.insert(stageit);
staged_ancestors.erase(stage);
totalSizeWithAncestors += stageit->GetTxSize();
if (stageit->GetSizeWithDescendants() + entry_size > limitDescendantSize) {
errString = strprintf("exceeds descendant size limit for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantSize);
return false;
} else if (stageit->GetCountWithDescendants() + entry_count > limitDescendantCount) {
errString = strprintf("too many descendants for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantCount);
return false;
} else if (totalSizeWithAncestors > limitAncestorSize) {
errString = strprintf("exceeds ancestor size limit [limit: %u]", limitAncestorSize);
return false;
}
const TxMemPoolEntry::Parents& parents = stageit->GetMemPoolParentsConst();
for (const TxMemPoolEntry& parent : parents) {
txiter parent_it = mapTx.iterator_to(parent);
// If this is a new ancestor, add it.
if (setAncestors.count(parent_it) == 0) {
staged_ancestors.insert(parent);
}
if (staged_ancestors.size() + setAncestors.size() + entry_count > limitAncestorCount) {
errString = strprintf("too many unconfirmed ancestors [limit: %u]", limitAncestorCount);
return false;
}
}
}
return true;
*/
}
/**
| Calculate all in-mempool ancestors
| of a set of transactions not already
| in the mempool and check ancestor and
| descendant limits. Heuristics are
| used to estimate the ancestor and descendant
| count of all entries if the package were
| to be added to the mempool. The limits
| are applied to the union of all package
| transactions. For example, if the package
| has 3 transactions and limitAncestorCount
| = 25, the union of all 3 sets of ancestors
| (including the transactions themselves)
| must be <= 22.
|
| -----------
| @param[in] package
|
| Transaction package being evaluated
| for acceptance to mempool. The transactions
| need not be direct ancestors/descendants
| of each other.
| ----------
| @param[in] limitAncestorCount
|
| Max number of txns including ancestors.
| ----------
| @param[in] limitAncestorSize
|
| Max virtual size including ancestors.
| ----------
| @param[in] limitDescendantCount
|
| Max number of txns including descendants.
| ----------
| @param[in] limitDescendantSize
|
| Max virtual size including descendants.
| ----------
| @param[out] errString
|
| Populated with error reason if a limit
| is hit.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn check_package_limits(&self,
package: &Package,
limit_ancestor_count: u64,
limit_ancestor_size: u64,
limit_descendant_count: u64,
limit_descendant_size: u64,
err_string: &mut String) -> bool {
todo!();
/*
TxMemPoolEntry::Parents staged_ancestors;
size_t total_size = 0;
for (const auto& tx : package) {
total_size += GetVirtualTransactionSize(*tx);
for (const auto& input : tx->vin) {
std::optional<txiter> piter = GetIter(input.prevout.hash);
if (piter) {
staged_ancestors.insert(**piter);
if (staged_ancestors.size() + package.size() > limitAncestorCount) {
errString = strprintf("too many unconfirmed parents [limit: %u]", limitAncestorCount);
return false;
}
}
}
}
// When multiple transactions are passed in, the ancestors and descendants of all transactions
// considered together must be within limits even if they are not interdependent. This may be
// stricter than the limits for each individual transaction.
setEntries setAncestors;
const auto ret = CalculateAncestorsAndCheckLimits(total_size, package.size(),
setAncestors, staged_ancestors,
limitAncestorCount, limitAncestorSize,
limitDescendantCount, limitDescendantSize, errString);
// It's possible to overestimate the ancestor/descendant totals.
if (!ret) errString.insert(0, "possibly ");
return ret;
*/
}
/**
| Try to calculate all in-mempool ancestors
| of entry. (these are all calculated
| including the tx itself)
|
| - limitAncestorCount = max number of
| ancestors
|
| - limitAncestorSize = max size of ancestors
|
| - limitDescendantCount = max number
| of descendants any ancestor can have
|
| - limitDescendantSize = max size of
| descendants any ancestor can have
|
| - errString = populated with error reason
| if any limits are hit
|
| - fSearchForParents = whether to search
| a tx's vin for in-mempool parents, or
| look up parents from mapLinks. Must
| be true for entries not in the mempool
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn calculate_mem_pool_ancestors(&self,
entry: &TxMemPoolEntry,
set_ancestors: &mut TxMemPoolSetEntries,
limit_ancestor_count: u64,
limit_ancestor_size: u64,
limit_descendant_count: u64,
limit_descendant_size: u64,
err_string: &mut String,
search_for_parents: Option<bool>) -> bool {
let search_for_parents: bool = search_for_parents.unwrap_or(true);
todo!();
/*
TxMemPoolEntry::Parents staged_ancestors;
const CTransaction &tx = entry.GetTx();
if (fSearchForParents) {
// Get parents of this transaction that are in the mempool
// GetMemPoolParents() is only valid for entries in the mempool, so we
// iterate mapTx to find parents.
for (unsigned int i = 0; i < tx.vin.size(); i++) {
std::optional<txiter> piter = GetIter(tx.vin[i].prevout.hash);
if (piter) {
staged_ancestors.insert(**piter);
if (staged_ancestors.size() + 1 > limitAncestorCount) {
errString = strprintf("too many unconfirmed parents [limit: %u]", limitAncestorCount);
return false;
}
}
}
} else {
// If we're not searching for parents, we require this to already be an
// entry in the mempool and use the entry's cached parents.
txiter it = mapTx.iterator_to(entry);
staged_ancestors = it->GetMemPoolParentsConst();
}
return CalculateAncestorsAndCheckLimits(entry.GetTxSize(), /* entry_count */ 1,
setAncestors, staged_ancestors,
limitAncestorCount, limitAncestorSize,
limitDescendantCount, limitDescendantSize, errString);
*/
}
/**
| Update ancestors of hash to add/remove
| it as a descendant transaction.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn update_ancestors_of(&mut self,
add: bool,
it: TxMemPoolTxIter,
set_ancestors: &mut TxMemPoolSetEntries) {
todo!();
/*
TxMemPoolEntry::Parents parents = it->GetMemPoolParents();
// add or remove this tx as a child of each parent
for (const TxMemPoolEntry& parent : parents) {
UpdateChild(mapTx.iterator_to(parent), it, add);
}
const int64_t updateCount = (add ? 1 : -1);
const int64_t updateSize = updateCount * it->GetTxSize();
const CAmount updateFee = updateCount * it->GetModifiedFee();
for (txiter ancestorIt : setAncestors) {
mapTx.modify(ancestorIt, update_descendant_state(updateSize, updateFee, updateCount));
}
*/
}
/**
| Set ancestor state for an entry
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn update_entry_for_ancestors(&mut self,
it: TxMemPoolTxIter,
set_ancestors: &TxMemPoolSetEntries) {
todo!();
/*
int64_t updateCount = setAncestors.size();
int64_t updateSize = 0;
CAmount updateFee = 0;
int64_t updateSigOpsCost = 0;
for (txiter ancestorIt : setAncestors) {
updateSize += ancestorIt->GetTxSize();
updateFee += ancestorIt->GetModifiedFee();
updateSigOpsCost += ancestorIt->GetSigOpCost();
}
mapTx.modify(it, update_ancestor_state(updateSize, updateFee, updateCount, updateSigOpsCost));
*/
}
/**
| Sever link between specified transaction
| and direct children.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn update_children_for_removal(&mut self, it: TxMemPoolTxIter) {
todo!();
/*
const TxMemPoolEntry::Children& children = it->GetMemPoolChildrenConst();
for (const TxMemPoolEntry& updateIt : children) {
UpdateParent(mapTx.iterator_to(updateIt), it, false);
}
*/
}
/**
| For each transaction being removed,
| update ancestors and any direct children.
|
| If updateDescendants is true, then
| also update in-mempool descendants'
| ancestor state.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn update_for_remove_from_mempool(&mut self,
entries_to_remove: &TxMemPoolSetEntries,
update_descendants: bool) {
todo!();
/*
// For each entry, walk back all ancestors and decrement size associated with this
// transaction
const uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
if (updateDescendants) {
// updateDescendants should be true whenever we're not recursively
// removing a tx and all its descendants, eg when a transaction is
// confirmed in a block.
// Here we only update statistics and not data in TxMemPool::Parents
// and TxMemPoolEntry::Children (which we need to preserve until we're
// finished with all operations that need to traverse the mempool).
for (txiter removeIt : entriesToRemove) {
setEntries setDescendants;
CalculateDescendants(removeIt, setDescendants);
setDescendants.erase(removeIt); // don't update state for self
int64_t modifySize = -((int64_t)removeIt->GetTxSize());
CAmount modifyFee = -removeIt->GetModifiedFee();
int modifySigOps = -removeIt->GetSigOpCost();
for (txiter dit : setDescendants) {
mapTx.modify(dit, update_ancestor_state(modifySize, modifyFee, -1, modifySigOps));
}
}
}
for (txiter removeIt : entriesToRemove) {
setEntries setAncestors;
const TxMemPoolEntry &entry = *removeIt;
std::string dummy;
// Since this is a tx that is already in the mempool, we can call CMPA
// with fSearchForParents = false. If the mempool is in a consistent
// state, then using true or false should both be correct, though false
// should be a bit faster.
// However, if we happen to be in the middle of processing a reorg, then
// the mempool can be in an inconsistent state. In this case, the set
// of ancestors reachable via GetMemPoolParents()/GetMemPoolChildren()
// will be the same as the set of ancestors whose packages include this
// transaction, because when we add a new transaction to the mempool in
// addUnchecked(), we assume it has no children, and in the case of a
// reorg where that assumption is false, the in-mempool children aren't
// linked to the in-block tx's until UpdateTransactionsFromBlock() is
// called.
// So if we're being called during a reorg, ie before
// UpdateTransactionsFromBlock() has been called, then
// GetMemPoolParents()/GetMemPoolChildren() will differ from the set of
// mempool parents we'd calculate by searching, and it's important that
// we use the cached notion of ancestor transactions as the set of
// things to update for removal.
CalculateMemPoolAncestors(entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false);
// Note that UpdateAncestorsOf severs the child links that point to
// removeIt in the entries for the parents of removeIt.
UpdateAncestorsOf(false, removeIt, setAncestors);
}
// After updating all the ancestor sizes, we can now sever the link between each
// transaction being removed and any mempool children (ie, update TxMemPoolEntry::m_parents
// for each direct child of a transaction being removed).
for (txiter removeIt : entriesToRemove) {
UpdateChildrenForRemoval(removeIt);
}
*/
}
/**
| Create a new TxMemPool.
|
| Sanity checks will be off by default
| for performance, because otherwise
| accepting transactions becomes O(N^2)
| where N is the number of transactions
| in the pool.
|
| -----------
| @param[in] estimator
|
| is used to estimate appropriate transaction
| fees.
| ----------
| @param[in] check_ratio
|
| is the ratio used to determine how often
| sanity checks will run.
|
*/
pub fn new(
estimator: *mut BlockPolicyEstimator,
check_ratio: Option<i32>) -> Self {
let check_ratio: i32 = check_ratio.unwrap_or(0);
todo!();
/*
: m_check_ratio(check_ratio), minerPolicyEstimator(estimator)
_clear(); //lock free clear
*/
}
pub fn is_spent(&self, outpoint: &OutPoint) -> bool {
todo!();
/*
LOCK(cs);
return mapNextTx.count(outpoint);
*/
}
pub fn get_transactions_updated(&self) -> u32 {
todo!();
/*
return nTransactionsUpdated;
*/
}
pub fn add_transactions_updated(&mut self, n: u32) {
todo!();
/*
nTransactionsUpdated += n;
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main)]
pub fn add_unchecked_with_set_ancestors(&mut self,
entry: &TxMemPoolEntry,
set_ancestors: &mut TxMemPoolSetEntries,
valid_fee_estimate: Option<bool>) {
let valid_fee_estimate: bool = valid_fee_estimate.unwrap_or(true);
todo!();
/*
// Add to memory pool without checking anything.
// Used by AcceptToMemoryPool(), which DOES do
// all the appropriate checks.
IndexedTransactionSet::Iterator newit = mapTx.insert(entry).first;
// Update transaction for any feeDelta created by PrioritiseTransaction
// TODO: refactor so that the fee delta is calculated before inserting
// into mapTx.
CAmount delta{0};
ApplyDelta(entry.GetTx().GetHash(), delta);
if (delta) {
mapTx.modify(newit, update_fee_delta(delta));
}
// Update cachedInnerUsage to include contained transaction's usage.
// (When we update the entry for in-mempool parents, memory usage will be
// further updated.)
cachedInnerUsage += entry.DynamicMemoryUsage();
const CTransaction& tx = newit->GetTx();
std::set<uint256> setParentTransactions;
for (unsigned int i = 0; i < tx.vin.size(); i++) {
mapNextTx.insert(std::make_pair(&tx.vin[i].prevout, &tx));
setParentTransactions.insert(tx.vin[i].prevout.hash);
}
// Don't bother worrying about child transactions of this one.
// Normal case of a new transaction arriving is that there can't be any
// children, because such children would be orphans.
// An exception to that is if a transaction enters that used to be in a block.
// In that case, our disconnect block logic will call UpdateTransactionsFromBlock
// to clean up the mess we're leaving here.
// Update ancestors with information about this tx
for (const auto& pit : GetIterSet(setParentTransactions)) {
UpdateParent(newit, pit, true);
}
UpdateAncestorsOf(true, newit, setAncestors);
UpdateEntryForAncestors(newit, setAncestors);
nTransactionsUpdated++;
totalTxSize += entry.GetTxSize();
m_total_fee += entry.GetFee();
if (minerPolicyEstimator) {
minerPolicyEstimator->processTransaction(entry, validFeeEstimate);
}
vTxHashes.emplace_back(tx.GetWitnessHash(), newit);
newit->vTxHashesIdx = vTxHashes.size() - 1;
*/
}
/**
| Before calling removeUnchecked for
| a given transaction,
|
| UpdateForRemoveFromMempool must
| be called on the entire (dependent)
| set of transactions being removed at
| the same time. We use each
|
| TxMemPoolEntry's setMemPoolParents
| in order to walk ancestors of a given
| transaction that is removed, so we can't
| remove intermediate transactions
| in a chain before we've updated all the
| state for the removal.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn remove_unchecked(&mut self,
it: TxMemPoolTxIter,
reason: MemPoolRemovalReason) {
todo!();
/*
// We increment mempool sequence value no matter removal reason
// even if not directly reported below.
uint64_t mempool_sequence = GetAndIncrementSequence();
if (reason != MemPoolRemovalReason::BLOCK) {
// Notify clients that a transaction has been removed from the mempool
// for any reason except being included in a block. Clients interested
// in transactions included in blocks can subscribe to the BlockConnected
// notification.
GetMainSignals().TransactionRemovedFromMempool(it->GetSharedTx(), reason, mempool_sequence);
}
const uint256 hash = it->GetTx().GetHash();
for (const CTxIn& txin : it->GetTx().vin)
mapNextTx.erase(txin.prevout);
RemoveUnbroadcastTx(hash, true /* add logging because unchecked */ );
if (vTxHashes.size() > 1) {
vTxHashes[it->vTxHashesIdx] = std::move(vTxHashes.back());
vTxHashes[it->vTxHashesIdx].second->vTxHashesIdx = it->vTxHashesIdx;
vTxHashes.pop_back();
if (vTxHashes.size() * 2 < vTxHashes.capacity())
vTxHashes.shrink_to_fit();
} else
vTxHashes.clear();
totalTxSize -= it->GetTxSize();
m_total_fee -= it->GetFee();
cachedInnerUsage -= it->DynamicMemoryUsage();
cachedInnerUsage -= memusage::DynamicUsage(it->GetMemPoolParentsConst()) + memusage::DynamicUsage(it->GetMemPoolChildrenConst());
mapTx.erase(it);
nTransactionsUpdated++;
if (minerPolicyEstimator) {minerPolicyEstimator->removeTx(hash, false);}
*/
}
/**
| Populate setDescendants with all in-mempool
| descendants of hash.
|
| Assumes that setDescendants includes
| all in-mempool descendants of anything
| already in it.
|
| Calculates descendants of entry that are not
| already in setDescendants, and adds to
| setDescendants. Assumes entryit is already a tx
| in the mempool and TxMemPoolEntry::m_children
| is correct for tx and all descendants.
|
| Also assumes that if an entry is in
| setDescendants already, then all in-mempool
| descendants of it are already in setDescendants
| as well, so that we can save time by not
| iterating over those entries.
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn calculate_descendants(&self,
entryit: TxMemPoolTxIter,
set_descendants: &mut TxMemPoolSetEntries) {
todo!();
/*
setEntries stage;
if (setDescendants.count(entryit) == 0) {
stage.insert(entryit);
}
// Traverse down the children of entry, only adding children that are not
// accounted for in setDescendants already (because those children have either
// already been walked, or will be walked in this iteration).
while (!stage.empty()) {
txiter it = *stage.begin();
setDescendants.insert(it);
stage.erase(it);
const TxMemPoolEntry::Children& children = it->GetMemPoolChildrenConst();
for (const TxMemPoolEntry& child : children) {
txiter childiter = mapTx.iterator_to(child);
if (!setDescendants.count(childiter)) {
stage.insert(childiter);
}
}
}
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn remove_recursive(&mut self,
orig_tx: &Transaction,
reason: MemPoolRemovalReason) {
todo!();
/*
// Remove transaction from memory pool
AssertLockHeld(cs);
setEntries txToRemove;
txiter origit = mapTx.find(origTx.GetHash());
if (origit != mapTx.end()) {
txToRemove.insert(origit);
} else {
// When recursively removing but origTx isn't in the mempool
// be sure to remove any children that are in the pool. This can
// happen during chain re-orgs if origTx isn't re-accepted into
// the mempool for any reason.
for (unsigned int i = 0; i < origTx.vout.size(); i++) {
auto it = mapNextTx.find(OutPoint(origTx.GetHash(), i));
if (it == mapNextTx.end())
continue;
txiter nextit = mapTx.find(it->second->GetHash());
assert(nextit != mapTx.end());
txToRemove.insert(nextit);
}
}
setEntries setAllRemoves;
for (txiter it : txToRemove) {
CalculateDescendants(it, setAllRemoves);
}
RemoveStaged(setAllRemoves, false, reason);
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn remove_conflicts(&mut self, tx: &Transaction) {
todo!();
/*
// Remove transactions which depend on inputs of tx, recursively
AssertLockHeld(cs);
for (const CTxIn &txin : tx.vin) {
auto it = mapNextTx.find(txin.prevout);
if (it != mapNextTx.end()) {
const CTransaction &txConflict = *it->second;
if (txConflict != tx)
{
ClearPrioritisation(txConflict.GetHash());
removeRecursive(txConflict, MemPoolRemovalReason::CONFLICT);
}
}
}
*/
}
/**
| Called when a block is connected. Removes
| from mempool and updates the miner fee
| estimator.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn remove_for_block(&mut self,
vtx: &Vec<TransactionRef>,
n_block_height: u32) {
todo!();
/*
AssertLockHeld(cs);
std::vector<const TxMemPoolEntry*> entries;
for (const auto& tx : vtx)
{
uint256 hash = tx->GetHash();
IndexedTransactionSet::Iterator i = mapTx.find(hash);
if (i != mapTx.end())
entries.push_back(&*i);
}
// Before the txs in the new block have been removed from the mempool, update policy estimates
if (minerPolicyEstimator) {minerPolicyEstimator->processBlock(nBlockHeight, entries);}
for (const auto& tx : vtx)
{
txiter it = mapTx.find(tx->GetHash());
if (it != mapTx.end()) {
setEntries stage;
stage.insert(it);
RemoveStaged(stage, true, MemPoolRemovalReason::BLOCK);
}
removeConflicts(*tx);
ClearPrioritisation(tx->GetHash());
}
lastRollingFeeUpdate = GetTime();
blockSinceLastRollingFeeBump = true;
*/
}
/**
| lock free
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
fn clear_impl(&mut self) {
todo!();
/*
mapTx.clear();
mapNextTx.clear();
totalTxSize = 0;
m_total_fee = 0;
cachedInnerUsage = 0;
lastRollingFeeUpdate = GetTime();
blockSinceLastRollingFeeBump = false;
rollingMinimumFeeRate = 0;
++nTransactionsUpdated;
*/
}
pub fn clear(&mut self) {
todo!();
/*
LOCK(cs);
_clear();
*/
}
/**
| If sanity-checking is turned on, check
| makes sure the pool is consistent (does
| not contain two transactions that spend
| the same inputs, all inputs are in the
| mapNextTx array). If sanity-checking
| is turned off, check does nothing.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(::cs_main)]
pub fn check(&self,
active_coins_tip: &CoinsViewCache,
spendheight: i64)
{
todo!();
/*
if (m_check_ratio == 0) return;
if (GetRand(m_check_ratio) >= 1) return;
AssertLockHeld(::cs_main);
LOCK(cs);
LogPrint(BCLog::MEMPOOL, "Checking mempool with %u transactions and %u inputs\n", (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size());
uint64_t checkTotal = 0;
CAmount check_total_fee{0};
uint64_t innerUsage = 0;
uint64_t prev_ancestor_count{0};
CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(&active_coins_tip));
for (const auto& it : GetSortedDepthAndScore()) {
checkTotal += it->GetTxSize();
check_total_fee += it->GetFee();
innerUsage += it->DynamicMemoryUsage();
const CTransaction& tx = it->GetTx();
innerUsage += memusage::DynamicUsage(it->GetMemPoolParentsConst()) + memusage::DynamicUsage(it->GetMemPoolChildrenConst());
TxMemPoolEntry::Parents setParentCheck;
for (const CTxIn &txin : tx.vin) {
// Check that every mempool transaction's inputs refer to available coins, or other mempool tx's.
IndexedTransactionSetConstIterator it2 = mapTx.find(txin.prevout.hash);
if (it2 != mapTx.end()) {
const CTransaction& tx2 = it2->GetTx();
assert(tx2.vout.size() > txin.prevout.n && !tx2.vout[txin.prevout.n].IsNull());
setParentCheck.insert(*it2);
}
// We are iterating through the mempool entries sorted in order by ancestor count.
// All parents must have been checked before their children and their coins added to
// the mempoolDuplicate coins cache.
assert(mempoolDuplicate.HaveCoin(txin.prevout));
// Check whether its inputs are marked in mapNextTx.
auto it3 = mapNextTx.find(txin.prevout);
assert(it3 != mapNextTx.end());
assert(it3->first == &txin.prevout);
assert(it3->second == &tx);
}
auto comp = [](const TxMemPoolEntry& a, const TxMemPoolEntry& b) -> bool {
return a.GetTx().GetHash() == b.GetTx().GetHash();
};
assert(setParentCheck.size() == it->GetMemPoolParentsConst().size());
assert(std::equal(setParentCheck.begin(), setParentCheck.end(), it->GetMemPoolParentsConst().begin(), comp));
// Verify ancestor state is correct.
setEntries setAncestors;
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
std::string dummy;
CalculateMemPoolAncestors(*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy);
uint64_t nCountCheck = setAncestors.size() + 1;
uint64_t nSizeCheck = it->GetTxSize();
CAmount nFeesCheck = it->GetModifiedFee();
int64_t nSigOpCheck = it->GetSigOpCost();
for (txiter ancestorIt : setAncestors) {
nSizeCheck += ancestorIt->GetTxSize();
nFeesCheck += ancestorIt->GetModifiedFee();
nSigOpCheck += ancestorIt->GetSigOpCost();
}
assert(it->GetCountWithAncestors() == nCountCheck);
assert(it->GetSizeWithAncestors() == nSizeCheck);
assert(it->GetSigOpCostWithAncestors() == nSigOpCheck);
assert(it->GetModFeesWithAncestors() == nFeesCheck);
// Sanity check: we are walking in ascending ancestor count order.
assert(prev_ancestor_count <= it->GetCountWithAncestors());
prev_ancestor_count = it->GetCountWithAncestors();
// Check children against mapNextTx
TxMemPoolEntry::Children setChildrenCheck;
auto iter = mapNextTx.lower_bound(OutPoint(it->GetTx().GetHash(), 0));
uint64_t child_sizes = 0;
for (; iter != mapNextTx.end() && iter->first->hash == it->GetTx().GetHash(); ++iter) {
txiter childit = mapTx.find(iter->second->GetHash());
assert(childit != mapTx.end()); // mapNextTx points to in-mempool transactions
if (setChildrenCheck.insert(*childit).second) {
child_sizes += childit->GetTxSize();
}
}
assert(setChildrenCheck.size() == it->GetMemPoolChildrenConst().size());
assert(std::equal(setChildrenCheck.begin(), setChildrenCheck.end(), it->GetMemPoolChildrenConst().begin(), comp));
// Also check to make sure size is greater than sum with immediate children.
// just a sanity check, not definitive that this calc is correct...
assert(it->GetSizeWithDescendants() >= child_sizes + it->GetTxSize());
TxValidationState dummy_state; // Not used. CheckTxInputs() should always pass
CAmount txfee = 0;
assert(!tx.IsCoinBase());
assert(consensus::CheckTxInputs(tx, dummy_state, mempoolDuplicate, spendheight, txfee));
for (const auto& input: tx.vin) mempoolDuplicate.SpendCoin(input.prevout);
AddCoins(mempoolDuplicate, tx, std::numeric_limits<int>::max());
}
for (auto it = mapNextTx.cbegin(); it != mapNextTx.cend(); it++) {
uint256 hash = it->second->GetHash();
IndexedTransactionSetConstIterator it2 = mapTx.find(hash);
const CTransaction& tx = it2->GetTx();
assert(it2 != mapTx.end());
assert(&tx == it->second);
}
assert(totalTxSize == checkTotal);
assert(m_total_fee == check_total_fee);
assert(innerUsage == cachedInnerUsage);
*/
}
pub fn compare_depth_and_score(&mut self,
hasha: &u256,
hashb: &u256,
wtxid: Option<bool>) -> bool {
let wtxid: bool = wtxid.unwrap_or(false);
todo!();
/*
LOCK(cs);
IndexedTransactionSetConstIterator i = wtxid ? get_iter_from_wtxid(hasha) : mapTx.find(hasha);
if (i == mapTx.end()) return false;
IndexedTransactionSetConstIterator j = wtxid ? get_iter_from_wtxid(hashb) : mapTx.find(hashb);
if (j == mapTx.end()) return true;
uint64_t counta = i->GetCountWithAncestors();
uint64_t countb = j->GetCountWithAncestors();
if (counta == countb) {
return CompareTxMemPoolEntryByScore()(*i, *j);
}
return counta < countb;
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn get_sorted_depth_and_score(&self) -> Vec<TxMemPoolIndexedTransactionSetConstIterator> {
todo!();
/*
std::vector<IndexedTransactionSetConstIterator> iters;
AssertLockHeld(cs);
iters.reserve(mapTx.size());
for (IndexedTransactionSet::Iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi) {
iters.push_back(mi);
}
std::sort(iters.begin(), iters.end(), DepthAndScoreComparator());
return iters;
*/
}
pub fn query_hashes(&self, vtxid: &mut Vec<u256>) {
todo!();
/*
LOCK(cs);
auto iters = GetSortedDepthAndScore();
vtxid.clear();
vtxid.reserve(mapTx.size());
for (auto it : iters) {
vtxid.push_back(it->GetTx().GetHash());
}
*/
}
pub fn info_all(&self) -> Vec<TxMemPoolInfo> {
todo!();
/*
LOCK(cs);
auto iters = GetSortedDepthAndScore();
std::vector<TxMemPoolInfo> ret;
ret.reserve(mapTx.size());
for (auto it : iters) {
ret.push_back(GetInfo(it));
}
return ret;
*/
}
pub fn get(&self, hash: &u256) -> TransactionRef {
todo!();
/*
LOCK(cs);
IndexedTransactionSetConstIterator i = mapTx.find(hash);
if (i == mapTx.end())
return nullptr;
return i->GetSharedTx();
*/
}
pub fn info(&self, gtxid: &GenTxId) -> TxMemPoolInfo {
todo!();
/*
LOCK(cs);
IndexedTransactionSetConstIterator i = (gtxid.IsWtxid() ? get_iter_from_wtxid(gtxid.GetHash()) : mapTx.find(gtxid.GetHash()));
if (i == mapTx.end())
return TxMemPoolInfo();
return GetInfo(i);
*/
}
/**
| Affect CreateNewBlock prioritisation
| of transactions
|
*/
pub fn prioritise_transaction(&mut self,
hash: &u256,
n_fee_delta: &Amount) {
todo!();
/*
{
LOCK(cs);
CAmount &delta = mapDeltas[hash];
delta += nFeeDelta;
txiter it = mapTx.find(hash);
if (it != mapTx.end()) {
mapTx.modify(it, update_fee_delta(delta));
// Now update all ancestors' modified fees with descendants
setEntries setAncestors;
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
std::string dummy;
CalculateMemPoolAncestors(*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false);
for (txiter ancestorIt : setAncestors) {
mapTx.modify(ancestorIt, update_descendant_state(0, nFeeDelta, 0));
}
// Now update all descendants' modified fees with ancestors
setEntries setDescendants;
CalculateDescendants(it, setDescendants);
setDescendants.erase(it);
for (txiter descendantIt : setDescendants) {
mapTx.modify(descendantIt, update_ancestor_state(0, nFeeDelta, 0, 0));
}
++nTransactionsUpdated;
}
}
LogPrintf("PrioritiseTransaction: %s fee += %s\n", hash.ToString(), FormatMoney(nFeeDelta));
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn apply_delta(&self,
hash: &u256,
n_fee_delta: &mut Amount) {
todo!();
/*
AssertLockHeld(cs);
std::map<uint256, CAmount>::const_iterator pos = mapDeltas.find(hash);
if (pos == mapDeltas.end())
return;
const CAmount &delta = pos->second;
nFeeDelta += delta;
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn clear_prioritisation(&mut self, hash: &u256) {
todo!();
/*
AssertLockHeld(cs);
mapDeltas.erase(hash);
*/
}
/**
| Get the transaction in the pool that
| spends the same prevout
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn get_conflict_tx(&self, prevout: &OutPoint) -> Arc<Transaction> {
todo!();
/*
const auto it = mapNextTx.find(prevout);
return it == mapNextTx.end() ? nullptr : it->second;
*/
}
/**
| Returns an iterator to the given hash,
| if found
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn get_iter(&self, txid: &u256) -> Option<TxMemPoolTxIter> {
todo!();
/*
auto it = mapTx.find(txid);
if (it != mapTx.end()) return it;
return std::nullopt;
*/
}
/**
| Translate a set of hashes into a set of
| pool iterators to avoid repeated lookups
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn get_iter_set(&self, hashes: &HashSet<u256>) -> TxMemPoolSetEntries {
todo!();
/*
TxMemPool::setEntries ret;
for (const auto& h : hashes) {
const auto mi = GetIter(h);
if (mi) ret.insert(*mi);
}
return ret;
*/
}
/**
| Check that none of this transactions
| inputs are in the mempool, and thus the
| tx is not dependent on other mempool
| transactions to be included in a block.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn has_no_inputs_of(&self, tx: &Transaction) -> bool {
todo!();
/*
for (unsigned int i = 0; i < tx.vin.size(); i++)
if (exists(GenTxId::Txid(tx.vin[i].prevout.hash)))
return false;
return true;
*/
}
pub fn dynamic_memory_usage(&self) -> usize {
todo!();
/*
LOCK(cs);
// Estimate the overhead of mapTx to be 15 pointers + an allocation, as no exact formula for boost::multi_index_contained is implemented.
return memusage::MallocUsage(sizeof(TxMemPoolEntry) + 15 * sizeof(c_void*)) * mapTx.size() + memusage::DynamicUsage(mapNextTx) + memusage::DynamicUsage(mapDeltas) + memusage::DynamicUsage(vTxHashes) + cachedInnerUsage;
*/
}
/**
| Removes a transaction from the unbroadcast
| set
|
*/
pub fn remove_unbroadcast_tx(&mut self,
txid: &u256,
unchecked: Option<bool>) {
let unchecked: bool = unchecked.unwrap_or(false);
todo!();
/*
LOCK(cs);
if (m_unbroadcast_txids.erase(txid))
{
LogPrint(BCLog::MEMPOOL, "Removed %i from set of unbroadcast txns%s\n", txid.GetHex(), (unchecked ? " before confirmation that txn was sent out" : ""));
}
*/
}
/**
| Remove a set of transactions from the
| mempool.
|
| If a transaction is in this set, then
| all in-mempool descendants must also
| be in the set, unless this transaction
| is being removed for being in a block.
|
| Set updateDescendants to true when
| removing a tx that was in a block, so that
| any in-mempool descendants have their
| ancestor state updated.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn remove_staged(&mut self,
stage: &mut TxMemPoolSetEntries,
update_descendants: bool,
reason: MemPoolRemovalReason) {
todo!();
/*
AssertLockHeld(cs);
UpdateForRemoveFromMempool(stage, updateDescendants);
for (txiter it : stage) {
removeUnchecked(it, reason);
}
*/
}
/**
| Expire all transaction (and their dependencies)
| in the mempool older than time. Return
| the number of removed transactions.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn expire(&mut self, time: Instant /* seconds */) -> i32 {
todo!();
/*
AssertLockHeld(cs);
IndexedTransactionSet::Index<EntryTime>::Iterator it = mapTx.get<entry_time>().begin();
setEntries toremove;
while (it != mapTx.get<entry_time>().end() && it->GetTime() < time) {
toremove.insert(mapTx.project<0>(it));
it++;
}
setEntries stage;
for (txiter removeit : toremove) {
CalculateDescendants(removeit, stage);
}
RemoveStaged(stage, false, MemPoolRemovalReason::EXPIRY);
return stage.size();
*/
}
/**
| addUnchecked must updated state for all
| ancestors of a given transaction, to track
| size/count of descendant transactions.
| First version of addUnchecked can be used
| to have it call
| CalculateMemPoolAncestors(), and then
| invoke the second version.
|
| Note that addUnchecked is ONLY called from
| ATMP outside of tests and any other callers
| may break wallet's in-mempool tracking (due
| to lack of
| CValidationInterface::TransactionAddedToMempool
| callbacks).
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main)]
pub fn add_unchecked(&mut self,
entry: &TxMemPoolEntry,
valid_fee_estimate: Option<bool>) {
let valid_fee_estimate: bool = valid_fee_estimate.unwrap_or(true);
todo!();
/*
setEntries setAncestors;
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
std::string dummy;
CalculateMemPoolAncestors(entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy);
return addUnchecked(entry, setAncestors, validFeeEstimate);
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn update_child(&mut self,
entry: TxMemPoolTxIter,
child: TxMemPoolTxIter,
add: bool) {
todo!();
/*
AssertLockHeld(cs);
TxMemPoolEntry::Children s;
if (add && entry->GetMemPoolChildren().insert(*child).second) {
cachedInnerUsage += memusage::IncrementalDynamicUsage(s);
} else if (!add && entry->GetMemPoolChildren().erase(*child)) {
cachedInnerUsage -= memusage::IncrementalDynamicUsage(s);
}
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn update_parent(&mut self,
entry: TxMemPoolTxIter,
parent: TxMemPoolTxIter,
add: bool) {
todo!();
/*
AssertLockHeld(cs);
TxMemPoolEntry::Parents s;
if (add && entry->GetMemPoolParents().insert(*parent).second) {
cachedInnerUsage += memusage::IncrementalDynamicUsage(s);
} else if (!add && entry->GetMemPoolParents().erase(*parent)) {
cachedInnerUsage -= memusage::IncrementalDynamicUsage(s);
}
*/
}
/**
| The minimum fee to get into the mempool,
| which may itself not be enough for larger-sized
| transactions.
|
| The incrementalRelayFee policy variable
| is used to bound the time it takes the
| fee rate to go back down all the way to
| 0. When the feerate would otherwise
| be half of this, it is set to 0 instead.
|
*/
pub fn get_min_fee(&self, sizelimit: usize) -> FeeRate {
todo!();
/*
LOCK(cs);
if (!blockSinceLastRollingFeeBump || rollingMinimumFeeRate == 0)
return CFeeRate(llround(rollingMinimumFeeRate));
int64_t time = GetTime();
if (time > lastRollingFeeUpdate + 10) {
double halflife = ROLLING_FEE_HALFLIFE;
if (DynamicMemoryUsage() < sizelimit / 4)
halflife /= 4;
else if (DynamicMemoryUsage() < sizelimit / 2)
halflife /= 2;
rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife);
lastRollingFeeUpdate = time;
if (rollingMinimumFeeRate < (double)incrementalRelayFee.GetFeePerK() / 2) {
rollingMinimumFeeRate = 0;
return CFeeRate(0);
}
}
return std::max(CFeeRate(llround(rollingMinimumFeeRate)), incrementalRelayFee);
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn track_package_removed(&mut self, rate: &FeeRate) {
todo!();
/*
AssertLockHeld(cs);
if (rate.GetFeePerK() > rollingMinimumFeeRate) {
rollingMinimumFeeRate = rate.GetFeePerK();
blockSinceLastRollingFeeBump = false;
}
*/
}
/**
| Remove transactions from the mempool
| until its dynamic size is <= sizelimit.
| pvNoSpendsRemaining, if set, will
| be populated with the list of outpoints
| which are not in mempool which no longer
| have any spends in this mempool.
|
*/
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn trim_to_size(&mut self,
sizelimit: usize,
pv_no_spends_remaining: Arc<Mutex<Vec<OutPoint>>>) {
todo!();
/*
AssertLockHeld(cs);
unsigned nTxnRemoved = 0;
CFeeRate maxFeeRateRemoved(0);
while (!mapTx.empty() && DynamicMemoryUsage() > sizelimit) {
IndexedTransactionSet::Index<DescendantScore>::Iterator it = mapTx.get<descendant_score>().begin();
// We set the new mempool min fee to the feerate of the removed set, plus the
// "minimum reasonable fee rate" (ie some value under which we consider txn
// to have 0 fee). This way, we don't allow txn to enter mempool with feerate
// equal to txn which were removed with no block in between.
CFeeRate removed(it->GetModFeesWithDescendants(), it->GetSizeWithDescendants());
removed += incrementalRelayFee;
trackPackageRemoved(removed);
maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
setEntries stage;
CalculateDescendants(mapTx.project<0>(it), stage);
nTxnRemoved += stage.size();
std::vector<CTransaction> txn;
if (pvNoSpendsRemaining) {
txn.reserve(stage.size());
for (txiter iter : stage)
txn.push_back(iter->GetTx());
}
RemoveStaged(stage, false, MemPoolRemovalReason::SIZELIMIT);
if (pvNoSpendsRemaining) {
for (const CTransaction& tx : txn) {
for (const CTxIn& txin : tx.vin) {
if (exists(GenTxId::Txid(txin.prevout.hash))) continue;
pvNoSpendsRemaining->push_back(txin.prevout);
}
}
}
}
if (maxFeeRateRemoved > CFeeRate(0)) {
LogPrint(BCLog::MEMPOOL, "Removed %u txn, rolling minimum fee bumped to %s\n", nTxnRemoved, maxFeeRateRemoved.ToString());
}
*/
}
#[EXCLUSIVE_LOCKS_REQUIRED(cs)]
pub fn calculate_descendant_maximum(&self, entry: TxMemPoolTxIter) -> u64 {
todo!();
/*
// find parent with highest descendant count
std::vector<txiter> candidates;
setEntries counted;
candidates.push_back(entry);
uint64_t maximum = 0;
while (candidates.size()) {
txiter candidate = candidates.back();
candidates.pop_back();
if (!counted.insert(candidate).second) continue;
const TxMemPoolEntry::Parents& parents = candidate->GetMemPoolParentsConst();
if (parents.size() == 0) {
maximum = std::max(maximum, candidate->GetCountWithDescendants());
} else {
for (const TxMemPoolEntry& i : parents) {
candidates.push_back(mapTx.iterator_to(i));
}
}
}
return maximum;
*/
}
/**
| Calculate the ancestor and descendant
| count for the given transaction.
|
| The counts include the transaction
| itself.
|
| When ancestors is non-zero (ie, the
| transaction itself is in the mempool),
| ancestorsize and ancestorfees will
| also be set to the appropriate values.
|
*/
pub fn get_transaction_ancestry(&self,
txid: &u256,
ancestors: &mut usize,
descendants: &mut usize,
ancestorsize: *mut usize,
ancestorfees: *mut Amount) {
todo!();
/*
LOCK(cs);
auto it = mapTx.find(txid);
ancestors = descendants = 0;
if (it != mapTx.end()) {
ancestors = it->GetCountWithAncestors();
if (ancestorsize) *ancestorsize = it->GetSizeWithAncestors();
if (ancestorfees) *ancestorfees = it->GetModFeesWithAncestors();
descendants = CalculateDescendantMaximum(it);
}
*/
}
/**
| @return
|
| true if the mempool is fully loaded
|
*/
pub fn is_loaded(&self) -> bool {
todo!();
/*
LOCK(cs);
return m_is_loaded;
*/
}
/**
| Sets the current loaded state
|
*/
pub fn set_is_loaded(&mut self, loaded: bool) {
todo!();
/*
LOCK(cs);
m_is_loaded = loaded;
*/
}
}
pub fn get_info(it: TxMemPoolIndexedTransactionSetConstIterator) -> TxMemPoolInfo {
todo!();
/*
return TxMemPoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
*/
}