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

feat: makes ip address of request available in application layer #2939

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4c0869e
Makes ip address of request available in application layer
konstantinabl Aug 30, 2024
4fb59a3
Fixes failing unit tests
konstantinabl Sep 4, 2024
f2697b6
Fixes conflicts
konstantinabl Sep 4, 2024
732f4f2
Adds requestDetails to estimate gas
konstantinabl Sep 4, 2024
a109e0f
Adds request details param to estimate gas unit tests
konstantinabl Sep 4, 2024
46e0fb4
Adds request detail to eth_call unit tests
konstantinabl Sep 4, 2024
445f3c8
passes requestDetail wherever needed
konstantinabl Sep 5, 2024
3dec6a5
Makes requestIdPrefix required
konstantinabl Sep 9, 2024
21a6d8d
Fixes tests
konstantinabl Sep 9, 2024
a2b2a2d
Fixes unit tests
konstantinabl Sep 9, 2024
8b51e5a
Fixes ws batch1 tests
konstantinabl Sep 10, 2024
0aa4c4f
Makes RequestDetails object available to all methods in the server
konstantinabl Sep 10, 2024
029aea2
Fixes unit tests after passing requestDetails to all methods in server
konstantinabl Sep 10, 2024
ec4f39b
adds request details to ws server
konstantinabl Sep 11, 2024
d7da18b
Adds request details to filter service
konstantinabl Sep 11, 2024
dd3d178
Makes requestId required in all methods of cacheService
konstantinabl Sep 11, 2024
31aa020
Fixes polling tests
konstantinabl Sep 12, 2024
09cbcbd
Removes unecessary 4th parameter in test for getStorageAt
konstantinabl Sep 12, 2024
3484449
Improves parameters handling in ws server
konstantinabl Sep 12, 2024
244ba06
Adds requestId to localLRUCache test
konstantinabl Sep 12, 2024
aa46c0d
Fixes redisCache test
konstantinabl Sep 12, 2024
eb218e2
Adds requestDetails to poller with generated request id
konstantinabl Sep 12, 2024
c748597
chore: draft changes
victor-yanev Sep 12, 2024
68c93b1
chore: draft changes
victor-yanev Sep 12, 2024
9c842b1
chore: fix localLRUCache.spec.ts
victor-yanev Sep 16, 2024
975df90
chore: fix debug.spec.ts
victor-yanev Sep 16, 2024
24e97dd
chore: fix cacheService.spec.ts
victor-yanev Sep 16, 2024
531f94c
chore: fix hbarLimiter.spec.ts
victor-yanev Sep 16, 2024
ee2dc12
chore: fix build
victor-yanev Sep 16, 2024
0c1a2bc
chore: fix ethAddressHbarSpendingPlanRepository.spec.ts and hbarSpend…
victor-yanev Sep 16, 2024
b75e1f7
Fixes acceptance tests using request details
konstantinabl Sep 16, 2024
ac74abd
Fixes ws-server acceptance tests
konstantinabl Sep 17, 2024
c8f042d
Adds better typing in accpetance tests as well as fixing them
konstantinabl Sep 17, 2024
d2f99c7
temporary fix
konstantinabl Sep 17, 2024
e48d7ec
fix: build error
victor-yanev Sep 18, 2024
ef6e2c0
fix: ws errors
victor-yanev Sep 18, 2024
6ee4195
fix: metricService.spec.ts
victor-yanev Sep 18, 2024
34be5ae
fix: mirrorNodeClient
victor-yanev Sep 18, 2024
88f85ce
fix: validators.ts
victor-yanev Sep 18, 2024
90ad401
fix: hapiService.spec.ts
victor-yanev Sep 18, 2024
42ed1a8
fix: precheck.spec.ts and hbarSpendingPlanRepository.spec.ts
victor-yanev Sep 18, 2024
e787c32
fixes hbar calculation in rpc batch1 test
konstantinabl Sep 19, 2024
2ebff41
Fixes precompile test
konstantinabl Sep 19, 2024
66aeeb6
Fixes unit tests after adding requestDetails as required
konstantinabl Sep 19, 2024
5b795b7
Fixes failing tests in filter accetance test
konstantinabl Sep 19, 2024
633e385
Fixes build after main merge
konstantinabl Sep 20, 2024
b8b0682
merge main and fix tests
konstantinabl Sep 20, 2024
c7e1ea1
Addresses PR comments
konstantinabl Sep 20, 2024
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
24 changes: 12 additions & 12 deletions docs/design/distributed-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Important details is that, if an operator does not want to use Redis or it went

