-
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
feat: make it possible to override method name
in subscriptions
#568
Conversation
method name
in subscription notif
I absolutely hate it. 😆 I would like to not have to support this, or at the very least understand why we need it. |
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 open questions, but looks good to me otherwise!
utils/src/server/rpc_module.rs
Outdated
} | ||
|
||
impl<Context> RpcModule<Context> { | ||
/// Create a new module with a given shared `Context`. | ||
pub fn new(ctx: Context) -> Self { | ||
Self { ctx: Arc::new(ctx), methods: Default::default() } | ||
Self { ctx: Arc::new(ctx), methods: Default::default(), notif_overrides: SubscriptionNotifOverride::default() } |
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.
This doesn't really prevent us from having the same notification name in two different modules (the set is local to the instance and is thrown away the moment you turn it into Methods
).
If we can't easily guarantee that notification names are unique, and there isn't really much of a point in checking that they are in the server (notifications will be sent regardless, and we rely on sub id more than name on the client anyway), I think it might actually be better to drop the check altogether.
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.
ty, can't we handle it in RpcModule::merge
?
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.
You can, but you'd have to move the hashset inside Methods
because that's what merge operates on.
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 keep it simple I removed all of this but kept the check in the proc macros for now, ok?
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 @maciejhirsz. I'm ok making this a "sharp" feature, but we need to document it properly. "NOTE: the author is expected to ensure the uniqueness of the override across all RpcModule
s used on the server." or some such.
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.
Note, we have a check for this in the proc macros
where each trait ensures uniqueness for each name.
Do you want me to remove it be to somewhat consistent?
…nto na-override-notif-method-name
method name
in subscription notifmethod name
in subscriptions
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.
Sorry for being a trouble maker wrt naming; I'm concerned about mixing up the concept of "notification" with the spec's definition.
We need to update the macro docs with a clear explanation of what this change is and when it's useful (stressing it should never be used for new code; people should use the subscription ID to track things).
@@ -312,7 +312,7 @@ async fn multiple_blocking_calls_overlap() { | |||
|
|||
#[tokio::test] | |||
async fn subscriptions_do_not_work_for_http_servers() { | |||
let htserver = HttpServerBuilder::default().build("127.0.0.1:0".parse().unwrap()).unwrap(); | |||
let htserver = HttpServerBuilder::default().build("127.0.0.1:0").unwrap(); |
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.
👍
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.
lgtm, fwiw I agree with David that some clearer naming could be a +1.
Co-authored-by: David <[email protected]>
So I did re-read things to make sure I have it right. There is nothing wrong with us using the term "Notification", and the spec explicitly allows / remains agnostic about server acting as a client:
We are using JSON-RPC notifications in a very specific fashion, but I don't see how that stops them from being notifications. TCP packets don't stop being TCP packets if they carry HTTP paylods. Everything we do with subscriptions is fully compliant with the JSON-RPC spec, we don't change anything about the spec, nor do we add anything to the spec, subscriptions are just a meta protocol bolted on top of it. |
Co-authored-by: David <[email protected]>
Co-authored-by: David <[email protected]>
Co-authored-by: David <[email protected]>
Co-authored-by: David <[email protected]>
Technically the naming is accurate because Good to get your review still to get some eyes outside the |
@niklasad1 Just read @maciejhirsz comments as well. Totally understand where the convention is coming from. Happy to see it kept as is as well. With a third glance over I can see it makes sense to have |
@maciejhirsz You are right and I am wrong; the spec is indeed agnostic just the way you quote it. My concern was we'd introduce a naming convention that conflicts with a specific meaning defined in the spec. Instead there is no such conflict. I'll go over my naming suggestions again and see if I know feel differently. Ty! |
@@ -31,6 +31,11 @@ pub trait Rpc { | |||
|
|||
#[subscription(name = "echo", aliases = ["ECHO"], item = u32, unsubscribe_aliases = ["NotInterested", "listenNoMore"])] | |||
fn sub_with_params(&self, val: u32) -> RpcResult<()>; | |||
|
|||
// This will send data to subscribers with the `method` field in the JSON payload set to `foo_subscribe_override` | |||
// because it's in the `foo` namespace. |
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.
oh that's a good point, let's not forget to include that in the docs for the macro.
Co-authored-by: David <[email protected]>
Co-authored-by: David <[email protected]>
Co-authored-by: David <[email protected]>
Co-authored-by: David <[email protected]>
Co-authored-by: David <[email protected]>
Fixes paritytech/substrate#8783 (comment) to be compatible with current the behavior on
substrate master
to make it possible to configure custom method name for subscriptions (i.e, not the same as subscription method name) to avoid breakage for libraries that can't distinguish betweenordinary notifications
andsubscription notifications
Example: