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: implement configuration to pre-populate the cache with spending plans #3058

Open
wants to merge 48 commits into
base: main
Choose a base branch
from

Conversation

victor-yanev
Copy link
Contributor

@victor-yanev victor-yanev commented Oct 3, 2024

Description:

Implements logic to pre-populate the cache with spending plans specified in a JSON file.

Also fixes logs in HbarSpendingPlanRepository, IPAddressHbarSpendingPlanRepository, EthAddressHbarSpendingPlanRepository to log the request ID in messages for better tracking.

Related issue(s):

Fixes #3055

Fixes #3025

Notes for reviewer:

Logs without configuration file:

[2024-10-03 13:12:55.959 +0000] INFO (relay/15455 on MacBook-Pro.local): Configurations successfully loaded
[2024-10-03 13:12:55.960 +0000] TRACE (hbar-rate-limit/15455 on MacBook-Pro.local): remainingBudget=11000000000 tℏ, resetTimestamp=1727961255960
[2024-10-03 13:12:55.980 +0000] INFO (relay/15455 on MacBook-Pro.local): SDK client successfully configured to "{\"127.0.0.1:50211\":\"0.0.3\"}" for account 0.0.2 with request timeout value: 10000
[2024-10-03 13:12:55.981 +0000] INFO (mirror-node/15455 on MacBook-Pro.local): Mirror Node client successfully configured to REST url: http://localhost:5551/api/v1/ and Web3 url: http://localhost:8545/api/v1/ 
[2024-10-03 13:12:55.982 +0000] INFO (relay/15455 on MacBook-Pro.local): Relay running with chainId=0x12a
[2024-10-03 13:12:55.985 +0000] WARN (relay/15455 on MacBook-Pro.local): Failed to load pre-configured spending plans: Configuration file not found at path "spendingPlansConfig.json"

Logs with a configuration file:

