-
Notifications
You must be signed in to change notification settings - Fork 173
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
Module API refactor #412
Module API refactor #412
Conversation
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.
Still a draft but here are my thought so far:
- I think that in the back of our heads we had in mind a setup flow where a ref to the
Server
would be passed around to different subsystems and each wouldregister_module()
to add "their" RPC calls. Instead what substrate does is the opposite, the subsystems are all asked for their sets of RPC calls and when they're all collected they are added to the server in a single place. (This architecture is what is making initialization tricky to do in more than one place, such as adding specific RPC modules on the basis of config files that are processed in different places. This is hackfix-solved by passing around closures.) - This work here makes it more obvious that setting up the server and the methods to call are quite separate things. I think it makes sense (and the DRYing is welcome obviously).
- A UI-test for a bad macro setup would be nice, one proving that the static method check works as expected.
- I might be wrong but I'm not sure we have good tests for setting up and starting both a ws and http server; would be good to have one.
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 like it. Minor grumbles.
#[method(name = "foo")] | ||
async fn foo(&self) -> u8; | ||
|
||
#[method(name = "foo")] |
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.
Ok, but this is the easy case. Let's do two separate modules?
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.
Separate modules need to be merged on runtime, and merge can return regular errors, there is no way to check them on compile time.
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.
Good pt!
Co-authored-by: David <dvdplm@gmail.com>
Since we want to support both HTTP and WS servers sharing the same
Methods
internally, it makes more sense to force the user to pre-merge all their modules into one before cloning it and passing it to their respective servers. This PR changes some of the module API to make this the expected behavior.register_module
on both WS and HTTP server, instead when starting a server you can pass a singleInto<Methods>
type.RpcModule<T>
implementsDeref<Target = Methods>
andDerefMut
to keep module merging logic DRY.into_rpc
need not return aResult
.method_names
returns anIterator
instead of aVec
.