-
Notifications
You must be signed in to change notification settings - Fork 630
if checkTxnPool true, try to fetch from pool first #8345
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
base: master
Are you sure you want to change the base?
Conversation
|
Why is that important? Theoretically we remove canonical transactions from pool in background thread, so we could have canonical transaction with a receipt still in the pool. |
|
I wouldn't say it's important, but it seemed to make more sense to check the pool first, as it would bring small perf boost in scenarios where e.g. user subscribes to the pending transactions and then fetches each of these pending txs by hash (all of them would be in the pool). |
|
@marcindsobczak WDYT? If we want we could potentially wait till channel becomes empty. We can add manual counter and reset event. @marcindsobczak WDYT? Made an attempt in #8348 |
marcindsobczak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we can go with it as it is.
It is used in two places: eth_getRawTransactionByHash and eth_getTransactionByHash. For the first one, there is no issue, as it doesn't require the receipt. For the second, after the changes, we might occasionally return a recently processed transaction without the receipt. However, in my opinion, this is fine, and this method doesn’t need to be 100% accurate. If someone needs the receipt, they can always request it again.
I disagree, if someone is notified about the head change, we can't give him inconsistent view of transaction |
|
Right. So we need either both this PR and #8348, or neither. We should consider if such changes are justified just for a micro-optimization. |
So for suggested use - builder wants to get transactions from mempol ASAP this is probably not that micro as can skip db call. If you take into account that we can have hundreds of concurrent calls for transactions. But it is a concreate scenario. |
Not only builder, but searcher as well, basically anyone who is subscribed to the mempool tx stream. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes transaction retrieval by checking the transaction pool first when fetching a transaction if the checkTxnPool flag is true.
- Prioritizes pending transactions from the pool if available
- Falls back to fetching canonical transactions when no pool transaction is found
|
Added "Don not merge" as dependent on other PR |
Changes
checkTxnPoolis set totrue, firstly try to fetch the tx from the poolTypes of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?
Documentation
Requires documentation update
Requires explanation in Release Notes
Remarks
This heuristic should be better than the previous one, if the caller of the method expects the tx to be in the pool, we should check it first.