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

PortalNetwork: Implement UltralightProvider Enhancements for EIP-1193 JSON-RPC Support #699

Merged
merged 9 commits into from
Jan 6, 2025

Conversation

cjustinobi
Copy link
Contributor

Key Enhancements:

  1. EIP-1193 Method Support:

    • Implements commonly used Ethereum JSON-RPC methods:
      • eth_getBlockByHash
      • eth_getBlockByNumber
      • eth_getTransactionCount
      • eth_getCode
      • eth_getBalance
      • eth_getStorageAt
      • eth_call
  2. Error Handling:

    • Adds robust error codes and messages based on JSON-RPC specifications:
      • 4200 for unsupported methods.
      • -32602 for invalid parameters.
      • -32603 for internal errors.
  3. Removed unused methods from provider.spec.ts

Copy link
Collaborator

@acolytec3 acolytec3 left a comment

Choose a reason for hiding this comment

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

This is looking great so far. One thing we need to address is that the provider should return JSON-RPC formatted data and not just the raw block/transaction/state data our portalnetwork.ETH module returns. If you want to do that work as well, let me know and I can provide guidance on next steps or else I can do that in a subsequent PR.

Basically, we need to use these helpers with some slight edits that I can outline.

@cjustinobi
Copy link
Contributor Author

This is looking great so far. One thing we need to address is that the provider should return JSON-RPC formatted data and not just the raw block/transaction/state data our portalnetwork.ETH module returns. If you want to do that work as well, let me know and I can provide guidance on next steps or else I can do that in a subsequent PR.

Basically, we need to use these helpers with some slight edits that I can outline.

Please go ahead with the guidance. Would love to handle as well

@cjustinobi cjustinobi changed the title WIP: Implement UltralightProvider Enhancements for EIP-1193 JSON-RPC Support Portalnetwork: Implement UltralightProvider Enhancements for EIP-1193 JSON-RPC Support Dec 28, 2024
@cjustinobi cjustinobi marked this pull request as ready for review December 28, 2024 14:37
@cjustinobi cjustinobi changed the title Portalnetwork: Implement UltralightProvider Enhancements for EIP-1193 JSON-RPC Support PortalNetwork: Implement UltralightProvider Enhancements for EIP-1193 JSON-RPC Support Dec 28, 2024
@acolytec3
Copy link
Collaborator

To make the provider fully EIP compliant, each of the supported methods needs to return the values formatted to match the Ethereum JSON-RPC specification. So for each method listed in the PR description, you need to verify that the values returned by that method correspond to the JSON-RPC spec.

For the methods that return blocks, you can copy the the toJSONRPCBlock from the ethereumjs-monorepo client helpers here.

You'll need to update the toJSONRPCBlock method to remove the chainId parameter and then remove the totalDifficulty calculation. Instead, just use the difficulty from the block header object as that field in the return value.

For the other methods (getCode, getBalance, getStorage, call), you can reference the corresponding methods in the eth module in the ethereumjs client RPC implementation as a reference point for how to format the return values (or just reference the official spec).

Also, if you can update your test script to make calls to these additional methods, that would be great. For the state related methods, you'll have to pick an account that was present in the Ethereum state in ancient chain history (so maybe before block 10000000) since the state network doesn't fully support current state yet. Let me know if you need help with this part of it.

@cjustinobi
Copy link
Contributor Author

To make the provider fully EIP compliant, each of the supported methods needs to return the values formatted to match the Ethereum JSON-RPC specification. So for each method listed in the PR description, you need to verify that the values returned by that method correspond to the JSON-RPC spec.

For the methods that return blocks, you can copy the the toJSONRPCBlock from the ethereumjs-monorepo client helpers here.

You'll need to update the toJSONRPCBlock method to remove the chainId parameter and then remove the totalDifficulty calculation. Instead, just use the difficulty from the block header object as that field in the return value.

For the other methods (getCode, getBalance, getStorage, call), you can reference the corresponding methods in the eth module in the ethereumjs client RPC implementation as a reference point for how to format the return values (or just reference the official spec).

Also, if you can update your test script to make calls to these additional methods, that would be great. For the state related methods, you'll have to pick an account that was present in the Ethereum state in ancient chain history (so maybe before block 10000000) since the state network doesn't fully support current state yet. Let me know if you need help with this part of it.

Got it

Copy link
Collaborator

@acolytec3 acolytec3 left a comment

Choose a reason for hiding this comment

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

I've pushed a commit that fixes a configuration thing I forgot about with state network and then cleans up the parameter typing within provider.ts.

getBlockByNumber isn't reliably returning a block yet so I need do some additional testing to see why that is since we should generally always be able to retrieve block by number. The state network calls still aren't working right so I need to also research that a bit further since state network stuff has reliably worked for me in the past.

Copy link
Collaborator

@acolytec3 acolytec3 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for your work on this one!

I found one small bug in one of our portal.ETH initializers I've fixed here as well as some response formatting on the provider methods. This has been a huge help though so thank you!

@acolytec3 acolytec3 merged commit 4be0de4 into ethereumjs:master Jan 6, 2025
5 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.

2 participants