-
Notifications
You must be signed in to change notification settings - Fork 463
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
REST API: Check for pending transactions in most recent rounds first. #3836
Conversation
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.
nice, thanks!
Before merging, why do we not bail here? https://github.com/algorand/go-algorand/blob/master/node/node.go#L643 |
@algorandskiy do you happen to know how likely (or how long) a transaction might exist in both the txn pool and be committed to a round? If that case is common, I could understand why we search the ledger when a txn is pending, otherwise it seems pretty wasteful. |
Will I think the comment above makes sense - the txn not in the ledger when looking there, then the thread gets suspended, new block assembled and written, txn gone from the pool, then thread resumed, looking up the pool - no such txn id found. |
Since we check the tx pool first, why not just return if the tx is found? Basically, when an unconfirmed transaction is in the tx pool, we STILL check the last 1000 rounds even though we could return immediately. |
We need to check ledger to return a round number at which it was persisted. |
What would be the consequence of returning the transaction we find in the pending pool right away? Is there a risk involved in returning a transaction that says it hasn't been confirmed yet? |
It is up to our REST clients (the indexer, SDKs users etc). I think in general users want to know the txn they submit is confirmed (and it is in some block X). |
@barnjamin I think the short answer is that we are not confident enough about the operation order to know if we can exit early or not. |
I strongly disagree. This feels like preemptively trying to optimize the API UX. Why wouldn’t a user just query both the pending txns and the txns in the latest block and filter client side for their txn id? As a dev I’d rather be exposed to a faster API I can query repeatedly than just having it just wait around to find the confirmed txns. |
With Humble & Folks + some crazy TX committers hitting Algonode with 200+ /pending/{txid} requests per second we were forced to either rate limit the endpoint or risk the early return on TX POOL hit and cut the CPU usage by x100 (for this endpoint). The only 2 usage patterns for TX POSTing we've observed:
There are zero cases where /pending/{txid} is repeated for more than 2 rounds.
The second pattern seems to be the only "legal" way on algoexplorer's endpoints. Anyways - Algonode is running alogd with both reverse order search and early return on TX POOL hit patches. Considered a patch that scans recent 2 rounds instead 1k in case of TX POOL hit but found no rationale for that. If the code is used only for this endpoint and the usage is as above then it was all I needed to proceed. |
If we're still concerned about the txnPool holding transactions that have been confirmed maybe we can just set the maxLife value to some value representing the max number of rounds the transaction may stay in pending?
|
Codecov Report
@@ Coverage Diff @@
## master #3836 +/- ##
=======================================
Coverage 49.96% 49.97%
=======================================
Files 392 392
Lines 68378 68378
=======================================
+ Hits 34167 34169 +2
- Misses 30466 30472 +6
+ Partials 3745 3737 -8
Continue to review full report at Codecov.
|
Co-authored-by: Ben Guidarelli <ben.guidarelli@gmail.com>
…gorand into will/more-efficient-pending
Summary
More efficient check for pending transactions. In most cases, the check will be done right away, so it would be in a recent round. The check starts at the oldest round, which is the opposite of what would normally happen.
Test Plan
Existing unit tests.