```javascript
interface ICacheClient {
get(key: string, callingMethod: string, requestIdPrefix?: string): any;
set(key: string, value: any, callingMethod: string, ttl?: number, requestIdPrefix?: string): void;
delete(key: string, callingMethod: string, requestIdPrefix?: string): void;
get(key: string, callingMethod: string): any;
set(key: string, value: any, callingMethod: string, ttl?: number): void;
delete(key: string, callingMethod: string): void;
clear(): void;
}
```
Expand All @@ -40,15 +40,15 @@ class LocalLRUCache implements ICacheClient{
public constructor() {
this.cache = new LRU(this.options);
}
get(key: string, callingMethod: string, requestIdPrefix?: string) {
get(key: string, callingMethod: string) {
// Get item from internal cache implementation
}

set(key: string, value: any, callingMethod: string, ttl?: number, requestIdPrefix?: string) {
set(key: string, value: any, callingMethod: string, ttl?: number) {
// Set item to internal cache implementation
}

delete(key: string, callingMethod: string, requestIdPrefix?: string) {
delete(key: string, callingMethod: string) {
// Delete item from internal cache implementation
}

Expand Down Expand Up @@ -81,15 +81,15 @@ class RedisCache implements ICacheClient{

this.cache = client;
}
get(key: string, callingMethod: string, requestIdPrefix?: string) {
get(key: string, callingMethod: string) {
// Get item from shared cache implementation
}

set(key: string, value: any, callingMethod: string, ttl?: number, requestIdPrefix?: string) {
set(key: string, value: any, callingMethod: string, ttl?: number) {
// Set item to shared cache implementation
}

delete(key: string, callingMethod: string, requestIdPrefix?: string) {
delete(key: string, callingMethod: string) {
// Delete item from shared cache implementation
}

Expand Down Expand Up @@ -120,19 +120,19 @@ class CacheClientService{
const sharedCache = new RedisCache();
}

get(key: string, callingMethod: string, requestIdPrefix?: string, shared: boolean = false) {
get(key: string, callingMethod: string, shared: boolean = false) {
// Depending on the shared boolean, this method decide from where it should request the data.
// Fallbacks to internalCache in case of error from the shared cache.
// Getting from shared cache depends on REDIS_ENABLED env. variable
}

set(key: string, value: any, callingMethod: string, ttl?: number, requestIdPrefix?: string, shared: boolean = false) {
set(key: string, value: any, callingMethod: string, ttl?: number, shared: boolean = false) {
// Depending on the shared boolean, this method decide where it should save the data.
// Fallbacks to internalCache in case of error from the shared cache.
// Setting to shared cache depends on REDIS_ENABLED env. variable
}

delete(key: string, callingMethod: string, requestIdPrefix?: string, shared: boolean = false) {
delete(key: string, callingMethod: string, shared: boolean = false) {
// Depending on the shared boolean, this method decide from where it should delete the data.
// Fallbacks to internalCache in case of error from the shared cache.
// Deleting from shared cache depends on REDIS_ENABLED env. variable
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"@types/chai-as-promised": "^7.1.5",
"@types/co-body": "6.1.0",
"@types/koa-cors": "^0.0.6",
"@types/lodash": "^4.17.7",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"axios-mock-adapter": "^1.20.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/relay/src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
import crypto from 'crypto';
import constants from './lib/constants';
import { BigNumber as BN } from 'bignumber.js';
import { TransactionRecord } from '@hashgraph/sdk';
import { BigNumber } from '@hashgraph/sdk/lib/Transfer';
import { MirrorNodeTransactionRecord } from './lib/types/mirrorNode';
import { Transaction, Transaction1559, Transaction2930 } from './lib/model';

const EMPTY_HEX = '0x';
Expand Down
101 changes: 59 additions & 42 deletions packages/relay/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

import { Block, Log, Receipt, Transaction } from './lib/model';
import { IContractCallRequest } from './lib/types';
import { IContractCallRequest, RequestDetails } from './lib/types';
import { JsonRpcError, predefined } from './lib/errors/JsonRpcError';
import WebSocketError from './lib/errors/WebSocketError';
import { MirrorNodeClientError } from './lib/errors/MirrorNodeClientError';
Expand Down Expand Up @@ -62,95 +62,112 @@ export interface Net {
}

export interface Eth {
blockNumber(requestId?: string): Promise<string>;
blockNumber(requestDetails: RequestDetails): Promise<string>;

call(call: any, blockParam: string | object | null, requestId?: string): Promise<string | JsonRpcError>;
call(call: any, blockParam: string | object | null, requestDetails: RequestDetails): Promise<string | JsonRpcError>;

coinbase(requestId?: string): JsonRpcError;
coinbase(requestDetails: RequestDetails): JsonRpcError;

estimateGas(
transaction: IContractCallRequest,
blockParam: string | null,
requestId?: string,
requestDetails: RequestDetails,
): Promise<string | JsonRpcError>;

gasPrice(requestId?: string): Promise<string>;
gasPrice(requestDetails: RequestDetails): Promise<string>;

getBalance(account: string, blockNumber: string | null, requestId?: string): Promise<string>;
getBalance(account: string, blockNumber: string | null, requestDetails: RequestDetails): Promise<string>;

getBlockByHash(hash: string, showDetails: boolean, requestId?: string): Promise<Block | null>;
getBlockByHash(hash: string, showDetails: boolean, requestDetails: RequestDetails): Promise<Block | null>;

getBlockByNumber(blockNum: string, showDetails: boolean, requestId?: string): Promise<Block | null>;
getBlockByNumber(blockNum: string, showDetails: boolean, requestDetails: RequestDetails): Promise<Block | null>;

getBlockTransactionCountByHash(hash: string, requestId?: string): Promise<string | null>;
getBlockTransactionCountByHash(hash: string, requestDetails: RequestDetails): Promise<string | null>;

getBlockTransactionCountByNumber(blockNum: string, requestId?: string): Promise<string | null>;
getBlockTransactionCountByNumber(blockNum: string, requestDetails: RequestDetails): Promise<string | null>;

getCode(address: string, blockNumber: string | null, requestId?: string): Promise<string>;
getCode(address: string, blockNumber: string | null, requestDetails: RequestDetails): Promise<string>;

chainId(requestId?: string): string;
chainId(requestDetails: RequestDetails): string;

getLogs(
blockHash: string | null,
fromBlock: string | null,
toBlock: string | null,
address: string | string[] | null,
topics: any[] | null,
requestId?: string,
requestDetails: RequestDetails,
): Promise<Log[]>;

getStorageAt(address: string, slot: string, blockNumber: string | null, requestId?: string): Promise<string>;

getTransactionByBlockHashAndIndex(hash: string, index: string, requestId?: string): Promise<Transaction | null>;

getTransactionByBlockNumberAndIndex(blockNum: string, index: string, requestId?: string): Promise<Transaction | null>;

getTransactionByHash(hash: string, requestId?: string): Promise<Transaction | null>;

getTransactionCount(address: string, blockNum: string, requestId?: string): Promise<string | JsonRpcError>;
getStorageAt(
address: string,
slot: string,
requestDetails: RequestDetails,
blockNumber: string | null,
): Promise<string>;

getTransactionByBlockHashAndIndex(
hash: string,
index: string,
requestDetails: RequestDetails,
): Promise<Transaction | null>;

getTransactionByBlockNumberAndIndex(
blockNum: string,
index: string,
requestDetails: RequestDetails,
): Promise<Transaction | null>;

getTransactionByHash(hash: string, requestDetails: RequestDetails): Promise<Transaction | null>;

getTransactionCount(
address: string,
blockNum: string,
requestDetails: RequestDetails,
): Promise<string | JsonRpcError>;

getTransactionReceipt(hash: string, requestId?: string): Promise<Receipt | null>;
getTransactionReceipt(hash: string, requestDetails: RequestDetails): Promise<Receipt | null>;

getUncleByBlockHashAndIndex(requestId?: string): Promise<any>;
getUncleByBlockHashAndIndex(requestDetails: RequestDetails): Promise<any>;

getUncleByBlockNumberAndIndex(requestId?: string): Promise<any>;
getUncleByBlockNumberAndIndex(requestDetails: RequestDetails): Promise<any>;

getUncleCountByBlockHash(requestId?: string): Promise<string>;
getUncleCountByBlockHash(requestDetails: RequestDetails): Promise<string>;

getUncleCountByBlockNumber(requestId?: string): Promise<string>;
getUncleCountByBlockNumber(requestDetails: RequestDetails): Promise<string>;

getWork(requestId?: string): JsonRpcError;
getWork(requestDetails: RequestDetails): JsonRpcError;

feeHistory(
blockCount: number,
newestBlock: string,
rewardPercentiles: Array<number> | null,
requestId?: string,
requestDetails: RequestDetails,
): Promise<any>;

hashrate(requestId?: string): Promise<string>;
hashrate(requestDetails: RequestDetails): Promise<string>;

maxPriorityFeePerGas(requestId?: string): Promise<string>;
maxPriorityFeePerGas(requestDetails: RequestDetails): Promise<string>;

mining(requestId?: string): Promise<boolean>;
mining(requestDetails: RequestDetails): Promise<boolean>;

protocolVersion(requestId?: string): JsonRpcError;
protocolVersion(requestDetails: RequestDetails): JsonRpcError;

sendRawTransaction(transaction: string, requestId: string): Promise<string | JsonRpcError>;
sendRawTransaction(transaction: string, requestDetails: RequestDetails): Promise<string | JsonRpcError>;

sendTransaction(requestId?: string): JsonRpcError;
sendTransaction(requestDetails: RequestDetails): JsonRpcError;

sign(requestId?: string): JsonRpcError;
sign(requestDetails: RequestDetails): JsonRpcError;

signTransaction(requestId?: string): JsonRpcError;
signTransaction(requestDetails: RequestDetails): JsonRpcError;

submitHashrate(requestId?: string): JsonRpcError;
submitHashrate(requestDetails: RequestDetails): JsonRpcError;

submitWork(requestId?: string): Promise<boolean>;
submitWork(requestDetails: RequestDetails): Promise<boolean>;

syncing(requestId?: string): Promise<boolean>;
syncing(requestDetails: RequestDetails): Promise<boolean>;

accounts(requestId?: string): Array<any>;
accounts(requestDetails: RequestDetails): Array<any>;

filterService(): IFilterService;

Expand Down
14 changes: 8 additions & 6 deletions packages/relay/src/lib/clients/cache/ICacheClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@
*
*/

import { RequestDetails } from '../../types';

export interface ICacheClient {
keys(pattern: string, callingMethod: string, requestIdPrefix?: string): Promise<string[]>;
get(key: string, callingMethod: string, requestIdPrefix?: string): Promise<any>;
set(key: string, value: any, callingMethod: string, ttl?: number, requestIdPrefix?: string): Promise<void>;
multiSet(keyValuePairs: Record<string, any>, callingMethod: string, requestIdPrefix?: string): Promise<void>;
keys(pattern: string, callingMethod: string, requestDetails: RequestDetails): Promise<string[]>;
get(key: string, callingMethod: string, requestDetails: RequestDetails): Promise<any>;
set(key: string, value: any, callingMethod: string, requestDetails: RequestDetails, ttl?: number): Promise<void>;
multiSet(keyValuePairs: Record<string, any>, callingMethod: string, requestDetails: RequestDetails): Promise<void>;
pipelineSet(
keyValuePairs: Record<string, any>,
callingMethod: string,
requestDetails: RequestDetails,
ttl?: number | undefined,
requestIdPrefix?: string,
): Promise<void>;
delete(key: string, callingMethod: string, requestIdPrefix?: string): Promise<void>;
delete(key: string, callingMethod: string, requestDetails: RequestDetails): Promise<void>;
clear(): Promise<void>;
}
13 changes: 10 additions & 3 deletions packages/relay/src/lib/clients/cache/IRedisCacheClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@
*/

import type { ICacheClient } from './ICacheClient';
import { RequestDetails } from '../../types';

export interface IRedisCacheClient extends ICacheClient {
disconnect: () => Promise<void>;
incrBy(key: string, amount: number, callingMethod: string, requestIdPrefix?: string): Promise<number>;
rPush(key: string, value: any, callingMethod: string, requestIdPrefix?: string): Promise<number>;
lRange(key: string, start: number, end: number, callingMethod: string, requestIdPrefix?: string): Promise<any[]>;
incrBy(key: string, amount: number, callingMethod: string, requestDetails: RequestDetails): Promise<number>;
rPush(key: string, value: any, callingMethod: string, requestDetails: RequestDetails): Promise<number>;
lRange(
key: string,
start: number,
end: number,
callingMethod: string,
requestDetails: RequestDetails,
): Promise<any[]>;
}
Loading
Loading