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

Support batching multiple RPC requests #455

Merged
merged 117 commits into from
May 20, 2024

Conversation

franciszekjob
Copy link
Contributor

@franciszekjob franciszekjob commented Apr 24, 2024

Describe your changes

  • add batchRequests method (vararg and list versions)
  • add JsonRpcRequest data class
  • add BatchHttpRequest class
  • add test to ProviderTest:
    • batch call contract with block hash and block tag
    • batch get transactions
  • add tests to JsonRpcResponseTest:
    • rpc provider parses batch getTransactionStatus
    • rpc provider parses batch callContract
    • rpc provider parses batch response with incorrect order
  • implement JsonRpcRequest data class representing single RPC request
  • update starknet-jvm.md readme with proper examples of batchRequests usage

Linked issues

Closes #443

Breaking changes

  • This issue contains breaking changes

@franciszekjob franciszekjob marked this pull request as ready for review April 25, 2024 01:29
Copy link
Collaborator

@DelevoXDG DelevoXDG left a comment

Choose a reason for hiding this comment

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

Some minor things remain to be addressed, but looking good overall

lib/src/test/kotlin/starknet/provider/ProviderTest.kt Outdated Show resolved Hide resolved
public class Main {
public static void main(String[] args) {
// Create a provider for interacting with Starknet
Provider provider = new JsonRpcProvider("https://example-node-url.com/rpc");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just making sure, have you tried running this example code?

It seems to me that this might not work, as provider is of Provider interface, and Provider interface (I assume intentionally) does not support batchRequests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, batchRequests is not supported by Provider. It is a custom method and not an equivalent of specified Starknet endpoint. That's why I decided not to include it in Provider.

However, it may be potentially confusing for users that they cannot use batchRequests on an instance of Provider.

Wdyt?

Regarding the test - I've updated sample code and replaced Provider with JsonRpcProvider 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is a custom method and not an equivalent of specified Starknet endpoint. That's why I decided not to include it in Provider.

I would say it's JSON-RPC specific method. Previously, we also had GatewayProvider which likely would not support batching. However, currently afaik there are no ways to communicate with Starknet other than JSON-RPC, so theoretically all providers are "JSON-RPC" providers, and the original naming was retained mainly for backward compatibility.

The way I see it, we either:

  1. Leave batching only in JsonRpcProvider, because it's JSON-RPC specific.
  2. Push batching up to Provider interface to allow users to keep using the Provider as an interface.

It seems to me 2. offers broader utility, however, it slightly breaks abstraction by introducing some underlying request and response mechanics to the provider interface.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While I generally uphold the principle of not violating the level of abstraction, the deviation in this case is rather minimal, making the 2. option possibly acceptable 👍 . Consequently, implementing Provider interface in JsonRpcpProvider currently seems unnecessary and doesn't add significant value. Do we want to keep it, if all providers are "JSON-RPC" providers?

WDYT?

Copy link
Collaborator

@DelevoXDG DelevoXDG May 9, 2024

Choose a reason for hiding this comment

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

Do we want to keep it, if all providers are "JSON-RPC" providers?

Discussed offline.

the deviation in this case is rather minimal, making the 2. option possibly acceptable

Another thing that concerns me is that we'd introduce HttpRequest<T> to the method signature of an interface, which is not abstract unlike `Request and is JSON-RPC specific.

I don't have a strong say on what's the best approach here, @THenry14 wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

No strong opinion either, but I guess it makes a bit more sense to me to keep it in JsonRpcProvider

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 89.15663% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 69.62%. Comparing base (d28b008) to head (ce6d87a).
Report is 4 commits behind head on main.

Files Patch % Lines
...starknet/provider/rpc/BuildJsonHttpDeserializer.kt 83.33% 2 Missing and 2 partials ⚠️
...swmansion/starknet/provider/rpc/JsonRpcProvider.kt 84.61% 3 Missing and 1 partial ⚠️
...com/swmansion/starknet/service/http/HttpRequest.kt 96.96% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #455      +/-   ##
==========================================
- Coverage   71.12%   69.62%   -1.50%     
==========================================
  Files          75       75              
  Lines        3338     3315      -23     
  Branches      367      365       -2     
==========================================
- Hits         2374     2308      -66     
- Misses        798      850      +52     
+ Partials      166      157       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@DelevoXDG DelevoXDG left a comment

Choose a reason for hiding this comment

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

LGTM

@franciszekjob franciszekjob merged commit 7fabfc8 into main May 20, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support batching multiple RPC requests
4 participants