[2024-10-04 14:52:35.405 +0000] INFO (relay/15296 on MacBook-Pro.local): Configurations successfully loaded
[2024-10-04 14:52:35.406 +0000] TRACE (hbar-rate-limit/15296 on MacBook-Pro.local): remainingBudget=11000000000 tℏ, resetTimestamp=1728053635406
[2024-10-04 14:52:35.417 +0000] INFO (relay/15296 on MacBook-Pro.local): SDK client successfully configured to "{\"127.0.0.1:50211\":\"0.0.3\"}" for account 0.0.2 with request timeout value: 10000
[2024-10-04 14:52:35.418 +0000] INFO (mirror-node/15296 on MacBook-Pro.local): Mirror Node client successfully configured to REST url: http://localhost:5551/api/v1/ and Web3 url: http://127.0.0.1:8545/api/v1/ 
[2024-10-04 14:52:35.419 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  retrieving keys matching hbarSpendingPlan:* on findAllActiveBySubscriptionType call
[2024-10-04 14:52:35.419 +0000] INFO (relay/15296 on MacBook-Pro.local): Relay running with chainId=0x12a
[2024-10-04 14:52:35.423 +0000] TRACE (hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Creating HbarSpendingPlan with ID c758c095-342c-4607-9db5-867d7e90ab9d...
[2024-10-04 14:52:35.424 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching hbarSpendingPlan:c758c095-342c-4607-9db5-867d7e90ab9d:{"id":"c758c095-342c-4607-9db5-867d7e90ab9d","subscriptionType":"PRIVILEGED","createdAt":"2024-10-04T14:52:35.423Z","active":true,"spendingHistory":[],"amountSpent":0} on create for indefinite time (cache size: 1, max: 1000)
[2024-10-04 14:52:35.424 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Created HBAR spending plan "partner name" with ID "c758c095-342c-4607-9db5-867d7e90ab9d" and subscriptionType "PRIVILEGED"
[2024-10-04 14:52:35.424 +0000] TRACE (hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Creating HbarSpendingPlan with ID a68488b0-6f7d-44a0-87c1-774ad64615f2...
[2024-10-04 14:52:35.424 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching hbarSpendingPlan:a68488b0-6f7d-44a0-87c1-774ad64615f2:{"id":"a68488b0-6f7d-44a0-87c1-774ad64615f2","subscriptionType":"PRIVILEGED","createdAt":"2024-10-04T14:52:35.424Z","active":true,"spendingHistory":[],"amountSpent":0} on create for indefinite time (cache size: 2, max: 1000)
[2024-10-04 14:52:35.424 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Created HBAR spending plan "some other partner that has given us only eth addresses" with ID "a68488b0-6f7d-44a0-87c1-774ad64615f2" and subscriptionType "PRIVILEGED"
[2024-10-04 14:52:35.424 +0000] TRACE (hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Creating HbarSpendingPlan with ID af13d6ed-d676-4d33-8b9d-cf05d1ad7134...
[2024-10-04 14:52:35.424 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching hbarSpendingPlan:af13d6ed-d676-4d33-8b9d-cf05d1ad7134:{"id":"af13d6ed-d676-4d33-8b9d-cf05d1ad7134","subscriptionType":"EXTENDED","createdAt":"2024-10-04T14:52:35.424Z","active":true,"spendingHistory":[],"amountSpent":0} on create for indefinite time (cache size: 3, max: 1000)
[2024-10-04 14:52:35.424 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Created HBAR spending plan "supported project name" with ID "af13d6ed-d676-4d33-8b9d-cf05d1ad7134" and subscriptionType "EXTENDED"
[2024-10-04 14:52:35.424 +0000] TRACE (hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Creating HbarSpendingPlan with ID 7f665aa3-6b73-41d7-bf9b-92d04cdab96b...
[2024-10-04 14:52:35.424 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching hbarSpendingPlan:7f665aa3-6b73-41d7-bf9b-92d04cdab96b:{"id":"7f665aa3-6b73-41d7-bf9b-92d04cdab96b","subscriptionType":"EXTENDED","createdAt":"2024-10-04T14:52:35.424Z","active":true,"spendingHistory":[],"amountSpent":0} on create for indefinite time (cache size: 4, max: 1000)
[2024-10-04 14:52:35.424 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Created HBAR spending plan "some other supported project that has given us only ip addresses" with ID "7f665aa3-6b73-41d7-bf9b-92d04cdab96b" and subscriptionType "EXTENDED"
[2024-10-04 14:52:35.424 +0000] TRACE (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Updating associations for HBAR spending plan 'partner name' with ID c758c095-342c-4607-9db5-867d7e90ab9d...
[2024-10-04 14:52:35.424 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  retrieving keys matching ethAddressHbarSpendingPlan:* on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.424 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching ethAddressHbarSpendingPlan:0x123:{"ethAddress":"0x123","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on save for indefinite time (cache size: 5, max: 1000)
[2024-10-04 14:52:35.424 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching ethAddressHbarSpendingPlan:0x124:{"ethAddress":"0x124","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on save for indefinite time (cache size: 6, max: 1000)
[2024-10-04 14:52:35.424 +0000] TRACE (eth-address-hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Linked ETH address 0x123 to HbarSpendingPlan with ID c758c095-342c-4607-9db5-867d7e90ab9d
[2024-10-04 14:52:35.424 +0000] TRACE (eth-address-hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Linked ETH address 0x124 to HbarSpendingPlan with ID c758c095-342c-4607-9db5-867d7e90ab9d
[2024-10-04 14:52:35.424 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Associated HBAR spending plan 'partner name' with ETH address 0x123
[2024-10-04 14:52:35.424 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Associated HBAR spending plan 'partner name' with ETH address 0x124
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  retrieving keys matching ipAddressHbarSpendingPlan:* on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on save for indefinite time (cache size: 7, max: 1000)
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on save for indefinite time (cache size: 8, max: 1000)
[2024-10-04 14:52:35.425 +0000] TRACE (ip-address-hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Linked new IP address to HbarSpendingPlan with ID c758c095-342c-4607-9db5-867d7e90ab9d
[2024-10-04 14:52:35.425 +0000] TRACE (ip-address-hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Linked new IP address to HbarSpendingPlan with ID c758c095-342c-4607-9db5-867d7e90ab9d
[2024-10-04 14:52:35.425 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Associated HBAR spending plan 'partner name' with IP address
[2024-10-04 14:52:35.425 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Associated HBAR spending plan 'partner name' with IP address
[2024-10-04 14:52:35.425 +0000] TRACE (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Updating associations for HBAR spending plan 'some other partner that has given us only eth addresses' with ID a68488b0-6f7d-44a0-87c1-774ad64615f2...
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  retrieving keys matching ethAddressHbarSpendingPlan:* on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ethAddressHbarSpendingPlan:0x123:{"ethAddress":"0x123","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ethAddressHbarSpendingPlan:0x124:{"ethAddress":"0x124","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching ethAddressHbarSpendingPlan:0x125:{"ethAddress":"0x125","planId":"a68488b0-6f7d-44a0-87c1-774ad64615f2"} on save for indefinite time (cache size: 9, max: 1000)
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching ethAddressHbarSpendingPlan:0x126:{"ethAddress":"0x126","planId":"a68488b0-6f7d-44a0-87c1-774ad64615f2"} on save for indefinite time (cache size: 10, max: 1000)
[2024-10-04 14:52:35.425 +0000] TRACE (eth-address-hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Linked ETH address 0x125 to HbarSpendingPlan with ID a68488b0-6f7d-44a0-87c1-774ad64615f2
[2024-10-04 14:52:35.425 +0000] TRACE (eth-address-hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Linked ETH address 0x126 to HbarSpendingPlan with ID a68488b0-6f7d-44a0-87c1-774ad64615f2
[2024-10-04 14:52:35.425 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Associated HBAR spending plan 'some other partner that has given us only eth addresses' with ETH address 0x125
[2024-10-04 14:52:35.425 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Associated HBAR spending plan 'some other partner that has given us only eth addresses' with ETH address 0x126
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  retrieving keys matching ipAddressHbarSpendingPlan:* on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Updating associations for HBAR spending plan 'supported project name' with ID af13d6ed-d676-4d33-8b9d-cf05d1ad7134...
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  retrieving keys matching ethAddressHbarSpendingPlan:* on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ethAddressHbarSpendingPlan:0x123:{"ethAddress":"0x123","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ethAddressHbarSpendingPlan:0x124:{"ethAddress":"0x124","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ethAddressHbarSpendingPlan:0x125:{"ethAddress":"0x125","planId":"a68488b0-6f7d-44a0-87c1-774ad64615f2"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ethAddressHbarSpendingPlan:0x126:{"ethAddress":"0x126","planId":"a68488b0-6f7d-44a0-87c1-774ad64615f2"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching ethAddressHbarSpendingPlan:0x127:{"ethAddress":"0x127","planId":"af13d6ed-d676-4d33-8b9d-cf05d1ad7134"} on save for indefinite time (cache size: 11, max: 1000)
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching ethAddressHbarSpendingPlan:0x128:{"ethAddress":"0x128","planId":"af13d6ed-d676-4d33-8b9d-cf05d1ad7134"} on save for indefinite time (cache size: 12, max: 1000)
[2024-10-04 14:52:35.425 +0000] TRACE (eth-address-hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Linked ETH address 0x127 to HbarSpendingPlan with ID af13d6ed-d676-4d33-8b9d-cf05d1ad7134
[2024-10-04 14:52:35.425 +0000] TRACE (eth-address-hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Linked ETH address 0x128 to HbarSpendingPlan with ID af13d6ed-d676-4d33-8b9d-cf05d1ad7134
[2024-10-04 14:52:35.425 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Associated HBAR spending plan 'supported project name' with ETH address 0x127
[2024-10-04 14:52:35.425 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Associated HBAR spending plan 'supported project name' with ETH address 0x128
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  retrieving keys matching ipAddressHbarSpendingPlan:* on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"af13d6ed-d676-4d33-8b9d-cf05d1ad7134"} on save for indefinite time (cache size: 13, max: 1000)
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"af13d6ed-d676-4d33-8b9d-cf05d1ad7134"} on save for indefinite time (cache size: 14, max: 1000)
[2024-10-04 14:52:35.425 +0000] TRACE (ip-address-hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Linked new IP address to HbarSpendingPlan with ID af13d6ed-d676-4d33-8b9d-cf05d1ad7134
[2024-10-04 14:52:35.425 +0000] TRACE (ip-address-hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Linked new IP address to HbarSpendingPlan with ID af13d6ed-d676-4d33-8b9d-cf05d1ad7134
[2024-10-04 14:52:35.425 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Associated HBAR spending plan 'supported project name' with IP address
[2024-10-04 14:52:35.425 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Associated HBAR spending plan 'supported project name' with IP address
[2024-10-04 14:52:35.425 +0000] TRACE (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Updating associations for HBAR spending plan 'some other supported project that has given us only ip addresses' with ID 7f665aa3-6b73-41d7-bf9b-92d04cdab96b...
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  retrieving keys matching ethAddressHbarSpendingPlan:* on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ethAddressHbarSpendingPlan:0x123:{"ethAddress":"0x123","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ethAddressHbarSpendingPlan:0x124:{"ethAddress":"0x124","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ethAddressHbarSpendingPlan:0x125:{"ethAddress":"0x125","planId":"a68488b0-6f7d-44a0-87c1-774ad64615f2"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ethAddressHbarSpendingPlan:0x126:{"ethAddress":"0x126","planId":"a68488b0-6f7d-44a0-87c1-774ad64615f2"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ethAddressHbarSpendingPlan:0x127:{"ethAddress":"0x127","planId":"af13d6ed-d676-4d33-8b9d-cf05d1ad7134"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.425 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ethAddressHbarSpendingPlan:0x128:{"ethAddress":"0x128","planId":"af13d6ed-d676-4d33-8b9d-cf05d1ad7134"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.426 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  retrieving keys matching ipAddressHbarSpendingPlan:* on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.426 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.426 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"c758c095-342c-4607-9db5-867d7e90ab9d"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.426 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"af13d6ed-d676-4d33-8b9d-cf05d1ad7134"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.426 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Returning cached value ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"af13d6ed-d676-4d33-8b9d-cf05d1ad7134"} on populatePreconfiguredSpendingPlans call
[2024-10-04 14:52:35.426 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"7f665aa3-6b73-41d7-bf9b-92d04cdab96b"} on save for indefinite time (cache size: 15, max: 1000)
[2024-10-04 14:52:35.426 +0000] TRACE (localLRUCache/15296 on MacBook-Pro.local):  Caching ipAddressHbarSpendingPlan:<REDACTED>:{"ipAddress":"<REDACTED>","planId":"7f665aa3-6b73-41d7-bf9b-92d04cdab96b"} on save for indefinite time (cache size: 16, max: 1000)
[2024-10-04 14:52:35.426 +0000] TRACE (ip-address-hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Linked new IP address to HbarSpendingPlan with ID 7f665aa3-6b73-41d7-bf9b-92d04cdab96b
[2024-10-04 14:52:35.426 +0000] TRACE (ip-address-hbar-spending-plan-repository/15296 on MacBook-Pro.local):  Linked new IP address to HbarSpendingPlan with ID 7f665aa3-6b73-41d7-bf9b-92d04cdab96b
[2024-10-04 14:52:35.426 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Associated HBAR spending plan 'some other supported project that has given us only ip addresses' with IP address
[2024-10-04 14:52:35.426 +0000] INFO (hbar-spending-plan-config-service/15296 on MacBook-Pro.local): Associated HBAR spending plan 'some other supported project that has given us only ip addresses' with IP address
[2024-10-04 14:52:35.426 +0000] INFO (relay/15296 on MacBook-Pro.local): Pre-configured spending plans populated successfully

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

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

# Conflicts:
#	packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts
#	packages/relay/src/lib/services/hbarLimitService/index.ts
#	packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

# Conflicts:
#	packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts
#	packages/relay/src/lib/services/hbarLimitService/index.ts
#	packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

# Conflicts:
#	packages/relay/src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository.ts
#	packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts
#	packages/relay/src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository.ts
#	packages/relay/src/lib/services/hbarLimitService/index.ts
#	packages/relay/tests/lib/repositories/hbarLimiter/hbarSpendingPlanRepository.spec.ts
#	packages/relay/tests/lib/sdkClient.spec.ts
#	packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>

# Conflicts:
#	packages/relay/src/lib/db/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository.ts
#	packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts
#	packages/relay/src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository.ts
#	packages/relay/src/lib/services/hbarLimitService/index.ts
#	packages/relay/tests/lib/repositories/hbarLimiter/hbarSpendingPlanRepository.spec.ts
#	packages/relay/tests/lib/sdkClient.spec.ts
#	packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
… plans

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
@victor-yanev victor-yanev changed the base branch from main to 2970-Note-what-configurations-are-used October 3, 2024 13:34
@victor-yanev victor-yanev self-assigned this Oct 3, 2024
@victor-yanev victor-yanev added enhancement New feature or request P1 labels Oct 3, 2024
@victor-yanev victor-yanev added this to the 0.58.0 milestone Oct 3, 2024
…ement-configuration-to-pre-populate-the-cache-with-spending-plans'

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
…ement-configuration-to-pre-populate-the-cache-with-spending-plans'

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
…m main branch

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

@ebadiere ebadiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG.

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
@@ -0,0 +1,28 @@
[
{
"id": "c758c095-342c-4607-9db5-867d7e90ab9d",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, are we now expected to include the plan ID in the config file? How would someone unfamiliar with the codebase, or loading the config file for the first time, come up with such IDs? I was under the impression that these IDs are auto-generated by the Relay and only used internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC: @Nana-EC @ebadiere

Well, there are two approaches in which this could be handled:

  1. Clear all spending plans from the cache on every start-up and re-populate them from the config file:
    • in this case we don't need to specify IDs in the config file, they can be randomly generated on each startup
    • historical logs on mainnet and testnet will be harder to debug because we would have generated new IDs on redeploys / restarted pods and the IDs we have from the logs before this moment wouldn't be valid anymore
    • if Kubernetes pods are restarted - the cache would be re-populated with the same spending plans but with new IDs and we would lose track of the current spending as it will also be restarted
  2. Only populate the "delta" from the config file (i.e., delete "obsolete" spending plans which are no longer present in the config file and create new spending plans which were not specified before):
    • in this case we need to have an ID specified in the config file, otherwise we cannot know if a given spending plan was already populated or not in the cache
    • historical logs on mainnet and testnet will be easy to debug since the same ID we are seeing in the logs, will be still valid and we can retrieve the spending plan from the cache by that ID
    • the Kubernetes pods can be freely restarted without affecting the behavior of the hbar limiter, as old spending plans wouldn't be cleared and only new ones that have appeared in the config file will be populated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would someone unfamiliar with the codebase, or loading the config file for the first time, come up with such IDs

You don't need to be familiar with the codebase to come up with a random UUID: https://www.uuidgenerator.net/version4

I was under the impression that these IDs are auto-generated by the Relay and only used internally.

They are if an "id" field is not specified in the config file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this correctly, with option 2, the config file can be the single source of truth regarding the spending plan.

Copy link
Member

@quiet-node quiet-node Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline and agreed on option 2 mentioned above. However, needed to come up with a plan to construct the plan ID beforehand and make it as a required field.

victor-yanev and others added 12 commits October 7, 2024 12:08
Co-authored-by: Logan Nguyen <logan.nguyen@swirldslabs.com>
Signed-off-by: Victor Yanev <161485803+victor-yanev@users.noreply.github.com>
Co-authored-by: Logan Nguyen <logan.nguyen@swirldslabs.com>
Signed-off-by: Victor Yanev <161485803+victor-yanev@users.noreply.github.com>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
…ment-configuration-to-pre-populate-the-cache-with-spending-plans

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

# Conflicts:
#	packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts
#	packages/relay/tests/lib/repositories/hbarLimiter/hbarSpendingPlanRepository.spec.ts
…ment-configuration-to-pre-populate-the-cache-with-spending-plans

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

# Conflicts:
#	packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts
#	packages/relay/tests/lib/repositories/hbarLimiter/hbarSpendingPlanRepository.spec.ts
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Copy link

sonarcloud bot commented Oct 7, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarCloud

Base automatically changed from 2970-Note-what-configurations-are-used to main October 7, 2024 17:31
@ebadiere ebadiere self-requested a review October 7, 2024 18:27
Copy link
Collaborator

@ebadiere ebadiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, but needs a conflict resolution.

```json
[
{
"name": "partner name",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a friendly reminder to ensure we don't forget to add the ID field here in case if we want to make the plan ID a required property for the preconfigured plan.

]
```

### Spending Limits of Different Tiers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's maintain consistency with the subscription packages. Currently, "tiers" and "types" are used interchangeably to describe different subscription packages. Let's agree on one term for clarity. I personally prefer "tiers," as it better reflects the hierarchy within the subscription structure.

Comment on lines +109 to +110
const censoredKey = key.replace(Utils.IP_ADDRESS_REGEX, '<REDACTED>');
const censoredValue = JSON.stringify(value).replace(/"ipAddress":"[^"]+"/, '"ipAddress":"<REDACTED>"');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea!

Just a concern but it seems that the key hasn’t been censored up until this point, but it has already been passed into this function, meaning it’s been floating around in the codebase. I just want to ensure that from the moment the key is constructed to when it gets censored, we don’t accidentally log any IP addresses.

);
const censoredKey = key.replace(Utils.IP_ADDRESS_REGEX, '<REDACTED>');
const censoredValue = JSON.stringify(value).replace(/"ipAddress":"[^"]+"/, '"ipAddress":"<REDACTED>"');
const message = `Returning cached value ${censoredKey}:${censoredValue} on ${callingMethod} call`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the ${censoredKey}:${censoredValue} be duplicating or overlapping with the same values?

@@ -0,0 +1,315 @@
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is also a service, should we consider moving it into the services/ folder? Perhaps something like services/config/hbarSpendService.ts?

Comment on lines +33 to +34
private readonly TTL = -1; // -1 means no TTL, i.e. the data will not expire
private readonly DEFAULT_SPENDING_PLANS_CONFIG_FILE = 'spendingPlansConfig.json';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not foget JSDoc for these vars

Comment on lines +33 to +34
private readonly TTL = -1; // -1 means no TTL, i.e. the data will not expire
private readonly DEFAULT_SPENDING_PLANS_CONFIG_FILE = 'spendingPlansConfig.json';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since DEFAULT_SPENDING_PLANS_CONFIG_FILE is only used once for the filename in loadSpendingPlansConfig(), can we simplify it to something like:

Suggested change
private readonly TTL = -1; // -1 means no TTL, i.e. the data will not expire
private readonly DEFAULT_SPENDING_PLANS_CONFIG_FILE = 'spendingPlansConfig.json';
private readonly TTL = -1; // -1 means no TTL, i.e. the data will not expire
private readonly SPENDING_PLANS_CONFIG_FILE = process.env.HBAR_SPENDING_PLANS_CONFIG_FILE || 'spendingPlansConfig.json';

Then instead of initializing a new filename variable in loadSpendingPlansConfig(), we can simply reuse this.SPENDING_PLANS_CONFIG_FILE.

Just a suggestion I'm fine with current flow.

@@ -27,7 +27,7 @@ import { RequestDetails } from '../../../types';

export class EthAddressHbarSpendingPlanRepository {
private readonly collectionKey = 'ethAddressHbarSpendingPlan';
private readonly threeMonthsInMillis = 90 * 24 * 60 * 60 * 1000;
private readonly oneDayInMillis = 24 * 60 * 60 * 1000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove if not used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1
Projects
None yet
3 participants