-
Notifications
You must be signed in to change notification settings - Fork 24
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
feat: cost tracking #146
base: master
Are you sure you want to change the base?
feat: cost tracking #146
Conversation
Co-authored-by: Ahmed Sagdati <[email protected]>
@rymnc let me know if this will work on the core side. Regarding the fields Instead of requesting the n last bundles I've went with a different approach where you tell us up until which height you have data and the committer respond with whatever came after. |
hmm, we could track cc'ing: @MitchTurner @xgreenx |
@MujkicA On a connected note, it sounds like you aren't making any guarantees to the decompression guys about the order in which the blocks are recorded. I'm not sure what our conversation was before, but I think it might (with some small modifications) be fine for us to receive things out of order... however, that complicates what we query for. |
@MitchTurner Note that both of these scenarios are edge-cases and since bundles usually consist of multiple fragments they're even less likely to be finalised out of order. The api will only report the cost for a block range if the corresponding bundle was marked as finalized (meaning all transactions carrying it's fragments have settled). I guess this doesn't absolve you from having to implement support for it but i maybe the details have some relevance to you. Alternatively, we could only report back costs up until we have a contiguous range. This would cause a delay in reporting more recent costs in those edge cases so it's up to you. At any rate, I'll deploy whatever version you prefer to the test networks so that we can test the integration. |
I'd rather receive them ASAP than in order. |
packages/storage/src/postgres.rs
Outdated
@@ -678,6 +685,136 @@ impl Postgres { | |||
Ok(()) | |||
} | |||
|
|||
pub(crate) async fn _update_costs( | |||
&self, | |||
cost_per_tx: Vec<TransactionCostUpdate>, |
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.
I'd change this fn so it is called for each TransactionCostUpdate
separately. Reason being that now that you're no longer doing db transactions, one bundle could pass, another could revert and you'd be left in a partially updated state.
If you do a tx by tx then if it fails it won't update anything on the db side.
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.
Another suggestion to make it even more robust is to merge together the tx state updating and the cost updating into one method seeing as they're always called together in the state listener.
That way you can wrap everything in one transaction and you cannot have a situation where you've updated the state but failed to update the costs. If anything fails you'll get another chance the next time the state listener runs.
The longer db tx locking time might be worth the retry-ability we'd get.
Closes #110
This PR introduces cost tracking and retrieval of bundle cost information through the api.
Implementation
The cost contributions of each transaction belonging to a bundle are incrementally accumulated each time a transaction is finalized. This is done to avoid computing the total cost of transactions on every api call and avoid inefficient response times.
Response Object
Method
Endpoint
GET /v1/costs?from_block_height=<HEIGHT>&limit=<LIMIT>