-
Notifications
You must be signed in to change notification settings - Fork 68
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: replaced HbarLimit module with the new HbarLimitService class #3024
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, avoid introducing unnecessary changes unrelated to what is asked from the issue:
- it makes the PR harder to review, because it is cluttered with too many empty / unrelated changes
- makes it easier to slip in bugs, because reviewers might overlook an important change among all the "empty" changes which surround it
- wastes other people's time because it creates unnecessary conflicts with other PRs
8523fe9
to
3a20364
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
e04b43b
to
349eb2d
Compare
5066ec9
to
ebc1b72
Compare
🚨 Memory Leak Detected 🚨A potential memory leak has been detected in the test titled Details📊 Memory Leak Detection Report 📊 GC Type: MarkSweepCompact Heap Statistics (before vs after executing the test):
Heap Space Statistics (before vs after executing the test):
RecommendationsPlease investigate the memory allocations in this test, focusing on objects that are not being properly deallocated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Good job!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a few small things
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Victor Yanev <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
7b46596
to
97f66d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Great job overall.
if (shouldPreemptivelyLimit) { | ||
throw predefined.HBAR_RATE_LIMIT_EXCEEDED; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If shouldPreemptivelyLimit
is set to false
, we will have no limiting for file transactions since we are passing always passing false
to executeTransaction
and executeQuery
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment here answers the question. The shouldPreemptivelyLimit
check was intended to validate the shouldLimit
logic for both executeTransaction()
for fileCreate
and executeAllTransaction()
for fileAppend
. That’s why I passed false
in both executeTransaction()
and executeAllTransaction()
below to skip
The shouldThrowHbarLimit
variable in executeTransaction()
and executeAllTransaction()
only checks if another shouldLimit
evaluation is needed. However, since this logic is already handled by the preemptive rate limit, there’s no need for an additional check in the individual flow. This was mentioned in the earlier comment.
@@ -859,7 +879,7 @@ export class SDKClient { | |||
callerName, | |||
interactingEntity, | |||
requestDetails, | |||
true, | |||
false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this reason, instead of passing false
we can pass: !shouldPreemptivelyLimit
so that this is set to true
if shouldPreemptivelyLimit
is false
false, | |
!shouldPreemptivelyLimit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -877,7 +897,7 @@ export class SDKClient { | |||
callerName, | |||
interactingEntity, | |||
requestDetails, | |||
true, | |||
false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false, | |
!shouldPreemptivelyLimit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…Plan Signed-off-by: Logan Nguyen <[email protected]>
Quality Gate failedFailed conditions See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
338de4a
into
FEATURE_BRANCH-HbarRateLimitService
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## FEATURE_BRANCH-HbarRateLimitService #3024 +/- ##
=======================================================================
- Coverage 83.16% 82.06% -1.11%
=======================================================================
Files 63 65 +2
Lines 4236 4338 +102
Branches 830 859 +29
=======================================================================
+ Hits 3523 3560 +37
- Misses 470 529 +59
- Partials 243 249 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
|
…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]>
…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]>
…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]>
…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]>
…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]>
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 * chore: added jsdoc to private vars in hapiService module * feat: initialized an instance of HbarLimitService in relay.ts * feat: integrated HbarLimitService instance into HapiService class * feat: integrated HbarLimitService instance into SDKClient class * feat: integrated HbarLimitService instance into MetricService class * 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. * feat: added getRemainingBudget() getter * feat: added originalCallerAddress to IExecuteTransactionEventPayload and IExecuteQueryEventPayload * feat: removed metricService instance in relay * feat: replaced hbarLimitter with hbarLimitService in MetricService class * fix: added estimateFileTransactionsFee to Utils * feat: added txConstructorName and updated log messages for shouldLimit * fix: rework logic for estimateFileTransactionsFee * feat: removed hbarLimiter instance in SDKClient classes * feat: deleted HbarLimit module from codease * feat: reverted logic reworked on estimateFileTransactionsFee * feat: added preemptive rate limit logic to createFile() method * test: updated hbarLimiter.spec.ts * fix: added names for child loggers for spending plan repo * chore: reverted "feat: added getRemainingBudget() getter" This reverts commit fd9e119 and updated related tests * fix: updated log message * test: added HBAR_DAILY_LIMIT_BASIC to localTestEnv * fix: converted function HBAR_RATE_LIMIT_DURATION from function into var * fix: reverted "feat: removed metricService instance in relay" This reverts commit e45c321. * chore: updated log message * fix: fixed failing test in hapiService * fix: reverted ethAddress back to be a required param for addExpense * fix: fixed failing test in hapiService.spec.ts * fix: loaded env into prcess.env for constant module * chore: removed duplicating doc for estimateFileTransactionsFee * chore: sort imports * fix: removed ipAddresses from log in hbarLimitService * fix: renamed isDailyBudgetExceeded -> isTotalBudgetExceeded * fix: fixed conflicts after rebased * fix: fixed acceptance test for exhausting HBAR case * fix: renamed HBAR_DAILY_LIMIT_BASIC to HBAR_RATE_LIMIT_BASIC * fix: overrode env vars for npm acceptancetest:hbarlimiter script * fix: moved logic of adding expenses to totalBudget above hbarSpendingPlan --------- * test: create e2e tests for basic spending plan limit (#3104) * Adds acceptance test for BASIC user spending plans Fixes failing acceptance test Revert accidental deletion of method * Fixes CI * Fixes failiing acceptance tests and improves setup Update hbarLimiter.spec.ts * fix: switched back HBAR_RATE_LIMIT_DURATION * fix: renamed HBAR_DAILY_LIMIT_BASIC to HBAR_RATE_LIMIT_BASIC Update localAcceptance.env * fix: fixed hbar limiter test * fix: re-ordered test cases * Improves test case and skips unecessary one * Improves unlinking of ip addresses * Revert "chore: remove unnecessary timeouts in tests" This reverts commit f688a4e. * Adds new deleteAll method in ipAddressRepository * Removes timeouts and adds logic to wait for limiter reset * Adds appropriate limits for acceptance tests * Adds new variables to .env * Improves test setup, removes unneeded limiter reset * Removes setting of env from terminal command, adds it to test setup instead * Adds necessary timeouts in tests relying on queries to mirror node * Fixes import in hbarLimiter spec * Removes unused imports, adds const where needed * Removes unused method * Makes improvements in ipAddressHbarRepo * Adds reset timestamp method to test * fix: added deleteAll() to EthAddressHbarSpendingPlanRepository class * fix: reverted and cleaned up * fix: removed duplicated test --------- Update hbarLimiter.spec.ts Update hbarLimiter.spec.ts * chore: added info log after HbarLimiter is successfully configured * chore: removed overriden variables in `acceptancetest:hbarlimiter` npm script * fix: bumped HBAR_RATE_LIMIT_BASIC to 40 HBARs * Shortens and improves logger name for new hbar plan repositories --------- Signed-off-by: Logan Nguyen <[email protected]> Signed-off-by: Victor Yanev <[email protected]> Signed-off-by: Konstantina Blazhukova <[email protected]> Co-authored-by: Logan Nguyen <[email protected]> Co-authored-by: Victor Yanev <[email protected]> Co-authored-by: konstantinabl <[email protected]>
Description:
HbarLimit
module with the newHbarLimitService
class in theSdkClient
andMetricService
classes.HbarLimit
module from the codebase.addExpense
logic in the newHbarLimitService
has been updated to accept a nullableethAddress
value. Certain queries, such asgetAccountInfo
,getBalanceInfo
,FileContentsQuery
, etc., also add expenses toremainingBalance
but don’t always require anoriginalCaller
(ethAddress
). Therefore,addExpense
can now handle a nullableethAddress
value. If eitherethAddress
oripAddress
is valid, thespendingPlan
logic is applied. Otherwise, it is skipped entirely.sdkClient.createFile()
method.HbarLimitService
class.Related issue(s):
Fixes #2896
Notes for reviewer:
Checklist