Skip to content

feat(rpc): gRPC reflection service support #5583

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ public class CommonParameter {
public int maxHeaderListSize;
@Getter
@Setter
public boolean isRpcReflectionServiceEnable;
@Getter
@Setter
@Parameter(names = {"--validate-sign-thread"}, description = "Num of validate thread")
public int validateSignThreadNum;
@Getter
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public class Constant {

public static final String NODE_RPC_MAX_HEADER_LIST_SIZE = "node.rpc.maxHeaderListSize";

public static final String NODE_RPC_REFLECTION_SERVICE = "node.rpc.reflectionService";

public static final String NODE_OPEN_HISTORY_QUERY_WHEN_LITEFN = "node.openHistoryQueryWhenLiteFN";

public static final String BLOCK_MAINTENANCE_TIME_INTERVAL = "block.maintenanceTimeInterval";
Expand Down
4 changes: 4 additions & 0 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ public static void setParam(final String[] args, final String confFileName) {
? config.getInt(Constant.NODE_RPC_MAX_HEADER_LIST_SIZE)
: GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE;

PARAMETER.isRpcReflectionServiceEnable =
config.hasPath(Constant.NODE_RPC_REFLECTION_SERVICE)
&& config.getBoolean(Constant.NODE_RPC_REFLECTION_SERVICE);

PARAMETER.maintenanceTimeInterval =
config.hasPath(Constant.BLOCK_MAINTENANCE_TIME_INTERVAL) ? config
.getInt(Constant.BLOCK_MAINTENANCE_TIME_INTERVAL) : 21600000L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.netty.NettyServerBuilder;
import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.stub.StreamObserver;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -250,6 +251,10 @@ public void start() {
// add lite fullnode query interceptor
serverBuilder.intercept(liteFnQueryGrpcInterceptor);

if (parameter.isRpcReflectionServiceEnable()) {
serverBuilder.addService(ProtoReflectionService.newInstance());
}

apiServer = serverBuilder.build();
rateLimiterInterceptor.init(apiServer);
super.start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.tron.core.services.interfaceOnPBFT;

import io.grpc.netty.NettyServerBuilder;
import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.stub.StreamObserver;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -123,6 +124,10 @@ public void start() {
// add lite fullnode query interceptor
serverBuilder.intercept(liteFnQueryGrpcInterceptor);

if (args.isRpcReflectionServiceEnable()) {
serverBuilder.addService(ProtoReflectionService.newInstance());
}

apiServer = serverBuilder.build();
rateLimiterInterceptor.init(apiServer);
super.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.protobuf.ByteString;
import io.grpc.netty.NettyServerBuilder;
import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.stub.StreamObserver;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -124,6 +125,10 @@ public void start() {
// add lite fullnode query interceptor
serverBuilder.intercept(liteFnQueryGrpcInterceptor);

if (parameter.isRpcReflectionServiceEnable()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the parameter rpcReflectionServiceEnable control all the RpcApiServices? It seems to be not flexible to use only one parameter to control all .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gRPC reflection is a tiny feature for a better UX, providing individual parameters for each service is a bit redundant

serverBuilder.addService(ProtoReflectionService.newInstance());
}

apiServer = serverBuilder.build();
rateLimiterInterceptor.init(apiServer);
super.start();
Expand Down
3 changes: 3 additions & 0 deletions framework/src/main/resources/config-localtest.conf
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ node {

# The maximum size of header list allowed to be received, default 8192
# maxHeaderListSize =

# The switch of the reflection service, effective for all gRPC services
reflectionService = false
}

jsonrpc {
Expand Down
3 changes: 3 additions & 0 deletions framework/src/main/resources/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ node {
# "getaccount",
# "getnowblock2"
# ]

# The switch of the reflection service, effective for all gRPC services
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config path "reflectionService" not match with the Args.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "not match with the Args", more details?

# reflectionService = true
}

## rate limiter config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void testConfig() {
RateLimiterInitialization rateLimiter = Args.getInstance().getRateLimiterInitialization();
Assert.assertEquals(rateLimiter.getHttpMap().size(), 1);
Assert.assertEquals(rateLimiter.getRpcMap().size(), 0);
Assert.assertTrue(Args.getInstance().isRpcReflectionServiceEnable());
}

@Test
Expand Down
3 changes: 3 additions & 0 deletions framework/src/test/resources/config-localtest.conf
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ node {

# The maximum size of header list allowed to be received, default 8192
# maxHeaderListSize =

# The switch of the reflection service, effective for all gRPC services
reflectionService = true
}

jsonrpc {
Expand Down
3 changes: 3 additions & 0 deletions framework/src/test/resources/config-test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ node {

# The maximum size of header list allowed to be received, default 8192
# maxHeaderListSize =

# The switch of the reflection service, effective for all gRPC services
reflectionService = true
}

}
Expand Down
2 changes: 2 additions & 0 deletions protocol/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies {
compile group: 'io.grpc', name: 'grpc-netty', version: grpcVersion
compile group: 'io.grpc', name: 'grpc-protobuf', version: grpcVersion
compile group: 'io.grpc', name: 'grpc-stub', version: grpcVersion
compile group: 'io.grpc', name: 'grpc-services', version: grpcVersion

// end google grpc

compile group: 'com.google.api.grpc', name: 'proto-google-common-protos', version: '2.15.0'
Expand Down