Skip to main content

IOffsettingRateLimiter

Git Source

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

NameTypeDescription
dstEid_uint32The destination endpoint identifier.

Returns

NameTypeDescription
inFlightuint256The stored in-flight amount.
limituint256The maximum amount that may be in flight at any point.
windowuint32The length in seconds of the sliding window.
lastUpdateduint48The 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

NameTypeDescription
srcEid_uint32The source endpoint identifier.

Returns

NameTypeDescription
inFlightuint256The stored in-flight amount.
limituint256The maximum amount that may be in flight at any point.
windowuint32The length in seconds of the sliding window.
lastUpdateduint48The 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

NameTypeDescription
dstEid_uint32The destination endpoint identifier.

Returns

NameTypeDescription
inFlightuint256The decayed in-flight amount at the current timestamp.
availableuint256The 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

NameTypeDescription
srcEid_uint32The source endpoint identifier.

Returns

NameTypeDescription
inFlightuint256The decayed in-flight amount at the current timestamp.
availableuint256The 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

NameTypeDescription
configsRateLimitConfig[]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

NameTypeDescription
configsRateLimitConfig[]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

NameTypeDescription
eidsuint32[]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

NameTypeDescription
eidsuint32[]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

NameTypeDescription
requesteduint256The amount that was attempted to be debited from the rate limit.
availableuint256The 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

NameTypeDescription
inFlightuint256The amount that has been recorded within the active window and
has not yet decayed to zero.
limituint256The maximum amount that may be in flight at any point.
windowuint32The length in seconds of the sliding window over which the
in-flight amount decays linearly from limit to zero.
lastUpdateduint48The 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

NameTypeDescription
eiduint32The endpoint identifier the configuration applies to.
limituint256The maximum amount that may be in flight at any point.
windowuint32The length in seconds of the sliding window over which the
in-flight amount decays linearly from limit to zero.