Skip to content

Commit

Permalink
fix: removed socketId from logs
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Nguyen <[email protected]>
  • Loading branch information
quiet-node committed Apr 5, 2024
1 parent 553488c commit bcbf4c6
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 72 deletions.
18 changes: 2 additions & 16 deletions packages/ws-server/src/controllers/eth_getTransactionByHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { handleSendingTransactionRequests } from './helpers';
* @param {Relay} relay - The relay object for interacting with the Hedera network.
* @param {any} request - The request object received from the client.
* @param {string} method - The JSON-RPC method associated with the request.
* @param {string} socketIdPrefix - The prefix for the socket ID.
* @param {string} requestIdPrefix - The prefix for the request ID.
* @param {string} connectionIdPrefix - The prefix for the connection ID.
* @returns {Promise<any>} Returns a promise that resolves with the JSON-RPC response to the client.
Expand All @@ -45,28 +44,16 @@ export const handleEthGetTransactionByHash = async (
relay: Relay,
request: any,
method: string,
socketIdPrefix: string,
requestIdPrefix: string,
connectionIdPrefix: string,
): Promise<any> => {
const TX_HASH = params[0];
const TAG = JSON.stringify({ method, signedTx: TX_HASH });

validateParamsLength(
ctx,
params,
method,
TAG,
logger,
sendToClient,
1,
socketIdPrefix,
requestIdPrefix,
connectionIdPrefix,
);
validateParamsLength(ctx, params, method, TAG, logger, sendToClient, 1, requestIdPrefix, connectionIdPrefix);

logger.info(
`${connectionIdPrefix} ${requestIdPrefix} ${socketIdPrefix}: Retrieving transaction info with txHash=${TX_HASH} for tag=${TAG}`,
`${connectionIdPrefix} ${requestIdPrefix}: Retrieving transaction info with txHash=${TX_HASH} for tag=${TAG}`,
);

return handleSendingTransactionRequests(
Expand All @@ -78,7 +65,6 @@ export const handleEthGetTransactionByHash = async (
request,
method,
'getTransactionByHash',
socketIdPrefix,
requestIdPrefix,
connectionIdPrefix,
);
Expand Down
18 changes: 2 additions & 16 deletions packages/ws-server/src/controllers/eth_getTransactionReceipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { handleSendingTransactionRequests } from './helpers';
* @param {Relay} relay - The relay object for interacting with the Hedera network.
* @param {any} request - The request object received from the client.
* @param {string} method - The JSON-RPC method associated with the request.
* @param {string} socketIdPrefix - The prefix for the socket ID.
* @param {string} requestIdPrefix - The prefix for the request ID.
* @param {string} connectionIdPrefix - The prefix for the connection ID.
* @returns {Promise<any>} Returns a promise that resolves with the JSON-RPC response to the client.
Expand All @@ -45,28 +44,16 @@ export const handleEthGetTransactionReceipt = async (
relay: Relay,
request: any,
method: string,
socketIdPrefix: string,
requestIdPrefix: string,
connectionIdPrefix: string,
): Promise<any> => {
const TX_HASH = params[0];
const TAG = JSON.stringify({ method, signedTx: TX_HASH });

validateParamsLength(
ctx,
params,
method,
TAG,
logger,
sendToClient,
1,
socketIdPrefix,
requestIdPrefix,
connectionIdPrefix,
);
validateParamsLength(ctx, params, method, TAG, logger, sendToClient, 1, requestIdPrefix, connectionIdPrefix);

logger.info(
`${connectionIdPrefix} ${requestIdPrefix} ${socketIdPrefix}: Retrieving transaction receipt with txHash=${TX_HASH} for tag=${TAG}`,
`${connectionIdPrefix} ${requestIdPrefix}: Retrieving transaction receipt with txHash=${TX_HASH} for tag=${TAG}`,
);

return handleSendingTransactionRequests(
Expand All @@ -78,7 +65,6 @@ export const handleEthGetTransactionReceipt = async (
request,
method,
'getTransactionReceipt',
socketIdPrefix,
requestIdPrefix,
connectionIdPrefix,
);
Expand Down
18 changes: 2 additions & 16 deletions packages/ws-server/src/controllers/eth_sendRawTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { handleSendingTransactionRequests } from './helpers';
* @param {Relay} relay - The relay object for interacting with the Hedera network.
* @param {any} request - The request object received from the client.
* @param {string} method - The name of the method.
* @param {string} socketIdPrefix - The prefix for the socket ID.
* @param {string} requestIdPrefix - The prefix for the request ID.
* @param {string} connectionIdPrefix - The prefix for the connection ID.
* @returns {Promise<any>} Returns a promise that resolves with the JSON-RPC response to the client.
Expand All @@ -45,27 +44,15 @@ export const handleEthSendRawTransaction = async (
relay: Relay,
request: any,
method: string,
socketIdPrefix: string,
requestIdPrefix: string,
connectionIdPrefix: string,
) => {
const SIGNED_TX = params[0];
const TAG = JSON.stringify({ method, signedTx: SIGNED_TX });

validateParamsLength(
ctx,
params,
method,
TAG,
logger,
sendToClient,
1,
socketIdPrefix,
requestIdPrefix,
connectionIdPrefix,
);
validateParamsLength(ctx, params, method, TAG, logger, sendToClient, 1, requestIdPrefix, connectionIdPrefix);
logger.info(
`${connectionIdPrefix} ${requestIdPrefix} ${socketIdPrefix}: Submitting raw transaction with signedTx=${SIGNED_TX} for tag=${TAG}`,
`${connectionIdPrefix} ${requestIdPrefix}: Submitting raw transaction with signedTx=${SIGNED_TX} for tag=${TAG}`,
);

return handleSendingTransactionRequests(
Expand All @@ -77,7 +64,6 @@ export const handleEthSendRawTransaction = async (
request,
method,
'sendRawTransaction',
socketIdPrefix,
requestIdPrefix,
connectionIdPrefix,
);
Expand Down
9 changes: 2 additions & 7 deletions packages/ws-server/src/controllers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import jsonResp from '@hashgraph/json-rpc-server/dist/koaJsonRpc/lib/RpcResponse
* @param {any} request - The request object received from the client.
* @param {string} method - The JSON-RPC method associated with the request.
* @param {string} rpcCallEndpoint - The Hedera RPC call endpoint to execute.
* @param {string} socketIdPrefix - The prefix for the socket ID.
* @param {string} requestIdPrefix - The prefix for the request ID.
* @param {string} connectionIdPrefix - The prefix for the connection ID.
* @returns {Promise<any>} Returns a promise that resolves with the JSON-RPC response to the client.
Expand All @@ -48,19 +47,16 @@ export const handleSendingTransactionRequests = async (
request: any,
method: string,
rpcCallEndpoint: string,
socketIdPrefix: string,
requestIdPrefix: string,
connectionIdPrefix: string,
): Promise<any> => {
try {
const txRes = await relay.eth()[rpcCallEndpoint](...args);

if (txRes) {
sendToClient(ctx.websocket, method, txRes, tag, logger, socketIdPrefix, requestIdPrefix, connectionIdPrefix);
sendToClient(ctx.websocket, method, txRes, tag, logger, requestIdPrefix, connectionIdPrefix);
} else {
logger.error(
`${connectionIdPrefix} ${requestIdPrefix} ${socketIdPrefix}: Fail to retrieve result for tag=${tag}`,
);
logger.error(`${connectionIdPrefix} ${requestIdPrefix}: Fail to retrieve result for tag=${tag}`);
}

return jsonResp(request.id, null, txRes);
Expand All @@ -71,7 +67,6 @@ export const handleSendingTransactionRequests = async (
JSON.stringify(error.message || error),
tag,
logger,
socketIdPrefix,
requestIdPrefix,
connectionIdPrefix,
);
Expand Down
4 changes: 1 addition & 3 deletions packages/ws-server/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export const getMultipleAddressesEnabled = (): boolean => {
* @param {any} data - The data to be included in the response.
* @param {string} tag - A tag used for logging and identifying the message.
* @param {any} logger - The logger object for logging messages and events.
* @param {string} socketIdPrefix - The prefix for the socket ID.
* @param {string} requestIdPrefix - The prefix for the request ID.
* @param {string} connectionIdPrefix - The prefix for the connection ID.
*/
Expand All @@ -60,12 +59,11 @@ export const sendToClient = (
data: any,
tag: string,
logger: any,
socketIdPrefix: string,
requestIdPrefix: string,
connectionIdPrefix: string,
) => {
logger.info(
`${connectionIdPrefix} ${requestIdPrefix} ${socketIdPrefix}: Sending data from tag: ${tag} to connectionId: ${connection.id}, data: ${data}`,
`${connectionIdPrefix} ${requestIdPrefix}: Sending data from tag: ${tag} to connectionId: ${connection.id}, data: ${data}`,
);

connection.send(
Expand Down
6 changes: 2 additions & 4 deletions packages/ws-server/src/utils/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export const validateSubscribeEthLogsParams = async (
* @param {any} logger - The logger object for logging messages and events.
* @param {any} sendToClient - The function for sending responses to the client.
* @param {number} expectedLength - The expected length of parameters for the method request.
* @param {string} socketIdPrefix - The prefix for the socket ID.
* @param {string} requestIdPrefix - The prefix for the request ID.
* @param {string} connectionIdPrefix - The prefix for the connection ID.
* @throws {JsonRpcError} Throws a JsonRpcError if the length of parameters does not match the expected length.
Expand All @@ -105,14 +104,13 @@ export const validateParamsLength = (
logger: any,
sendToClient: any,
expectedLength: number,
socketIdPrefix: string,
requestIdPrefix: string,
connectionIdPrefix: string,
) => {
if (params.length !== expectedLength) {
const ERR_MSG = 'INVALID PARAMETERS';
logger.error(`${connectionIdPrefix} ${requestIdPrefix} ${socketIdPrefix}: Invalid parameters ${params}`);
sendToClient(ctx.websocket, method, ERR_MSG, tag, logger, socketIdPrefix, requestIdPrefix, connectionIdPrefix);
logger.error(`${connectionIdPrefix} ${requestIdPrefix}: Invalid parameters ${params}`);
sendToClient(ctx.websocket, method, ERR_MSG, tag, logger, requestIdPrefix, connectionIdPrefix);
throw predefined.INVALID_PARAMETERS;
}
};
12 changes: 2 additions & 10 deletions packages/ws-server/src/webSocketServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ app.ws.use(async (ctx) => {

// Format ID prefixes for logging purposes
const requestIdPrefix = formatIdMessage('Request ID', uuid());
const socketIdPrefix = formatIdMessage('Socket ID', ctx.websocket.id);

// parse the received message from the client into a JSON object
let request;
Expand All @@ -115,19 +114,15 @@ app.ws.use(async (ctx) => {
} catch (e) {
// Log an error if the message cannot be decoded and send an invalid request error to the client
logger.error(
`${connectionIdPrefix} ${requestIdPrefix} ${ctx.websocket.id}: Could not decode message from connection, message: ${msg}, error: ${e}`,
`${connectionIdPrefix} ${requestIdPrefix}: Could not decode message from connection, message: ${msg}, error: ${e}`,
);
ctx.websocket.send(JSON.stringify(new JsonRpcError(predefined.INVALID_REQUEST, undefined)));
return;
}

// Extract the method and parameters from the received request
const { method, params } = request;
logger.debug(
`${connectionIdPrefix} ${requestIdPrefix} ${socketIdPrefix}: Method: ${method}. Params: ${JSON.stringify(
params,
)}`,
);
logger.debug(`${connectionIdPrefix} ${requestIdPrefix}: Method: ${method}. Params: ${JSON.stringify(params)}`);

// Increment metrics for the received method
methodsCounter.labels(method).inc();
Expand Down Expand Up @@ -170,7 +165,6 @@ app.ws.use(async (ctx) => {
relay,
request,
method,
socketIdPrefix,
requestIdPrefix,
connectionIdPrefix,
);
Expand All @@ -183,7 +177,6 @@ app.ws.use(async (ctx) => {
relay,
request,
method,
socketIdPrefix,
requestIdPrefix,
connectionIdPrefix,
);
Expand All @@ -196,7 +189,6 @@ app.ws.use(async (ctx) => {
relay,
request,
method,
socketIdPrefix,
requestIdPrefix,
connectionIdPrefix,
);
Expand Down

0 comments on commit bcbf4c6

Please sign in to comment.