I'm using this PR to get an initial review on the new structure of the Erlay PR.
Erlay refactored #21335
pull naumenkogs wants to merge 29 commits into bitcoin:master from naumenkogs:erlay_refactored_public changing 84 files +8450 −58-
naumenkogs commented at 1:17 PM on March 2, 2021: member
-
Add minisketch dependency 6474c9f1ed
-
0a495a213b
Squashed 'src/minisketch/' content from commit 80481500c
git-subtree-dir: src/minisketch git-subtree-split: 80481500cdb3328adab751db30a3fa7e76fe1147
-
Merge commit '0a495a213bbc56bc4e90070e9081371ec6ea1da7' as 'src/minisketch' fec47ad22d
-
f3aeaee634
Announce reconciliation support
If a peer supports wtxid our node should notify them that we are willing to participate in tx reconciliation. At this point we generate a salt for computing short tx IDs for reconciliations over this connection.
-
e7d1293f76
Count outbound tx relay peers except one
This helper will be used to determine whether we should suggest our new peer reconciling with us.
-
7ca561b7cf
Handle reconciliation support announcement
Once we receive a message from a peer signalling reconciliation support, we initialize the data structures required to perform reconciliations. If we are planning to initiate reconciliations with this peer (if it's an outbound connection), add this peer to the reconciliation queue.
-
ed4f3e1f9b
Limit transaction flooding
See how many flooding and how many reconciling outbound peers we have, which is useful to see whether our new peer should be using flooding or reconciliation. It helps to save bandwidth and presumably reduces privacy leak.
-
Remove node from reconciliation queue when disconnecting f49b144f71
-
bcc795dbe3
Add a function to announce transactions after reconciliation
Have a separate function to announce transactions to a peer (via INVs) considering INV message limitations.
-
b41b4674c2
Prepare to distinguish transactions to flood and to reconcile
We need assign and keep track of the way we're going to relay a transaction based on the connection type the transaction arrived from, to enable transaction reconciliation protocol.
-
2fb3d69509
Distinguish transactions to flood and to reconcile
Flooding and reconciliation are two different ways to announce transactions to the peers. For transactions received from inbound links, use flooding to enable a rapid relay across the reachable nodes. Use reconciliation (add transactions to the reconciliation sets) for all transactions which were received from outbound links to enable an slower but more efficient relay to unreachable nodes.
-
a28be569dd
Reduce tx broadcast interval
Since reconciliation is naturally slower than flooding, and also since we limit the flooding aspect, we should reduce the intervals between broadcasts (flooding out or adding to reconciliation sets). Otherwise, transaction relay will be too slow (and probably less inefficient). 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.
-
60d59a449e
Request tx reconciliation as scheduled
If the peer is next in the queue for reconciliation, and enough time is passed from the previous reconciliation, consider a peer for reconciliation. If there is no pending reconciliation request to the peer, send one, otherwise just move to the end of queue and update global next reconciliation request time.
-
b0659c36b7
Process incoming reconciliation request
Upon receiving a reconciliation request, a node stores it and schedules a response. Do not respond to a request right away as it would enable a DoS attack and allow monitoring of transaction a node has. Instead, respond to all reconciliation requests at a same time after a small delay.
-
5aadce7cdf
Add helper to compute reconciliation tx short id
Short ids are used to compute reconciliation sketches.
-
244b59a481
Add helper to compute sketches for tx reconciliation
Sketch is a representation of list of transaction IDs, which enables reconciliation (an efficient sync of lists between peers).
-
0474bf7424
Respond to a reconciliation request
When the time comes, a node computes a sketch of the local transactions based on the parameters sent in the reconciliation request, and sends that sketch to the requestor. Clear local state.
-
b13bc7f7f1
Add a function to get wtxids by shortids
At the end of a reconciliation round, a peer may ask us for transactions by their short id. Add a function for a local lookup short_id->wtxid.
-
b99eded333
Add a finalize 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.
-
05d7e5a21f
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.
-
c498a7f0c9
Handle reconciliation sketch and successful decoding
Send/request missing transactions, clear the state, and send a finalization message.
-
be367b70ba
Request extension if decoding failed
If after decoding a reconciliation sketch it turned out to be insufficient to find set difference, request extension. Store the initial sketches so that we are able to process extension sketch.
-
7db69870b6
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.
-
15f9a956cd
Prepare to responding to extension requests
Add 2 variables tracking reconciliation state: (1) recon set snapshot and (2) capacity snapshot. (1) is used to store transactions arrived after we sent out an initial sketch, but before the reconciliation is over, since these transactions should not go into a sketch extension. (2) is used to set the capacity of the extended sketch because it provides good estimation (efficiency/failure tradeoff).
-
5b0303a631
Respond to an extension request
Compute a sketch with extra capacity and send those extra syndromes to the peer. It is safe to respond to an extension request without a delay because these requests are already limited by initial requests.
-
ea6b07b84d
Handle extension sketch
If a peer responded to our request with a sketch extension, attempt to decode it to find missing transactions by combining it with the initial sketch. If success, share/request missing transactions. If failure, send all the transactions we had for the peer.
-
d578090d97
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.
-
tests: support (inbound) connecting to mininode b843662818
-
Add tests for set reconciliation 108748f1eb
- fanquake added the label P2P on Mar 2, 2021
- naumenkogs closed this on Mar 2, 2021
-
naumenkogs commented at 1:19 PM on March 2, 2021: member
Sorry, I meant to do this in under own repo.
- DrahtBot locked this on Aug 16, 2022
Contributors
Labels