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

[V6] Implement RPC Batch #758

Closed
tabaktoni opened this issue Sep 15, 2023 · 11 comments · Fixed by #1125
Closed

[V6] Implement RPC Batch #758

tabaktoni opened this issue Sep 15, 2023 · 11 comments · Fixed by #1125
Assignees
Labels
OnlyDust Open for OnlyDust contributors released on @next Type: feature New feature or request

Comments

@tabaktoni
Copy link
Collaborator

Similar to Viem, time-based batch with config options.
Ref: #653
Viem docs: https://viem.sh/docs/clients/transports/http.html#batch-optional

@tabaktoni tabaktoni added Type: feature New feature or request OnlyDust Open for OnlyDust contributors labels Sep 15, 2023
@PhilippeR26
Copy link
Collaborator

What will be the benefits for the user ?

@ivpavici
Copy link
Collaborator

ivpavici commented Sep 18, 2023

@PhilippeR26 I'm copying this proposal from Francesco:
Hello, how do you feel about an option in the RpcProvider to automatically batch rpc calls made in the same loop of the event loop (or within a time period) together? That's what viem does and it helps avoid 429 errors. Implementation (by copying viem code, so licensing/attribution requires consideration) is trivial to add.
It's useful because not only it avoids 429s, but also it helps on page load to have all content appear on the screen at the same time
RPC providers also limit how many requests you can make in a limited time window
...
so they limit making 100 requests at the same time, but one batch with 100 method calls inside is fine

@PhilippeR26
Copy link
Collaborator

PhilippeR26 commented Sep 18, 2023

Are Starknet nodes already able to handle such batched requests?
The JSON-RPC spec https://www.jsonrpc.org/specification#batch() is telling :

The Server MAY process a batch rpc call as a set of concurrent tasks, processing them in any order and with any width of parallelism.

Couldn't this be messy for our use case? and to be useful only for a batch of Read commands (not for Write command) ; for example 50 commands of getBlock()?
If the webpage has to wait the end of a batch of 10 invokes, it could be frozen for a very long time. Isn't it better to show progress after each transaction?

So, I see an interest for a large batch of Calls, mainly getBlock(). I am rather anxious for other usage...

@PhilippeR26
Copy link
Collaborator

PhilippeR26 commented Sep 18, 2023

I have found this interesting doc of Ethereum node Geth : https://geth.ethereum.org/docs/interacting-with-geth/rpc/batch
Similar spirit to mine.

@tabaktoni tabaktoni changed the title Implement RPC Batch [V6] Implement RPC Batch Nov 13, 2023
@ivpavici ivpavici added the ODHack Issue to assign for the ODHack event label Apr 19, 2024
@ugur-eren
Copy link
Contributor

ugur-eren commented May 13, 2024

Hi @tabaktoni , if this issue is still available i can work on it. Since Starknet nodes supports batch requests, it can be implemented rather easily.
I've tried a few things, and IMO it can be implemented in this way: A new BatchClient class can be created and initialized in the rpc_0_6 and rpc_0_7 RpcChannel classes. If the batch option is enabled, we can use the BatchClient to send the requests at the fetch method, if not enabled, current fetch method will be used.

@ivpavici ivpavici removed the ODHack Issue to assign for the ODHack event label May 13, 2024
@ivpavici
Copy link
Collaborator

@ugur-eren sure, you can try

@tabaktoni
Copy link
Collaborator Author

To be honest i don't see the point as startknet provide multi call but, instead of user creating call array, it cold be done behind the scene.
This could be DX improvement in some way if implemented good. Try and will see.

@ugur-eren
Copy link
Contributor

ugur-eren commented May 13, 2024

I agree, contract calls can be used with multicall, a simple function to batch requests can be implemented, for example unraggle.meme multiCallContract function. However adding batch would also enable batching for built-in methods, like getBlockNumber or getEvents.

Copy link

🎉 This issue has been resolved in version 6.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ugur-eren
Copy link
Contributor

Hi @tabaktoni this issue is resolved with my PR #1125 can be closed.
Also, sorry for asking but will there be a reward for this through onlydust?

@ivpavici
Copy link
Collaborator

ivpavici commented Aug 12, 2024

@ugur-eren reward sent!

thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OnlyDust Open for OnlyDust contributors released on @next Type: feature New feature or request
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

4 participants