Skip to content

Commit d73c0ab

Browse files
authored
docs: update hbar-limiter.md with information about OPERATOR plans (#3338)
Signed-off-by: Victor Yanev <[email protected]>
1 parent 1ee437d commit d73c0ab

File tree

1 file changed

+45
-24
lines changed

1 file changed

+45
-24
lines changed

docs/design/hbar-limiter.md

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,45 +99,64 @@ An `HbarSpendingPlan` is a record that tracks the total amount of HBars spent by
9999
- **active**: A flag indicating whether the spending plan is currently active.
100100
- **spendingHistory**: A list of spending records, each containing the amount spent and the timestamp.
101101

102-
### General Users (BASIC tier):
102+
### Relay Operator (OPERATOR tier):
103103

104-
**NOTE:** Each general user will have a unique spending plan, linked both to their ETH and IP addresses. Each new user will be automatically assigned a BASIC spending plan when they send their first transaction and this plan will remain linked to them for any subsequent requests.
104+
The relay operator will have a total budget for the HBARs that can be spent in a given time window (this is the total limit for all users).
105+
The operator will have a separate spending plan, linked to the operator's EVM address, which will track the total amount spent by the operator.
106+
The operator's spending plan will be used to check if the total amount spent exceeds the budget and to pause all spending if necessary.
107+
If at some point, the operator's total spending exceeds the budget, all subsequent requests from any user will be blocked until the next reset.
105108

106109
```mermaid
107110
flowchart TD
108111
A[User] -->|sends transaction| B[JSON-RPC Relay]
109-
B --> C[Estimate fees which will be paid by the relay operator]
110-
C --> D{HBAR Limiter}
111-
D -->|new user, i.e., who is not linked to a spending plan| E[Create a new BASIC spending plan]
112-
E --> F[Link user's ETH & IP addresses to plan]
113-
D -->|existing user, i.e., who is linked to a spending plan| G[Retrieve spending plan linked to user]
114-
F --> H{Plan has enough balance to cover fees}
115-
G --> H
116-
H --> |no| I[Limit request]
117-
H --> |yes| J[Execute transaction]
118-
J --> K[Capture all fees the operator has been charged during execution]
119-
K --> L[Update the spending plan's remaining balance]
112+
B --> C{Estimate fees to be paid by the relay operator}
113+
C --> |total budget would get exceeded| I[Limit request]
114+
C --> |there is enough remaining budget to cover fees| J[Execute transaction]
115+
J --> K[Capture all fees charged during the execution]
116+
K --> L[Update the amount spent of the operator's spending plan]
120117
```
121118

122-
### Supported Projects (EXTENDED tier) and Trusted Partners (PRIVILEGED tier):
119+
### Tiered Spending Limits:
123120

124-
**NOTE:** There will be one spending plan per project/partner with a total spending limit, shared amongst a group of users (IP and EVM addresses) linked to that plan. This means that they will share a common total spending limit for the project/partner.
121+
Apart from the total limit which is imposed by the operator's spending plan, there will be separate spending plans for different tiers of users (BASIC, EXTENDED, and PRIVILEGED).
125122

126-
All users associated with a project/partner will be pre-configured in the relay as shown in the
123+
Thus, the HBAR limiter will have the following responsibilities:
124+
- **Create and manage spending plans for different tiers of users.**
125+
- **Link users to their respective spending plans based on their addresses.**
126+
- **On every transaction**:
127+
- **Check if a user's spending plan has enough balance to cover the fees of a transaction.**
128+
- **Check if the operator's total spending exceeds the budget.**
129+
- **If the user's spending plan does not have enough balance or if the operator's total spending exceeds the budget, limit the request.**
130+
- **Otherwise, execute the transaction and capture all fees charged both into the operator's and the individual user's spending plan.**
127131

128132
```mermaid
129133
flowchart TD
130134
A[User] -->|sends transaction| B[JSON-RPC Relay]
131135
B --> C[Estimate fees which will be paid by the relay operator]
132-
C --> D{HBAR Limiter}
133-
D --> E[Retrieve spending plan linked to user's ETH and/or IP address]
134-
E --> F{Plan has enough balance to cover fees}
135-
F --> |no| G[Limit request]
136-
F --> |yes| H[Execute transaction]
137-
H --> I[Capture all fees the operator has been charged during execution]
138-
I --> J[Update the spending plan's remaining balance]
136+
C --> D{Retrieve the operator's spending plan}
137+
D --> |operator has enough remaining budget| F{Proceed with the transaction}
138+
D --> |operator would exceed the budget| I[Limit the request]
139+
F -->|new user, i.e., who is not linked to a spending plan| G[Create a new BASIC spending plan]
140+
G --> H[Link user's ETH & IP addresses to plan]
141+
F -->|existing user, i.e., who is linked to a spending plan| I2[Retrieve spending plan linked to user]
142+
I2 --> J{Plan has enough balance to cover fees}
143+
H --> J
144+
J --> |no| I[Limit the request]
145+
J --> |yes| K[Execute transaction]
146+
K --> L[Capture all fees the operator has been charged during execution]
147+
L --> M[Update the amount spent of the operator's spending plan and the user's spending plan]
139148
```
140149

150+
### General Users (BASIC tier):
151+
152+
**NOTE:** Each general user will have a unique spending plan, linked both to their ETH and IP addresses. Each new user will be automatically assigned a BASIC spending plan when they send their first transaction and this plan will remain linked to them for any subsequent requests.
153+
154+
### Supported Projects (EXTENDED tier) and Trusted Partners (PRIVILEGED tier):
155+
156+
**NOTE:** There will be one spending plan per project/partner with a total spending limit, shared amongst a group of users (IP and EVM addresses) linked to that plan. This means that they will share a common total spending limit for the project/partner.
157+
158+
All users associated with a project/partner will be pre-configured in the relay as shown in the
159+
141160
### Class Diagram
142161

143162
#### Service Layer
@@ -256,6 +275,7 @@ classDiagram
256275
SubscriptionTier : BASIC
257276
SubscriptionTier : EXTENDED
258277
SubscriptionTier : PRIVILEGED
278+
SubscriptionTier : OPERATOR
259279
260280
HbarSpendingPlan --> SubscriptionTier : could be one of the types
261281
HbarSpendingPlan --> HbarSpendingRecord : stores history of
@@ -455,8 +475,9 @@ The total budget and the limit duration are defined as environment variables:
455475
- On initialization of `HbarLimitService`, a reset timestamp is calculated by adding the `HBAR_RATE_LIMIT_DURATION` to the current timestamp.
456476
- The total budget and spending limits are reset when the current timestamp exceeds the reset timestamp.
457477
- `HBAR_RATE_LIMIT_TINYBAR`: The ceiling on the total amount (in tℏ) that can be spent in the limit duration.
478+
- This is the spending limit (tℏ) for the operator (tier 0).
458479
- This is the largest bucket from which others pull from.
459-
- If the total amount spent exceeds this limit, all spending is paused until the next reset.
480+
- If the operator's spending exceeds this limit, **all spending is paused until the next reset**.
460481

461482
Example configuration for a total budget and limit duration:
462483
```dotenv

0 commit comments

Comments
 (0)