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

Add WebSocket RPC methods: subscribeNewHeads, unsubscribe #634

Merged
merged 42 commits into from
Nov 8, 2024

Conversation

FabijanC
Copy link
Contributor

@FabijanC FabijanC commented Oct 25, 2024

Usage related changes

  • Introduce support for starknet_subscribeNewHeads and starknet_unsubscribe.
    • Other methods using todo!.
  • Partially address JSON-RPC API 0.8.0 adaptation #613
  • Address TODO in main.rs which prevented SIGINT from killing Devnet instantly in block-on-interval mode.
  • Remove general RPC support, i.e. methods like starknet_getNonce or devnet_mint are no longer supported via WebSocket. Apparently they never should have been, only starknet_(un)subscribe methods should be available via this protocol.
    • Not a breaking change since this was never a part of the main branch.

Development related changes

  • Socket ID and subscription ID generated randomly - should have low collision probability since they use i64.
    • Just search for rand::random() to find occurrences of this.
    • Alternatively we could generate in loop until an unused value is generated.
  • Refactor JsonRpcHandler:
    • Introduce new helper function to_json_rpc_request
    • Add new helper method allows_method which checks restrictedness, relying on previously defined is_json_rpc_method_restricted
  • Expand the server's api property with a sockets map.
  • Parts of code related to unimplemented subscription methods is commented out. This is to prevent warnings suggesting Boxing of enum variants.
  • Since general RPC support via WebSocket is removed, the corresponding tests are ignored, but a new test is introduced which asserts that the general RPC support is indeed not supported.
  • The case for invalid subscription request due to TooManyBlocksBack is not tested because I couldn't make it generate 1024 blocks efficiently.

Checklist:

  • Checked out the contribution guidelines
  • Applied formatting - ./scripts/format.sh
  • No linter errors - ./scripts/clippy_check.sh
  • No unused dependencies - ./scripts/check_unused_deps.sh
  • No spelling errors - ./scripts/check_spelling.sh
  • Performed code self-review
  • Rebased to the latest commit of the target branch (or merged it into my branch)
    • Once you make the PR reviewable, please avoid force-pushing
  • Updated the docs if needed - ./website/README.md
  • Linked the issues resolvable by this PR - linking info
  • Updated the tests if needed; all passing - execution info

@FabijanC FabijanC changed the title Introduce WebSocket RPC methods Add WebSocket RPC methods: subscribeNewHeads, unsubscribe Nov 6, 2024
@FabijanC FabijanC marked this pull request as ready for review November 6, 2024 10:52
@FabijanC FabijanC merged commit c5e3a61 into json-rpc-v0.8.0 Nov 8, 2024
1 check passed
@FabijanC FabijanC deleted the ws-methods branch November 8, 2024 11:44
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