p2p tx broadcasting improvements and some other changes#2052
Open
ImplOfAnImpl wants to merge 10 commits intoupdate_rust_editionfrom
Open
p2p tx broadcasting improvements and some other changes#2052ImplOfAnImpl wants to merge 10 commits intoupdate_rust_editionfrom
ImplOfAnImpl wants to merge 10 commits intoupdate_rust_editionfrom
Conversation
…t will be broadcast to the peers again. Rename mempool event types.
…r tx relay delay for outbound connections. Replace "inbound: bool" with "direction: ConnectionDirection" in P2pEvent for consistency.
… instead of adding a random delay before each tx). Track which txs with local origin were broadcast but not sent, and rebroadcast them.
…stead of the existing one. Cleanup.
…ime_to_announce_txs are now delayed at the start.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
exponential_rand's implementation was slightly wrong - it used a distribution that could produce zero and then manually checked for zero replacing it withf64::MIN_POSITIVE, thus introducing an artificially high upper bound on whatexponential_randcan return (the actual minimum non-zero value that the f64 uniform distributions can produce isf64::EPSILON/2, which is much bigger thanf64::MIN_POSITIVE). So I replaced the usage of theStandardUniformdistribution (used byRng::random) withOpen01, which can't produce zero. The max result ofexponential_randis now about 36, so I removed theMAX_DELAY_FACTORconstant in peer manager that was used to clamp the result.I renamed some event types in mempool, e.g.
TransactionProcessedis nowTransactionProcessedEvent,NewTipisNewTipEventetc.When a duplicate tx is added to the mempool and it has local origin,
TransactionProcessedEventwill now be sent for it again. P2p will re-announce such a tx if its relayble.Tx announcement was revamped - previously we would generate a random delay for each individual tx announcement and the txs would be announced in the order defined by the generated delays. This had 2 problems - a guaranteed lag before each tx and the arbitrary order of tx announcements. Now
PeerTransactionSyncManagerwill collect all tx ids that must be announced into a set and announce them all in one batch, ordering them according to the mempool's understanding of what tx is best. The interval between the batch announcements is still chosen at random, but the base delay now depends on the connection direction - it's 2s for outbound connections and 5s for inbound ones (same values are used in bitcoin).SyncManagernow tracks txs with local origin that have been announced but not sent to any peer and queues them for re-announcement every few minutes.The delays that
SyncManagerandPeerTransactionSyncManagergenerate are based on the monotonic clock (std::time::Instant). Normally,tokio::time::advanceshould be used to manipulate this time in tests; unfortunately it only works with thecurrent_threadruntime and the tests need the multithreaded one, so I had to introduce aMonotonicTimeGetterin addition to the ordinaryTimeGetterthat we had.