Skip to content

Commit 34ec5a2

Browse files
quiet-nodevictor-yanevkonstantinabl
authored
feat: replaced HbarLimit module with the new HbarLimitService class (#3110)
* feat: replaced HbarLimit module with the new HbarLimitService class (#3024) * fix: converted constant HBAR_RATE_LIMIT_DURATION from var into function Signed-off-by: Logan Nguyen <[email protected]> * chore: added jsdoc to private vars in hapiService module Signed-off-by: Logan Nguyen <[email protected]> * feat: initialized an instance of HbarLimitService in relay.ts Signed-off-by: Logan Nguyen <[email protected]> * feat: integrated HbarLimitService instance into HapiService class Signed-off-by: Logan Nguyen <[email protected]> * feat: integrated HbarLimitService instance into SDKClient class Signed-off-by: Logan Nguyen <[email protected]> * feat: integrated HbarLimitService instance into MetricService class Signed-off-by: Logan Nguyen <[email protected]> * fix: modified addExpense to turn ethAddress to be optional Some queries like getAccountInfo, getBalanceInfo, FileContentsQuery, etc. also add expense to remainingBalance but don't necessarily need to have an originalCaller (ethAddress). Therefore, addExpense can accept nullable ethAddress value. Only when ethAddress or ipAddress is valid, utilize spendingPlan logic. Otherwise, skip completely. Signed-off-by: Logan Nguyen <[email protected]> * feat: added getRemainingBudget() getter Signed-off-by: Logan Nguyen <[email protected]> * feat: added originalCallerAddress to IExecuteTransactionEventPayload and IExecuteQueryEventPayload Signed-off-by: Logan Nguyen <[email protected]> * feat: removed metricService instance in relay Signed-off-by: Logan Nguyen <[email protected]> * feat: replaced hbarLimitter with hbarLimitService in MetricService class Signed-off-by: Logan Nguyen <[email protected]> * fix: added estimateFileTransactionsFee to Utils Signed-off-by: Logan Nguyen <[email protected]> * feat: added txConstructorName and updated log messages for shouldLimit Signed-off-by: Logan Nguyen <[email protected]> * fix: rework logic for estimateFileTransactionsFee Signed-off-by: Logan Nguyen <[email protected]> * feat: removed hbarLimiter instance in SDKClient classes Signed-off-by: Logan Nguyen <[email protected]> * feat: deleted HbarLimit module from codease Signed-off-by: Logan Nguyen <[email protected]> * feat: reverted logic reworked on estimateFileTransactionsFee Signed-off-by: Logan Nguyen <[email protected]> * feat: added preemptive rate limit logic to createFile() method Signed-off-by: Logan Nguyen <[email protected]> * test: updated hbarLimiter.spec.ts Signed-off-by: Logan Nguyen <[email protected]> * fix: added names for child loggers for spending plan repo Signed-off-by: Logan Nguyen <[email protected]> * chore: reverted "feat: added getRemainingBudget() getter" This reverts commit fd9e119 and updated related tests Signed-off-by: Logan Nguyen <[email protected]> * fix: updated log message Signed-off-by: Logan Nguyen <[email protected]> * test: added HBAR_DAILY_LIMIT_BASIC to localTestEnv Signed-off-by: Logan Nguyen <[email protected]> * fix: converted function HBAR_RATE_LIMIT_DURATION from function into var Signed-off-by: Logan Nguyen <[email protected]> * fix: reverted "feat: removed metricService instance in relay" This reverts commit e45c321. Signed-off-by: Logan Nguyen <[email protected]> * chore: updated log message Signed-off-by: Logan Nguyen <[email protected]> * fix: fixed failing test in hapiService Signed-off-by: Logan Nguyen <[email protected]> * fix: reverted ethAddress back to be a required param for addExpense Signed-off-by: Logan Nguyen <[email protected]> * fix: fixed failing test in hapiService.spec.ts Signed-off-by: Logan Nguyen <[email protected]> * fix: loaded env into prcess.env for constant module Signed-off-by: Logan Nguyen <[email protected]> * chore: removed duplicating doc for estimateFileTransactionsFee Signed-off-by: Logan Nguyen <[email protected]> * chore: sort imports Signed-off-by: Victor Yanev <[email protected]> * fix: removed ipAddresses from log in hbarLimitService Signed-off-by: Logan Nguyen <[email protected]> * fix: renamed isDailyBudgetExceeded -> isTotalBudgetExceeded Signed-off-by: Logan Nguyen <[email protected]> * fix: fixed conflicts after rebased Signed-off-by: Logan Nguyen <[email protected]> * fix: fixed acceptance test for exhausting HBAR case Signed-off-by: Logan Nguyen <[email protected]> * fix: renamed HBAR_DAILY_LIMIT_BASIC to HBAR_RATE_LIMIT_BASIC Signed-off-by: Logan Nguyen <[email protected]> * fix: overrode env vars for npm acceptancetest:hbarlimiter script Signed-off-by: Logan Nguyen <[email protected]> * fix: moved logic of adding expenses to totalBudget above hbarSpendingPlan Signed-off-by: Logan Nguyen <[email protected]> --------- Signed-off-by: Logan Nguyen <[email protected]> Signed-off-by: Victor Yanev <[email protected]> Co-authored-by: Victor Yanev <[email protected]> Signed-off-by: Logan Nguyen <[email protected]> * test: create e2e tests for basic spending plan limit (#3104) * Adds acceptance test for BASIC user spending plans Signed-off-by: Konstantina Blazhukova <[email protected]> Fixes failing acceptance test Signed-off-by: Konstantina Blazhukova <[email protected]> Revert accidental deletion of method Signed-off-by: Konstantina Blazhukova <[email protected]> * Fixes CI Signed-off-by: Konstantina Blazhukova <[email protected]> * Fixes failiing acceptance tests and improves setup Signed-off-by: Konstantina Blazhukova <[email protected]> Update hbarLimiter.spec.ts Signed-off-by: Logan Nguyen <[email protected]> * fix: switched back HBAR_RATE_LIMIT_DURATION Signed-off-by: Logan Nguyen <[email protected]> * fix: renamed HBAR_DAILY_LIMIT_BASIC to HBAR_RATE_LIMIT_BASIC Signed-off-by: Logan Nguyen <[email protected]> Update localAcceptance.env Signed-off-by: Logan Nguyen <[email protected]> * fix: fixed hbar limiter test Signed-off-by: Logan Nguyen <[email protected]> * fix: re-ordered test cases Signed-off-by: Logan Nguyen <[email protected]> * Improves test case and skips unecessary one Signed-off-by: Konstantina Blazhukova <[email protected]> * Improves unlinking of ip addresses Signed-off-by: Konstantina Blazhukova <[email protected]> * Revert "chore: remove unnecessary timeouts in tests" This reverts commit f688a4e. Signed-off-by: Konstantina Blazhukova <[email protected]> * Adds new deleteAll method in ipAddressRepository Signed-off-by: Konstantina Blazhukova <[email protected]> * Removes timeouts and adds logic to wait for limiter reset Signed-off-by: Konstantina Blazhukova <[email protected]> * Adds appropriate limits for acceptance tests Signed-off-by: Konstantina Blazhukova <[email protected]> * Adds new variables to .env Signed-off-by: Konstantina Blazhukova <[email protected]> * Improves test setup, removes unneeded limiter reset Signed-off-by: Konstantina Blazhukova <[email protected]> * Removes setting of env from terminal command, adds it to test setup instead Signed-off-by: Konstantina Blazhukova <[email protected]> * Adds necessary timeouts in tests relying on queries to mirror node Signed-off-by: Konstantina Blazhukova <[email protected]> * Fixes import in hbarLimiter spec Signed-off-by: Konstantina Blazhukova <[email protected]> * Removes unused imports, adds const where needed Signed-off-by: Konstantina Blazhukova <[email protected]> * Removes unused method Signed-off-by: Konstantina Blazhukova <[email protected]> * Makes improvements in ipAddressHbarRepo Signed-off-by: Konstantina Blazhukova <[email protected]> * Adds reset timestamp method to test Signed-off-by: Konstantina Blazhukova <[email protected]> * fix: added deleteAll() to EthAddressHbarSpendingPlanRepository class Signed-off-by: Logan Nguyen <[email protected]> * fix: reverted and cleaned up Signed-off-by: Logan Nguyen <[email protected]> * fix: removed duplicated test Signed-off-by: Logan Nguyen <[email protected]> --------- Signed-off-by: Konstantina Blazhukova <[email protected]> Signed-off-by: Logan Nguyen <[email protected]> Signed-off-by: Logan Nguyen <[email protected]> Update hbarLimiter.spec.ts Signed-off-by: Logan Nguyen <[email protected]> Update hbarLimiter.spec.ts Signed-off-by: Logan Nguyen <[email protected]> Co-Authored-By: Logan Nguyen <[email protected]> * chore: added info log after HbarLimiter is successfully configured Signed-off-by: Logan Nguyen <[email protected]> * chore: removed overriden variables in `acceptancetest:hbarlimiter` npm script Signed-off-by: Logan Nguyen <[email protected]> * fix: bumped HBAR_RATE_LIMIT_BASIC to 40 HBARs Signed-off-by: Logan Nguyen <[email protected]> * Shortens and improves logger name for new hbar plan repositories Signed-off-by: Konstantina Blazhukova <[email protected]> --------- Signed-off-by: Logan Nguyen <[email protected]> Signed-off-by: Victor Yanev <[email protected]> Signed-off-by: Konstantina Blazhukova <[email protected]> Co-authored-by: Victor Yanev <[email protected]> Co-authored-by: konstantinabl <[email protected]>
1 parent a1ae911 commit 34ec5a2

29 files changed

+958
-1005
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"acceptancetest:api_batch3": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@api-batch-3' --exit",
4848
"acceptancetest:erc20": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@erc20' --exit",
4949
"acceptancetest:ratelimiter": "nyc ts-mocha packages/ws-server/tests/acceptance/index.spec.ts -g '@web-socket-ratelimiter' --exit && ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@ratelimiter' --exit",
50-
"acceptancetest:hbarlimiter": "HBAR_RATE_LIMIT_TINYBAR=3000000000 nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@hbarlimiter' --exit",
50+
"acceptancetest:hbarlimiter": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@hbarlimiter' --exit",
5151
"acceptancetest:tokencreate": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@tokencreate' --exit",
5252
"acceptancetest:tokenmanagement": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@tokenmanagement' --exit",
5353
"acceptancetest:htsprecompilev1": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@htsprecompilev1' --exit",

packages/relay/src/lib/clients/sdkClient.ts

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ import {
5353
TransactionResponse,
5454
} from '@hashgraph/sdk';
5555
import { Logger } from 'pino';
56+
import { Utils } from '../../utils';
5657
import { EventEmitter } from 'events';
57-
import HbarLimit from '../hbarlimiter';
5858
import constants from './../constants';
5959
import { BigNumber } from '@hashgraph/sdk/lib/Transfer';
60-
import { SDKClientError } from '../errors/SDKClientError';
61-
import { JsonRpcError, predefined } from '../errors/JsonRpcError';
62-
import { CacheService } from '../services/cacheService/cacheService';
6360
import { weibarHexToTinyBarInt } from '../../formatters';
61+
import { SDKClientError } from './../errors/SDKClientError';
62+
import { HbarLimitService } from '../services/hbarLimitService';
63+
import { JsonRpcError, predefined } from './../errors/JsonRpcError';
64+
import { CacheService } from '../services/cacheService/cacheService';
6465
import {
6566
IExecuteQueryEventPayload,
6667
IExecuteTransactionEventPayload,
@@ -85,12 +86,6 @@ export class SDKClient {
8586
*/
8687
private readonly logger: Logger;
8788

88-
/**
89-
* This limiter tracks hbar expenses and limits.
90-
* @private
91-
*/
92-
private readonly hbarLimiter: HbarLimit;
93-
9489
/**
9590
* LRU cache container.
9691
* @private
@@ -118,21 +113,28 @@ export class SDKClient {
118113
*/
119114
private readonly eventEmitter: EventEmitter;
120115

116+
/**
117+
* An instance of the HbarLimitService that tracks hbar expenses and limits.
118+
* @private
119+
* @readonly
120+
* @type {HbarLimitService}
121+
*/
122+
private readonly hbarLimitService: HbarLimitService;
123+
121124
/**
122125
* Constructs an instance of the SDKClient and initializes various services and settings.
123126
*
124127
* @param {Client} clientMain - The primary Hedera client instance used for executing transactions and queries.
125128
* @param {Logger} logger - The logger instance for logging information, warnings, and errors.
126-
* @param {HbarLimit} hbarLimiter - The Hbar rate limiter instance for managing Hbar transaction budgets.
127129
* @param {CacheService} cacheService - The cache service instance used for caching and retrieving data.
128130
* @param {EventEmitter} eventEmitter - The eventEmitter used for emitting and handling events within the class.
129131
*/
130132
constructor(
131133
clientMain: Client,
132134
logger: Logger,
133-
hbarLimiter: HbarLimit,
134135
cacheService: CacheService,
135136
eventEmitter: EventEmitter,
137+
hbarLimitService: HbarLimitService,
136138
) {
137139
this.clientMain = clientMain;
138140

@@ -143,9 +145,9 @@ export class SDKClient {
143145
}
144146

145147
this.logger = logger;
146-
this.hbarLimiter = hbarLimiter;
147148
this.cacheService = cacheService;
148149
this.eventEmitter = eventEmitter;
150+
this.hbarLimitService = hbarLimitService;
149151
this.maxChunks = Number(process.env.FILE_APPEND_MAX_CHUNKS) || 20;
150152
this.fileAppendChunkSize = Number(process.env.FILE_APPEND_CHUNK_SIZE) || 5120;
151153
}
@@ -417,30 +419,14 @@ export class SDKClient {
417419
if (ethereumTransactionData.callData.length <= this.fileAppendChunkSize) {
418420
ethereumTransaction.setEthereumData(ethereumTransactionData.toBytes());
419421
} else {
420-
const isPreemptiveCheckOn = process.env.HBAR_RATE_LIMIT_PREEMPTIVE_CHECK === 'true';
421-
422-
if (isPreemptiveCheckOn) {
423-
const hexCallDataLength = Buffer.from(ethereumTransactionData.callData).toString('hex').length;
424-
const shouldPreemptivelyLimit = this.hbarLimiter.shouldPreemptivelyLimitFileTransactions(
425-
originalCallerAddress,
426-
hexCallDataLength,
427-
this.fileAppendChunkSize,
428-
currentNetworkExchangeRateInCents,
429-
requestDetails,
430-
);
431-
432-
if (shouldPreemptivelyLimit) {
433-
throw predefined.HBAR_RATE_LIMIT_PREEMPTIVE_EXCEEDED;
434-
}
435-
}
436-
437422
fileId = await this.createFile(
438423
ethereumTransactionData.callData,
439424
this.clientMain,
440425
requestDetails,
441426
callerName,
442427
interactingEntity,
443428
originalCallerAddress,
429+
currentNetworkExchangeRateInCents,
444430
);
445431
if (!fileId) {
446432
throw new SDKClientError({}, `${requestDetails.formattedRequestId} No fileId created for transaction. `);
@@ -506,7 +492,7 @@ export class SDKClient {
506492
contractCallQuery.setPaymentTransactionId(TransactionId.generate(this.clientMain.operatorAccountId));
507493
}
508494

509-
return this.executeQuery(contractCallQuery, this.clientMain, callerName, to, requestDetails);
495+
return this.executeQuery(contractCallQuery, this.clientMain, callerName, to, requestDetails, from);
510496
}
511497

512498
/**
@@ -603,6 +589,7 @@ export class SDKClient {
603589
* @param {string} callerName - The name of the caller executing the query.
604590
* @param {string} interactingEntity - The entity interacting with the query.
605591
* @param {RequestDetails} requestDetails - The request details for logging and tracking.
592+
* @param {string} [originalCallerAddress] - The optional address of the original caller making the request.
606593
* @returns {Promise<T>} A promise resolving to the query response.
607594
* @throws {Error} Throws an error if the query fails or if rate limits are exceeded.
608595
* @template T - The type of the query response.
@@ -613,6 +600,7 @@ export class SDKClient {
613600
callerName: string,
614601
interactingEntity: string,
615602
requestDetails: RequestDetails,
603+
originalCallerAddress?: string,
616604
): Promise<T> {
617605
const queryConstructorName = query.constructor.name;
618606
const requestIdPrefix = requestDetails.formattedRequestId;
@@ -669,6 +657,7 @@ export class SDKClient {
669657
interactingEntity,
670658
status,
671659
requestDetails,
660+
originalCallerAddress,
672661
} as IExecuteQueryEventPayload);
673662
}
674663
}
@@ -683,6 +672,7 @@ export class SDKClient {
683672
* @param {RequestDetails} requestDetails - The request details for logging and tracking.
684673
* @param {boolean} shouldThrowHbarLimit - Flag to indicate whether to check HBAR limits.
685674
* @param {string} originalCallerAddress - The address of the original caller making the request.
675+
* @param {number} [estimatedTxFee] - The optioanl total estimated transaction fee.
686676
* @returns {Promise<TransactionResponse>} - A promise that resolves to the transaction response.
687677
* @throws {SDKClientError} - Throws if an error occurs during transaction execution.
688678
*/
@@ -693,19 +683,22 @@ export class SDKClient {
693683
requestDetails: RequestDetails,
694684
shouldThrowHbarLimit: boolean,
695685
originalCallerAddress: string,
686+
estimatedTxFee?: number,
696687
): Promise<TransactionResponse> {
697688
const txConstructorName = transaction.constructor.name;
698689
let transactionId: string = '';
699690
let transactionResponse: TransactionResponse | null = null;
700691

701692
if (shouldThrowHbarLimit) {
702-
const shouldLimit = this.hbarLimiter.shouldLimit(
703-
Date.now(),
693+
const shouldLimit = await this.hbarLimitService.shouldLimit(
704694
constants.EXECUTION_MODE.TRANSACTION,
705695
callerName,
696+
txConstructorName,
706697
originalCallerAddress,
707698
requestDetails,
699+
estimatedTxFee,
708700
);
701+
709702
if (shouldLimit) {
710703
throw predefined.HBAR_RATE_LIMIT_EXCEEDED;
711704
}
@@ -756,6 +749,7 @@ export class SDKClient {
756749
txConstructorName,
757750
operatorAccountId: this.clientMain.operatorAccountId!.toString(),
758751
interactingEntity,
752+
originalCallerAddress,
759753
} as IExecuteTransactionEventPayload);
760754
}
761755
}
@@ -770,6 +764,7 @@ export class SDKClient {
770764
* @param {RequestDetails} requestDetails - The request details for logging and tracking.
771765
* @param {boolean} shouldThrowHbarLimit - Flag to indicate whether to check HBAR limits.
772766
* @param {string} originalCallerAddress - The address of the original caller making the request.
767+
* @param {number} [estimatedTxFee] - The optioanl total estimated transaction fee.
773768
* @returns {Promise<void>} - A promise that resolves when the batch execution is complete.
774769
* @throws {SDKClientError} - Throws if an error occurs during batch transaction execution.
775770
*/
@@ -780,18 +775,21 @@ export class SDKClient {
780775
requestDetails: RequestDetails,
781776
shouldThrowHbarLimit: boolean,
782777
originalCallerAddress: string,
778+
estimatedTxFee?: number,
783779
): Promise<void> {
784780
const txConstructorName = transaction.constructor.name;
785781
let transactionResponses: TransactionResponse[] | null = null;
786782

787783
if (shouldThrowHbarLimit) {
788-
const shouldLimit = this.hbarLimiter.shouldLimit(
789-
Date.now(),
784+
const shouldLimit = await this.hbarLimitService.shouldLimit(
790785
constants.EXECUTION_MODE.TRANSACTION,
791786
callerName,
787+
txConstructorName,
792788
originalCallerAddress,
793789
requestDetails,
790+
estimatedTxFee,
794791
);
792+
795793
if (shouldLimit) {
796794
throw predefined.HBAR_RATE_LIMIT_EXCEEDED;
797795
}
@@ -822,6 +820,7 @@ export class SDKClient {
822820
txConstructorName,
823821
operatorAccountId: this.clientMain.operatorAccountId!.toString(),
824822
interactingEntity,
823+
originalCallerAddress,
825824
} as IExecuteTransactionEventPayload);
826825
}
827826
}
@@ -837,6 +836,7 @@ export class SDKClient {
837836
* @param {string} callerName - The name of the caller creating the file.
838837
* @param {string} interactingEntity - The entity interacting with the transaction.
839838
* @param {string} originalCallerAddress - The address of the original caller making the request.
839+
* @param {number} currentNetworkExchangeRateInCents - The current network exchange rate in cents per HBAR.
840840
* @returns {Promise<FileId | null>} A promise that resolves to the created file ID or null if the creation failed.
841841
* @throws Will throw an error if the created file is empty or if any transaction fails during execution.
842842
*/
@@ -847,9 +847,29 @@ export class SDKClient {
847847
callerName: string,
848848
interactingEntity: string,
849849
originalCallerAddress: string,
850+
currentNetworkExchangeRateInCents: number,
850851
): Promise<FileId | null> {
851852
const hexedCallData = Buffer.from(callData).toString('hex');
852853

854+
const estimatedTxFee = Utils.estimateFileTransactionsFee(
855+
hexedCallData.length,
856+
this.fileAppendChunkSize,
857+
currentNetworkExchangeRateInCents,
858+
);
859+
860+
const shouldPreemptivelyLimit = await this.hbarLimitService.shouldLimit(
861+
constants.EXECUTION_MODE.TRANSACTION,
862+
callerName,
863+
this.createFile.name,
864+
originalCallerAddress,
865+
requestDetails,
866+
estimatedTxFee,
867+
);
868+
869+
if (shouldPreemptivelyLimit) {
870+
throw predefined.HBAR_RATE_LIMIT_EXCEEDED;
871+
}
872+
853873
const fileCreateTx = new FileCreateTransaction()
854874
.setContents(hexedCallData.substring(0, this.fileAppendChunkSize))
855875
.setKeys(client.operatorPublicKey ? [client.operatorPublicKey] : []);
@@ -859,7 +879,7 @@ export class SDKClient {
859879
callerName,
860880
interactingEntity,
861881
requestDetails,
862-
true,
882+
false,
863883
originalCallerAddress,
864884
);
865885

@@ -877,7 +897,7 @@ export class SDKClient {
877897
callerName,
878898
interactingEntity,
879899
requestDetails,
880-
true,
900+
false,
881901
originalCallerAddress,
882902
);
883903
}
@@ -889,6 +909,7 @@ export class SDKClient {
889909
callerName,
890910
interactingEntity,
891911
requestDetails,
912+
originalCallerAddress,
892913
);
893914

894915
if (fileInfo.size.isZero()) {
@@ -942,6 +963,7 @@ export class SDKClient {
942963
callerName,
943964
interactingEntity,
944965
requestDetails,
966+
originalCallerAddress,
945967
);
946968

947969
if (fileInfo.isDeleted) {

packages/relay/src/lib/constants.ts

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

21+
import dotenv from 'dotenv';
22+
import findConfig from 'find-config';
2123
import { BigNumber } from 'bignumber.js';
2224

25+
dotenv.config({ path: findConfig('.env') || '' });
26+
2327
enum CACHE_KEY {
2428
ACCOUNT = 'account',
2529
ETH_BLOCK_NUMBER = 'eth_block_number',

packages/relay/src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ export class EthAddressHbarSpendingPlanRepository {
102102
}
103103
}
104104

105+
/**
106+
* Deletes all spending plans associted with EVM addresses from cache.
107+
*
108+
* @param {RequestDetails} requestDetails - The request details for logging and tracking.
109+
* @returns {Promise<void>} - A promise that resolves when all IP address spending plans are deleted.
110+
*/
111+
async deleteAll(requestDetails: RequestDetails): Promise<void> {
112+
const key = this.getKey('*');
113+
const keys = await this.cache.keys(key, this.deleteAll.name, requestDetails);
114+
for (const key of keys) {
115+
await this.cache.delete(key, this.deleteAll.name, requestDetails);
116+
}
117+
this.logger.trace(`${requestDetails.formattedRequestId} Deleted all EVM address spending plans`);
118+
}
119+
105120
/**
106121
* Finds an {@link EthAddressHbarSpendingPlan} for an ETH address.
107122
*

packages/relay/src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ export class IPAddressHbarSpendingPlanRepository {
102102
}
103103
}
104104

105+
/**
106+
* Deletes all spending plans associated with IP address from cache.
107+
*
108+
* @param {RequestDetails} requestDetails - The request details for logging and tracking.
109+
* @returns {Promise<void>} - A promise that resolves when all IP address spending plans are deleted.
110+
*/
111+
async deleteAll(requestDetails: RequestDetails): Promise<void> {
112+
const key = this.getKey('*');
113+
const keys = await this.cache.keys(key, this.deleteAll.name, requestDetails);
114+
for (const key of keys) {
115+
await this.cache.delete(key, this.deleteAll.name, requestDetails);
116+
}
117+
this.logger.trace(`${requestDetails.formattedRequestId} Deleted all IP address spending plans`);
118+
}
119+
105120
/**
106121
* Finds an {@link IPAddressHbarSpendingPlan} for an IP address.
107122
*

0 commit comments

Comments
 (0)