sui icon indicating copy to clipboard operation
sui copied to clipboard

[RPC backward compatibility] - RPC method routing base on client version

Open patrickkuo opened this issue 2 years ago • 4 comments

Summary

This PR adds method routing capability to RPC server base on client's information provided in the request header, this provides some level of backward compatibility on the server side.

List of client header

"client-sdk-type"; "client-sdk-version"; "client-target-api-version";

How it works

The RPC server construct a routing table of all the methods on start up, the RoutingLayer uses the mapping to redirect incoming jsonrpc request to corresponding methods base on client version.

When there is a breaking change to a rpc method, we can retain the old method in the RPC API and annotate it with the version information, e.g.

#[open_rpc(namespace = "test")]
#[rpc(server, client, namespace = "test")]
trait TestApi {
    #[method(name = "foo")]
    async fn foo(&self, some_bool: bool) -> RpcResult<String>;

    #[method(name = "foo", version <= "1.5")]
    async fn bar(&self, some_str: String) -> RpcResult<String>;
}

In this example, bar is the older version of foo, all client with version less than or eq to 1.5 will be routed to the bar method.

Also in this PR: added deprecated flag to openrpc spec

patrickkuo avatar Feb 16 '23 01:02 patrickkuo

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
explorer ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 21, 2023 at 6:39PM (UTC)
explorer-storybook ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 21, 2023 at 6:39PM (UTC)
frenemies ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 21, 2023 at 6:39PM (UTC)
wallet-adapter ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 21, 2023 at 6:39PM (UTC)

vercel[bot] avatar Feb 16 '23 01:02 vercel[bot]

rust code is ready for review, I am investigating the End-to-end Tests / Localnet failing test

patrickkuo avatar Feb 17 '23 17:02 patrickkuo

Saw this warning in the logs

HTTP serve connection failed hyper::Error(User(Service), Error("invalid type: map, expected a string \"2.0\"", line: 1, column: 1))

which might be why the e2e tests are failing

666lcz avatar Feb 19 '23 18:02 666lcz

Saw this warning in the logs

HTTP serve connection failed hyper::Error(User(Service), Error("invalid type: map, expected a string \"2.0\"", line: 1, column: 1))

which might be why the e2e tests are failing

ya it was because of batched jsonrpc request

patrickkuo avatar Feb 19 '23 22:02 patrickkuo