rate_limit

package
v0.0.0-...-baf6593 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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
	// Prunes rate limits for the provided context.
	PruneRateLimits(ctx sdk.Context)
}

Used to RateLimit for a key K.

func NewCancelOrderRateLimiter

func NewCancelOrderRateLimiter(config types.BlockRateLimitConfiguration) RateLimiter[*types.MsgCancelOrder]

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

  • how many short term order cancellations 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 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 NewPlaceOrderRateLimiter

func NewPlaceOrderRateLimiter(config types.BlockRateLimitConfiguration) RateLimiter[*types.MsgPlaceOrder]

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

  • how many short term 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