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

Some optimizations for JSON #3498

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Some optimizations for JSON #3498

wants to merge 5 commits into from

Conversation

toppk
Copy link

@toppk toppk commented Sep 24, 2024

What was wrong?

Closes #3496

How was it fixed?

This makes some modest changes to JSON, to squeeze out some spaces, get rid of some unnecessary object instantiation. added some test cases because JSONBaseProvider was tested, not AsyncJSONBaseProvider. The big issue I wanted to solve was to send text to websockets package, so the logging there would be in text, and not binary (see issue). But i didn't change Legacy for that, which still is bytes.

Todo:

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

Cute Animal Picture

image

@toppk
Copy link
Author

toppk commented Sep 25, 2024

fwiw, i think there are some things in this PR that might want to be picked up here, like making the web3.providers.auto not circular importing on web3.providers, even if some of the other bits are not wanted.

Copy link
Collaborator

@fselmo fselmo left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @toppk. There's definitely some good changes in here! I don't think we should break these existing methods and I don't think strictly passing a string to the socket is really the way to go. I'm not against opening the type up there though and encoding when a string is passed.

Thoughts on the comments here? We can take these changes on in a week or two, otherwise feel free to update here and I'll give this another pass.

def _json_list_errors(self, iterable: Iterable[Any]) -> Iterable[str]:
@classmethod
def _json_list_errors(
self,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self,
cls,

def _json_mapping_errors(self, mapping: Dict[Any, Any]) -> Iterable[str]:
@classmethod
def _json_mapping_errors(
self,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self,
cls,

@@ -164,7 +164,7 @@ async def make_batch_request(
# -- abstract methods -- #

@abstractmethod
async def socket_send(self, request_data: bytes) -> None:
async def socket_send(self, request_data: str) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'm good with opening up this type but this is a breaking change otherwise and I'm not keen on keeping it as string only. If you want to handle the string case, encoding the data if it's a string, I think that would be the best approach here.

We should make sure we update the docstring to reflect the change as well.

@@ -158,7 +158,7 @@ async def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse:
f"Making request HTTP. URI: {self.endpoint_uri}, Method: {method}"
)
request_data = self.encode_rpc_request(method, params)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This flow ends up in a strange "encoding" limbo where we have an encode_rpc_request that generates the request_data and yet we call request_data.encode() below. We should properly handle encoding within the encode_rpc_request method.

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.

make json improvements
2 participants