rate_limit

package
v0.0.0-...-23a414b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BATCH_CANCEL_RATE_LIMIT_WEIGHT = uint32(2)
)

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter[K any] interface {
	// Returns an error if the RateLimiter exceeds any configured rate limits for the key K and context state.
	RateLimit(ctx sdk.Context, key K) error
	// Returns an error if the RateLimiter exceeds any configured rate limits for the key K and context state
	// Increments the rate limit counter by incrBy.
	RateLimitIncrBy(ctx sdk.Context, key K, incrBy uint32) error
	// Prunes rate limits for the provided context.
	PruneRateLimits(ctx sdk.Context)
}

Used to RateLimit for a key K.

func NewMultiBlockRateLimiter

func NewMultiBlockRateLimiter[K comparable](context string, config []types.MaxPerNBlocksRateLimit) RateLimiter[K]

Returns a RateLimiter over multiple blocks.

`ctx.BlockHeight()` is used in RateLimit to track which block the rate limit should apply to.

`ctx.BlockHeight()` is used in PruneRateLimits to remove rate limits for a block `maxNumBlocks` ago. If invoked during `EndBlocker` then you can pass in the `ctx` as is but if invoked during `PrepareCheckState` one must supply a `ctx` with the previous block height via `ctx.WithBlockHeight(ctx.BlockHeight()-1)`.

func NewNoOpRateLimiter

func NewNoOpRateLimiter[K any]() RateLimiter[K]

Returns a RateLimiter that does not enforce any limits.

func NewPanicRateLimiter

func NewPanicRateLimiter[K any]() RateLimiter[K]

Returns a RateLimiter that will panic on invocation.

func NewPlaceCancelOrderRateLimiter

func NewPlaceCancelOrderRateLimiter(config types.BlockRateLimitConfiguration) RateLimiter[sdk.Msg]

NewPlaceCancelOrderRateLimiter returns a RateLimiter which rate limits types.MsgPlaceOrder, types.MsgCancelOrder, types.MsgBatchCancel based upon the provided types.BlockRateLimitConfiguration. The rate limiter currently supports limiting based upon:

  • how many short term place/cancel orders per account (by using string).
  • how many stateful order per account (by using string).

The rate limiting must only be used during `CheckTx` because the rate limiting information is not recovered on application restart preventing it from being deterministic during `DeliverTx`.

Depending upon the provided types.BlockRateLimitConfiguration, the returned RateLimiter may rely on:

  • `ctx.BlockHeight()` in RateLimit to track which block the rate limit should apply to.
  • `ctx.BlockHeight()` in PruneRateLimits and should be invoked during `EndBlocker`. If invoked during `PrepareCheckState` one must supply a `ctx` with the previous block height via `ctx.WithBlockHeight(ctx.BlockHeight()-1)`.

func NewSingleBlockRateLimiter

func NewSingleBlockRateLimiter[K comparable](context string, config types.MaxPerNBlocksRateLimit) RateLimiter[K]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL