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

Let the thread which fetched a TX add it to the mempool #4984

Draft
wants to merge 5 commits into
base: bolt12/coot/tx-submission
Choose a base branch
from

Conversation

karknu
Copy link
Contributor

@karknu karknu commented Oct 4, 2024

Description

Previously all peers that had the TXid of a downloaded TX would attempt to add it to the mempool (a rather costly operation).

This patch moves the addition to the mempool to the Server's CollectTxs state. Which means that the downloaded TXs is only added by the thread that actually downloaded it.

The legacy TX submission protocol has been left as is.

Checklist

Quality

  • Commit sequence makes sense and have useful messages, see ref.
  • New tests are added and existing tests are updated.
  • Self-reviewed the PR.

Maintenance

  • Linked an issue or added the PR to the current sprint of ouroboros-network project.
  • Added labels.
  • Updated changelog files.
  • The documentation has been properly updated, see ref.

@karknu karknu marked this pull request as ready for review October 4, 2024 10:47
@karknu karknu requested a review from a team as a code owner October 4, 2024 10:47
Copy link
Contributor

@crocodile-dentist crocodile-dentist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@karknu karknu marked this pull request as draft October 8, 2024 06:28
Add the time it took to add TXs to the mempool to the
TxInboundAddedToMempool tracer.
DeltaQ metrics is only available for our warm and hot peers that also
have us as hot. So a fraction of all downstream clients will have a
metric.

This change the ranking of peers to use simple scoring system. Deliver a
new TX before in time before it gets into the block gives you one point.
Delivering a TXs thats already in the mempool, is invalid, or fail
because it was included in a recent blocks gives you a penalty.
@karknu karknu force-pushed the karknu/bolt12/coot/tx-submission branch from 4a99a6e to a3de87b Compare October 8, 2024 07:24
@coot coot added the tx-submission Issues related to tx-submission protocol label Oct 8, 2024
let !accepted = length txidsAccepted

traceWith tracer $ TraceTxSubmissionProcessed ProcessedTxCount {
ptxcAccepted = accepted
, ptxcRejected = collected - accepted
, ptxcScore = 0 -- This implementatin does not track score
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be a TODO?

Comment on lines 243 to 247
cntRejects :: SharedTxState peeraddr txid tx
-> SharedTxState peeraddr txid tx
cntRejects st@SharedTxState { peerTxStates } =
let peerTxStates' = Map.update (\ps -> Just $! ps { rejectedTxs = min 42 (max (-42) (rejectedTxs ps + n)) }) peeraddr peerTxStates in
st {peerTxStates = peerTxStates'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be more efficient to update it for all peers at once, but it might be harder to implement it. Another way would be to store the counts in Map peerAddt (TVar ...), so that we don't block on taking the whole state to update the count just for one peer.

let receivedL = [ (txId tx, tx) | tx <- txs ]
fetchedSet <- consumeFetchedTxs (Set.fromList (map fst receivedL))

-- Only attempt to add TXs if we actually has fetched some.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- Only attempt to add TXs if we actually has fetched some.
-- Only attempt to add TXs if we actually have fetched some.

Comment on lines +95 to +97
-- Note that checking if the mempool contains a TX before
-- spending several ms attempting to add it to the pool has
-- been judged immoral.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😁

@coot coot changed the title Let the correct thread add TXs to the mempool Let the thread which fetched a TX add it to the mempool Oct 11, 2024
Use hashWithSalt to breaks ties when ranking peers with equal score.
Track rejections in a bucket that slowly drains over time.
Bind responder threads to the lower cores, reserving the higest two cores
for other tasks (block adoption, draining mempool etc.).
Make demos and framework sim-tests compile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tx-submission Issues related to tx-submission protocol
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants