[DO NOT MERGE] Erlay: bandwidth-efficient transaction relay protocol (Full implementation) #30277

pull sr-gi wants to merge 38 commits into bitcoin:master from sr-gi:202406-erlay-full-draft changing 24 files +2925 −102
  1. sr-gi commented at 5:18 pm on June 12, 2024: member

    Erlay Project Tracking: #30249


    This is a full implementation of Erlay. Its purpose is to check the integrity and correctness of the implementation against changes/additions that may originate from the review process and/or rebases on top of newer functionality.

    This is not to be merged. Functionality will be spread across multiple smaller PRs to ease the review process.

  2. DrahtBot commented at 5:18 pm on June 12, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #30385 ([WIP] p2p: send not_found msgs for unknown, pruned or unwilling to share blocks by furszy)
    • #30256 (Allow to configure custom libzmq prefix by l2xl)
    • #30116 (p2p: Fill reconciliation sets (Erlay) attempt 2 by sr-gi)
    • #30111 (locks: introduce mutex for tx download, flush rejection filters on UpdatedBlockTip by glozow)
    • #30043 (net: Replace libnatpmp with built-in PCP+NATPMP implementation by laanwj)
    • #29790 ([DO NOT MERGE] cmake: Migrate CI scripts to CMake-based build system – WIP by hebasto)
    • #29625 (Several randomness improvements by sipa)
    • #29415 (Broadcast own transactions only via short-lived Tor or I2P connections by vasild)
    • #28463 (p2p: Increase inbound capacity for block-relay only connections by mzumsande)
    • #27826 (validation: log which peer sent us a header by Sjors)
    • #27052 (test: rpc: add last block announcement time to getpeerinfo result by LarryRuane)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. sr-gi marked this as a draft on Jun 12, 2024
  4. sr-gi force-pushed on Jun 12, 2024
  5. DrahtBot added the label CI failed on Jun 13, 2024
  6. DrahtBot commented at 4:17 am on June 13, 2024: contributor

    🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the documentation.

    Possibly this is due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    Leave a comment here, if you need help tracking down a confusing failure.

    Debug: https://github.com/bitcoin/bitcoin/runs/26144314909

  7. sr-gi force-pushed on Jun 13, 2024
  8. sr-gi force-pushed on Jun 13, 2024
  9. sr-gi force-pushed on Jun 14, 2024
  10. sr-gi force-pushed on Jun 14, 2024
  11. DrahtBot removed the label CI failed on Jun 14, 2024
  12. hebasto commented at 9:22 pm on June 18, 2024: member
  13. DrahtBot added the label CI failed on Jun 19, 2024
  14. sr-gi force-pushed on Jun 20, 2024
  15. DrahtBot added the label Needs rebase on Jun 20, 2024
  16. refactor: move m_is_inbound out of CNodeState
    `m_is_inbound` cannot be changed throughout the life of a `Peer`. However, we
    are currently storing it in `CNodeState`, which requires locking `cs_main` in
    order to access it. This can be moved to the outside scope and only require
    `m_peer_mutex`.
    
    This is a refactor in preparation for Erlay reworks.
    530148f243
  17. refactor: remove legacy comments
    These comments became irrelevant in one of the previous code changes.
    They simply don't make sense anymore.
    394acf9442
  18. p2p: Functions to add/remove wtxids to tx reconciliation sets
    They will be used later on.
    e165e9a0d1
  19. p2p: Make short id collision detectable when adding wtxids to tx reconciliation sets 2d50c14f04
  20. p2p: Add transactions to reconciliation sets
    Transactions eligible for reconciliation are added to the
    reconciliation sets. For the remaining txs, low-fanout is used.
    
    Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
    Co-authored-by: Pieter Wuille <pieter.wuille@gmail.com>
    8d25b32ca5
  21. bench: add bench for ShouldFanoutTo 53fd4b8b5b
  22. p2p: Cache fanout candidates to optimize txreconciliation
    Co-authored-by: Sergi Delgado Segura <sergi.delgado.s@gmail.com>
    919d841529
  23. p2p: Cache inbound reconciling peers count
    It helps to avoid recomputing every time we consider
    a transaction for fanout/reconciliation.
    
    Co-authored-by: Sergi Delgado Segura <sergi.delgado.s@gmail.com>
    31fa29dae0
  24. p2p: Add helper to compute reconciliation tx short ids and a cache of short ids to wtxids f30c3f589e
  25. sr-gi force-pushed on Jun 20, 2024
  26. DrahtBot removed the label Needs rebase on Jun 20, 2024
  27. p2p: Deal with shortid collisions for reconciliation sets
    If a wtxid to be added to a peer's recon set has a shot id collisions (a previously
    added wtxid maps to the same short id), both transaction should be fanout, given
    our peer may have added the opposite transaction to our recon set, and reconciliation
    will fail. Moreover, all descendants of the previously added transaction that were in
    the recon set should also be removed and fanout.
    ed5a0cc232
  28. p2p: Add PeerManager method to count the amount of inbound/outbounds fanout peers c62bc09c67
  29. p2p: Moves fanout logic to RelayTransaction and properly fanouts ancestors
    If a transaction to be reconciled has in mempool ancestors, we need to be consistent
    with the way in which we announce this transaction (either by fanning out or reconciling
    all the ancestor set). In order for Erlay to work best, a minimum amount of fanout is required.
    Therefore, we cannot simply reconcile with everyone in this case either. Find the subset of peers
    that have the least ancestors to be reconciled and send all of them via fanout
    fc13a9f801
  30. p2p: Introduce reconciliation-fanout tx broadcast interval
    For a subset of reconciling peers we announce transactions
    via low fanout. We need to set lower intervals for that to
    achieve lower relay latency.
    
    Note that for privacy reasons the ratio between inbound and outbound
    delays matter much more than the actual delays. That ratio is preserved
    here, so it is not a privacy degradation.
    ebea3e6378
  31. p2p: Add peers to reconciliation queue on negotiation
    When we're finalizing negotiation, we should add the peers
    for which we will initiate reconciliations to the queue.
    540a8e5ce5
  32. p2p: Track reconciliation requests schedule
    We initiate reconciliation by looking at the queue periodically
    with equal intervals between peers to achieve efficiency.
    
    This will be later used to see whether it's time to initiate.
    f92dd4f690
  33. p2p: Initiate reconciliation round
    When the time comes for the peer, we send a
    reconciliation request with the parameters which
    will help the peer to construct a (hopefully) sufficient
    reconciliation sketch for us. We will then use that
    sketch to find missing transactions.
    1dd126b267
  34. test: functional test for reqtxrcncl 4388968442
  35. p2p: Handle reconciliation request
    Store the parameters the peer sent us inside the
    reconciliation request.
    ab4191a06b
  36. Add helper to see whether we should respond to recon request
    For initial reconciliatin requests we track whether was the last time
    we responded to them, and if it was too recent, we respond after
    a small delay.
    ec5839bbf7
  37. build: Link minisketch libraries 6f37a7e20c
  38. Add helper to compute sketches for tx reconciliation 69d51d5136
  39. Respond to a reconciliation request
    When the time comes, we should send a sketch of our
    local reconciliation set to the reconciliation initiator.
    ac92846a0b
  40. p2p: Add a function to identify local/remote missing txs
    When the sketches from both sides are combined successfully,
    the diff is produced. Then this diff can (together with the local txs)
    be used to identified which transactions are missing locally and remotely.
    2028118a63
  41. Use txid/uint256 in CompareInvMempoolOrder
    This will help to reuse the code later on in the function
    to announce transactions.
    d849013318
  42. p2p: Handle reconciliation sketch and successful decoding 48bf4d4f3d
  43. p2p: Request extension if decoding failed
    If after decoding a reconciliation sketch it turned out
    to be insufficient to find set difference, request extension.
    6913b939a6
  44. Be ready to receive sketch extension
    Store the initial sketches so that we are able to process
    extension sketch while avoiding transmitting the same data.
    874fd2d33a
  45. p2p: Prepare for sketch extension request
    To be ready to respond to a sketch extension request
    from our peer, we should store a snapshot of our state
    and capacity of the initial sketch, so that we compute
    extension of the same size and over the exact same
    transactions.
    
    Transactions arriving during this reconciliation will
    be instead stored in the regular set.
    706901da9f
  46. p2p: Keep track of announcements during txrcncl extension 2fd65c65a2
  47. p2p: Handle reconciliation extension request
    If peer failed to reconcile based on our initial response sketch,
    they will ask us for a sketch extension. Store this request to respond later.
    bc3db22ca0
  48. p2p: Respond to sketch extension request
    Sending an extension may allow the peer to reconcile
    transactions, because now the full sketch has twice
    as much capacity.
    fa2c04ed99
  49. Handle sketch extension
    If a peer sent us an extension sketch, we should
    reconstruct a full sketch from it with the snapshot
    we stored initially, and attempt to decode the difference.
    
    p2p: Handle sketch extension
    
    If a peer sent us an extension sketch, we should
    reconstruct a full sketch from it with the snapshot
    we stored initially, and attempt to decode the difference.
    1c1ac7fece
  50. p2p: Add a finalize incoming reconciliation function
    This currently unused function is supposed to be used once
    a reconciliation round is done. It cleans the state corresponding
    to the passed reconciliation.
    8bdc2af3d2
  51. Handle reconciliation finalization message
    Once a peer tells us reconciliation is done, we should behave as follows:
    - if it was successful, just respond them with the transactions they asked
      by short ID.
    - if it was a full failure, respond with all local transactions from the reconciliation
      set snapshot
    - if it was a partial failure (only low or high part was failed after a bisection),
      respond with all transactions which were asked for by short id,
      and announce local txs which belong to the failed chunk.
    570c8dd38c
  52. p2p, test: Add tx reconciliation functional tests d6ca939297
  53. test: Patches tx_recon generate_transaction approach
    I'm assuming Gleb didn't want to have transactions collisions in this
    tests, but some are manifesting in CI, this is due to how coins are selected.
    
    Fixing this plus making it a bit more idiomatic. This can be squashed to the
    previous commit
    417561cecf
  54. test: Update mempool_packages.py test for reconciliation
    First, extend the timeout to facilitate reconciliation
    relay which might take longer than previously.
    
    Second, since reconciliation can't guarantee that
    descendants of same-degree (from the parent) are
    relayed in the same order they were received, loosen
    the check for descendant limit.
    This is the case because, if the parent is flooded,
    the children might be both flooded and reconciled,
    and the decision is made independently. So even if
    one arrived earlier, it can be relayed later because
    flooding.
    Note, it's possible to make txreconciliation.cpp be aware
    of the order of adding transactions to the set, but this
    won't help to solve the above issue.
    6f9cbc47b4
  55. build, msvc: Adjust MSVC project files 0a7adc36a4
  56. sr-gi force-pushed on Jun 21, 2024
  57. DrahtBot removed the label CI failed on Jun 21, 2024
  58. DrahtBot commented at 11:15 am on July 4, 2024: contributor

    🐙 This pull request conflicts with the target branch and needs rebase.

  59. DrahtBot added the label Needs rebase on Jul 4, 2024
  60. DrahtBot commented at 1:24 am on October 1, 2024: contributor

    ⌛ There hasn’t been much activity lately and the patch still needs rebase. What is the status here?

    • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
    • Is it no longer relevant? ➡️ Please close.
    • Did the author lose interest or time to work on this? ➡️ Please close it and mark it ‘Up for grabs’ with the label, so that it can be picked up in the future.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-04 22:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me