Skip to content

Commit 2d64668

Browse files
feat(grpc): add reflection service (#5583)
1 parent 4557c72 commit 2d64668

File tree

12 files changed

+39
-0
lines changed

12 files changed

+39
-0
lines changed

common/src/main/java/org/tron/common/parameter/CommonParameter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ public class CommonParameter {
255255
public int maxHeaderListSize;
256256
@Getter
257257
@Setter
258+
public boolean isRpcReflectionServiceEnable;
259+
@Getter
260+
@Setter
258261
@Parameter(names = {"--validate-sign-thread"}, description = "Num of validate thread")
259262
public int validateSignThreadNum;
260263
@Getter

common/src/main/java/org/tron/core/Constant.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ public class Constant {
151151

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

154+
public static final String NODE_RPC_REFLECTION_SERVICE = "node.rpc.reflectionService";
155+
154156
public static final String NODE_OPEN_HISTORY_QUERY_WHEN_LITEFN = "node.openHistoryQueryWhenLiteFN";
155157

156158
public static final String BLOCK_MAINTENANCE_TIME_INTERVAL = "block.maintenanceTimeInterval";

framework/src/main/java/org/tron/core/config/args/Args.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ public static void setParam(final String[] args, final String confFileName) {
748748
? config.getInt(Constant.NODE_RPC_MAX_HEADER_LIST_SIZE)
749749
: GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE;
750750

751+
PARAMETER.isRpcReflectionServiceEnable =
752+
config.hasPath(Constant.NODE_RPC_REFLECTION_SERVICE)
753+
&& config.getBoolean(Constant.NODE_RPC_REFLECTION_SERVICE);
754+
751755
PARAMETER.maintenanceTimeInterval =
752756
config.hasPath(Constant.BLOCK_MAINTENANCE_TIME_INTERVAL) ? config
753757
.getInt(Constant.BLOCK_MAINTENANCE_TIME_INTERVAL) : 21600000L;

framework/src/main/java/org/tron/core/services/RpcApiService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.grpc.Status;
99
import io.grpc.StatusRuntimeException;
1010
import io.grpc.netty.NettyServerBuilder;
11+
import io.grpc.protobuf.services.ProtoReflectionService;
1112
import io.grpc.stub.StreamObserver;
1213
import java.util.Objects;
1314
import java.util.concurrent.TimeUnit;
@@ -250,6 +251,10 @@ public void start() {
250251
// add lite fullnode query interceptor
251252
serverBuilder.intercept(liteFnQueryGrpcInterceptor);
252253

254+
if (parameter.isRpcReflectionServiceEnable()) {
255+
serverBuilder.addService(ProtoReflectionService.newInstance());
256+
}
257+
253258
apiServer = serverBuilder.build();
254259
rateLimiterInterceptor.init(apiServer);
255260
super.start();

framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.tron.core.services.interfaceOnPBFT;
22

33
import io.grpc.netty.NettyServerBuilder;
4+
import io.grpc.protobuf.services.ProtoReflectionService;
45
import io.grpc.stub.StreamObserver;
56
import java.util.concurrent.TimeUnit;
67
import lombok.extern.slf4j.Slf4j;
@@ -123,6 +124,10 @@ public void start() {
123124
// add lite fullnode query interceptor
124125
serverBuilder.intercept(liteFnQueryGrpcInterceptor);
125126

127+
if (args.isRpcReflectionServiceEnable()) {
128+
serverBuilder.addService(ProtoReflectionService.newInstance());
129+
}
130+
126131
apiServer = serverBuilder.build();
127132
rateLimiterInterceptor.init(apiServer);
128133
super.start();

framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.protobuf.ByteString;
44
import io.grpc.netty.NettyServerBuilder;
5+
import io.grpc.protobuf.services.ProtoReflectionService;
56
import io.grpc.stub.StreamObserver;
67
import java.util.concurrent.TimeUnit;
78
import lombok.extern.slf4j.Slf4j;
@@ -124,6 +125,10 @@ public void start() {
124125
// add lite fullnode query interceptor
125126
serverBuilder.intercept(liteFnQueryGrpcInterceptor);
126127

128+
if (parameter.isRpcReflectionServiceEnable()) {
129+
serverBuilder.addService(ProtoReflectionService.newInstance());
130+
}
131+
127132
apiServer = serverBuilder.build();
128133
rateLimiterInterceptor.init(apiServer);
129134
super.start();

framework/src/main/resources/config-localtest.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ node {
149149

150150
# The maximum size of header list allowed to be received, default 8192
151151
# maxHeaderListSize =
152+
153+
# The switch of the reflection service, effective for all gRPC services
154+
reflectionService = false
152155
}
153156

154157
jsonrpc {

framework/src/main/resources/config.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ node {
284284
# "getaccount",
285285
# "getnowblock2"
286286
# ]
287+
288+
# The switch of the reflection service, effective for all gRPC services
289+
# reflectionService = true
287290
}
288291

289292
## rate limiter config

framework/src/test/java/org/tron/common/config/args/ArgsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public void testConfig() {
4848
RateLimiterInitialization rateLimiter = Args.getInstance().getRateLimiterInitialization();
4949
Assert.assertEquals(rateLimiter.getHttpMap().size(), 1);
5050
Assert.assertEquals(rateLimiter.getRpcMap().size(), 0);
51+
Assert.assertTrue(Args.getInstance().isRpcReflectionServiceEnable());
5152
}
5253

5354
@Test

framework/src/test/resources/config-localtest.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ node {
146146

147147
# The maximum size of header list allowed to be received, default 8192
148148
# maxHeaderListSize =
149+
150+
# The switch of the reflection service, effective for all gRPC services
151+
reflectionService = true
149152
}
150153

151154
jsonrpc {

framework/src/test/resources/config-test.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ node {
190190

191191
# The maximum size of header list allowed to be received, default 8192
192192
# maxHeaderListSize =
193+
194+
# The switch of the reflection service, effective for all gRPC services
195+
reflectionService = true
193196
}
194197

195198
}

protocol/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ dependencies {
1313
compile group: 'io.grpc', name: 'grpc-netty', version: grpcVersion
1414
compile group: 'io.grpc', name: 'grpc-protobuf', version: grpcVersion
1515
compile group: 'io.grpc', name: 'grpc-stub', version: grpcVersion
16+
compile group: 'io.grpc', name: 'grpc-services', version: grpcVersion
17+
1618
// end google grpc
1719

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

0 commit comments

Comments
 (0)