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

Expected to support gRPCurl tool for grpc interface invocation easily #5391

Closed
hitlxy opened this issue Aug 2, 2023 · 4 comments · Fixed by #5583
Closed

Expected to support gRPCurl tool for grpc interface invocation easily #5391

hitlxy opened this issue Aug 2, 2023 · 4 comments · Fixed by #5583

Comments

@hitlxy
Copy link

hitlxy commented Aug 2, 2023

Rationale

Expected Java-tron to support gRPCurl tool for grpc interface invocation.

Why should this feature exist?

Java-tron supports HTTP、json-rpc and grpc APIs, some users may usually test them through command line tool, For example, curl and grpcurl and so on. For http and json-rpc API, they may use curl command, but for grpc call, gRPCurl is not supported by Java-tron. Although other tools can be used: postman or bloomRPC, but they may generally need to import proto files, which is not convenient enough for users to use.

@tomatoishealthy
Copy link
Contributor

tomatoishealthy commented Aug 3, 2023

they may generally need to import proto files, which is not convenient enough for users to use.

Yes. TRON now does not support the reflection of gRPC, if you are maintaining a fullnode, you can try to update the code to support the reflection.

Demo(just a demo, some additional steps may be required):

// add the dependency in `build.gradle` in the framework module
compile "io.grpc:grpc-services:1.14.0"

// add ReflectionService in `RpcApiService` before  `serverBuilder.build()`
serverBuilder.addService(ProtoReflectionService.newInstance());

Or would you like to submit a PR to help TRON support this feature?

@tomatoishealthy
Copy link
Contributor

We are ready to implement this function, but need to remind the following points:

The scope of reflection enabled

Whether include all gRPC services, such as solidity and pBFT? I tend to enable it in all services to ensure that all services behave consistently.

Impact on performance

Although no very authoritative information was found, after review and analysis, I think adding the reflection to the gRPC servers probably will not affect the performance, because the principle of the reflection is only to retain the meta-information of the proto in the memory and does not affect other logic.

Whether need to add a switch configuration
Due to design principles, we hope to leave the right to turn on this function to the user, a new configuration item will be added to control whether the reflection is turned on in the code implementation

Dismatch encoding of results

Since different gRPC clients use different encodings for the json results, the display of some fields in the results may not be as expected.

For example, in the responses of grpcurl, the bytes type is displayed by base64-string instead of hex-string, which may mislead, but this is not a bug. Some nested fields are not even recognized. grpc_cli uses another type of encoding for bytes type. The users need to do the encoding and decoding again by themselves.

Therefore, here is a strong reminder that the reflection may be more about helping developers quickly locate bugs, and may not serve online services well.

I will post how to encode and decode the results of grpcurl later as an example.

@tomatoishealthy
Copy link
Contributor

Here I show how to encode and decode the results of grpcurl.

The return value of GetBlockByNum by grpcurl is like this:

{
  "block_header": {
    "raw_data": {
      "timestamp": "1698751668000",
      "txTrieRoot": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
      "parentHash": "AAAAAAAAAAAZtZBoxgWP9GbM9Z8sOKDfHDMLm36NzEw=",
      "number": "1",
      "witness_address": "QYSJS0L2bc6MuErsLtEWBMmRNRrI",
      "version": 28
    },
    "witness_signature": "595XUp7Y0XYwJCyomlgP6sde86XRpBCVgjB1Eltx3TEcy+0TYW2GukfYyCRrF3FNLTHnxQPoFBjlJHP7nNbsDwA="
  }
}

Below is the return result of HTTP service:

{
    "block_header":{
        "raw_data":{
            "timestamp":1698751668000,
            "number":1,
            "txTrieRoot":"0000000000000000000000000000000000000000000000000000000000000000",
            "witness_address":"4184894b42f66dce8cb84aec2ed11604c991351ac8",
            "parentHash":"000000000000000019b59068c6058ff466ccf59f2c38a0df1c330b9b7e8dcc4c",
            "version":28
        },
       "witness_signature":"e7de57529ed8d17630242ca89a580feac75ef3a5d1a41095823075125b71dd311ccbed13616d86ba47d8c8246b17714d2d31e7c503e81418e52473fb9cd6ec0f00"
    }
}

Taking witness_address as an example:

// code logic
String witness = "QYSJS0L2bc6MuErsLtEWBMmRNRrI";
System.out.println("the witness addr is: " + ByteArray.toHexString(Base64.decode(witness)));

// the output
the witness addr is: 4184894b42f66dce8cb84aec2ed11604c991351ac8

@Mgarcia1996
Copy link

Bien

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants