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

Non-standard JSON-RPC request fields #797

Closed
tgmichel opened this issue Jun 17, 2022 · 3 comments
Closed

Non-standard JSON-RPC request fields #797

tgmichel opened this issue Jun 17, 2022 · 3 comments

Comments

@tgmichel
Copy link
Contributor

Some http providers by default include non-standard fields (i.e. skipCache) in the request. This results in Invalid Request as the Request explicitly denies deserialization of unknown fields.

To support this type of requests on jsonrpsee, some options:

  • Adding a generic parameter to Request to allow accepting specific non-standard fields. This generic must implement Deserialize, represented as a flatten field in Request, and default to an empty type, something like:
#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Request<'a, RequestExtension: Deserialize> {
	/// JSON-RPC version.
	pub jsonrpc: TwoPointZero,
	/// Request ID
	#[serde(borrow)]
	pub id: Id<'a>,
	/// Name of the method to be invoked.
	#[serde(borrow)]
	pub method: Cow<'a, str>,
	/// Parameter values of the request.
	#[serde(borrow)]
	pub params: Option<&'a RawValue>,
	#[serde(flatten, default = "EmptyRequestExtension::default")]
        pub extension: RequestExtension,
}

#[derive(Deserialize, Debug, Default)]
struct EmptyRequestExtension;
  • Other option can be putting deny_unknown_fields behind a feature flag, which will optionally accept any non-standard field.
@niklasad1
Copy link
Member

all right, I see.

Do you know if there's any documentation about these extra fields and what the other servers does with that information?

We could also just remove deny_unknown_fields, IIRC we did this to be explicit when testing but question is if we want to handle these "extensions". I guess we don't want to...

@tgmichel
Copy link
Contributor Author

tgmichel commented Jun 17, 2022

Do you know if there's any documentation about these extra fields and what the other servers does with that information?

Unforntunately I couldn't find any. I believe in some server implementation there is some cache for response payloads, and this skipCache flag indicates wether to use this cache or not.

question is if we want to handle these "extensions". I guess we don't want to...

I agree, discriminating valid and invalid non-standard fields will likely become a problem (what is a valid non-standard field anyway?) Removing deny_unknown_fields (or setting this as default feature) seems reasonable to me.

@niklasad1
Copy link
Member

Closed by #803

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

No branches or pull requests

2 participants