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

gRPC wasm Clients #102

Open
liangping opened this issue May 25, 2022 · 13 comments
Open

gRPC wasm Clients #102

liangping opened this issue May 25, 2022 · 13 comments

Comments

@liangping
Copy link
Contributor

NOTE: This might not strongly related to telescope.

Currently, most of web apps have to use Javascript/Typescript to connect with light client server, since most web explorers don’t support gRPC and http2.

It's very useful to build a gRPC client with Web assembly and http2. Once it is built, developers can easily invoke gRPC services underlying the Rest services. and it is smaller, faster, laser resources consumed.

With Telescope, This could be much earlier.

List all services

% ./grpcurl grpc-osmosis-ia.notional.ventures:443 list
bech32ibc.bech32ibc.v1beta1.Query
cosmos.auth.v1beta1.Query
cosmos.authz.v1beta1.Query
cosmos.bank.v1beta1.Query
cosmos.base.reflection.v1beta1.ReflectionService
cosmos.base.reflection.v2alpha1.ReflectionService
cosmos.base.tendermint.v1beta1.Service
cosmos.distribution.v1beta1.Query
cosmos.evidence.v1beta1.Query
cosmos.gov.v1beta1.Query
cosmos.params.v1beta1.Query
cosmos.slashing.v1beta1.Query
cosmos.staking.v1beta1.Query
cosmos.tx.v1beta1.Service
cosmos.upgrade.v1beta1.Query
cosmwasm.wasm.v1.Query
grpc.reflection.v1alpha.ServerReflection
ibc.applications.transfer.v1.Query
ibc.core.channel.v1.Query
ibc.core.client.v1.Query
ibc.core.connection.v1.Query
ibc.core.port.v1.Query
osmosis.claim.v1beta1.Query
osmosis.epochs.v1beta1.Query
osmosis.gamm.v1beta1.Query
osmosis.incentives.Query
osmosis.lockup.Query
osmosis.mint.v1beta1.Query
osmosis.poolincentives.v1beta1.Query
osmosis.superfluid.Query
osmosis.txfees.v1beta1.Query
testdata.Query

List Methods of a service:

% ./grpcurl grpc-osmosis-ia.notional.ventures:443 list cosmos.base.tendermint.v1beta1.Service
cosmos.base.tendermint.v1beta1.Service.GetBlockByHeight
cosmos.base.tendermint.v1beta1.Service.GetLatestBlock
cosmos.base.tendermint.v1beta1.Service.GetLatestValidatorSet
cosmos.base.tendermint.v1beta1.Service.GetNodeInfo
cosmos.base.tendermint.v1beta1.Service.GetSyncing
cosmos.base.tendermint.v1beta1.Service.GetValidatorSetByHeight

invoke gRPC calls:

Call cosmos.base.tendermint.v1beta1.Service.GetLatestBlock return proto message.

Therefore, We can call all services directly via gRPC

@pyramation
Copy link
Collaborator

thanks @liangping ! will be integrating this into our gRPC client class. Appreciate the help!

@liangping
Copy link
Contributor Author

thanks @liangping ! will be integrating this into our gRPC client class. Appreciate the help!

Awesome! If so i would like to use this instead of the current LCD endpoint on ping.pub.

@sascha1337
Copy link

gRPCFTW

@pyramation pyramation mentioned this issue May 26, 2022
2 tasks
@pyramation pyramation changed the title GRPC WASM Clients gRPC Clients May 26, 2022
@pyramation
Copy link
Collaborator

pyramation commented May 26, 2022

@sascha1337 @liangping does this look like a good reference implementation?

https://github.com/cosmos/cosmjs/blob/main/packages/stargate/src/modules/bank/queries.ts#L20-L59

It looks like they were actually using this? https://github.com/confio/cosmjs-types/blob/main/src/cosmos/bank/v1beta1/query.ts#L1079

I think we can improve it a bit?

Some ideas:

  1. class methods could be camelCase not SuperCase (this could also be configurable per dev's config).
  2. we can combine what is inside of QueryClientImpl here with how it's used here to make one cohesive class.

Any feedback or thoughts you may have on how we should implement this?

@liangping
Copy link
Contributor Author

On protobuf, It's good reference.

It might be almost same, except this one:

const rpc = createProtobufRpcClient(base);

gRPC client need Http2(almost all web explorer(chrome, firefox) don't support it so far), we need implement it with WASM.

@liangping
Copy link
Contributor Author

look at

export function createProtobufRpcClient(base: QueryClient): ProtobufRpcClient {
  return {
    request: (service: string, method: string, data: Uint8Array): Promise<Uint8Array> => {
      const path = `/${service}/${method}`;
      return base.queryUnverified(path, data);
    },
  };
}

seems that we can just simply re-implement this method.

public async queryUnverified(path: string, request: Uint8Array): Promise<Uint8Array> {
    const response = await this.tmClient.abciQuery({
      path: path,
      data: request,
      prove: false,
    });

    if (response.code) {
      throw new Error(`Query failed with (${response.code}): ${response.log}`);
    }

    return response.value;
  }

@liangping
Copy link
Contributor Author

liangping commented May 27, 2022

@pyramation
Copy link
Collaborator

thank you @liangping 🙌🏻

this is great to have all the information we need for this issue in one place.

I confirm that tmclient is implemented based on http, not http2 https://github.com/cosmos/cosmjs/blob/b63075aca18538a0c9f312dfaf43be271f5d39aa/packages/tendermint-rpc/src/tendermint34/tendermint34client.ts#L17

I think secret.js uses this for http2 https://github.com/improbable-eng/grpc-web

Should we look at what secret is doing? https://github.com/scrtlabs/secret.js/blob/master/src/secret_network_client.ts#L636-L723

@liangping
Copy link
Contributor Author

I think we are almost there. Secret did amazing works.
We can improve it. In this implementation, we need a gRPC proxy which is not friendly to users.
That's why I want to use WASM.

@pyramation
Copy link
Collaborator

Looking at more clients out there, found this one:
https://github.com/deeplay-io/nice-grpc

@pyramation
Copy link
Collaborator

cosmos/cosmjs#885

@daniel-farina daniel-farina mentioned this issue Jun 28, 2022
15 tasks
@pyramation pyramation changed the title gRPC Clients gRPC wasm Clients Jul 20, 2022
@sascha1337
Copy link

Sometimes GitHub ui sucks, using mobile GitHub app now, i see meantion and comments that completely were kinda hidden on desktop 🤦‍♂️

I've worked a lot on grpc / introspection methods and solutions lately, if combined with cosmology repo // chain registry api's, this is really powerful stuff, need and built this for myself, so time to get that wrapped and packed to npm sers.

@sascha1337
Copy link

Also check efficiency // references here on bottom

cosmos/cosmos-sdk#10045

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

3 participants