Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Cluster mempool implementation #28676

Draft
wants to merge 71 commits into
base: master
Choose a base branch
from

Commits on May 8, 2024

  1. Add cluster linearization code

    TODO: add tests
    sipa authored and sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    fc331fb View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8e53828 View commit details
    Browse the repository at this point in the history
  3. Add txgraph module

    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    923ae0a View commit details
    Browse the repository at this point in the history
  4. add fuzz test for txgraph

    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    dc8f3a8 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    66a72b4 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    4778971 View commit details
    Browse the repository at this point in the history
  7. Limit mempool size based on chunk feerate

    Rather than evicting the transactions with the lowest descendant feerate,
    instead evict transactions that have the lowest chunk feerate.
    
    Once mining is implemented based on choosing transactions with highest chunk
    feerate (see next commit), mining and eviction will be opposites, so that we
    will evict the transactions that would be mined last.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    01b148f View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    72731e0 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    0f78393 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    917952d View commit details
    Browse the repository at this point in the history
  11. policy: Remove CPFP carveout rule

    The addition of a cluster size limit makes the CPFP carveout rule useless,
    because carveout cannot be used to bypass the cluster size limit. Remove this
    policy rule and update tests to no longer rely on the behavior.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    04e8acd View commit details
    Browse the repository at this point in the history
  12. fixup! Add txgraph module

    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    be6bf4d View commit details
    Browse the repository at this point in the history
  13. Implement new RBF logic for cluster mempool

    With a total ordering on mempool transactions, we are now able to calculate a
    transaction's mining score at all times. Use this to improve the RBF logic:
    
    - we no longer enforce a "no new unconfirmed parents" rule
    
    - we now require that the mempool's feerate diagram must improve in order
      to accept a replacement
    
    TODO: update functional test feature_rbf.py to cover all our new scenarios.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    9b75c1f View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    acd2e12 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    4407d70 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    81a1873 View commit details
    Browse the repository at this point in the history
  17. Use cluster linearization for transaction relay sort order

    Previously, transaction batches were first sorted by ancestor count and then
    feerate, to ensure transactions are announced in a topologically valid order,
    while prioritizing higher feerate transactions. Ancestor count is a crude
    topological sort criteria, so replace this with linearization order so that the
    highest feerate transactions (as would be observed by the mining algorithm) are
    relayed before lower feerate ones, in a topologically valid way.
    
    This also fixes a test that only worked due to the ancestor-count-based sort
    order.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    7cc6e80 View commit details
    Browse the repository at this point in the history
  18. Remove CTxMemPool::GetSortedDepthAndScore

    The mempool clusters and linearization permit sorting the mempool topologically
    without making use of ancestor counts.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    9730c4c View commit details
    Browse the repository at this point in the history
  19. Reimplement GetTransactionAncestry() to not rely on cached data

    In preparation for removing ancestor data from CTxMemPoolEntry, recalculate the
    ancestor statistics on demand wherever needed.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    d36db77 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    acdad95 View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    59caf38 View commit details
    Browse the repository at this point in the history
  22. Stop enforcing ancestor size/count limits

    The cluster limits should be sufficient.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    4610706 View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    ba1030a View commit details
    Browse the repository at this point in the history
  24. Use mempool/txgraph to determine if a tx has descendants

    Remove a reference to GetCountWithDescendants() in preparation for removing
    this function and the associated cached state from the mempool.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    02e8648 View commit details
    Browse the repository at this point in the history
  25. Calculate descendant information for mempool RPC output on-the-fly

    This is in preparation for removing the cached descendant state from the
    mempool.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    644949d View commit details
    Browse the repository at this point in the history
  26. test: fix rbf carveout test in mempool_limit.py

    Minimal fix to the test that the RBF carveout doesn't apply in certain package
    validation cases. Now that RBF carveout doesn't exist, we can just test that
    the cluster count limit is respected (in preparation for removing the
    descendant limit altogether).
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    392f5e0 View commit details
    Browse the repository at this point in the history
  27. Stop enforcing descendant size/count limits

    Cluster size limits should be enough.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    113ef57 View commit details
    Browse the repository at this point in the history
  28. wallet: Replace max descendantsize with clustersize

    With the descendant size limits removed, replace the concept of "max number of
    descendants of any ancestor of a given tx" with the cluster count of the cluster
    that the transaction belongs to.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    d5dfc7a View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    6d2d662 View commit details
    Browse the repository at this point in the history
  30. Eliminate RBF workaround for CPFP carveout transactions

    The new cluster mempool RBF rules take into account clusters sizes exactly, so
    with the removal of descendant count enforcement this idea is obsolete.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    492d3b3 View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    c57b96d View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    4e60ada View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    6b7474c View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    ac467d5 View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    9e3ee4d View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    944b402 View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    6f47ef2 View commit details
    Browse the repository at this point in the history
  38. Configuration menu
    Copy the full SHA
    e6775bd View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    4c0c429 View commit details
    Browse the repository at this point in the history
  40. Rework removeForBlock so that clusters are only touched once

    Also remove extra linearization that was happening and some logging
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    ec7e0a4 View commit details
    Browse the repository at this point in the history
  41. Simplify ancestor calculation functions

    Now that ancestor calculation never fails (due to ancestor/descendant limits
    being eliminated), we can eliminate the error handling from
    CalculateMemPoolAncestors.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    f6482a6 View commit details
    Browse the repository at this point in the history
  42. Configuration menu
    Copy the full SHA
    fa7a146 View commit details
    Browse the repository at this point in the history
  43. Configuration menu
    Copy the full SHA
    23e8167 View commit details
    Browse the repository at this point in the history
  44. Configuration menu
    Copy the full SHA
    70f21d4 View commit details
    Browse the repository at this point in the history
  45. Configuration menu
    Copy the full SHA
    05bef2b View commit details
    Browse the repository at this point in the history
  46. Configuration menu
    Copy the full SHA
    958e7e9 View commit details
    Browse the repository at this point in the history
  47. Configuration menu
    Copy the full SHA
    02f2661 View commit details
    Browse the repository at this point in the history
  48. Configuration menu
    Copy the full SHA
    4da6979 View commit details
    Browse the repository at this point in the history
  49. Configuration menu
    Copy the full SHA
    1792fc3 View commit details
    Browse the repository at this point in the history
  50. Switch to using the faster CalculateDescendants

    The only place we still use the older interface is in policy/rbf.cpp, where
    it's helpful to incrementally calculate descendants to avoid calculating too
    many at once (or cluttering the CalculateDescendants interface with a
    calculation limit).
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    91f7d10 View commit details
    Browse the repository at this point in the history
  51. Configuration menu
    Copy the full SHA
    bf37a8b View commit details
    Browse the repository at this point in the history
  52. Configuration menu
    Copy the full SHA
    0515a60 View commit details
    Browse the repository at this point in the history
  53. Configuration menu
    Copy the full SHA
    d6defcf View commit details
    Browse the repository at this point in the history
  54. Configuration menu
    Copy the full SHA
    5c4f01f View commit details
    Browse the repository at this point in the history
  55. Configuration menu
    Copy the full SHA
    240f5b4 View commit details
    Browse the repository at this point in the history
  56. Configuration menu
    Copy the full SHA
    aaf45b5 View commit details
    Browse the repository at this point in the history
  57. Configuration menu
    Copy the full SHA
    af45c12 View commit details
    Browse the repository at this point in the history
  58. Configuration menu
    Copy the full SHA
    0fa99a8 View commit details
    Browse the repository at this point in the history
  59. Configuration menu
    Copy the full SHA
    668399b View commit details
    Browse the repository at this point in the history
  60. Eliminate need for ancestors in PackageV3Checks

    TO DO: Rewrite unit tests for PV3C to not lie about mempool parents, so that we
    can push down the parent calculation into v3_policy from validation.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    11258a8 View commit details
    Browse the repository at this point in the history
  61. Configuration menu
    Copy the full SHA
    998ef3a View commit details
    Browse the repository at this point in the history
  62. ==== END OPTIMIZATIONS ====

    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    afbcce4 View commit details
    Browse the repository at this point in the history
  63. ==== BEGIN TESTS ====

    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    facaa08 View commit details
    Browse the repository at this point in the history
  64. bench: add more mempool benchmarks

    Add benchmarks for:
    
      - mempool update time when blocks are found
      - adding a transaction
      - performing the mempool's RBF calculation
      - calculating mempool ancestors/descendants
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    3a5650c View commit details
    Browse the repository at this point in the history
  65. fuzz: try to add more code coverage for mempool fuzzing

    Including test coverage for mempool eviction and expiry
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    f96104b View commit details
    Browse the repository at this point in the history
  66. Configuration menu
    Copy the full SHA
    e8b3db0 View commit details
    Browse the repository at this point in the history
  67. Configuration menu
    Copy the full SHA
    0f558e3 View commit details
    Browse the repository at this point in the history
  68. Configuration menu
    Copy the full SHA
    b10940f View commit details
    Browse the repository at this point in the history
  69. Configuration menu
    Copy the full SHA
    0303d8f View commit details
    Browse the repository at this point in the history
  70. fuzz: remove comparison between mini_miner block construction and miner

    This is in preparation for eliminating the block template building happening in
    mini_miner, in favor of directly using the linearizations done in the mempool.
    sdaftuar committed May 8, 2024
    Configuration menu
    Copy the full SHA
    8c4ec6c View commit details
    Browse the repository at this point in the history
  71. Configuration menu
    Copy the full SHA
    f3482ed View commit details
    Browse the repository at this point in the history