Skip to content

Commit

Permalink
feat: Add OPERATOR tier (#3316)
Browse files Browse the repository at this point in the history
* feat: Add `OPERATOR` tier

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* fix: build error

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* fix: remove duplicated fetch of remaining budget

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* chore: improve readability

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* fix: make sure that operator address is always up-to-date with the client

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* chore: formatting

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* chore: formatting

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* chore: fix tests

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* fix: do not ignore error when EVM address is not provided to `addExpense`

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* chore: revert unnecessary change

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* chore: revert unnecessary change

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* chore: reduce code duplication in metricService.spec.ts

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* chore: reduce code duplication in metricService.spec.ts

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* fix: error in charts:install workflow

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* fix: hbarLimiter.spec.ts

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* fix: remove unnecessary rest in hbarLimiter.spec.ts

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* chore: prepend 0x to operator address

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

* test: extend assertions in hbarLimitService.spec.ts

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

---------

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
  • Loading branch information
victor-yanev authored Dec 17, 2024
1 parent d73c0ab commit 13d09e9
Show file tree
Hide file tree
Showing 14 changed files with 595 additions and 514 deletions.
1 change: 0 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ Unless you need to set a non-default value, it is recommended to only populate o
| `REDIS_RECONNECT_DELAY_MS` | "1000" | Sets the delay between reconnect retries from the Redis client in ms |
| `SEND_RAW_TRANSACTION_SIZE_LIMIT` | "131072" | Sets the limit of the transaction size the relay accepts on eth_sendRawTransaction |
| `GET_RECORD_DEFAULT_TO_CONSENSUS_NODE` | "false" | Flag to set if get transaction record logic should first query the mirror node (false) or consensus node via the SDK (true). |
| `HBAR_RATE_LIMIT_WHITELIST` | [""] | An array of EVM addresses that are allowed to bypass the HBAR rate limits |

## WS-Server

Expand Down
22 changes: 5 additions & 17 deletions packages/config-service/src/services/globalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,43 +283,31 @@ export class GlobalConfig {
envName: 'HBAR_RATE_LIMIT_BASIC',
type: 'number',
required: false,
defaultValue: null,
defaultValue: 1_120_000_000, // 11.2 hbar
},
HBAR_RATE_LIMIT_EXTENDED: {
envName: 'HBAR_RATE_LIMIT_EXTENDED',
type: 'number',
required: false,
defaultValue: null,
defaultValue: 3_200_000_000, // 32 hbar
},
HBAR_RATE_LIMIT_PRIVILEGED: {
envName: 'HBAR_RATE_LIMIT_PRIVILEGED',
type: 'number',
required: false,
defaultValue: null,
defaultValue: 8_000_000_000, // 80 hbar
},
HBAR_RATE_LIMIT_DURATION: {
envName: 'HBAR_RATE_LIMIT_DURATION',
type: 'number',
required: false,
defaultValue: null,
},
HBAR_RATE_LIMIT_PREEMPTIVE_CHECK: {
envName: 'HBAR_RATE_LIMIT_PREEMPTIVE_CHECK',
type: 'boolean',
required: false,
defaultValue: null,
defaultValue: 86_400_000, // 24 hours
},
HBAR_RATE_LIMIT_TINYBAR: {
envName: 'HBAR_RATE_LIMIT_TINYBAR',
type: 'number',
required: false,
defaultValue: null,
},
HBAR_RATE_LIMIT_WHITELIST: {
envName: 'HBAR_RATE_LIMIT_WHITELIST',
type: 'array',
required: false,
defaultValue: null,
defaultValue: 800_000_000_000, // 8000 hbar
},
HEDERA_NETWORK: {
envName: 'HEDERA_NETWORK',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ export enum SubscriptionTier {
* Trusted Partners
*/
PRIVILEGED = 'PRIVILEGED',

/**
* Relay Operators
*/
OPERATOR = 'OPERATOR',
}
6 changes: 4 additions & 2 deletions packages/relay/src/lib/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
import { Client, Hbar } from '@hashgraph/sdk';
import { Client } from '@hashgraph/sdk';
import EventEmitter from 'events';
import { Logger } from 'pino';
import { Gauge, Registry } from 'prom-client';
Expand Down Expand Up @@ -160,13 +160,15 @@ export class RelayImpl implements Relay {
ipAddressHbarSpendingPlanRepository,
logger.child({ name: 'hbar-rate-limit' }),
register,
Hbar.fromTinybars(total),
duration,
);

const hapiService = new HAPIService(logger, register, this.cacheService, this.eventEmitter, hbarLimitService);

this.clientMain = hapiService.getMainClientInstance();
if (this.clientMain.operatorAccountId) {
hbarLimitService.setOperatorAddress(this.clientMain.operatorAccountId.toSolidityAddress());
}

this.web3Impl = new Web3Impl(this.clientMain);
this.netImpl = new NetImpl(this.clientMain);
Expand Down
20 changes: 12 additions & 8 deletions packages/relay/src/lib/services/hapiService/hapiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
*
*/

import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
import { AccountId, Client, PrivateKey } from '@hashgraph/sdk';
import dotenv from 'dotenv';
import { Logger } from 'pino';
import EventEmitter from 'events';
import findConfig from 'find-config';
import constants from '../../constants';
import { Utils } from './../../../utils';
import fs from 'fs';
import { Logger } from 'pino';
import { Counter, Registry } from 'prom-client';
import { SDKClient } from '../../clients/sdkClient';
import { HbarLimitService } from '../hbarLimitService';

import { Utils } from '../../../utils';
import { SDKClient } from '../../clients';
import constants from '../../constants';
import { CacheService } from '../cacheService/cacheService';
import { AccountId, Client, PrivateKey } from '@hashgraph/sdk';
import fs from 'fs';
import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
import { HbarLimitService } from '../hbarLimitService';

export default class HAPIService {
/**
Expand Down Expand Up @@ -289,6 +290,9 @@ export default class HAPIService {
this.clientMain = this.initClient(this.logger, this.hederaNetwork);
this.client = this.initSDKClient(this.logger);
this.resetCounters();
if (this.clientMain.operatorAccountId) {
this.hbarLimitService.setOperatorAddress(this.clientMain.operatorAccountId.toSolidityAddress());
}
}

/**
Expand Down
Loading

0 comments on commit 13d09e9

Please sign in to comment.