Make RPC server path configurable

This commit is contained in:
Prathamesh Musale 2024-09-18 14:26:30 +05:30
parent 10c8581f46
commit cbedd9ecdf
4 changed files with 30 additions and 18 deletions

View File

@ -25,13 +25,7 @@
# Flag to specify whether RPC endpoint supports block hash as block tag parameter # Flag to specify whether RPC endpoint supports block hash as block tag parameter
rpcSupportsBlockHashParam = true rpcSupportsBlockHashParam = true
# Enable ETH JSON RPC server at /rpc # GQL server config
enableEthRPCServer = true
# Max number of logs that can be returned in a single getLogs request (default: 10000)
ethGetLogsResultLimit = 10000
# Server GQL config
[server.gql] [server.gql]
path = "/graphql" path = "/graphql"
@ -55,6 +49,14 @@
timeTravelMaxAge = 86400 # 1 day timeTravelMaxAge = 86400 # 1 day
{{/if}} {{/if}}
# ETH RPC server config
[server.ethRPC]
enabled = true
path = "/rpc"
# Max number of logs that can be returned in a single getLogs request (default: 10000)
getLogsResultLimit = 10000
[metrics] [metrics]
host = "127.0.0.1" host = "127.0.0.1"
port = 9000 port = 9000

View File

@ -227,6 +227,18 @@ export interface GQLConfig {
logDir?: string; logDir?: string;
} }
// ETH RPC server config
export interface EthRPCConfig {
// Enable ETH JSON RPC server
enabled: boolean;
// Path to expose the RPC server at
path?: string;
// Max number of logs that can be returned in a single getLogs request
getLogsResultLimit?: number;
}
export interface ServerConfig { export interface ServerConfig {
host: string; host: string;
port: number; port: number;
@ -253,11 +265,8 @@ export interface ServerConfig {
// https://ethereum.org/en/developers/docs/apis/json-rpc/#default-block // https://ethereum.org/en/developers/docs/apis/json-rpc/#default-block
rpcSupportsBlockHashParam: boolean; rpcSupportsBlockHashParam: boolean;
// Enable ETH JSON RPC server at /rpc // ETH JSON RPC server config
enableEthRPCServer: boolean; ethRPC: EthRPCConfig;
// Max number of logs that can be returned in a single getLogs request
ethGetLogsResultLimit?: number;
} }
export interface FundingAmountsConfig { export interface FundingAmountsConfig {

View File

@ -153,7 +153,7 @@ export const createEthRPCHandlers = async (
// Fetch events from the db // Fetch events from the db
// Load block relation // Load block relation
const resultLimit = indexer.serverConfig.ethGetLogsResultLimit || DEFAULT_ETH_GET_LOGS_RESULT_LIMIT; const resultLimit = indexer.serverConfig.ethRPC.getLogsResultLimit || DEFAULT_ETH_GET_LOGS_RESULT_LIMIT;
const events = await indexer.getEvents({ where, relations: ['block'], take: resultLimit + 1 }); const events = await indexer.getEvents({ where, relations: ['block'], take: resultLimit + 1 });
// Limit number of results can be returned by a single query // Limit number of results can be returned by a single query

View File

@ -24,7 +24,7 @@ import { PaymentsManager, paymentsPlugin } from './payments';
const log = debug('vulcanize:server'); const log = debug('vulcanize:server');
const DEFAULT_GQL_PATH = '/graphql'; const DEFAULT_GQL_PATH = '/graphql';
const ETH_RPC_PATH = '/rpc'; const DEFAULT_ETH_RPC_PATH = '/rpc';
export const createAndStartServer = async ( export const createAndStartServer = async (
app: Application, app: Application,
@ -102,13 +102,14 @@ export const createAndStartServer = async (
path: gqlPath path: gqlPath
}); });
if (serverConfig.enableEthRPCServer) { const rpcPath = serverConfig.ethRPC?.path ?? DEFAULT_ETH_RPC_PATH;
if (serverConfig.ethRPC?.enabled) {
// Create a JSON-RPC server to handle ETH RPC calls // Create a JSON-RPC server to handle ETH RPC calls
const rpcServer = jayson.Server(ethRPCHandlers); const rpcServer = jayson.Server(ethRPCHandlers);
// Mount the JSON-RPC server to ETH_RPC_PATH // Mount the JSON-RPC server to ETH_RPC_PATH
app.use( app.use(
ETH_RPC_PATH, rpcPath,
jsonParser(), jsonParser(),
(req: any, res: any, next: () => void) => { (req: any, res: any, next: () => void) => {
// Convert all GET requests to POST to avoid getting rejected from jayson server middleware // Convert all GET requests to POST to avoid getting rejected from jayson server middleware
@ -124,8 +125,8 @@ export const createAndStartServer = async (
httpServer.listen(port, host, () => { httpServer.listen(port, host, () => {
log(`GQL server is listening on http://${host}:${port}${server.graphqlPath}`); log(`GQL server is listening on http://${host}:${port}${server.graphqlPath}`);
if (serverConfig.enableEthRPCServer) { if (serverConfig.ethRPC?.enabled) {
log(`ETH JSON RPC server is listening on http://${host}:${port}${ETH_RPC_PATH}`); log(`ETH JSON RPC server is listening on http://${host}:${port}${rpcPath}`);
} }
}); });