ratelimiter

package
v0.0.0-...-2da98db Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ratelimiter provides functionalities for rate limiting the cross-chain transactions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRateLimiterUsable

func IsRateLimiterUsable(rateLimiterFlags crosschaintypes.RateLimiterFlags) bool

IsRateLimiterUsable checks if the rate limiter is usable or not

Types

type Input

type Input struct {
	// zeta chain height
	Height int64

	// the missed cctxs in range [?, NonceLow) across all chains
	CctxsMissed []*crosschaintypes.CrossChainTx

	// the pending cctxs in range [NonceLow, NonceHigh) across all chains
	CctxsPending []*crosschaintypes.CrossChainTx

	// the total value of the past cctxs within window across all chains
	PastCctxsValue sdkmath.Int

	// the total value of the pending cctxs across all chains
	PendingCctxsValue sdkmath.Int

	// the lowest height of the pending (not missed) cctxs across all chains
	LowestPendingCctxHeight int64
}

Input is the input data for the rate limiter

func NewInput

NewInput creates a rate limiter input from gRPC response

type Output

type Output struct {
	// the cctxs to be scheduled after rate limit check
	CctxsMap map[int64][]*crosschaintypes.CrossChainTx

	// the current sliding window within which the withdrawals are considered by the rate limiter
	CurrentWithdrawWindow int64

	// the current withdraw rate (azeta/block) within the current sliding window
	CurrentWithdrawRate sdkmath.Int

	// wehther the current withdraw rate exceeds the given rate limit or not
	RateLimitExceeded bool
}

Output is the output data for the rate limiter

func ApplyRateLimiter

func ApplyRateLimiter(input *Input, window int64, rate sdkmath.Uint) *Output

ApplyRateLimiter applies the rate limiter to the input and produces output

Jump to

Keyboard shortcuts

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