Skip to content

Commit

Permalink
feat(grpc): add reflection service (tronprotocol#5583)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomatoishealthy authored Nov 23, 2023
1 parent 4557c72 commit 2d64668
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 0 deletions.
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()) {
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
# 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

0 comments on commit 2d64668

Please sign in to comment.