diff --git a/framework/src/main/java/org/tron/common/application/AbstractService.java b/framework/src/main/java/org/tron/common/application/AbstractService.java index 025be1d471c..482022d5909 100644 --- a/framework/src/main/java/org/tron/common/application/AbstractService.java +++ b/framework/src/main/java/org/tron/common/application/AbstractService.java @@ -1,6 +1,7 @@ package org.tron.common.application; import com.google.common.base.Objects; +import java.util.concurrent.CompletableFuture; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.tron.core.config.args.Args; @@ -12,30 +13,36 @@ public abstract class AbstractService implements Service { protected int port; @Getter protected boolean enable; + @Getter protected final String name = this.getClass().getSimpleName(); @Override - public void start() { + public CompletableFuture start() { + logger.info("{} starting on {}", name, port); + final CompletableFuture resultFuture = new CompletableFuture<>(); try { innerStart(); + resultFuture.complete(null); logger.info("{} started, listening on {}", name, port); } catch (Exception e) { - logger.error("{}", name, e); + resultFuture.completeExceptionally(e); } + return resultFuture; } @Override - public void stop() { + public CompletableFuture stop() { logger.info("{} shutdown...", name); + final CompletableFuture resultFuture = new CompletableFuture<>(); try { innerStop(); + resultFuture.complete(null); + logger.info("{} shutdown complete", name); } catch (Exception e) { - logger.warn("{}", name, e); + resultFuture.completeExceptionally(e); } - logger.info("{} shutdown complete", name); - - + return resultFuture; } @Override diff --git a/framework/src/main/java/org/tron/common/application/HttpService.java b/framework/src/main/java/org/tron/common/application/HttpService.java index f9eef50461d..79ae61d7db4 100644 --- a/framework/src/main/java/org/tron/common/application/HttpService.java +++ b/framework/src/main/java/org/tron/common/application/HttpService.java @@ -15,14 +15,20 @@ package org.tron.common.application; +import java.util.concurrent.CompletableFuture; import lombok.extern.slf4j.Slf4j; +import org.eclipse.jetty.server.ConnectionLimit; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.tron.core.config.args.Args; @Slf4j(topic = "rpc") public abstract class HttpService extends AbstractService { protected Server apiServer; + protected String contextPath; + @Override public void innerStart() throws Exception { if (apiServer != null) { @@ -36,4 +42,34 @@ public void innerStop() throws Exception { apiServer.stop(); } } + + @Override + public CompletableFuture start() { + initServer(); + ServletContextHandler context = initContextHandler(); + addServlet(context); + addFilter(context); + return super.start(); + } + + protected void initServer() { + apiServer = new Server(port); + int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); + if (maxHttpConnectNumber > 0) { + apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); + } + } + + protected ServletContextHandler initContextHandler() { + ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); + context.setContextPath(contextPath); + apiServer.setHandler(context); + return context; + } + + protected abstract void addServlet(ServletContextHandler context); + + protected void addFilter(ServletContextHandler context) { + + } } diff --git a/framework/src/main/java/org/tron/common/application/RpcService.java b/framework/src/main/java/org/tron/common/application/RpcService.java index 129348f12e7..ec59f0f7d22 100644 --- a/framework/src/main/java/org/tron/common/application/RpcService.java +++ b/framework/src/main/java/org/tron/common/application/RpcService.java @@ -16,13 +16,33 @@ package org.tron.common.application; import io.grpc.Server; +import io.grpc.netty.NettyServerBuilder; +import io.grpc.protobuf.services.ProtoReflectionService; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.tron.common.es.ExecutorServiceManager; +import org.tron.common.parameter.CommonParameter; +import org.tron.core.config.args.Args; +import org.tron.core.services.filter.LiteFnQueryGrpcInterceptor; +import org.tron.core.services.ratelimiter.RateLimiterInterceptor; +import org.tron.core.services.ratelimiter.RpcApiAccessInterceptor; @Slf4j(topic = "rpc") public abstract class RpcService extends AbstractService { - protected Server apiServer; + private Server apiServer; + protected String executorName; + + @Autowired + private RateLimiterInterceptor rateLimiterInterceptor; + + @Autowired + private LiteFnQueryGrpcInterceptor liteFnQueryGrpcInterceptor; + + @Autowired + private RpcApiAccessInterceptor apiAccessInterceptor; @Override public void innerStart() throws Exception { @@ -38,4 +58,54 @@ public void innerStop() throws Exception { } } + @Override + public CompletableFuture start() { + NettyServerBuilder serverBuilder = initServerBuilder(); + addService(serverBuilder); + addInterceptor(serverBuilder); + initServer(serverBuilder); + rateLimiterInterceptor.init(apiServer); + return super.start(); + } + + protected NettyServerBuilder initServerBuilder() { + NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(port); + CommonParameter parameter = Args.getInstance(); + if (parameter.getRpcThreadNum() > 0) { + serverBuilder = serverBuilder + .executor(ExecutorServiceManager.newFixedThreadPool( + executorName, parameter.getRpcThreadNum())); + } + // Set configs from config.conf or default value + serverBuilder + .maxConcurrentCallsPerConnection(parameter.getMaxConcurrentCallsPerConnection()) + .flowControlWindow(parameter.getFlowControlWindow()) + .maxConnectionIdle(parameter.getMaxConnectionIdleInMillis(), TimeUnit.MILLISECONDS) + .maxConnectionAge(parameter.getMaxConnectionAgeInMillis(), TimeUnit.MILLISECONDS) + .maxInboundMessageSize(parameter.getMaxMessageSize()) + .maxHeaderListSize(parameter.getMaxHeaderListSize()); + + if (parameter.isRpcReflectionServiceEnable()) { + serverBuilder.addService(ProtoReflectionService.newInstance()); + } + return serverBuilder; + } + + protected abstract void addService(NettyServerBuilder serverBuilder); + + protected void addInterceptor(NettyServerBuilder serverBuilder) { + // add a ratelimiter interceptor + serverBuilder.intercept(rateLimiterInterceptor); + + // add api access interceptor + serverBuilder.intercept(apiAccessInterceptor); + + // add lite fullnode query interceptor + serverBuilder.intercept(liteFnQueryGrpcInterceptor); + } + + protected void initServer(NettyServerBuilder serverBuilder) { + apiServer = serverBuilder.build(); + } + } diff --git a/framework/src/main/java/org/tron/common/application/Service.java b/framework/src/main/java/org/tron/common/application/Service.java index 7255391108c..ec807d0da01 100644 --- a/framework/src/main/java/org/tron/common/application/Service.java +++ b/framework/src/main/java/org/tron/common/application/Service.java @@ -15,11 +15,25 @@ package org.tron.common.application; +import java.util.concurrent.CompletableFuture; + public interface Service { - void start(); + /** + * Starts the service and all needed backend systems. + * + * @return completion state + */ + CompletableFuture start(); - void stop(); + /** + * Stops the service and performs needed cleanup. + * + * @return completion state + */ + CompletableFuture stop(); boolean isEnable(); + + String getName(); } diff --git a/framework/src/main/java/org/tron/common/application/ServiceContainer.java b/framework/src/main/java/org/tron/common/application/ServiceContainer.java index bd00a2584af..943f4617c1e 100644 --- a/framework/src/main/java/org/tron/common/application/ServiceContainer.java +++ b/framework/src/main/java/org/tron/common/application/ServiceContainer.java @@ -16,6 +16,10 @@ package org.tron.common.application; import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; import javax.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; @@ -43,13 +47,45 @@ private void initEnabledServices() { void start() { logger.info("Starting api services."); - this.enabledServices.forEach(Service::start); + this.enabledServices.forEach(this::waitForServiceToStart); logger.info("All api services started."); } void stop() { logger.info("Stopping api services."); - this.enabledServices.forEach(Service::stop); + this.enabledServices.forEach(this::waitForServiceToStop); logger.info("All api services stopped."); } + + private void waitForServiceToStart(Service service) { + final String serviceName = service.getName(); + final CompletableFuture startFuture = service.start(); + do { + try { + startFuture.get(60, TimeUnit.SECONDS); + } catch (final InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IllegalStateException("Interrupted while waiting for service to start", e); + } catch (final ExecutionException e) { + throw new IllegalStateException("Service " + serviceName + " failed to start", e); + } catch (final TimeoutException e) { + logger.warn("Service {} is taking an unusually long time to start", serviceName); + } + } while (!startFuture.isDone()); + } + + private void waitForServiceToStop(Service service) { + final String serviceName = service.getName(); + final CompletableFuture stopFuture = service.stop(); + try { + stopFuture.get(30, TimeUnit.SECONDS); + } catch (final InterruptedException e) { + logger.debug("Interrupted while waiting for service {} to complete", serviceName, e); + Thread.currentThread().interrupt(); + } catch (final ExecutionException e) { + logger.error("Service {} failed to shutdown", serviceName, e); + } catch (final TimeoutException e) { + logger.error("Service {} did not shut down cleanly", serviceName); + } + } } diff --git a/framework/src/main/java/org/tron/core/services/RpcApiService.java b/framework/src/main/java/org/tron/core/services/RpcApiService.java index 1e6162c8532..8f9c6b15bb7 100755 --- a/framework/src/main/java/org/tron/core/services/RpcApiService.java +++ b/framework/src/main/java/org/tron/core/services/RpcApiService.java @@ -8,10 +8,8 @@ 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; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -75,7 +73,6 @@ import org.tron.api.WalletGrpc.WalletImplBase; import org.tron.api.WalletSolidityGrpc.WalletSolidityImplBase; import org.tron.common.application.RpcService; -import org.tron.common.es.ExecutorServiceManager; import org.tron.common.parameter.CommonParameter; import org.tron.common.utils.ByteArray; import org.tron.common.utils.Sha256Hash; @@ -97,9 +94,6 @@ import org.tron.core.exception.VMIllegalException; import org.tron.core.exception.ZksnarkException; import org.tron.core.metrics.MetricsApiService; -import org.tron.core.services.filter.LiteFnQueryGrpcInterceptor; -import org.tron.core.services.ratelimiter.RateLimiterInterceptor; -import org.tron.core.services.ratelimiter.RpcApiAccessInterceptor; import org.tron.core.utils.TransactionUtil; import org.tron.core.zen.address.DiversifierT; import org.tron.core.zen.address.IncomingViewingKey; @@ -182,12 +176,6 @@ public class RpcApiService extends RpcService { @Autowired private NodeInfoService nodeInfoService; @Autowired - private RateLimiterInterceptor rateLimiterInterceptor; - @Autowired - private LiteFnQueryGrpcInterceptor liteFnQueryGrpcInterceptor; - @Autowired - private RpcApiAccessInterceptor apiAccessInterceptor; - @Autowired private MetricsApiService metricsApiService; @Getter private DatabaseApi databaseApi = new DatabaseApi(); @@ -197,65 +185,27 @@ public class RpcApiService extends RpcService { @Getter private MonitorApi monitorApi = new MonitorApi(); - private final String executorName = "rpc-full-executor"; - public RpcApiService() { port = Args.getInstance().getRpcPort(); enable = Args.getInstance().isRpcEnable(); + executorName = "rpc-full-executor"; } @Override - public void start() { - try { - NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(port).addService(databaseApi); - CommonParameter parameter = Args.getInstance(); - - if (parameter.getRpcThreadNum() > 0) { - serverBuilder = serverBuilder - .executor(ExecutorServiceManager.newFixedThreadPool( - executorName, parameter.getRpcThreadNum())); - } - - if (parameter.isSolidityNode()) { - serverBuilder = serverBuilder.addService(walletSolidityApi); - if (parameter.isWalletExtensionApi()) { - serverBuilder = serverBuilder.addService(new WalletExtensionApi()); - } - } else { - serverBuilder = serverBuilder.addService(walletApi); - } - - if (parameter.isNodeMetricsEnable()) { - serverBuilder = serverBuilder.addService(monitorApi); - } - - // Set configs from config.conf or default value - serverBuilder - .maxConcurrentCallsPerConnection(parameter.getMaxConcurrentCallsPerConnection()) - .flowControlWindow(parameter.getFlowControlWindow()) - .maxConnectionIdle(parameter.getMaxConnectionIdleInMillis(), TimeUnit.MILLISECONDS) - .maxConnectionAge(parameter.getMaxConnectionAgeInMillis(), TimeUnit.MILLISECONDS) - .maxInboundMessageSize(parameter.getMaxMessageSize()) - .maxHeaderListSize(parameter.getMaxHeaderListSize()); - - // add a rate limiter interceptor - serverBuilder.intercept(rateLimiterInterceptor); - - // add api access interceptor - serverBuilder.intercept(apiAccessInterceptor); - - // add lite fullnode query interceptor - serverBuilder.intercept(liteFnQueryGrpcInterceptor); - - if (parameter.isRpcReflectionServiceEnable()) { - serverBuilder.addService(ProtoReflectionService.newInstance()); + protected void addService(NettyServerBuilder serverBuilder) { + serverBuilder.addService(databaseApi); + CommonParameter parameter = Args.getInstance(); + if (parameter.isSolidityNode()) { + serverBuilder.addService(walletSolidityApi); + if (parameter.isWalletExtensionApi()) { + serverBuilder.addService(new WalletExtensionApi()); } + } else { + serverBuilder.addService(walletApi); + } - apiServer = serverBuilder.build(); - rateLimiterInterceptor.init(apiServer); - super.start(); - } catch (Exception e) { - logger.debug(e.getMessage(), e); + if (parameter.isNodeMetricsEnable()) { + serverBuilder.addService(monitorApi); } } diff --git a/framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java b/framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java index 81ffaa0da72..76785218096 100644 --- a/framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java +++ b/framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java @@ -4,8 +4,6 @@ import javax.servlet.DispatcherType; import javax.servlet.Filter; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHandler; @@ -296,254 +294,244 @@ public class FullNodeHttpApiService extends HttpService { public FullNodeHttpApiService() { port = Args.getInstance().getFullNodeHttpPort(); enable = isFullNode() && Args.getInstance().isFullNodeHttpEnable(); + contextPath = "/"; } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - apiServer.setHandler(context); + protected void addServlet(ServletContextHandler context) { + context.addServlet(new ServletHolder(getAccountServlet), "/wallet/getaccount"); + context.addServlet(new ServletHolder(transferServlet), "/wallet/createtransaction"); + context.addServlet(new ServletHolder(broadcastServlet), "/wallet/broadcasttransaction"); + context.addServlet(new ServletHolder(updateAccountServlet), "/wallet/updateaccount"); + context.addServlet(new ServletHolder(voteWitnessAccountServlet), + "/wallet/votewitnessaccount"); + context.addServlet(new ServletHolder(createAssetIssueServlet), "/wallet/createassetissue"); + context.addServlet(new ServletHolder(updateWitnessServlet), "/wallet/updatewitness"); + context.addServlet(new ServletHolder(createAccountServlet), "/wallet/createaccount"); + context.addServlet(new ServletHolder(createWitnessServlet), "/wallet/createwitness"); + context.addServlet(new ServletHolder(transferAssetServlet), "/wallet/transferasset"); + context.addServlet(new ServletHolder(participateAssetIssueServlet), + "/wallet/participateassetissue"); + context.addServlet(new ServletHolder(freezeBalanceServlet), "/wallet/freezebalance"); + context.addServlet(new ServletHolder(unFreezeBalanceServlet), "/wallet/unfreezebalance"); + context.addServlet(new ServletHolder(unFreezeAssetServlet), "/wallet/unfreezeasset"); + context.addServlet(new ServletHolder(withdrawBalanceServlet), "/wallet/withdrawbalance"); + context.addServlet(new ServletHolder(updateAssetServlet), "/wallet/updateasset"); + context.addServlet(new ServletHolder(listNodesServlet), "/wallet/listnodes"); + context.addServlet( + new ServletHolder(getAssetIssueByAccountServlet), "/wallet/getassetissuebyaccount"); + context.addServlet(new ServletHolder(getAccountNetServlet), "/wallet/getaccountnet"); + context.addServlet(new ServletHolder(getAssetIssueByNameServlet), + "/wallet/getassetissuebyname"); + context.addServlet(new ServletHolder(getAssetIssueListByNameServlet), + "/wallet/getassetissuelistbyname"); + context.addServlet(new ServletHolder(getAssetIssueByIdServlet), "/wallet/getassetissuebyid"); + context.addServlet(new ServletHolder(getNowBlockServlet), "/wallet/getnowblock"); + context.addServlet(new ServletHolder(getBlockByNumServlet), "/wallet/getblockbynum"); + context.addServlet(new ServletHolder(getBlockByIdServlet), "/wallet/getblockbyid"); + context.addServlet(new ServletHolder(getBlockByLimitNextServlet), + "/wallet/getblockbylimitnext"); + context.addServlet(new ServletHolder(getBlockByLatestNumServlet), + "/wallet/getblockbylatestnum"); + context.addServlet(new ServletHolder(getTransactionByIdServlet), + "/wallet/gettransactionbyid"); + context.addServlet( + new ServletHolder(getTransactionInfoByIdServlet), "/wallet/gettransactioninfobyid"); + context.addServlet( + new ServletHolder(getTransactionReceiptByIdServlet), "/wallet/gettransactionreceiptbyid"); + context.addServlet( + new ServletHolder(getTransactionCountByBlockNumServlet), + "/wallet/gettransactioncountbyblocknum"); + context.addServlet(new ServletHolder(listWitnessesServlet), "/wallet/listwitnesses"); + context.addServlet(new ServletHolder(getAssetIssueListServlet), "/wallet/getassetissuelist"); + context.addServlet( + new ServletHolder(getPaginatedAssetIssueListServlet), + "/wallet/getpaginatedassetissuelist"); + context.addServlet( + new ServletHolder(getPaginatedProposalListServlet), "/wallet/getpaginatedproposallist"); + context.addServlet( + new ServletHolder(getPaginatedExchangeListServlet), "/wallet/getpaginatedexchangelist"); + context.addServlet(new ServletHolder(totalTransactionServlet), "/wallet/totaltransaction"); + context.addServlet( + new ServletHolder(getNextMaintenanceTimeServlet), "/wallet/getnextmaintenancetime"); + context.addServlet(new ServletHolder(validateAddressServlet), "/wallet/validateaddress"); + context.addServlet(new ServletHolder(deployContractServlet), "/wallet/deploycontract"); + context.addServlet(new ServletHolder(triggerSmartContractServlet), + "/wallet/triggersmartcontract"); + context.addServlet(new ServletHolder(triggerConstantContractServlet), + "/wallet/triggerconstantcontract"); + context.addServlet(new ServletHolder(estimateEnergyServlet), "/wallet/estimateenergy"); + context.addServlet(new ServletHolder(getContractServlet), "/wallet/getcontract"); + context.addServlet(new ServletHolder(getContractInfoServlet), "/wallet/getcontractinfo"); + context.addServlet(new ServletHolder(clearABIServlet), "/wallet/clearabi"); + context.addServlet(new ServletHolder(proposalCreateServlet), "/wallet/proposalcreate"); + context.addServlet(new ServletHolder(proposalApproveServlet), "/wallet/proposalapprove"); + context.addServlet(new ServletHolder(proposalDeleteServlet), "/wallet/proposaldelete"); + context.addServlet(new ServletHolder(listProposalsServlet), "/wallet/listproposals"); + context.addServlet(new ServletHolder(getProposalByIdServlet), "/wallet/getproposalbyid"); + context.addServlet(new ServletHolder(exchangeCreateServlet), "/wallet/exchangecreate"); + context.addServlet(new ServletHolder(exchangeInjectServlet), "/wallet/exchangeinject"); + context.addServlet(new ServletHolder(exchangeTransactionServlet), + "/wallet/exchangetransaction"); + context.addServlet(new ServletHolder(exchangeWithdrawServlet), "/wallet/exchangewithdraw"); + context.addServlet(new ServletHolder(getExchangeByIdServlet), "/wallet/getexchangebyid"); + context.addServlet(new ServletHolder(listExchangesServlet), "/wallet/listexchanges"); + context.addServlet(new ServletHolder(getChainParametersServlet), + "/wallet/getchainparameters"); + context.addServlet(new ServletHolder(getAccountResourceServlet), + "/wallet/getaccountresource"); + context.addServlet(new ServletHolder(getTransactionSignWeightServlet), + "/wallet/getsignweight"); + context.addServlet(new ServletHolder(getTransactionApprovedListServlet), + "/wallet/getapprovedlist"); + context.addServlet(new ServletHolder(accountPermissionUpdateServlet), + "/wallet/accountpermissionupdate"); + context.addServlet(new ServletHolder(getNodeInfoServlet), "/wallet/getnodeinfo"); + context.addServlet(new ServletHolder(updateSettingServlet), "/wallet/updatesetting"); + context.addServlet(new ServletHolder(updateEnergyLimitServlet), "/wallet/updateenergylimit"); + context.addServlet(new ServletHolder(getDelegatedResourceServlet), + "/wallet/getdelegatedresource"); + context.addServlet(new ServletHolder(getDelegatedResourceV2Servlet), + "/wallet/getdelegatedresourcev2"); + context.addServlet(new ServletHolder(getCanDelegatedMaxSizeServlet), + "/wallet/getcandelegatedmaxsize"); + context.addServlet(new ServletHolder(getAvailableUnfreezeCountServlet), + "/wallet/getavailableunfreezecount"); + context.addServlet(new ServletHolder(getCanWithdrawUnfreezeAmountServlet), + "/wallet/getcanwithdrawunfreezeamount"); + context.addServlet( + new ServletHolder(getDelegatedResourceAccountIndexServlet), + "/wallet/getdelegatedresourceaccountindex"); + context.addServlet( + new ServletHolder(getDelegatedResourceAccountIndexV2Servlet), + "/wallet/getdelegatedresourceaccountindexv2"); + context.addServlet(new ServletHolder(setAccountServlet), "/wallet/setaccountid"); + context.addServlet(new ServletHolder(getAccountByIdServlet), "/wallet/getaccountbyid"); + context + .addServlet(new ServletHolder(getExpandedSpendingKeyServlet), + "/wallet/getexpandedspendingkey"); + context.addServlet(new ServletHolder(getAkFromAskServlet), "/wallet/getakfromask"); + context.addServlet(new ServletHolder(getNkFromNskServlet), "/wallet/getnkfromnsk"); + context.addServlet(new ServletHolder(getSpendingKeyServlet), "/wallet/getspendingkey"); + context + .addServlet(new ServletHolder(getNewShieldedAddressServlet), + "/wallet/getnewshieldedaddress"); + context.addServlet(new ServletHolder(getDiversifierServlet), "/wallet/getdiversifier"); + context.addServlet(new ServletHolder(getIncomingViewingKeyServlet), + "/wallet/getincomingviewingkey"); + context.addServlet(new ServletHolder(getZenPaymentAddressServlet), + "/wallet/getzenpaymentaddress"); + // context.addServlet(new ServletHolder(createShieldedTransactionServlet), + // "/wallet/createshieldedtransaction"); + // context.addServlet(new ServletHolder(createShieldedTransactionWithoutSpendAuthSigServlet), + // "/wallet/createshieldedtransactionwithoutspendauthsig"); + // context.addServlet(new ServletHolder(scanNoteByIvkServlet), "/wallet/scannotebyivk"); + // context.addServlet(new ServletHolder(scanAndMarkNoteByIvkServlet), + // "/wallet/scanandmarknotebyivk"); + // context.addServlet(new ServletHolder(scanNoteByOvkServlet), "/wallet/scannotebyovk"); + context.addServlet(new ServletHolder(getRcmServlet), "/wallet/getrcm"); + // context.addServlet(new ServletHolder(getMerkleTreeVoucherInfoServlet), + // "/wallet/getmerkletreevoucherinfo"); + // context.addServlet(new ServletHolder(isSpendServlet), "/wallet/isspend"); + context.addServlet(new ServletHolder(createSpendAuthSigServlet), + "/wallet/createspendauthsig"); + // context.addServlet(new ServletHolder(createShieldNullifierServlet), + // "/wallet/createshieldnullifier"); + // context.addServlet(new ServletHolder(getShieldTransactionHashServlet), + // "/wallet/getshieldtransactionhash"); - context.addServlet(new ServletHolder(getAccountServlet), "/wallet/getaccount"); - context.addServlet(new ServletHolder(transferServlet), "/wallet/createtransaction"); - context.addServlet(new ServletHolder(broadcastServlet), "/wallet/broadcasttransaction"); - context.addServlet(new ServletHolder(updateAccountServlet), "/wallet/updateaccount"); - context.addServlet(new ServletHolder(voteWitnessAccountServlet), - "/wallet/votewitnessaccount"); - context.addServlet(new ServletHolder(createAssetIssueServlet), "/wallet/createassetissue"); - context.addServlet(new ServletHolder(updateWitnessServlet), "/wallet/updatewitness"); - context.addServlet(new ServletHolder(createAccountServlet), "/wallet/createaccount"); - context.addServlet(new ServletHolder(createWitnessServlet), "/wallet/createwitness"); - context.addServlet(new ServletHolder(transferAssetServlet), "/wallet/transferasset"); - context.addServlet(new ServletHolder(participateAssetIssueServlet), - "/wallet/participateassetissue"); - context.addServlet(new ServletHolder(freezeBalanceServlet), "/wallet/freezebalance"); - context.addServlet(new ServletHolder(unFreezeBalanceServlet), "/wallet/unfreezebalance"); - context.addServlet(new ServletHolder(unFreezeAssetServlet), "/wallet/unfreezeasset"); - context.addServlet(new ServletHolder(withdrawBalanceServlet), "/wallet/withdrawbalance"); - context.addServlet(new ServletHolder(updateAssetServlet), "/wallet/updateasset"); - context.addServlet(new ServletHolder(listNodesServlet), "/wallet/listnodes"); - context.addServlet( - new ServletHolder(getAssetIssueByAccountServlet), "/wallet/getassetissuebyaccount"); - context.addServlet(new ServletHolder(getAccountNetServlet), "/wallet/getaccountnet"); - context.addServlet(new ServletHolder(getAssetIssueByNameServlet), - "/wallet/getassetissuebyname"); - context.addServlet(new ServletHolder(getAssetIssueListByNameServlet), - "/wallet/getassetissuelistbyname"); - context.addServlet(new ServletHolder(getAssetIssueByIdServlet), "/wallet/getassetissuebyid"); - context.addServlet(new ServletHolder(getNowBlockServlet), "/wallet/getnowblock"); - context.addServlet(new ServletHolder(getBlockByNumServlet), "/wallet/getblockbynum"); - context.addServlet(new ServletHolder(getBlockByIdServlet), "/wallet/getblockbyid"); - context.addServlet(new ServletHolder(getBlockByLimitNextServlet), - "/wallet/getblockbylimitnext"); - context.addServlet(new ServletHolder(getBlockByLatestNumServlet), - "/wallet/getblockbylatestnum"); - context.addServlet(new ServletHolder(getTransactionByIdServlet), - "/wallet/gettransactionbyid"); - context.addServlet( - new ServletHolder(getTransactionInfoByIdServlet), "/wallet/gettransactioninfobyid"); - context.addServlet( - new ServletHolder(getTransactionReceiptByIdServlet), "/wallet/gettransactionreceiptbyid"); - context.addServlet( - new ServletHolder(getTransactionCountByBlockNumServlet), - "/wallet/gettransactioncountbyblocknum"); - context.addServlet(new ServletHolder(listWitnessesServlet), "/wallet/listwitnesses"); - context.addServlet(new ServletHolder(getAssetIssueListServlet), "/wallet/getassetissuelist"); - context.addServlet( - new ServletHolder(getPaginatedAssetIssueListServlet), - "/wallet/getpaginatedassetissuelist"); - context.addServlet( - new ServletHolder(getPaginatedProposalListServlet), "/wallet/getpaginatedproposallist"); - context.addServlet( - new ServletHolder(getPaginatedExchangeListServlet), "/wallet/getpaginatedexchangelist"); - context.addServlet(new ServletHolder(totalTransactionServlet), "/wallet/totaltransaction"); - context.addServlet( - new ServletHolder(getNextMaintenanceTimeServlet), "/wallet/getnextmaintenancetime"); - context.addServlet(new ServletHolder(validateAddressServlet), "/wallet/validateaddress"); - context.addServlet(new ServletHolder(deployContractServlet), "/wallet/deploycontract"); - context.addServlet(new ServletHolder(triggerSmartContractServlet), - "/wallet/triggersmartcontract"); - context.addServlet(new ServletHolder(triggerConstantContractServlet), - "/wallet/triggerconstantcontract"); - context.addServlet(new ServletHolder(estimateEnergyServlet), "/wallet/estimateenergy"); - context.addServlet(new ServletHolder(getContractServlet), "/wallet/getcontract"); - context.addServlet(new ServletHolder(getContractInfoServlet), "/wallet/getcontractinfo"); - context.addServlet(new ServletHolder(clearABIServlet), "/wallet/clearabi"); - context.addServlet(new ServletHolder(proposalCreateServlet), "/wallet/proposalcreate"); - context.addServlet(new ServletHolder(proposalApproveServlet), "/wallet/proposalapprove"); - context.addServlet(new ServletHolder(proposalDeleteServlet), "/wallet/proposaldelete"); - context.addServlet(new ServletHolder(listProposalsServlet), "/wallet/listproposals"); - context.addServlet(new ServletHolder(getProposalByIdServlet), "/wallet/getproposalbyid"); - context.addServlet(new ServletHolder(exchangeCreateServlet), "/wallet/exchangecreate"); - context.addServlet(new ServletHolder(exchangeInjectServlet), "/wallet/exchangeinject"); - context.addServlet(new ServletHolder(exchangeTransactionServlet), - "/wallet/exchangetransaction"); - context.addServlet(new ServletHolder(exchangeWithdrawServlet), "/wallet/exchangewithdraw"); - context.addServlet(new ServletHolder(getExchangeByIdServlet), "/wallet/getexchangebyid"); - context.addServlet(new ServletHolder(listExchangesServlet), "/wallet/listexchanges"); - context.addServlet(new ServletHolder(getChainParametersServlet), - "/wallet/getchainparameters"); - context.addServlet(new ServletHolder(getAccountResourceServlet), - "/wallet/getaccountresource"); - context.addServlet(new ServletHolder(getTransactionSignWeightServlet), - "/wallet/getsignweight"); - context.addServlet(new ServletHolder(getTransactionApprovedListServlet), - "/wallet/getapprovedlist"); - context.addServlet(new ServletHolder(accountPermissionUpdateServlet), - "/wallet/accountpermissionupdate"); - context.addServlet(new ServletHolder(getNodeInfoServlet), "/wallet/getnodeinfo"); - context.addServlet(new ServletHolder(updateSettingServlet), "/wallet/updatesetting"); - context.addServlet(new ServletHolder(updateEnergyLimitServlet), "/wallet/updateenergylimit"); - context.addServlet(new ServletHolder(getDelegatedResourceServlet), - "/wallet/getdelegatedresource"); - context.addServlet(new ServletHolder(getDelegatedResourceV2Servlet), - "/wallet/getdelegatedresourcev2"); - context.addServlet(new ServletHolder(getCanDelegatedMaxSizeServlet), - "/wallet/getcandelegatedmaxsize"); - context.addServlet(new ServletHolder(getAvailableUnfreezeCountServlet), - "/wallet/getavailableunfreezecount"); - context.addServlet(new ServletHolder(getCanWithdrawUnfreezeAmountServlet), - "/wallet/getcanwithdrawunfreezeamount"); - context.addServlet( - new ServletHolder(getDelegatedResourceAccountIndexServlet), - "/wallet/getdelegatedresourceaccountindex"); - context.addServlet( - new ServletHolder(getDelegatedResourceAccountIndexV2Servlet), - "/wallet/getdelegatedresourceaccountindexv2"); - context.addServlet(new ServletHolder(setAccountServlet), "/wallet/setaccountid"); - context.addServlet(new ServletHolder(getAccountByIdServlet), "/wallet/getaccountbyid"); - context - .addServlet(new ServletHolder(getExpandedSpendingKeyServlet), - "/wallet/getexpandedspendingkey"); - context.addServlet(new ServletHolder(getAkFromAskServlet), "/wallet/getakfromask"); - context.addServlet(new ServletHolder(getNkFromNskServlet), "/wallet/getnkfromnsk"); - context.addServlet(new ServletHolder(getSpendingKeyServlet), "/wallet/getspendingkey"); - context - .addServlet(new ServletHolder(getNewShieldedAddressServlet), - "/wallet/getnewshieldedaddress"); - context.addServlet(new ServletHolder(getDiversifierServlet), "/wallet/getdiversifier"); - context.addServlet(new ServletHolder(getIncomingViewingKeyServlet), - "/wallet/getincomingviewingkey"); - context.addServlet(new ServletHolder(getZenPaymentAddressServlet), - "/wallet/getzenpaymentaddress"); - // context.addServlet(new ServletHolder(createShieldedTransactionServlet), - // "/wallet/createshieldedtransaction"); - // context.addServlet(new ServletHolder(createShieldedTransactionWithoutSpendAuthSigServlet), - // "/wallet/createshieldedtransactionwithoutspendauthsig"); - // context.addServlet(new ServletHolder(scanNoteByIvkServlet), "/wallet/scannotebyivk"); - // context.addServlet(new ServletHolder(scanAndMarkNoteByIvkServlet), - // "/wallet/scanandmarknotebyivk"); - // context.addServlet(new ServletHolder(scanNoteByOvkServlet), "/wallet/scannotebyovk"); - context.addServlet(new ServletHolder(getRcmServlet), "/wallet/getrcm"); - // context.addServlet(new ServletHolder(getMerkleTreeVoucherInfoServlet), - // "/wallet/getmerkletreevoucherinfo"); - // context.addServlet(new ServletHolder(isSpendServlet), "/wallet/isspend"); - context.addServlet(new ServletHolder(createSpendAuthSigServlet), - "/wallet/createspendauthsig"); - // context.addServlet(new ServletHolder(createShieldNullifierServlet), - // "/wallet/createshieldnullifier"); - // context.addServlet(new ServletHolder(getShieldTransactionHashServlet), - // "/wallet/getshieldtransactionhash"); + context + .addServlet(new ServletHolder(isShieldedTRC20ContractNoteSpentServlet), + "/wallet/isshieldedtrc20contractnotespent"); + context.addServlet(new ServletHolder(createShieldedContractParametersServlet), + "/wallet/createshieldedcontractparameters"); + context.addServlet(new ServletHolder(createShieldedContractParametersWithoutAskServlet), + "/wallet/createshieldedcontractparameterswithoutask"); + context.addServlet(new ServletHolder(scanShieldedTRC20NotesByIvkServlet), + "/wallet/scanshieldedtrc20notesbyivk"); + context.addServlet(new ServletHolder(scanShieldedTRC20NotesByOvkServlet), + "/wallet/scanshieldedtrc20notesbyovk"); + context.addServlet(new ServletHolder(getTriggerInputForShieldedTRC20ContractServlet), + "/wallet/gettriggerinputforshieldedtrc20contract"); - context - .addServlet(new ServletHolder(isShieldedTRC20ContractNoteSpentServlet), - "/wallet/isshieldedtrc20contractnotespent"); - context.addServlet(new ServletHolder(createShieldedContractParametersServlet), - "/wallet/createshieldedcontractparameters"); - context.addServlet(new ServletHolder(createShieldedContractParametersWithoutAskServlet), - "/wallet/createshieldedcontractparameterswithoutask"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByIvkServlet), - "/wallet/scanshieldedtrc20notesbyivk"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByOvkServlet), - "/wallet/scanshieldedtrc20notesbyovk"); - context.addServlet(new ServletHolder(getTriggerInputForShieldedTRC20ContractServlet), - "/wallet/gettriggerinputforshieldedtrc20contract"); + context.addServlet(new ServletHolder(broadcastHexServlet), "/wallet/broadcasthex"); + context.addServlet(new ServletHolder(getBrokerageServlet), "/wallet/getBrokerage"); + context.addServlet(new ServletHolder(getRewardServlet), "/wallet/getReward"); + context.addServlet(new ServletHolder(updateBrokerageServlet), "/wallet/updateBrokerage"); + context.addServlet(new ServletHolder(createCommonTransactionServlet), + "/wallet/createCommonTransaction"); + context.addServlet(new ServletHolder(getTransactionInfoByBlockNumServlet), + "/wallet/gettransactioninfobyblocknum"); + context.addServlet(new ServletHolder(listNodesServlet), "/net/listnodes"); - context.addServlet(new ServletHolder(broadcastHexServlet), "/wallet/broadcasthex"); - context.addServlet(new ServletHolder(getBrokerageServlet), "/wallet/getBrokerage"); - context.addServlet(new ServletHolder(getRewardServlet), "/wallet/getReward"); - context.addServlet(new ServletHolder(updateBrokerageServlet), "/wallet/updateBrokerage"); - context.addServlet(new ServletHolder(createCommonTransactionServlet), - "/wallet/createCommonTransaction"); - context.addServlet(new ServletHolder(getTransactionInfoByBlockNumServlet), - "/wallet/gettransactioninfobyblocknum"); - context.addServlet(new ServletHolder(listNodesServlet), "/net/listnodes"); + context.addServlet(new ServletHolder(metricsServlet), "/monitor/getstatsinfo"); + context.addServlet(new ServletHolder(getNodeInfoServlet), "/monitor/getnodeinfo"); + context.addServlet(new ServletHolder(marketSellAssetServlet), "/wallet/marketsellasset"); + context.addServlet(new ServletHolder(marketCancelOrderServlet), "/wallet/marketcancelorder"); + context.addServlet(new ServletHolder(getMarketOrderByAccountServlet), + "/wallet/getmarketorderbyaccount"); + context.addServlet(new ServletHolder(getMarketOrderByIdServlet), + "/wallet/getmarketorderbyid"); + context.addServlet(new ServletHolder(getMarketPriceByPairServlet), + "/wallet/getmarketpricebypair"); + context.addServlet(new ServletHolder(getMarketOrderListByPairServlet), + "/wallet/getmarketorderlistbypair"); + context.addServlet(new ServletHolder(getMarketPairListServlet), + "/wallet/getmarketpairlist"); - context.addServlet(new ServletHolder(metricsServlet), "/monitor/getstatsinfo"); - context.addServlet(new ServletHolder(getNodeInfoServlet), "/monitor/getnodeinfo"); - context.addServlet(new ServletHolder(marketSellAssetServlet), "/wallet/marketsellasset"); - context.addServlet(new ServletHolder(marketCancelOrderServlet), "/wallet/marketcancelorder"); - context.addServlet(new ServletHolder(getMarketOrderByAccountServlet), - "/wallet/getmarketorderbyaccount"); - context.addServlet(new ServletHolder(getMarketOrderByIdServlet), - "/wallet/getmarketorderbyid"); - context.addServlet(new ServletHolder(getMarketPriceByPairServlet), - "/wallet/getmarketpricebypair"); - context.addServlet(new ServletHolder(getMarketOrderListByPairServlet), - "/wallet/getmarketorderlistbypair"); - context.addServlet(new ServletHolder(getMarketPairListServlet), - "/wallet/getmarketpairlist"); + context.addServlet(new ServletHolder(getAccountBalanceServlet), + "/wallet/getaccountbalance"); + context.addServlet(new ServletHolder(getBlockBalanceServlet), + "/wallet/getblockbalance"); + context.addServlet(new ServletHolder(getBurnTrxServlet), "/wallet/getburntrx"); + context.addServlet(new ServletHolder(getTransactionFromPendingServlet), + "/wallet/gettransactionfrompending"); + context.addServlet(new ServletHolder(getTransactionListFromPendingServlet), + "/wallet/gettransactionlistfrompending"); + context.addServlet(new ServletHolder(getPendingSizeServlet), "/wallet/getpendingsize"); + context.addServlet(new ServletHolder(getEnergyPricesServlet), "/wallet/getenergyprices"); + context.addServlet(new ServletHolder(getBandwidthPricesServlet), + "/wallet/getbandwidthprices"); + context.addServlet(new ServletHolder(getBlockServlet), "/wallet/getblock"); + context.addServlet(new ServletHolder(getMemoFeePricesServlet), "/wallet/getmemofee"); - context.addServlet(new ServletHolder(getAccountBalanceServlet), - "/wallet/getaccountbalance"); - context.addServlet(new ServletHolder(getBlockBalanceServlet), - "/wallet/getblockbalance"); - context.addServlet(new ServletHolder(getBurnTrxServlet), "/wallet/getburntrx"); - context.addServlet(new ServletHolder(getTransactionFromPendingServlet), - "/wallet/gettransactionfrompending"); - context.addServlet(new ServletHolder(getTransactionListFromPendingServlet), - "/wallet/gettransactionlistfrompending"); - context.addServlet(new ServletHolder(getPendingSizeServlet), "/wallet/getpendingsize"); - context.addServlet(new ServletHolder(getEnergyPricesServlet), "/wallet/getenergyprices"); - context.addServlet(new ServletHolder(getBandwidthPricesServlet), - "/wallet/getbandwidthprices"); - context.addServlet(new ServletHolder(getBlockServlet), "/wallet/getblock"); - context.addServlet(new ServletHolder(getMemoFeePricesServlet), "/wallet/getmemofee"); + context.addServlet(new ServletHolder(freezeBalanceV2Servlet), + "/wallet/freezebalancev2"); + context.addServlet(new ServletHolder(unFreezeBalanceV2Servlet), + "/wallet/unfreezebalancev2"); + context.addServlet(new ServletHolder(withdrawExpireUnfreezeServlet), + "/wallet/withdrawexpireunfreeze"); + context.addServlet(new ServletHolder(delegateResourceServlet), + "/wallet/delegateresource"); + context.addServlet(new ServletHolder(unDelegateResourceServlet), + "/wallet/undelegateresource"); + context.addServlet(new ServletHolder(cancelAllUnfreezeV2Servlet), + "/wallet/cancelallunfreezev2"); - context.addServlet(new ServletHolder(freezeBalanceV2Servlet), - "/wallet/freezebalancev2"); - context.addServlet(new ServletHolder(unFreezeBalanceV2Servlet), - "/wallet/unfreezebalancev2"); - context.addServlet(new ServletHolder(withdrawExpireUnfreezeServlet), - "/wallet/withdrawexpireunfreeze"); - context.addServlet(new ServletHolder(delegateResourceServlet), - "/wallet/delegateresource"); - context.addServlet(new ServletHolder(unDelegateResourceServlet), - "/wallet/undelegateresource"); - context.addServlet(new ServletHolder(cancelAllUnfreezeV2Servlet), - "/wallet/cancelallunfreezev2"); - - int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } + } - // filters the specified APIs - // when node is lite fullnode and openHistoryQueryWhenLiteFN is false - context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*", - EnumSet.allOf(DispatcherType.class)); + @Override + protected void addFilter(ServletContextHandler context) { + // filters the specified APIs + // when node is lite fullnode and openHistoryQueryWhenLiteFN is false + context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*", + EnumSet.allOf(DispatcherType.class)); - // http access filter, it should have higher priority than HttpInterceptor - context.addFilter(new FilterHolder(httpApiAccessFilter), "/*", - EnumSet.allOf(DispatcherType.class)); - // note: if the pathSpec of servlet is not started with wallet, it should be included here - context.getServletHandler().getFilterMappings()[1] - .setPathSpecs(new String[] {"/wallet/*", - "/net/listnodes", - "/monitor/getstatsinfo", - "/monitor/getnodeinfo"}); + // http access filter, it should have higher priority than HttpInterceptor + context.addFilter(new FilterHolder(httpApiAccessFilter), "/*", + EnumSet.allOf(DispatcherType.class)); + // note: if the pathSpec of servlet is not started with wallet, it should be included here + context.getServletHandler().getFilterMappings()[1] + .setPathSpecs(new String[] {"/wallet/*", + "/net/listnodes", + "/monitor/getstatsinfo", + "/monitor/getnodeinfo"}); - // metrics filter - ServletHandler handler = new ServletHandler(); - FilterHolder fh = handler - .addFilterWithMapping((Class) HttpInterceptor.class, "/*", - EnumSet.of(DispatcherType.REQUEST)); - context.addFilter(fh, "/*", EnumSet.of(DispatcherType.REQUEST)); - super.start(); - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + // metrics filter + ServletHandler handler = new ServletHandler(); + FilterHolder fh = handler + .addFilterWithMapping((Class) HttpInterceptor.class, "/*", + EnumSet.of(DispatcherType.REQUEST)); + context.addFilter(fh, "/*", EnumSet.of(DispatcherType.REQUEST)); } } diff --git a/framework/src/main/java/org/tron/core/services/http/solidity/SolidityNodeHttpApiService.java b/framework/src/main/java/org/tron/core/services/http/solidity/SolidityNodeHttpApiService.java index dbe54f282a3..ea08d2d42cf 100644 --- a/framework/src/main/java/org/tron/core/services/http/solidity/SolidityNodeHttpApiService.java +++ b/framework/src/main/java/org/tron/core/services/http/solidity/SolidityNodeHttpApiService.java @@ -3,8 +3,6 @@ import java.util.EnumSet; import javax.servlet.DispatcherType; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; @@ -168,133 +166,120 @@ public class SolidityNodeHttpApiService extends HttpService { public SolidityNodeHttpApiService() { port = Args.getInstance().getSolidityHttpPort(); enable = !isFullNode() && Args.getInstance().isSolidityNodeHttpEnable(); + contextPath = "/"; } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - apiServer.setHandler(context); + protected void addServlet(ServletContextHandler context) { + // same as FullNode + context.addServlet(new ServletHolder(getAccountServlet), "/walletsolidity/getaccount"); + context.addServlet(new ServletHolder(listWitnessesServlet), "/walletsolidity/listwitnesses"); + context.addServlet(new ServletHolder(getAssetIssueListServlet), + "/walletsolidity/getassetissuelist"); + context.addServlet(new ServletHolder(getPaginatedAssetIssueListServlet), + "/walletsolidity/getpaginatedassetissuelist"); + context.addServlet(new ServletHolder(getAssetIssueByNameServlet), + "/walletsolidity/getassetissuebyname"); + context.addServlet(new ServletHolder(getAssetIssueByIdServlet), + "/walletsolidity/getassetissuebyid"); + context.addServlet(new ServletHolder(getAssetIssueListByNameServlet), + "/walletsolidity/getassetissuelistbyname"); + context.addServlet(new ServletHolder(getNowBlockServlet), "/walletsolidity/getnowblock"); + context.addServlet(new ServletHolder(getBlockByNumServlet), "/walletsolidity/getblockbynum"); + context.addServlet(new ServletHolder(getDelegatedResourceServlet), + "/walletsolidity/getdelegatedresource"); + context.addServlet(new ServletHolder(getDelegatedResourceV2Servlet), + "/walletsolidity/getdelegatedresourcev2"); + context.addServlet(new ServletHolder(getCanDelegatedMaxSizeServlet), + "/walletsolidity/getcandelegatedmaxsize"); + context.addServlet(new ServletHolder(getAvailableUnfreezeCountServlet), + "/walletsolidity/getavailableunfreezecount"); + context.addServlet(new ServletHolder(getCanWithdrawUnfreezeAmountServlet), + "/walletsolidity/getcanwithdrawunfreezeamount"); + context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexServlet), + "/walletsolidity/getdelegatedresourceaccountindex"); + context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexV2Servlet), + "/walletsolidity/getdelegatedresourceaccountindexv2"); + context + .addServlet(new ServletHolder(getExchangeByIdServlet), + "/walletsolidity/getexchangebyid"); + context.addServlet(new ServletHolder(listExchangesServlet), + "/walletsolidity/listexchanges"); - // same as FullNode - context.addServlet(new ServletHolder(getAccountServlet), "/walletsolidity/getaccount"); - context.addServlet(new ServletHolder(listWitnessesServlet), "/walletsolidity/listwitnesses"); - context.addServlet(new ServletHolder(getAssetIssueListServlet), - "/walletsolidity/getassetissuelist"); - context.addServlet(new ServletHolder(getPaginatedAssetIssueListServlet), - "/walletsolidity/getpaginatedassetissuelist"); - context.addServlet(new ServletHolder(getAssetIssueByNameServlet), - "/walletsolidity/getassetissuebyname"); - context.addServlet(new ServletHolder(getAssetIssueByIdServlet), - "/walletsolidity/getassetissuebyid"); - context.addServlet(new ServletHolder(getAssetIssueListByNameServlet), - "/walletsolidity/getassetissuelistbyname"); - context.addServlet(new ServletHolder(getNowBlockServlet), "/walletsolidity/getnowblock"); - context.addServlet(new ServletHolder(getBlockByNumServlet), "/walletsolidity/getblockbynum"); - context.addServlet(new ServletHolder(getDelegatedResourceServlet), - "/walletsolidity/getdelegatedresource"); - context.addServlet(new ServletHolder(getDelegatedResourceV2Servlet), - "/walletsolidity/getdelegatedresourcev2"); - context.addServlet(new ServletHolder(getCanDelegatedMaxSizeServlet), - "/walletsolidity/getcandelegatedmaxsize"); - context.addServlet(new ServletHolder(getAvailableUnfreezeCountServlet), - "/walletsolidity/getavailableunfreezecount"); - context.addServlet(new ServletHolder(getCanWithdrawUnfreezeAmountServlet), - "/walletsolidity/getcanwithdrawunfreezeamount"); - context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexServlet), - "/walletsolidity/getdelegatedresourceaccountindex"); - context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexV2Servlet), - "/walletsolidity/getdelegatedresourceaccountindexv2"); - context - .addServlet(new ServletHolder(getExchangeByIdServlet), - "/walletsolidity/getexchangebyid"); - context.addServlet(new ServletHolder(listExchangesServlet), - "/walletsolidity/listexchanges"); + context.addServlet(new ServletHolder(getAccountByIdServlet), + "/walletsolidity/getaccountbyid"); + context.addServlet(new ServletHolder(getBlockByIdServlet), + "/walletsolidity/getblockbyid"); + context.addServlet(new ServletHolder(getBlockByLimitNextServlet), + "/walletsolidity/getblockbylimitnext"); + context.addServlet(new ServletHolder(getBlockByLatestNumServlet), + "/walletsolidity/getblockbylatestnum"); - context.addServlet(new ServletHolder(getAccountByIdServlet), - "/walletsolidity/getaccountbyid"); - context.addServlet(new ServletHolder(getBlockByIdServlet), - "/walletsolidity/getblockbyid"); - context.addServlet(new ServletHolder(getBlockByLimitNextServlet), - "/walletsolidity/getblockbylimitnext"); - context.addServlet(new ServletHolder(getBlockByLatestNumServlet), - "/walletsolidity/getblockbylatestnum"); + // context.addServlet(new ServletHolder(getMerkleTreeVoucherInfoServlet), + // "/walletsolidity/getmerkletreevoucherinfo"); + // context.addServlet(new ServletHolder(scanAndMarkNoteByIvkServlet), + // "/walletsolidity/scanandmarknotebyivk"); + // context.addServlet(new ServletHolder(scanNoteByIvkServlet), + // "/walletsolidity/scannotebyivk"); + // context.addServlet(new ServletHolder(scanNoteByOvkServlet), + // "/walletsolidity/scannotebyovk"); + // context.addServlet(new ServletHolder(isSpendServlet), + // "/walletsolidity/isspend"); + context.addServlet(new ServletHolder(scanShieldedTRC20NotesByIvkServlet), + "/walletsolidity/scanshieldedtrc20notesbyivk"); + context.addServlet(new ServletHolder(scanShieldedTRC20NotesByOvkServlet), + "/walletsolidity/scanshieldedtrc20notesbyovk"); + context.addServlet(new ServletHolder(isShieldedTRC20ContractNoteSpentServlet), + "/walletsolidity/isshieldedtrc20contractnotespent"); - // context.addServlet(new ServletHolder(getMerkleTreeVoucherInfoServlet), - // "/walletsolidity/getmerkletreevoucherinfo"); - // context.addServlet(new ServletHolder(scanAndMarkNoteByIvkServlet), - // "/walletsolidity/scanandmarknotebyivk"); - // context.addServlet(new ServletHolder(scanNoteByIvkServlet), - // "/walletsolidity/scannotebyivk"); - // context.addServlet(new ServletHolder(scanNoteByOvkServlet), - // "/walletsolidity/scannotebyovk"); - // context.addServlet(new ServletHolder(isSpendServlet), - // "/walletsolidity/isspend"); + context.addServlet(new ServletHolder(getTransactionInfoByBlockNumServlet), + "/walletsolidity/gettransactioninfobyblocknum"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByIvkServlet), - "/walletsolidity/scanshieldedtrc20notesbyivk"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByOvkServlet), - "/walletsolidity/scanshieldedtrc20notesbyovk"); - context.addServlet(new ServletHolder(isShieldedTRC20ContractNoteSpentServlet), - "/walletsolidity/isshieldedtrc20contractnotespent"); + context.addServlet(new ServletHolder(getMarketOrderByAccountServlet), + "/walletsolidity/getmarketorderbyaccount"); + context.addServlet(new ServletHolder(getMarketOrderByIdServlet), + "/walletsolidity/getmarketorderbyid"); + context.addServlet(new ServletHolder(getMarketPriceByPairServlet), + "/walletsolidity/getmarketpricebypair"); + context.addServlet(new ServletHolder(getMarketOrderListByPairServlet), + "/walletsolidity/getmarketorderlistbypair"); + context.addServlet(new ServletHolder(getMarketPairListServlet), + "/walletsolidity/getmarketpairlist"); - context.addServlet(new ServletHolder(getTransactionInfoByBlockNumServlet), - "/walletsolidity/gettransactioninfobyblocknum"); + // only for SolidityNode + context.addServlet(new ServletHolder(getTransactionByIdServlet), + "/walletsolidity/gettransactionbyid"); - context.addServlet(new ServletHolder(getMarketOrderByAccountServlet), - "/walletsolidity/getmarketorderbyaccount"); - context.addServlet(new ServletHolder(getMarketOrderByIdServlet), - "/walletsolidity/getmarketorderbyid"); - context.addServlet(new ServletHolder(getMarketPriceByPairServlet), - "/walletsolidity/getmarketpricebypair"); - context.addServlet(new ServletHolder(getMarketOrderListByPairServlet), - "/walletsolidity/getmarketorderlistbypair"); - context.addServlet(new ServletHolder(getMarketPairListServlet), - "/walletsolidity/getmarketpairlist"); + context + .addServlet(new ServletHolder(getTransactionInfoByIdServlet), + "/walletsolidity/gettransactioninfobyid"); + context + .addServlet(new ServletHolder(getTransactionCountByBlockNumServlet), + "/walletsolidity/gettransactioncountbyblocknum"); + context.addServlet(new ServletHolder(triggerConstantContractServlet), + "/walletsolidity/triggerconstantcontract"); + context.addServlet(new ServletHolder(estimateEnergyServlet), + "/walletsolidity/estimateenergy"); - // only for SolidityNode - context.addServlet(new ServletHolder(getTransactionByIdServlet), - "/walletsolidity/gettransactionbyid"); - - context - .addServlet(new ServletHolder(getTransactionInfoByIdServlet), - "/walletsolidity/gettransactioninfobyid"); - context - .addServlet(new ServletHolder(getTransactionCountByBlockNumServlet), - "/walletsolidity/gettransactioncountbyblocknum"); - context.addServlet(new ServletHolder(triggerConstantContractServlet), - "/walletsolidity/triggerconstantcontract"); - context.addServlet(new ServletHolder(estimateEnergyServlet), - "/walletsolidity/estimateenergy"); - - context.addServlet(new ServletHolder(getNodeInfoServlet), "/wallet/getnodeinfo"); - context.addServlet(new ServletHolder(getNodeInfoServlet), "/walletsolidity/getnodeinfo"); - context.addServlet(new ServletHolder(getBrokerageServlet), "/walletsolidity/getBrokerage"); - context.addServlet(new ServletHolder(getRewardServlet), "/walletsolidity/getReward"); - context.addServlet(new ServletHolder(getBurnTrxServlet), "/walletsolidity/getburntrx"); - context.addServlet(new ServletHolder(getBlockServlet), "/walletsolidity/getblock"); - context.addServlet(new ServletHolder(getBandwidthPricesServlet), - "/walletsolidity/getbandwidthprices"); - context.addServlet(new ServletHolder(getEnergyPricesServlet), - "/walletsolidity/getenergyprices"); - - // http access filter - context.addFilter(new FilterHolder(httpApiAccessFilter), "/walletsolidity/*", - EnumSet.allOf(DispatcherType.class)); - context.getServletHandler().getFilterMappings()[0] - .setPathSpecs(new String[] {"/walletsolidity/*", - "/wallet/getnodeinfo"}); - - int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } + context.addServlet(new ServletHolder(getNodeInfoServlet), "/wallet/getnodeinfo"); + context.addServlet(new ServletHolder(getNodeInfoServlet), "/walletsolidity/getnodeinfo"); + context.addServlet(new ServletHolder(getBrokerageServlet), "/walletsolidity/getBrokerage"); + context.addServlet(new ServletHolder(getRewardServlet), "/walletsolidity/getReward"); + context.addServlet(new ServletHolder(getBurnTrxServlet), "/walletsolidity/getburntrx"); + context.addServlet(new ServletHolder(getBlockServlet), "/walletsolidity/getblock"); + context.addServlet(new ServletHolder(getBandwidthPricesServlet), + "/walletsolidity/getbandwidthprices"); + context.addServlet(new ServletHolder(getEnergyPricesServlet), + "/walletsolidity/getenergyprices"); + } - super.start(); - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + @Override + protected void addFilter(ServletContextHandler context) { + // http access filter + context.addFilter(new FilterHolder(httpApiAccessFilter), "/walletsolidity/*", + EnumSet.allOf(DispatcherType.class)); + context.getServletHandler().getFilterMappings()[0] + .setPathSpecs(new String[] {"/walletsolidity/*", + "/wallet/getnodeinfo"}); } } diff --git a/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnPBFT/JsonRpcServiceOnPBFT.java b/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnPBFT/JsonRpcServiceOnPBFT.java index d251ba1f276..fffaf8d4e7b 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnPBFT/JsonRpcServiceOnPBFT.java +++ b/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnPBFT/JsonRpcServiceOnPBFT.java @@ -1,8 +1,6 @@ package org.tron.core.services.interfaceJsonRpcOnPBFT; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.springframework.beans.factory.annotation.Autowired; @@ -20,27 +18,11 @@ public class JsonRpcServiceOnPBFT extends HttpService { public JsonRpcServiceOnPBFT() { port = Args.getInstance().getJsonRpcHttpPBFTPort(); enable = isFullNode() && Args.getInstance().isJsonRpcHttpPBFTNodeEnable(); + contextPath = "/"; } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - apiServer.setHandler(context); - - context.addServlet(new ServletHolder(jsonRpcOnPBFTServlet), "/jsonrpc"); - - int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } - - super.start(); - - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + public void addServlet(ServletContextHandler context) { + context.addServlet(new ServletHolder(jsonRpcOnPBFTServlet), "/jsonrpc"); } } diff --git a/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnSolidity/JsonRpcServiceOnSolidity.java b/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnSolidity/JsonRpcServiceOnSolidity.java index d29b598d285..a6f7d5dd5e7 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnSolidity/JsonRpcServiceOnSolidity.java +++ b/framework/src/main/java/org/tron/core/services/interfaceJsonRpcOnSolidity/JsonRpcServiceOnSolidity.java @@ -1,8 +1,6 @@ package org.tron.core.services.interfaceJsonRpcOnSolidity; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.springframework.beans.factory.annotation.Autowired; @@ -20,26 +18,11 @@ public class JsonRpcServiceOnSolidity extends HttpService { public JsonRpcServiceOnSolidity() { port = Args.getInstance().getJsonRpcHttpSolidityPort(); enable = isFullNode() && Args.getInstance().isJsonRpcHttpSolidityNodeEnable(); + contextPath = "/"; } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - apiServer.setHandler(context); - - context.addServlet(new ServletHolder(jsonRpcOnSolidityServlet), "/jsonrpc"); - - int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } - super.start(); - - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + public void addServlet(ServletContextHandler context) { + context.addServlet(new ServletHolder(jsonRpcOnSolidityServlet), "/jsonrpc"); } } diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java index 9117ea1b1b7..54e7b69f7fc 100755 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java @@ -1,9 +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; import org.springframework.beans.factory.annotation.Autowired; import org.tron.api.DatabaseGrpc.DatabaseImplBase; @@ -36,13 +34,8 @@ import org.tron.api.GrpcAPI.WitnessList; import org.tron.api.WalletSolidityGrpc.WalletSolidityImplBase; import org.tron.common.application.RpcService; -import org.tron.common.es.ExecutorServiceManager; -import org.tron.common.parameter.CommonParameter; import org.tron.core.config.args.Args; import org.tron.core.services.RpcApiService; -import org.tron.core.services.filter.LiteFnQueryGrpcInterceptor; -import org.tron.core.services.ratelimiter.RateLimiterInterceptor; -import org.tron.core.services.ratelimiter.RpcApiAccessInterceptor; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; import org.tron.protos.Protocol.DelegatedResourceAccountIndex; @@ -70,66 +63,16 @@ public class RpcApiServiceOnPBFT extends RpcService { @Autowired private RpcApiService rpcApiService; - @Autowired - private RateLimiterInterceptor rateLimiterInterceptor; - - @Autowired - private LiteFnQueryGrpcInterceptor liteFnQueryGrpcInterceptor; - - @Autowired - private RpcApiAccessInterceptor apiAccessInterceptor; - - private final String executorName = "rpc-pbft-executor"; - public RpcApiServiceOnPBFT() { port = Args.getInstance().getRpcOnPBFTPort(); enable = isFullNode() && Args.getInstance().isRpcPBFTEnable(); + executorName = "rpc-pbft-executor"; } @Override - public void start() { - try { - NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(port) - .addService(new DatabaseApi()); - - CommonParameter args = CommonParameter.getInstance(); - - if (args.getRpcThreadNum() > 0) { - serverBuilder = serverBuilder - .executor(ExecutorServiceManager.newFixedThreadPool( - executorName, args.getRpcThreadNum())); - } - - serverBuilder = serverBuilder.addService(new WalletPBFTApi()); - - // Set configs from config.conf or default value - serverBuilder - .maxConcurrentCallsPerConnection(args.getMaxConcurrentCallsPerConnection()) - .flowControlWindow(args.getFlowControlWindow()) - .maxConnectionIdle(args.getMaxConnectionIdleInMillis(), TimeUnit.MILLISECONDS) - .maxConnectionAge(args.getMaxConnectionAgeInMillis(), TimeUnit.MILLISECONDS) - .maxInboundMessageSize(args.getMaxMessageSize()) - .maxHeaderListSize(args.getMaxHeaderListSize()); - - // add a ratelimiter interceptor - serverBuilder.intercept(rateLimiterInterceptor); - - // add api access interceptor - serverBuilder.intercept(apiAccessInterceptor); - - // add lite fullnode query interceptor - serverBuilder.intercept(liteFnQueryGrpcInterceptor); - - if (args.isRpcReflectionServiceEnable()) { - serverBuilder.addService(ProtoReflectionService.newInstance()); - } - - apiServer = serverBuilder.build(); - rateLimiterInterceptor.init(apiServer); - super.start(); - } catch (Exception e) { - logger.debug(e.getMessage(), e); - } + protected void addService(NettyServerBuilder serverBuilder) { + serverBuilder.addService(new DatabaseApi()); + serverBuilder.addService(new WalletPBFTApi()); } /** diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/HttpApiOnPBFTService.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/HttpApiOnPBFTService.java index 654526b7318..828d36e664f 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/HttpApiOnPBFTService.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/http/PBFT/HttpApiOnPBFTService.java @@ -3,8 +3,6 @@ import java.util.EnumSet; import javax.servlet.DispatcherType; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; @@ -174,118 +172,106 @@ public class HttpApiOnPBFTService extends HttpService { public HttpApiOnPBFTService() { port = Args.getInstance().getPBFTHttpPort(); enable = isFullNode() && Args.getInstance().isPBFTHttpEnable(); + contextPath = "/walletpbft/"; } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/walletpbft/"); - apiServer.setHandler(context); + protected void addServlet(ServletContextHandler context) { + // same as FullNode + context.addServlet(new ServletHolder(accountOnPBFTServlet), "/getaccount"); + context.addServlet(new ServletHolder(listWitnessesOnPBFTServlet), "/listwitnesses"); + context.addServlet(new ServletHolder(getAssetIssueListOnPBFTServlet), "/getassetissuelist"); + context.addServlet(new ServletHolder(getPaginatedAssetIssueListOnPBFTServlet), + "/getpaginatedassetissuelist"); + context + .addServlet(new ServletHolder(getAssetIssueByNameOnPBFTServlet), "/getassetissuebyname"); + context.addServlet(new ServletHolder(getAssetIssueByIdOnPBFTServlet), "/getassetissuebyid"); + context.addServlet(new ServletHolder(getAssetIssueListByNameOnPBFTServlet), + "/getassetissuelistbyname"); + context.addServlet(new ServletHolder(getNowBlockOnPBFTServlet), "/getnowblock"); + context.addServlet(new ServletHolder(getBlockByNumOnPBFTServlet), "/getblockbynum"); + context.addServlet(new ServletHolder(getDelegatedResourceOnPBFTServlet), + "/getdelegatedresource"); + context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexOnPBFTServlet), + "/getdelegatedresourceaccountindex"); + context.addServlet(new ServletHolder(getExchangeByIdOnPBFTServlet), "/getexchangebyid"); + context.addServlet(new ServletHolder(listExchangesOnPBFTServlet), "/listexchanges"); + context.addServlet(new ServletHolder(getAccountByIdOnPBFTServlet), "/getaccountbyid"); + context.addServlet(new ServletHolder(getBlockByIdOnPBFTServlet), "/getblockbyid"); + context + .addServlet(new ServletHolder(getBlockByLimitNextOnPBFTServlet), "/getblockbylimitnext"); + context + .addServlet(new ServletHolder(getBlockByLatestNumOnPBFTServlet), "/getblockbylatestnum"); + context.addServlet(new ServletHolder(getMerkleTreeVoucherInfoOnPBFTServlet), + "/getmerkletreevoucherinfo"); + context.addServlet(new ServletHolder(scanAndMarkNoteByIvkOnPBFTServlet), + "/scanandmarknotebyivk"); + context.addServlet(new ServletHolder(scanNoteByIvkOnPBFTServlet), "/scannotebyivk"); + context.addServlet(new ServletHolder(scanNoteByOvkOnPBFTServlet), "/scannotebyovk"); + context.addServlet(new ServletHolder(isSpendOnPBFTServlet), "/isspend"); + context.addServlet(new ServletHolder(triggerConstantContractOnPBFTServlet), + "/triggerconstantcontract"); + context.addServlet(new ServletHolder(estimateEnergyOnPBFTServlet), "/estimateenergy"); - // same as FullNode - context.addServlet(new ServletHolder(accountOnPBFTServlet), "/getaccount"); - context.addServlet(new ServletHolder(listWitnessesOnPBFTServlet), "/listwitnesses"); - context.addServlet(new ServletHolder(getAssetIssueListOnPBFTServlet), "/getassetissuelist"); - context.addServlet(new ServletHolder(getPaginatedAssetIssueListOnPBFTServlet), - "/getpaginatedassetissuelist"); - context - .addServlet(new ServletHolder(getAssetIssueByNameOnPBFTServlet), "/getassetissuebyname"); - context.addServlet(new ServletHolder(getAssetIssueByIdOnPBFTServlet), "/getassetissuebyid"); - context.addServlet(new ServletHolder(getAssetIssueListByNameOnPBFTServlet), - "/getassetissuelistbyname"); - context.addServlet(new ServletHolder(getNowBlockOnPBFTServlet), "/getnowblock"); - context.addServlet(new ServletHolder(getBlockByNumOnPBFTServlet), "/getblockbynum"); - context.addServlet(new ServletHolder(getDelegatedResourceOnPBFTServlet), - "/getdelegatedresource"); - context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexOnPBFTServlet), - "/getdelegatedresourceaccountindex"); - context.addServlet(new ServletHolder(getExchangeByIdOnPBFTServlet), "/getexchangebyid"); - context.addServlet(new ServletHolder(listExchangesOnPBFTServlet), "/listexchanges"); - context.addServlet(new ServletHolder(getAccountByIdOnPBFTServlet), "/getaccountbyid"); - context.addServlet(new ServletHolder(getBlockByIdOnPBFTServlet), "/getblockbyid"); - context - .addServlet(new ServletHolder(getBlockByLimitNextOnPBFTServlet), "/getblockbylimitnext"); - context - .addServlet(new ServletHolder(getBlockByLatestNumOnPBFTServlet), "/getblockbylatestnum"); - context.addServlet(new ServletHolder(getMerkleTreeVoucherInfoOnPBFTServlet), - "/getmerkletreevoucherinfo"); - context.addServlet(new ServletHolder(scanAndMarkNoteByIvkOnPBFTServlet), - "/scanandmarknotebyivk"); - context.addServlet(new ServletHolder(scanNoteByIvkOnPBFTServlet), "/scannotebyivk"); - context.addServlet(new ServletHolder(scanNoteByOvkOnPBFTServlet), "/scannotebyovk"); - context.addServlet(new ServletHolder(isSpendOnPBFTServlet), "/isspend"); - context.addServlet(new ServletHolder(triggerConstantContractOnPBFTServlet), - "/triggerconstantcontract"); - context.addServlet(new ServletHolder(estimateEnergyOnPBFTServlet), "/estimateenergy"); + // only for PBFTNode + context.addServlet(new ServletHolder(getTransactionByIdOnPBFTServlet), "/gettransactionbyid"); + context.addServlet(new ServletHolder(getTransactionInfoByIdOnPBFTServlet), + "/gettransactioninfobyid"); - // only for PBFTNode - context.addServlet(new ServletHolder(getTransactionByIdOnPBFTServlet), "/gettransactionbyid"); - context.addServlet(new ServletHolder(getTransactionInfoByIdOnPBFTServlet), - "/gettransactioninfobyid"); + context.addServlet(new ServletHolder(getTransactionCountByBlockNumOnPBFTServlet), + "/gettransactioncountbyblocknum"); - context.addServlet(new ServletHolder(getTransactionCountByBlockNumOnPBFTServlet), - "/gettransactioncountbyblocknum"); + context.addServlet(new ServletHolder(getNodeInfoOnPBFTServlet), "/getnodeinfo"); + context.addServlet(new ServletHolder(getBrokerageServlet), "/getBrokerage"); + context.addServlet(new ServletHolder(getRewardServlet), "/getReward"); - context.addServlet(new ServletHolder(getNodeInfoOnPBFTServlet), "/getnodeinfo"); - context.addServlet(new ServletHolder(getBrokerageServlet), "/getBrokerage"); - context.addServlet(new ServletHolder(getRewardServlet), "/getReward"); + context.addServlet(new ServletHolder(getMarketOrderByAccountOnPBFTServlet), + "/getmarketorderbyaccount"); + context.addServlet(new ServletHolder(getMarketOrderByIdOnPBFTServlet), + "/getmarketorderbyid"); + context.addServlet(new ServletHolder(getMarketPriceByPairOnPBFTServlet), + "/getmarketpricebypair"); + context.addServlet(new ServletHolder(getMarketOrderListByPairOnPBFTServlet), + "/getmarketorderlistbypair"); + context.addServlet(new ServletHolder(getMarketPairListOnPBFTServlet), + "/getmarketpairlist"); - context.addServlet(new ServletHolder(getMarketOrderByAccountOnPBFTServlet), - "/getmarketorderbyaccount"); - context.addServlet(new ServletHolder(getMarketOrderByIdOnPBFTServlet), - "/getmarketorderbyid"); - context.addServlet(new ServletHolder(getMarketPriceByPairOnPBFTServlet), - "/getmarketpricebypair"); - context.addServlet(new ServletHolder(getMarketOrderListByPairOnPBFTServlet), - "/getmarketorderlistbypair"); - context.addServlet(new ServletHolder(getMarketPairListOnPBFTServlet), - "/getmarketpairlist"); + context.addServlet(new ServletHolder(scanShieldedTRC20NotesByIvkOnPBFTServlet), + "/scanshieldedtrc20notesbyivk"); + context.addServlet(new ServletHolder(scanShieldedTRC20NotesByOvkOnPBFTServlet), + "/scanshieldedtrc20notesbyovk"); + context.addServlet(new ServletHolder(isShieldedTRC20ContractNoteSpentOnPBFTServlet), + "/isshieldedtrc20contractnotespent"); + context.addServlet(new ServletHolder(getBurnTrxOnPBFTServlet), + "/getburntrx"); + context.addServlet(new ServletHolder(getBandwidthPricesOnPBFTServlet), + "/getbandwidthprices"); + context.addServlet(new ServletHolder(getEnergyPricesOnPBFTServlet), + "/getenergyprices"); + context.addServlet(new ServletHolder(getBlockOnPBFTServlet), + "/getblock"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByIvkOnPBFTServlet), - "/scanshieldedtrc20notesbyivk"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByOvkOnPBFTServlet), - "/scanshieldedtrc20notesbyovk"); - context.addServlet(new ServletHolder(isShieldedTRC20ContractNoteSpentOnPBFTServlet), - "/isshieldedtrc20contractnotespent"); - context.addServlet(new ServletHolder(getBurnTrxOnPBFTServlet), - "/getburntrx"); - context.addServlet(new ServletHolder(getBandwidthPricesOnPBFTServlet), - "/getbandwidthprices"); - context.addServlet(new ServletHolder(getEnergyPricesOnPBFTServlet), - "/getenergyprices"); - context.addServlet(new ServletHolder(getBlockOnPBFTServlet), - "/getblock"); - - context.addServlet(new ServletHolder(getAvailableUnfreezeCountOnPBFTServlet), - "/getavailableunfreezecount"); - context.addServlet(new ServletHolder(getCanDelegatedMaxSizeOnPBFTServlet), - "/getcandelegatedmaxsize"); - context.addServlet(new ServletHolder(getCanWithdrawUnfreezeAmountOnPBFTServlet), - "/getcanwithdrawunfreezeamount"); - context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexV2OnPBFTServlet), - "/getdelegatedresourceaccountindexv2"); - context.addServlet(new ServletHolder(getDelegatedResourceV2OnPBFTServlet), - "/getdelegatedresourcev2"); - - int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } - - // filters the specified APIs - // when node is lite fullnode and openHistoryQueryWhenLiteFN is false - context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*", - EnumSet.allOf(DispatcherType.class)); + context.addServlet(new ServletHolder(getAvailableUnfreezeCountOnPBFTServlet), + "/getavailableunfreezecount"); + context.addServlet(new ServletHolder(getCanDelegatedMaxSizeOnPBFTServlet), + "/getcandelegatedmaxsize"); + context.addServlet(new ServletHolder(getCanWithdrawUnfreezeAmountOnPBFTServlet), + "/getcanwithdrawunfreezeamount"); + context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexV2OnPBFTServlet), + "/getdelegatedresourceaccountindexv2"); + context.addServlet(new ServletHolder(getDelegatedResourceV2OnPBFTServlet), + "/getdelegatedresourcev2"); + } - // api access filter - context.addFilter(new FilterHolder(httpApiAccessFilter), "/*", - EnumSet.allOf(DispatcherType.class)); + @Override + protected void addFilter(ServletContextHandler context) { + // filters the specified APIs + // when node is lite fullnode and openHistoryQueryWhenLiteFN is false + context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*", + EnumSet.allOf(DispatcherType.class)); - super.start(); - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + // api access filter + context.addFilter(new FilterHolder(httpApiAccessFilter), "/*", + EnumSet.allOf(DispatcherType.class)); } } diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java index aeab78b04eb..aa566f56042 100755 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java @@ -2,9 +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; import org.springframework.beans.factory.annotation.Autowired; import org.tron.api.DatabaseGrpc.DatabaseImplBase; @@ -35,15 +33,11 @@ import org.tron.api.GrpcAPI.WitnessList; import org.tron.api.WalletSolidityGrpc.WalletSolidityImplBase; import org.tron.common.application.RpcService; -import org.tron.common.es.ExecutorServiceManager; import org.tron.common.parameter.CommonParameter; import org.tron.common.utils.Sha256Hash; import org.tron.core.capsule.BlockCapsule; import org.tron.core.config.args.Args; import org.tron.core.services.RpcApiService; -import org.tron.core.services.filter.LiteFnQueryGrpcInterceptor; -import org.tron.core.services.ratelimiter.RateLimiterInterceptor; -import org.tron.core.services.ratelimiter.RpcApiAccessInterceptor; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; import org.tron.protos.Protocol.DelegatedResourceAccountIndex; @@ -72,65 +66,16 @@ public class RpcApiServiceOnSolidity extends RpcService { @Autowired private RpcApiService rpcApiService; - @Autowired - private RateLimiterInterceptor rateLimiterInterceptor; - - @Autowired - private LiteFnQueryGrpcInterceptor liteFnQueryGrpcInterceptor; - - @Autowired - private RpcApiAccessInterceptor apiAccessInterceptor; - - private final String executorName = "rpc-solidity-executor"; - public RpcApiServiceOnSolidity() { port = Args.getInstance().getRpcOnSolidityPort(); enable = isFullNode() && Args.getInstance().isRpcSolidityEnable(); + executorName = "rpc-solidity-executor"; } @Override - public void start() { - try { - NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(port) - .addService(new DatabaseApi()); - - CommonParameter parameter = Args.getInstance(); - - if (parameter.getRpcThreadNum() > 0) { - serverBuilder = serverBuilder - .executor(ExecutorServiceManager.newFixedThreadPool( - executorName, parameter.getRpcThreadNum())); - } - - serverBuilder = serverBuilder.addService(new WalletSolidityApi()); - - // Set configs from config.conf or default value - serverBuilder.maxConcurrentCallsPerConnection(parameter.getMaxConcurrentCallsPerConnection()) - .flowControlWindow(parameter.getFlowControlWindow()) - .maxConnectionIdle(parameter.getMaxConnectionIdleInMillis(), TimeUnit.MILLISECONDS) - .maxConnectionAge(parameter.getMaxConnectionAgeInMillis(), TimeUnit.MILLISECONDS) - .maxInboundMessageSize(parameter.getMaxMessageSize()) - .maxHeaderListSize(parameter.getMaxHeaderListSize()); - - // add a ratelimiter interceptor - serverBuilder.intercept(rateLimiterInterceptor); - - // add api access interceptor - serverBuilder.intercept(apiAccessInterceptor); - - // add lite fullnode query interceptor - serverBuilder.intercept(liteFnQueryGrpcInterceptor); - - if (parameter.isRpcReflectionServiceEnable()) { - serverBuilder.addService(ProtoReflectionService.newInstance()); - } - - apiServer = serverBuilder.build(); - rateLimiterInterceptor.init(apiServer); - super.start(); - } catch (Exception e) { - logger.debug(e.getMessage(), e); - } + protected void addService(NettyServerBuilder serverBuilder) { + serverBuilder.addService(new DatabaseApi()); + serverBuilder.addService(new WalletSolidityApi()); } private TransactionExtention transaction2Extention(Transaction transaction) { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/HttpApiOnSolidityService.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/HttpApiOnSolidityService.java index 5a1328d1a5e..b1d940ce2cd 100644 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/HttpApiOnSolidityService.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/HttpApiOnSolidityService.java @@ -180,136 +180,126 @@ public class HttpApiOnSolidityService extends HttpService { public HttpApiOnSolidityService() { port = Args.getInstance().getSolidityHttpPort(); enable = isFullNode() && Args.getInstance().isSolidityNodeHttpEnable(); + contextPath = "/"; } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - apiServer.setHandler(context); + protected void addServlet(ServletContextHandler context) { + // same as FullNode + context.addServlet(new ServletHolder(accountOnSolidityServlet), "/walletsolidity/getaccount"); + context.addServlet(new ServletHolder(listWitnessesOnSolidityServlet), + "/walletsolidity/listwitnesses"); + context.addServlet(new ServletHolder(getAssetIssueListOnSolidityServlet), + "/walletsolidity/getassetissuelist"); + context.addServlet(new ServletHolder(getPaginatedAssetIssueListOnSolidityServlet), + "/walletsolidity/getpaginatedassetissuelist"); + context.addServlet(new ServletHolder(getAssetIssueByNameOnSolidityServlet), + "/walletsolidity/getassetissuebyname"); + context.addServlet(new ServletHolder(getAssetIssueByIdOnSolidityServlet), + "/walletsolidity/getassetissuebyid"); + context.addServlet(new ServletHolder(getAssetIssueListByNameOnSolidityServlet), + "/walletsolidity/getassetissuelistbyname"); + context.addServlet(new ServletHolder(getNowBlockOnSolidityServlet), + "/walletsolidity/getnowblock"); + context.addServlet(new ServletHolder(getBlockByNumOnSolidityServlet), + "/walletsolidity/getblockbynum"); + context.addServlet(new ServletHolder(getDelegatedResourceOnSolidityServlet), + "/walletsolidity/getdelegatedresource"); + context.addServlet(new ServletHolder(getDelegatedResourceV2OnSolidityServlet), + "/walletsolidity/getdelegatedresourcev2"); + context.addServlet(new ServletHolder(getCanDelegatedMaxSizeOnSolidityServlet), + "/walletsolidity/getcandelegatedmaxsize"); + context.addServlet(new ServletHolder(getAvailableUnfreezeCountOnSolidityServlet), + "/walletsolidity/getavailableunfreezecount"); + context.addServlet(new ServletHolder(getCanWithdrawUnfreezeAmountOnSolidityServlet), + "/walletsolidity/getcanwithdrawunfreezeamount"); + context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexOnSolidityServlet), + "/walletsolidity/getdelegatedresourceaccountindex"); + context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexV2OnSolidityServlet), + "/walletsolidity/getdelegatedresourceaccountindexv2"); + context.addServlet(new ServletHolder(getExchangeByIdOnSolidityServlet), + "/walletsolidity/getexchangebyid"); + context.addServlet(new ServletHolder(listExchangesOnSolidityServlet), + "/walletsolidity/listexchanges"); + context.addServlet(new ServletHolder(getAccountByIdOnSolidityServlet), + "/walletsolidity/getaccountbyid"); + context.addServlet(new ServletHolder(getBlockByIdOnSolidityServlet), + "/walletsolidity/getblockbyid"); + context.addServlet(new ServletHolder(getBlockByLimitNextOnSolidityServlet), + "/walletsolidity/getblockbylimitnext"); + context.addServlet(new ServletHolder(getBlockByLatestNumOnSolidityServlet), + "/walletsolidity/getblockbylatestnum"); + // context.addServlet(new ServletHolder(getMerkleTreeVoucherInfoOnSolidityServlet), + // "/walletsolidity/getmerkletreevoucherinfo"); + // context.addServlet(new ServletHolder(scanAndMarkNoteByIvkOnSolidityServlet), + // "/walletsolidity/scanandmarknotebyivk"); + // context.addServlet(new ServletHolder(scanNoteByIvkOnSolidityServlet), + // "/walletsolidity/scannotebyivk"); + // context.addServlet(new ServletHolder(scanNoteByOvkOnSolidityServlet), + // "/walletsolidity/scannotebyovk"); + // context.addServlet(new ServletHolder(isSpendOnSolidityServlet), + // "/walletsolidity/isspend"); + context.addServlet(new ServletHolder(scanShieldedTRC20NotesByIvkOnSolidityServlet), + "/walletsolidity/scanshieldedtrc20notesbyivk"); + context.addServlet(new ServletHolder(scanShieldedTRC20NotesByOvkOnSolidityServlet), + "/walletsolidity/scanshieldedtrc20notesbyovk"); + context.addServlet(new ServletHolder(isShieldedTRC20ContractNoteSpentOnSolidityServlet), + "/walletsolidity/isshieldedtrc20contractnotespent"); + context.addServlet(new ServletHolder(triggerConstantContractOnSolidityServlet), + "/walletsolidity/triggerconstantcontract"); + context.addServlet(new ServletHolder(estimateEnergyOnSolidityServlet), + "/walletsolidity/estimateenergy"); + context.addServlet(new ServletHolder(getTransactionInfoByBlockNumOnSolidityServlet), + "/walletsolidity/gettransactioninfobyblocknum"); + context.addServlet(new ServletHolder(getMarketOrderByAccountOnSolidityServlet), + "/walletsolidity/getmarketorderbyaccount"); + context.addServlet(new ServletHolder(getMarketOrderByIdOnSolidityServlet), + "/walletsolidity/getmarketorderbyid"); + context.addServlet(new ServletHolder(getMarketPriceByPairOnSolidityServlet), + "/walletsolidity/getmarketpricebypair"); + context.addServlet(new ServletHolder(getMarketOrderListByPairOnSolidityServlet), + "/walletsolidity/getmarketorderlistbypair"); + context.addServlet(new ServletHolder(getMarketPairListOnSolidityServlet), + "/walletsolidity/getmarketpairlist"); - // same as FullNode - context.addServlet(new ServletHolder(accountOnSolidityServlet), "/walletsolidity/getaccount"); - context.addServlet(new ServletHolder(listWitnessesOnSolidityServlet), - "/walletsolidity/listwitnesses"); - context.addServlet(new ServletHolder(getAssetIssueListOnSolidityServlet), - "/walletsolidity/getassetissuelist"); - context.addServlet(new ServletHolder(getPaginatedAssetIssueListOnSolidityServlet), - "/walletsolidity/getpaginatedassetissuelist"); - context.addServlet(new ServletHolder(getAssetIssueByNameOnSolidityServlet), - "/walletsolidity/getassetissuebyname"); - context.addServlet(new ServletHolder(getAssetIssueByIdOnSolidityServlet), - "/walletsolidity/getassetissuebyid"); - context.addServlet(new ServletHolder(getAssetIssueListByNameOnSolidityServlet), - "/walletsolidity/getassetissuelistbyname"); - context.addServlet(new ServletHolder(getNowBlockOnSolidityServlet), - "/walletsolidity/getnowblock"); - context.addServlet(new ServletHolder(getBlockByNumOnSolidityServlet), - "/walletsolidity/getblockbynum"); - context.addServlet(new ServletHolder(getDelegatedResourceOnSolidityServlet), - "/walletsolidity/getdelegatedresource"); - context.addServlet(new ServletHolder(getDelegatedResourceV2OnSolidityServlet), - "/walletsolidity/getdelegatedresourcev2"); - context.addServlet(new ServletHolder(getCanDelegatedMaxSizeOnSolidityServlet), - "/walletsolidity/getcandelegatedmaxsize"); - context.addServlet(new ServletHolder(getAvailableUnfreezeCountOnSolidityServlet), - "/walletsolidity/getavailableunfreezecount"); - context.addServlet(new ServletHolder(getCanWithdrawUnfreezeAmountOnSolidityServlet), - "/walletsolidity/getcanwithdrawunfreezeamount"); - context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexOnSolidityServlet), - "/walletsolidity/getdelegatedresourceaccountindex"); - context.addServlet(new ServletHolder(getDelegatedResourceAccountIndexV2OnSolidityServlet), - "/walletsolidity/getdelegatedresourceaccountindexv2"); - context.addServlet(new ServletHolder(getExchangeByIdOnSolidityServlet), - "/walletsolidity/getexchangebyid"); - context.addServlet(new ServletHolder(listExchangesOnSolidityServlet), - "/walletsolidity/listexchanges"); - context.addServlet(new ServletHolder(getAccountByIdOnSolidityServlet), - "/walletsolidity/getaccountbyid"); - context.addServlet(new ServletHolder(getBlockByIdOnSolidityServlet), - "/walletsolidity/getblockbyid"); - context.addServlet(new ServletHolder(getBlockByLimitNextOnSolidityServlet), - "/walletsolidity/getblockbylimitnext"); - context.addServlet(new ServletHolder(getBlockByLatestNumOnSolidityServlet), - "/walletsolidity/getblockbylatestnum"); - // context.addServlet(new ServletHolder(getMerkleTreeVoucherInfoOnSolidityServlet), - // "/walletsolidity/getmerkletreevoucherinfo"); - // context.addServlet(new ServletHolder(scanAndMarkNoteByIvkOnSolidityServlet), - // "/walletsolidity/scanandmarknotebyivk"); - // context.addServlet(new ServletHolder(scanNoteByIvkOnSolidityServlet), - // "/walletsolidity/scannotebyivk"); - // context.addServlet(new ServletHolder(scanNoteByOvkOnSolidityServlet), - // "/walletsolidity/scannotebyovk"); - // context.addServlet(new ServletHolder(isSpendOnSolidityServlet), - // "/walletsolidity/isspend"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByIvkOnSolidityServlet), - "/walletsolidity/scanshieldedtrc20notesbyivk"); - context.addServlet(new ServletHolder(scanShieldedTRC20NotesByOvkOnSolidityServlet), - "/walletsolidity/scanshieldedtrc20notesbyovk"); - context.addServlet(new ServletHolder(isShieldedTRC20ContractNoteSpentOnSolidityServlet), - "/walletsolidity/isshieldedtrc20contractnotespent"); - context.addServlet(new ServletHolder(triggerConstantContractOnSolidityServlet), - "/walletsolidity/triggerconstantcontract"); - context.addServlet(new ServletHolder(estimateEnergyOnSolidityServlet), - "/walletsolidity/estimateenergy"); - context.addServlet(new ServletHolder(getTransactionInfoByBlockNumOnSolidityServlet), - "/walletsolidity/gettransactioninfobyblocknum"); - context.addServlet(new ServletHolder(getMarketOrderByAccountOnSolidityServlet), - "/walletsolidity/getmarketorderbyaccount"); - context.addServlet(new ServletHolder(getMarketOrderByIdOnSolidityServlet), - "/walletsolidity/getmarketorderbyid"); - context.addServlet(new ServletHolder(getMarketPriceByPairOnSolidityServlet), - "/walletsolidity/getmarketpricebypair"); - context.addServlet(new ServletHolder(getMarketOrderListByPairOnSolidityServlet), - "/walletsolidity/getmarketorderlistbypair"); - context.addServlet(new ServletHolder(getMarketPairListOnSolidityServlet), - "/walletsolidity/getmarketpairlist"); + // only for SolidityNode + context.addServlet(new ServletHolder(getTransactionByIdOnSolidityServlet), + "/walletsolidity/gettransactionbyid"); + context.addServlet(new ServletHolder(getTransactionInfoByIdOnSolidityServlet), + "/walletsolidity/gettransactioninfobyid"); - // only for SolidityNode - context.addServlet(new ServletHolder(getTransactionByIdOnSolidityServlet), - "/walletsolidity/gettransactionbyid"); - context.addServlet(new ServletHolder(getTransactionInfoByIdOnSolidityServlet), - "/walletsolidity/gettransactioninfobyid"); + context.addServlet(new ServletHolder(getTransactionCountByBlockNumOnSolidityServlet), + "/walletsolidity/gettransactioncountbyblocknum"); - context.addServlet(new ServletHolder(getTransactionCountByBlockNumOnSolidityServlet), - "/walletsolidity/gettransactioncountbyblocknum"); + context.addServlet(new ServletHolder(getNodeInfoOnSolidityServlet), "/wallet/getnodeinfo"); + context.addServlet(new ServletHolder(getNodeInfoOnSolidityServlet), + "/walletsolidity/getnodeinfo"); + context.addServlet(new ServletHolder(getBrokerageServlet), "/walletsolidity/getBrokerage"); + context.addServlet(new ServletHolder(getRewardServlet), "/walletsolidity/getReward"); + context + .addServlet(new ServletHolder(getBurnTrxOnSolidityServlet), "/walletsolidity/getburntrx"); + context.addServlet(new ServletHolder(getBandwidthPricesOnSolidityServlet), + "/walletsolidity/getbandwidthprices"); + context.addServlet(new ServletHolder(getEnergyPricesOnSolidityServlet), + "/walletsolidity/getenergyprices"); - context.addServlet(new ServletHolder(getNodeInfoOnSolidityServlet), "/wallet/getnodeinfo"); - context.addServlet(new ServletHolder(getNodeInfoOnSolidityServlet), - "/walletsolidity/getnodeinfo"); - context.addServlet(new ServletHolder(getBrokerageServlet), "/walletsolidity/getBrokerage"); - context.addServlet(new ServletHolder(getRewardServlet), "/walletsolidity/getReward"); - context - .addServlet(new ServletHolder(getBurnTrxOnSolidityServlet), "/walletsolidity/getburntrx"); - context.addServlet(new ServletHolder(getBandwidthPricesOnSolidityServlet), - "/walletsolidity/getbandwidthprices"); - context.addServlet(new ServletHolder(getEnergyPricesOnSolidityServlet), - "/walletsolidity/getenergyprices"); + context.addServlet(new ServletHolder(getBlockOnSolidityServlet), + "/walletsolidity/getblock"); - context.addServlet(new ServletHolder(getBlockOnSolidityServlet), - "/walletsolidity/getblock"); - - // filters the specified APIs - // when node is lite fullnode and openHistoryQueryWhenLiteFN is false - context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*", - EnumSet.allOf(DispatcherType.class)); + } - // api access filter - context.addFilter(new FilterHolder(httpApiAccessFilter), "/walletsolidity/*", - EnumSet.allOf(DispatcherType.class)); - context.getServletHandler().getFilterMappings()[1] - .setPathSpecs(new String[] {"/walletsolidity/*", - "/wallet/getnodeinfo"}); + @Override + protected void addFilter(ServletContextHandler context) { + // filters the specified APIs + // when node is lite fullnode and openHistoryQueryWhenLiteFN is false + context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*", + EnumSet.allOf(DispatcherType.class)); - int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } - super.start(); - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + // api access filter + context.addFilter(new FilterHolder(httpApiAccessFilter), "/walletsolidity/*", + EnumSet.allOf(DispatcherType.class)); + context.getServletHandler().getFilterMappings()[1] + .setPathSpecs(new String[] {"/walletsolidity/*", + "/wallet/getnodeinfo"}); } } diff --git a/framework/src/main/java/org/tron/core/services/jsonrpc/FullNodeJsonRpcHttpService.java b/framework/src/main/java/org/tron/core/services/jsonrpc/FullNodeJsonRpcHttpService.java index 1b6e921a387..566ad33a722 100644 --- a/framework/src/main/java/org/tron/core/services/jsonrpc/FullNodeJsonRpcHttpService.java +++ b/framework/src/main/java/org/tron/core/services/jsonrpc/FullNodeJsonRpcHttpService.java @@ -3,8 +3,6 @@ import java.util.EnumSet; import javax.servlet.DispatcherType; import lombok.extern.slf4j.Slf4j; -import org.eclipse.jetty.server.ConnectionLimit; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHandler; @@ -25,34 +23,21 @@ public class FullNodeJsonRpcHttpService extends HttpService { public FullNodeJsonRpcHttpService() { port = Args.getInstance().getJsonRpcHttpFullNodePort(); enable = isFullNode() && Args.getInstance().isJsonRpcHttpFullNodeEnable(); + contextPath = "/"; } @Override - public void start() { - try { - apiServer = new Server(port); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - apiServer.setHandler(context); - - context.addServlet(new ServletHolder(jsonRpcServlet), "/jsonrpc"); - - int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); - if (maxHttpConnectNumber > 0) { - apiServer.addBean(new ConnectionLimit(maxHttpConnectNumber, apiServer)); - } - - // filter - ServletHandler handler = new ServletHandler(); - FilterHolder fh = handler - .addFilterWithMapping(HttpInterceptor.class, "/*", - EnumSet.of(DispatcherType.REQUEST)); - context.addFilter(fh, "/*", EnumSet.of(DispatcherType.REQUEST)); - - super.start(); + protected void addServlet(ServletContextHandler context) { + context.addServlet(new ServletHolder(jsonRpcServlet), "/jsonrpc"); + } - } catch (Exception e) { - logger.debug("IOException: {}", e.getMessage()); - } + @Override + protected void addFilter(ServletContextHandler context) { + // filter + ServletHandler handler = new ServletHandler(); + FilterHolder fh = handler + .addFilterWithMapping(HttpInterceptor.class, "/*", + EnumSet.of(DispatcherType.REQUEST)); + context.addFilter(fh, "/*", EnumSet.of(DispatcherType.REQUEST)); } } diff --git a/framework/src/test/java/org/tron/core/metrics/MetricsApiServiceTest.java b/framework/src/test/java/org/tron/core/metrics/MetricsApiServiceTest.java index 51a46b09388..5203f035e4f 100644 --- a/framework/src/test/java/org/tron/core/metrics/MetricsApiServiceTest.java +++ b/framework/src/test/java/org/tron/core/metrics/MetricsApiServiceTest.java @@ -12,6 +12,7 @@ import org.tron.common.application.ApplicationFactory; import org.tron.common.application.TronApplicationContext; import org.tron.common.parameter.CommonParameter; +import org.tron.common.utils.PublicMethod; import org.tron.core.Constant; import org.tron.core.config.DefaultConfig; import org.tron.core.config.args.Args; @@ -46,15 +47,25 @@ public void init() throws IOException { }, "config.conf" ); + Args.getInstance().setRpcEnable(false); + Args.getInstance().setRpcSolidityEnable(false); + Args.getInstance().setRpcPBFTEnable(false); + Args.getInstance().setFullNodeHttpEnable(false); + Args.getInstance().setFullNodeHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setPBFTHttpEnable(false); + Args.getInstance().setPBFTHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setSolidityNodeHttpEnable(false); + Args.getInstance().setSolidityHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setJsonRpcHttpFullNodeEnable(false); + Args.getInstance().setJsonRpcHttpSolidityNodeEnable(false); + Args.getInstance().setJsonRpcHttpPBFTNodeEnable(false); CommonParameter parameter = Args.getInstance(); parameter.setNodeListenPort(port); parameter.getSeedNode().getAddressList().clear(); parameter.setNodeExternalIp("127.0.0.1"); context = new TronApplicationContext(DefaultConfig.class); appT = ApplicationFactory.create(context); - rpcApiService = context.getBean(RpcApiService.class); metricsApiService = context.getBean(MetricsApiService.class); - appT.addService(rpcApiService); appT.startup(); } diff --git a/framework/src/test/java/org/tron/core/services/WalletApiTest.java b/framework/src/test/java/org/tron/core/services/WalletApiTest.java index 0a87c348fdb..443bbe96068 100644 --- a/framework/src/test/java/org/tron/core/services/WalletApiTest.java +++ b/framework/src/test/java/org/tron/core/services/WalletApiTest.java @@ -3,18 +3,14 @@ import io.grpc.ManagedChannelBuilder; import java.io.IOException; import lombok.extern.slf4j.Slf4j; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.junit.rules.TemporaryFolder; import org.tron.api.GrpcAPI.EmptyMessage; import org.tron.api.WalletGrpc; import org.tron.common.application.Application; import org.tron.common.application.ApplicationFactory; import org.tron.common.application.TronApplicationContext; -import org.tron.common.utils.client.Configuration; +import org.tron.common.utils.PublicMethod; import org.tron.core.Constant; import org.tron.core.config.DefaultConfig; import org.tron.core.config.args.Args; @@ -23,34 +19,42 @@ @Slf4j public class WalletApiTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @ClassRule + public static TemporaryFolder temporaryFolder = new TemporaryFolder(); private static TronApplicationContext context; - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private RpcApiService rpcApiService; - private Application appT; + private static Application appT; - @Before - public void init() throws IOException { + + @BeforeClass + public static void init() throws IOException { Args.setParam(new String[]{ "-d", temporaryFolder.newFolder().toString(), "--p2p-disable", "true"}, Constant.TEST_CONF); + Args.getInstance().setRpcPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setRpcEnable(true); + Args.getInstance().setRpcSolidityEnable(false); + Args.getInstance().setRpcPBFTEnable(false); + Args.getInstance().setFullNodeHttpEnable(false); + Args.getInstance().setPBFTHttpEnable(false); + Args.getInstance().setSolidityNodeHttpEnable(false); + Args.getInstance().setJsonRpcHttpFullNodeEnable(false); + Args.getInstance().setJsonRpcHttpSolidityNodeEnable(false); + Args.getInstance().setJsonRpcHttpPBFTNodeEnable(false); context = new TronApplicationContext(DefaultConfig.class); appT = ApplicationFactory.create(context); - rpcApiService = context.getBean(RpcApiService.class); - appT.addService(rpcApiService); appT.startup(); } @Test public void listNodesTest() { + String fullNode = String.format("%s:%d", "127.0.0.1", + Args.getInstance().getRpcPort()); WalletGrpc.WalletBlockingStub walletStub = WalletGrpc - .newBlockingStub(ManagedChannelBuilder.forTarget(fullnode) + .newBlockingStub(ManagedChannelBuilder.forTarget(fullNode) .usePlaintext() .build()); Assert.assertTrue(walletStub.listNodes(EmptyMessage.getDefaultInstance()) - .getNodesList().size() == 0); + .getNodesList().isEmpty()); } @After diff --git a/framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java b/framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java index 5f883fc8c07..c0a199542a4 100644 --- a/framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java +++ b/framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java @@ -14,10 +14,10 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; import org.tron.common.BaseTest; import org.tron.common.parameter.CommonParameter; +import org.tron.common.utils.PublicMethod; import org.tron.core.Constant; import org.tron.core.config.args.Args; import org.tron.core.services.http.FullNodeHttpApiService; @@ -39,21 +39,23 @@ public class HttpApiAccessFilterTest extends BaseTest { static { Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); Args.getInstance().setFullNodeAllowShieldedTransactionArgs(false); - } - - /** - * init dependencies. - */ - @Before - public void init() { - appT.addService(httpApiService); - appT.addService(httpApiOnSolidityService); - appT.addService(httpApiOnPBFTService); - appT.startup(); + Args.getInstance().setRpcEnable(false); + Args.getInstance().setRpcSolidityEnable(false); + Args.getInstance().setRpcPBFTEnable(false); + Args.getInstance().setFullNodeHttpEnable(true); + Args.getInstance().setFullNodeHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setPBFTHttpEnable(true); + Args.getInstance().setPBFTHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setSolidityNodeHttpEnable(true); + Args.getInstance().setSolidityHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setJsonRpcHttpFullNodeEnable(false); + Args.getInstance().setJsonRpcHttpSolidityNodeEnable(false); + Args.getInstance().setJsonRpcHttpPBFTNodeEnable(false); } @Test public void testHttpFilter() { + appT.startup(); List disabledApiList = new ArrayList<>(); disabledApiList.add("getaccount"); disabledApiList.add("getnowblock"); diff --git a/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryHttpFilterTest.java b/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryHttpFilterTest.java index 5fd4711273e..a9068c228b6 100644 --- a/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryHttpFilterTest.java +++ b/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryHttpFilterTest.java @@ -7,7 +7,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.Set; -import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -19,28 +18,32 @@ import org.junit.Before; import org.junit.Test; import org.tron.common.BaseTest; +import org.tron.common.utils.PublicMethod; import org.tron.core.Constant; import org.tron.core.config.args.Args; -import org.tron.core.services.http.FullNodeHttpApiService; -import org.tron.core.services.interfaceOnPBFT.http.PBFT.HttpApiOnPBFTService; -import org.tron.core.services.interfaceOnSolidity.http.solidity.HttpApiOnSolidityService; @Slf4j public class LiteFnQueryHttpFilterTest extends BaseTest { private final String ip = "127.0.0.1"; private int fullHttpPort; - @Resource - private FullNodeHttpApiService httpApiService; - @Resource - private HttpApiOnSolidityService httpApiOnSolidityService; - @Resource - private HttpApiOnPBFTService httpApiOnPBFTService; private final CloseableHttpClient httpClient = HttpClients.createDefault(); static { Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); Args.getInstance().setFullNodeAllowShieldedTransactionArgs(false); + Args.getInstance().setRpcEnable(false); + Args.getInstance().setRpcSolidityEnable(false); + Args.getInstance().setRpcPBFTEnable(false); + Args.getInstance().setFullNodeHttpEnable(true); + Args.getInstance().setFullNodeHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setPBFTHttpEnable(true); + Args.getInstance().setPBFTHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setSolidityNodeHttpEnable(true); + Args.getInstance().setSolidityHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setJsonRpcHttpFullNodeEnable(false); + Args.getInstance().setJsonRpcHttpSolidityNodeEnable(false); + Args.getInstance().setJsonRpcHttpPBFTNodeEnable(false); } /** @@ -48,9 +51,6 @@ public class LiteFnQueryHttpFilterTest extends BaseTest { */ @Before public void init() { - appT.addService(httpApiService); - appT.addService(httpApiOnSolidityService); - appT.addService(httpApiOnPBFTService); appT.startup(); } diff --git a/framework/src/test/java/org/tron/core/services/http/TriggerSmartContractServletTest.java b/framework/src/test/java/org/tron/core/services/http/TriggerSmartContractServletTest.java index f363b7fbefc..7332cf83cba 100644 --- a/framework/src/test/java/org/tron/core/services/http/TriggerSmartContractServletTest.java +++ b/framework/src/test/java/org/tron/core/services/http/TriggerSmartContractServletTest.java @@ -1,7 +1,6 @@ package org.tron.core.services.http; import com.google.gson.JsonObject; -import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.bouncycastle.util.encoders.Hex; @@ -9,10 +8,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.tron.common.BaseTest; import org.tron.common.utils.ByteArray; -import org.tron.common.utils.client.Configuration; +import org.tron.common.utils.PublicMethod; import org.tron.common.utils.client.utils.HttpMethed; import org.tron.core.Constant; import org.tron.core.capsule.ContractCapsule; @@ -25,31 +23,32 @@ @Slf4j public class TriggerSmartContractServletTest extends BaseTest { - private static final String httpNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list") - .get(0); + private static String httpNode; private static final byte[] ownerAddr = Hex.decode("410000000000000000000000000000000000000000"); private static final byte[] contractAddr = Hex.decode( "41000000000000000000000000000000000000dEaD"); - @Resource - private FullNodeHttpApiService httpApiService; - @BeforeClass public static void init() throws Exception { Args.setParam( new String[]{"--output-directory", dbPath(), "--debug", "--witness"}, Constant.TEST_CONF); Args.getInstance().needSyncCheck = false; - - // build app context - DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - beanFactory.setAllowCircularReferences(false); + Args.getInstance().setRpcEnable(false); + Args.getInstance().setRpcSolidityEnable(false); + Args.getInstance().setRpcPBFTEnable(false); + Args.getInstance().setFullNodeHttpEnable(true); + Args.getInstance().setFullNodeHttpPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setPBFTHttpEnable(false); + Args.getInstance().setSolidityNodeHttpEnable(false); + Args.getInstance().setJsonRpcHttpFullNodeEnable(false); + Args.getInstance().setJsonRpcHttpSolidityNodeEnable(false); + Args.getInstance().setJsonRpcHttpPBFTNodeEnable(false); + httpNode = String.format("%s:%d", "127.0.0.1", + Args.getInstance().getFullNodeHttpPort()); } @Before public void before() { - appT.addService(httpApiService); - // start services appT.startup(); diff --git a/plugins/src/test/java/org/tron/plugins/DbLiteTest.java b/plugins/src/test/java/org/tron/plugins/DbLiteTest.java index 5cb8c26c4bc..5153acc9c11 100644 --- a/plugins/src/test/java/org/tron/plugins/DbLiteTest.java +++ b/plugins/src/test/java/org/tron/plugins/DbLiteTest.java @@ -76,6 +76,15 @@ public void init() throws IOException { // allow account root Args.getInstance().setAllowAccountStateRoot(1); Args.getInstance().setRpcPort(PublicMethod.chooseRandomPort()); + Args.getInstance().setRpcEnable(true); + Args.getInstance().setRpcSolidityEnable(false); + Args.getInstance().setRpcPBFTEnable(false); + Args.getInstance().setFullNodeHttpEnable(false); + Args.getInstance().setPBFTHttpEnable(false); + Args.getInstance().setSolidityNodeHttpEnable(false); + Args.getInstance().setJsonRpcHttpFullNodeEnable(false); + Args.getInstance().setJsonRpcHttpSolidityNodeEnable(false); + Args.getInstance().setJsonRpcHttpPBFTNodeEnable(false); databaseDir = Args.getInstance().getStorage().getDbDirectory(); // init dbBackupConfig to avoid NPE Args.getInstance().dbBackupConfig = DbBackupConfig.getInstance();