Skip to content

Commit 13d09e9

Browse files
authored
feat: Add OPERATOR tier (#3316)
* 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>
1 parent d73c0ab commit 13d09e9

File tree

14 files changed

+595
-514
lines changed

14 files changed

+595
-514
lines changed

docs/configuration.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ Unless you need to set a non-default value, it is recommended to only populate o
111111
| `REDIS_RECONNECT_DELAY_MS` | "1000" | Sets the delay between reconnect retries from the Redis client in ms |
112112
| `SEND_RAW_TRANSACTION_SIZE_LIMIT` | "131072" | Sets the limit of the transaction size the relay accepts on eth_sendRawTransaction |
113113
| `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). |
114-
| `HBAR_RATE_LIMIT_WHITELIST` | [""] | An array of EVM addresses that are allowed to bypass the HBAR rate limits |
115114

116115
## WS-Server
117116

packages/config-service/src/services/globalConfig.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -283,43 +283,31 @@ export class GlobalConfig {
283283
envName: 'HBAR_RATE_LIMIT_BASIC',
284284
type: 'number',
285285
required: false,
286-
defaultValue: null,
286+
defaultValue: 1_120_000_000, // 11.2 hbar
287287
},
288288
HBAR_RATE_LIMIT_EXTENDED: {
289289
envName: 'HBAR_RATE_LIMIT_EXTENDED',
290290
type: 'number',
291291
required: false,
292-
defaultValue: null,
292+
defaultValue: 3_200_000_000, // 32 hbar
293293
},
294294
HBAR_RATE_LIMIT_PRIVILEGED: {
295295
envName: 'HBAR_RATE_LIMIT_PRIVILEGED',
296296
type: 'number',
297297
required: false,
298-
defaultValue: null,
298+
defaultValue: 8_000_000_000, // 80 hbar
299299
},
300300
HBAR_RATE_LIMIT_DURATION: {
301301
envName: 'HBAR_RATE_LIMIT_DURATION',
302302
type: 'number',
303303
required: false,
304-
defaultValue: null,
305-
},
306-
HBAR_RATE_LIMIT_PREEMPTIVE_CHECK: {
307-
envName: 'HBAR_RATE_LIMIT_PREEMPTIVE_CHECK',
308-
type: 'boolean',
309-
required: false,
310-
defaultValue: null,
304+
defaultValue: 86_400_000, // 24 hours
311305
},
312306
HBAR_RATE_LIMIT_TINYBAR: {
313307
envName: 'HBAR_RATE_LIMIT_TINYBAR',
314308
type: 'number',
315309
required: false,
316-
defaultValue: null,
317-
},
318-
HBAR_RATE_LIMIT_WHITELIST: {
319-
envName: 'HBAR_RATE_LIMIT_WHITELIST',
320-
type: 'array',
321-
required: false,
322-
defaultValue: null,
310+
defaultValue: 800_000_000_000, // 8000 hbar
323311
},
324312
HEDERA_NETWORK: {
325313
envName: 'HEDERA_NETWORK',

packages/relay/src/lib/db/types/hbarLimiter/subscriptionTier.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ export enum SubscriptionTier {
3333
* Trusted Partners
3434
*/
3535
PRIVILEGED = 'PRIVILEGED',
36+
37+
/**
38+
* Relay Operators
39+
*/
40+
OPERATOR = 'OPERATOR',
3641
}

packages/relay/src/lib/relay.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020

2121
import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
22-
import { Client, Hbar } from '@hashgraph/sdk';
22+
import { Client } from '@hashgraph/sdk';
2323
import EventEmitter from 'events';
2424
import { Logger } from 'pino';
2525
import { Gauge, Registry } from 'prom-client';
@@ -160,13 +160,15 @@ export class RelayImpl implements Relay {
160160
ipAddressHbarSpendingPlanRepository,
161161
logger.child({ name: 'hbar-rate-limit' }),
162162
register,
163-
Hbar.fromTinybars(total),
164163
duration,
165164
);
166165

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

169168
this.clientMain = hapiService.getMainClientInstance();
169+
if (this.clientMain.operatorAccountId) {
170+
hbarLimitService.setOperatorAddress(this.clientMain.operatorAccountId.toSolidityAddress());
171+
}
170172

171173
this.web3Impl = new Web3Impl(this.clientMain);
172174
this.netImpl = new NetImpl(this.clientMain);

packages/relay/src/lib/services/hapiService/hapiService.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@
1818
*
1919
*/
2020

21+
import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
22+
import { AccountId, Client, PrivateKey } from '@hashgraph/sdk';
2123
import dotenv from 'dotenv';
22-
import { Logger } from 'pino';
2324
import EventEmitter from 'events';
2425
import findConfig from 'find-config';
25-
import constants from '../../constants';
26-
import { Utils } from './../../../utils';
26+
import fs from 'fs';
27+
import { Logger } from 'pino';
2728
import { Counter, Registry } from 'prom-client';
28-
import { SDKClient } from '../../clients/sdkClient';
29-
import { HbarLimitService } from '../hbarLimitService';
29+
30+
import { Utils } from '../../../utils';
31+
import { SDKClient } from '../../clients';
32+
import constants from '../../constants';
3033
import { CacheService } from '../cacheService/cacheService';
31-
import { AccountId, Client, PrivateKey } from '@hashgraph/sdk';
32-
import fs from 'fs';
33-
import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
34+
import { HbarLimitService } from '../hbarLimitService';
3435

3536
export default class HAPIService {
3637
/**
@@ -289,6 +290,9 @@ export default class HAPIService {
289290
this.clientMain = this.initClient(this.logger, this.hederaNetwork);
290291
this.client = this.initSDKClient(this.logger);
291292
this.resetCounters();
293+
if (this.clientMain.operatorAccountId) {
294+
this.hbarLimitService.setOperatorAddress(this.clientMain.operatorAccountId.toSolidityAddress());
295+
}
292296
}
293297

294298
/**

0 commit comments

Comments
 (0)