Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: masks ip address in request details passed as argument to MN client #3268

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions packages/relay/src/lib/clients/mirrorNodeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
*
*/

import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
import Axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import axiosRetry from 'axios-retry';
import { install as betterLookupInstall } from 'better-lookup';
import { ethers } from 'ethers';
import http from 'http';
import https from 'https';
import { Logger } from 'pino';
import { ethers } from 'ethers';
import axiosRetry from 'axios-retry';
import constants from './../constants';
import { Histogram, Registry } from 'prom-client';

import { formatRequestIdMessage, formatTransactionId, parseNumericEnvVar } from '../../formatters';
import { predefined } from '../errors/JsonRpcError';
import { MirrorNodeClientError } from '../errors/MirrorNodeClientError';
import { SDKClientError } from '../errors/SDKClientError';
import { IOpcodesResponse } from './models/IOpcodesResponse';
import { install as betterLookupInstall } from 'better-lookup';
import { EthImpl } from '../eth';
import { CacheService } from '../services/cacheService/cacheService';
import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
import { MirrorNodeClientError } from '../errors/MirrorNodeClientError';
import Axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import { formatRequestIdMessage, formatTransactionId, parseNumericEnvVar } from '../../formatters';
import {
IContractCallRequest,
IContractCallResponse,
Expand All @@ -45,7 +45,8 @@ import {
MirrorNodeTransactionRecord,
RequestDetails,
} from '../types';
import { EthImpl } from '../eth';
import constants from './../constants';
import { IOpcodesResponse } from './models/IOpcodesResponse';

type REQUEST_METHODS = 'GET' | 'POST';

Expand Down Expand Up @@ -1364,9 +1365,15 @@ export class MirrorNodeClient {
);
}

// Create a modified copy of requestDetails
const modifiedRequestDetails = {
...requestDetails,
ipAddress: 'xxx.xxx.xxx.xxx',
};

const transactionRecords = await this.repeatedRequest(
this.getTransactionById.name,
[transactionId, requestDetails, 0],
[transactionId, modifiedRequestDetails, 0],
this.MIRROR_NODE_REQUEST_RETRY_COUNT,
requestDetails,
);
Expand Down
54 changes: 31 additions & 23 deletions packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,13 @@
*
*/

import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
import { FileId, Hbar, PrecheckStatusError } from '@hashgraph/sdk';
import crypto from 'crypto';
import { Transaction as EthersTransaction } from 'ethers';
import { Logger } from 'pino';
import { Eth } from '../index';
import { Utils } from '../utils';
import constants from './constants';
import { Precheck } from './precheck';
import { MirrorNodeClient } from './clients';
import { Counter, Registry } from 'prom-client';
import { IAccountInfo } from './types/mirrorNode';
import { LogsBloomUtils } from '../logsBloomUtils';
import { DebugService } from './services/debugService';
import { SDKClientError } from './errors/SDKClientError';
import { Transaction as EthersTransaction } from 'ethers';
import HAPIService from './services/hapiService/hapiService';
import { JsonRpcError, predefined } from './errors/JsonRpcError';
import { Block, Log, Transaction, Transaction1559 } from './model';
import { FileId, Hbar, PrecheckStatusError } from '@hashgraph/sdk';
import { CacheService } from './services/cacheService/cacheService';
import { CommonService, FilterService } from './services/ethService';
import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
import { IDebugService } from './services/debugService/IDebugService';
import { MirrorNodeClientError } from './errors/MirrorNodeClientError';
import { IReceiptRootHash, ReceiptsRootUtils } from '../receiptsRootUtils';
import { IFilterService } from './services/ethService/ethFilterService/IFilterService';
import { IContractCallRequest, IContractCallResponse, IFeeHistory, ITransactionReceipt, RequestDetails } from './types';

import {
ASCIIToHex,
formatContractResult,
Expand All @@ -59,6 +41,25 @@ import {
trimPrecedingZeros,
weibarHexToTinyBarInt,
} from '../formatters';
import { Eth } from '../index';
import { LogsBloomUtils } from '../logsBloomUtils';
import { IReceiptRootHash, ReceiptsRootUtils } from '../receiptsRootUtils';
import { Utils } from '../utils';
import { MirrorNodeClient } from './clients';
import constants from './constants';
import { JsonRpcError, predefined } from './errors/JsonRpcError';
import { MirrorNodeClientError } from './errors/MirrorNodeClientError';
import { SDKClientError } from './errors/SDKClientError';
import { Block, Log, Transaction, Transaction1559 } from './model';
import { Precheck } from './precheck';
import { CacheService } from './services/cacheService/cacheService';
import { DebugService } from './services/debugService';
import { IDebugService } from './services/debugService/IDebugService';
import { CommonService, FilterService } from './services/ethService';
import { IFilterService } from './services/ethService/ethFilterService/IFilterService';
import HAPIService from './services/hapiService/hapiService';
import { IContractCallRequest, IContractCallResponse, IFeeHistory, ITransactionReceipt, RequestDetails } from './types';
import { IAccountInfo } from './types/mirrorNode';

const _ = require('lodash');
const createHash = require('keccak');
Expand Down Expand Up @@ -1720,9 +1721,16 @@ export class EthImpl implements Eth {
if (submittedTransactionId) {
try {
const formattedTransactionId = formatTransactionIdWithoutQueryParams(submittedTransactionId);

// Create a modified copy of requestDetails
const modifiedRequestDetails = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but is there a place where we can do this once before it's passed into the eth.ts but after it's utilized locally?

...requestDetails,
ipAddress: 'xxx.xxx.xxx.xxx',
};

const contractResult = await this.mirrorNodeClient.repeatedRequest(
this.mirrorNodeClient.getContractResult.name,
[formattedTransactionId, requestDetails],
[formattedTransactionId, modifiedRequestDetails],
this.mirrorNodeClient.getMirrorNodeRequestRetryCount(),
requestDetails,
);
Expand Down
Loading