IOffsettingRateLimiter
Title: IOffsettingRateLimiter
The external interface of a rate limiter that tracks the amount moved between this contract and a remote endpoint, and offsets activity in one direction against in-flight activity in the other.
Functions
outRateLimits
Returns the stored outbound rate limit state for a destination endpoint.
function outRateLimits(
uint32 dstEid_
) external view returns (uint256 inFlight, uint256 limit, uint32 window, uint48 lastUpdated);
Parameters
| Name | Type | Description |
|---|---|---|
| dstEid_ | uint32 | The destination endpoint identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| inFlight | uint256 | The stored in-flight amount. |
| limit | uint256 | The maximum amount that may be in flight at any point. |
| window | uint32 | The length in seconds of the sliding window. |
| lastUpdated | uint48 | The timestamp of the most recent update. |
inRateLimits
Returns the stored inbound rate limit state for a source endpoint.
function inRateLimits(
uint32 srcEid_
) external view returns (uint256 inFlight, uint256 limit, uint32 window, uint48 lastUpdated);
Parameters
| Name | Type | Description |
|---|---|---|
| srcEid_ | uint32 | The source endpoint identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| inFlight | uint256 | The stored in-flight amount. |
| limit | uint256 | The maximum amount that may be in flight at any point. |
| window | uint32 | The length in seconds of the sliding window. |
| lastUpdated | uint48 | The timestamp of the most recent update. |
sendable
Returns the current outbound capacity for a destination endpoint, with the in-flight amount decayed against the current timestamp.
function sendable(uint32 dstEid_) external view returns (uint256 inFlight, uint256 available);
Parameters
| Name | Type | Description |
|---|---|---|
| dstEid_ | uint32 | The destination endpoint identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| inFlight | uint256 | The decayed in-flight amount at the current timestamp. |
| available | uint256 | The amount that may still be sent before the rate limit is exceeded. |
receivable
Returns the current inbound capacity for a source endpoint, with the in-flight amount decayed against the current timestamp.
function receivable(uint32 srcEid_) external view returns (uint256 inFlight, uint256 available);
Parameters
| Name | Type | Description |
|---|---|---|
| srcEid_ | uint32 | The source endpoint identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| inFlight | uint256 | The decayed in-flight amount at the current timestamp. |
| available | uint256 | The amount that may still be received before the rate limit is exceeded. |
Events
OutRateLimitsSet
Emitted when one or more outbound rate limits have been configured.
event OutRateLimitsSet(RateLimitConfig[] configs);
Parameters
| Name | Type | Description |
|---|---|---|
| configs | RateLimitConfig[] | The configurations that have been applied, in the order in which they were applied. |
InRateLimitsSet
Emitted when one or more inbound rate limits have been configured.
event InRateLimitsSet(RateLimitConfig[] configs);
Parameters
| Name | Type | Description |
|---|---|---|
| configs | RateLimitConfig[] | The configurations that have been applied, in the order in which they were applied. |
OutboundInFlightCleared
Emitted when the outbound in-flight amount has been cleared for one or more endpoints.
The corresponding inbound rate limits for the listed endpoints are not affected by this operation.
event OutboundInFlightCleared(uint32[] eids);
Parameters
| Name | Type | Description |
|---|---|---|
| eids | uint32[] | The endpoint identifiers whose outbound in-flight amount has been cleared. |
InboundInFlightCleared
Emitted when the inbound in-flight amount has been cleared for one or more endpoints.
The corresponding outbound rate limits for the listed endpoints are not affected by this operation.
event InboundInFlightCleared(uint32[] eids);
Parameters
| Name | Type | Description |
|---|---|---|
| eids | uint32[] | The endpoint identifiers whose inbound in-flight amount has been cleared. |
Errors
RateLimitExceeded
Thrown when a flow would exceed the remaining capacity of a rate limit for a given direction.
error RateLimitExceeded(uint256 requested, uint256 available);
Parameters
| Name | Type | Description |
|---|---|---|
| requested | uint256 | The amount that was attempted to be debited from the rate limit. |
| available | uint256 | The remaining capacity of the rate limit at the current timestamp. |
Structs
RateLimit
The state of a rate limit for a single endpoint identifier and direction.
struct RateLimit {
uint256 inFlight;
uint256 limit;
uint32 window;
uint48 lastUpdated;
}
Properties
| Name | Type | Description |
|---|---|---|
| inFlight | uint256 | The amount that has been recorded within the active window and has not yet decayed to zero. |
| limit | uint256 | The maximum amount that may be in flight at any point. |
| window | uint32 | The length in seconds of the sliding window over which the in-flight amount decays linearly from limit to zero. |
| lastUpdated | uint48 | The timestamp of the most recent update applied to this rate limit, used as the starting point of the decay calculation. |
RateLimitConfig
The configuration payload used to set a rate limit for a given endpoint.
A configuration with limit set to zero pauses the direction it
applies to, since no further capacity can be granted in that direction.
struct RateLimitConfig {
uint32 eid;
uint256 limit;
uint32 window;
}
Properties
| Name | Type | Description |
|---|---|---|
| eid | uint32 | The endpoint identifier the configuration applies to. |
| limit | uint256 | The maximum amount that may be in flight at any point. |
| window | uint32 | The length in seconds of the sliding window over which the in-flight amount decays linearly from limit to zero. |