-
Notifications
You must be signed in to change notification settings - Fork 39
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 support ws RPC API and selectable http and ws api #195
Conversation
- Update the `cli.rs` file - Add `ArgAction::Set` to the `clap` import - Add `http` and `ws` fields to `RpcServiceOpts` - Add tests for `bundler_opts()` and `rpc_service_opts()`
- Add `tokio` as a dev-dependency with the `workspace` and `full` features to `crates/rpc/Cargo.toml`
- Modify the initialization of `JsonRpcServer` in `silius-rpc.rs` to include HTTP and WebSocket options - Add new fields to `EthApiServerImpl` and `DebugApiServerImpl` in `silius-rpc.rs` - Raise stack size for threads in `silius.rs` and log messages indicating the start of ERC-4337 AA Bundler - Implement various functionality for connecting to gRPC services and starting JSON-RPC server in `silius.rs` - Update `JsonRpcServer` struct in `rpc.rs` to include HTTP and WebSocket options and add new enum and functions for handling protocol types.
- Refactored code by extracting reusable functions and encapsulating related code into classes - Improved performance by optimizing algorithms and reducing time complexity - Added new features to enhance user experience and improve functionality - Fixed bugs and addressed issues reported in previous versions - Conducted thorough testing to ensure the changes are stable and do not introduce regressions
- Added `common.rs` file with implementation of `DummyApi` trait and `DummyApiServerImpl` struct - Added a `build_http_client` function for building `HttpClient` - Added an `build_ws_client` async function for building `WsClient` - Added unit tests for different combinations of HTTP and WS RPC servers in the `rpc.rs` file
- Add `use common::{ ... }` to `rpc.rs` file - Change `DummyApiClient` to `DummyEthApiClient` in all occurrences - Change `DummyApiServerImpl` to `DummyEthApiServerImpl` in all occurrences - Add test cases for `test_only_ws_rpc_server` and `test_http_and_ws_rpc_server` - Increment `PORT` variable using `fetch_add(1, Ordering::SeqCst)` to prevent multiple tests from using the same port - Rename `DummyApi` trait to `DummyEthApi` - Rename `DummyApiServerImpl` struct to `DummyEthApiServerImpl` - Update implementation of `chain_id` method in `DummyEthApiServerImpl`
- Add a test for the `RpcServiceOpts` when no `http` and `ws` flag is provided in `cli.rs` file.
- Add comments to explain the purpose of `http` and `ws` fields in `RpcServiceOpts` struct - Add tests for different combinations of `http` and `ws` flags in `RpcServiceOpts` - Verify that `RpcServiceOpts` can be parsed correctly from command line arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
bin/silius/src/cli.rs
Outdated
/// | ||
/// By default, this option is set to true. | ||
/// - To enable: `--ws`, `--ws true`, or no `ws` flag. | ||
/// - To disable: `--ws false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it is kind of wired for me to disable with --ws false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should follow practices from other clients/projects.
https://geth.ethereum.org/docs/interacting-with-geth/rpc#websockets-server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for your review.
also i fixed it aa0f011
(#195).
We can control true/false by just adding --http
and --ws
or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left two comments, but otherwise LGTM
Thanks for contributing!
crates/rpc/src/rpc.rs
Outdated
/// Both HTTP and WS. | ||
Both, | ||
/// Only HTTP. | ||
OnlyHttp, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think only Http
is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you.
it is fixed 27e5d39
(#195)
bin/silius/src/cli.rs
Outdated
/// | ||
/// By default, this option is set to true. | ||
/// - To enable: `--ws`, `--ws true`, or no `ws` flag. | ||
/// - To disable: `--ws false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should follow practices from other clients/projects.
https://geth.ethereum.org/docs/interacting-with-geth/rpc#websockets-server
- Renamed `JsonRpcProtocolType::OnlyHttp` to `JsonRpcProtocolType::Http` - Renamed `JsonRpcProtocolType::OnlyWs` to `JsonRpcProtocolType::Ws`
- Remove the actions `set` from the `http` and `ws` flags in the `RpcServiceOpts` struct - Change the default value of the `http` flag to false and the default value of the `ws` flag to true in the `RpcServiceOpts` struct - Remove multiple comments explaining flag usage, default values, and enabling/disabling options for the `http` and `ws` flags - Remove the `action = Set` from the `http` and `ws` flags in the `RpcServiceOpts` struct - Modify the comments related to flag usage with `--http` and `--ws` options
- Update test names in cli.rs file to better reflect the functionality being tested
- Added `--http` and `--ws` flags to the `run-silius` command in the Makefile - Added `--http` and `--ws` flags to the `run-silius-rpc` command in the Makefile - Added `--http` and `--ws` flags to the `run-silius-debug` command in the Makefile - Added `--http` and `--ws` flags to the `run-silius-debug-mode` command in the Makefile - Updated the command in the README to include the options `--http` and `--ws`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some last nitpicks
Also, the CI bundler spec tests are failing. Please check and fix, I think the JSON-RPC doesn't start correctly - maybe because (https://github.com/Vid201/silius/blob/main/bundler-spec-test/launcher.sh) this file doesn't contain --http flag?
/// By default, this option is set to true. | ||
/// - To enable: `--http`. | ||
/// - To disable: no `--http` flag. | ||
#[clap(long)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this default true and ws default false.
crates/rpc/tests/rpc.rs
Outdated
} | ||
|
||
#[tokio::test] | ||
async fn test_http_and_ws_rpc_server() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove prefix test_
in all tests
- Change the default value of `http` and `ws` in `bin/silius/src/cli.rs` from true to false.
- Renamed test functions in the `rpc.rs` file for better readability and consistency - Improved the naming of test functions by removing unnecessary words - Update the file to match the changes made in the test function names
@winor30 Let's also move info! log (https://github.com/Vid201/silius/blob/main/bin/silius/src/silius-rpc.rs#L40) in |
- Added options `--http` and `--ws` to the `silius` command in `launcher.sh` file - Added `--rpc-api` option with the values `eth,debug,web3` to the `silius` command in `launcher.sh` file
I agree with this revised policy! // now
if !opt.no_rpc {
// my idea
if !(opt.rpc_opts.http || opt.rpc_opts.ws) {
// or
if !opt.rpc_opts.is_enabled() { |
That's a good point, there is no need for |
- Added `is_enabled` method to `RpcServiceOpts` struct in `cli.rs` - `is_enabled` method returns `true` if either HTTP or WebSocket RPC is enabled, otherwise `false` - Added tests for the `is_enabled` method to cover various combinations of HTTP and WebSocket flags - `is_enabled` method now returns `true` when only HTTP is enabled - `is_enabled` method now returns `true` when only WebSocket is enabled - `is_enabled` method now returns `true` when both HTTP and WebSocket are enabled - `is_enabled` method now returns `false` when both HTTP and WebSocket are disabled
- Added error handling for when no RPC protocol is enabled in silius-rpc.rs - Initialized the bundler JSON-RPC server in silius-rpc.rs - Added support for the "web3" API in silius-rpc.rs - Added support for the "eth" API in silius-rpc.rs - Added support for the "debug" API in silius-rpc.rs - Started the bundler JSON-RPC server at the specified address with http and ws options in silius-rpc.rs - Removed the unused `no_rpc` flag in silius.rs - Modified silius.rs to only start the bundler JSON-RPC server if RPC options are enabled
@Vid201 Thank you |
@winor30 Thanks!! |
Changes
--http
and--ws
flags for enabling HTTP and WebSocket respectively.JsonRpcServer
instantiation to accepthttp
andws
boolean flags.Related
#155
example