keeper

package
v14.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: Apache-2.0, Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitTransferDeniedEvent

func EmitTransferDeniedEvent(ctx sdk.Context, reason, denom, channelId string, direction types.PacketDirection, amount sdkmath.Int, err error)

If the rate limit is exceeded or the denom is blacklisted, we emit an event

func GetRateLimitItemKey

func GetRateLimitItemKey(denom string, channelId string) []byte

Get the rate limit byte key built from the denom and channelId

func ParseDenomFromRecvPacket

func ParseDenomFromRecvPacket(packet channeltypes.Packet, packetData transfertypes.FungibleTokenPacketData) (denom string)

Parse the denom from the Recv Packet that will be used by the rate limit module The denom that the rate limiter will use for a RECEIVE packet depends on whether it was a source or sink

Sink:   The token moves forward, to a chain different than its previous hop
        The new port and channel are APPENDED to the denom trace.
        (e.g. A -> B, B is a sink) (e.g. A -> B -> C, C is a sink)

Source: The token moves backwards (i.e. revisits the last chain it was sent from)
        The port and channel are REMOVED from the denom trace - undoing the last hop.
        (e.g. A -> B -> A, A is a source) (e.g. A -> B -> C -> B, B is a source)

If the chain is acting as a SINK: We add on the Stride port and channel and hash it
  Ex1: uosmo sent from Osmosis to Stride
       Packet Denom:   uosmo
        -> Add Prefix: transfer/channel-X/uosmo
        -> Hash:       ibc/...

  Ex2: ujuno sent from Osmosis to Stride
       PacketDenom:    transfer/channel-Y/ujuno  (channel-Y is the Juno <> Osmosis channel)
        -> Add Prefix: transfer/channel-X/transfer/channel-Y/ujuno
        -> Hash:       ibc/...

If the chain is acting as a SOURCE: First, remove the prefix. Then if there is still a denom trace, hash it
  Ex1: ustrd sent back to Stride from Osmosis
       Packet Denom:      transfer/channel-X/ustrd
        -> Remove Prefix: ustrd
        -> Leave as is:   ustrd

  Ex2: juno was sent to Stride, then to Osmosis, then back to Stride
       Packet Denom:      transfer/channel-X/transfer/channel-Z/ujuno
        -> Remove Prefix: transfer/channel-Z/ujuno
        -> Hash:          ibc/...

func ParseDenomFromSendPacket

func ParseDenomFromSendPacket(packet transfertypes.FungibleTokenPacketData) (denom string)

Parse the denom from the Send Packet that will be used by the rate limit module The denom that the rate limiter will use for a SEND packet depends on whether it was a NATIVE token (e.g. ustrd, stuatom, etc.) or NON-NATIVE token (e.g. ibc/...)...

We can identify if the token is native or not by parsing the trace denom from the packet If the token is NATIVE, it will not have a prefix (e.g. ustrd), and if it is NON-NATIVE, it will have a prefix (e.g. transfer/channel-2/uosmo)

For NATIVE denoms, return as is (e.g. ustrd) For NON-NATIVE denoms, take the ibc hash (e.g. hash "transfer/channel-2/usoms" into "ibc/...")

Types

type Hooks

type Hooks struct {
	// contains filtered or unexported fields
}

func (Hooks) AfterEpochEnd

func (h Hooks) AfterEpochEnd(ctx sdk.Context, epochInfo epochstypes.EpochInfo)

func (Hooks) BeforeEpochStart

func (h Hooks) BeforeEpochStart(ctx sdk.Context, epochInfo epochstypes.EpochInfo)

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	key storetypes.StoreKey,
	ps paramtypes.Subspace,
	bankKeeper types.BankKeeper,
	channelKeeper types.ChannelKeeper,
	ics4Wrapper types.ICS4Wrapper,
) *Keeper

func (Keeper) AcknowledgeRateLimitedPacket

func (k Keeper) AcknowledgeRateLimitedPacket(ctx sdk.Context, packet channeltypes.Packet, acknowledgement []byte) error

Middleware implementation for OnAckPacket with rate limiting If the packet failed, we should decrement the Outflow

func (Keeper) AddDenomToBlacklist

func (k Keeper) AddDenomToBlacklist(ctx sdk.Context, denom string)

Adds a denom to a blacklist to prevent all IBC transfers with this denom

func (Keeper) AfterEpochEnd

func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochInfo epochstypes.EpochInfo)

func (Keeper) AllBlacklistedDenoms

Query all blacklisted denoms

func (Keeper) AllRateLimits

Query all rate limits

func (Keeper) AllWhitelistedAddresses

Query all whitelisted addresses

func (Keeper) BeforeEpochStart

func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochInfo epochstypes.EpochInfo)

Before each hour epoch, check if any of the rate limits have expired,

and reset them if they have

func (Keeper) CheckPacketSentDuringCurrentQuota

func (k Keeper) CheckPacketSentDuringCurrentQuota(ctx sdk.Context, channelId string, sequence uint64) bool

Checks whether the packet sequence number is in the store - indicating that it was sent during the current quota

func (Keeper) CheckRateLimitAndUpdateFlow

func (k Keeper) CheckRateLimitAndUpdateFlow(
	ctx sdk.Context,
	direction types.PacketDirection,
	packetInfo RateLimitedPacketInfo,
) (updatedFlow bool, err error)

Checks whether the given packet will exceed the rate limit Called by OnRecvPacket and OnSendPacket

func (Keeper) GetAllBlacklistedDenoms

func (k Keeper) GetAllBlacklistedDenoms(ctx sdk.Context) []string

Get all the blacklisted denoms

func (Keeper) GetAllPendingSendPackets

func (k Keeper) GetAllPendingSendPackets(ctx sdk.Context) []string

Get all pending packet sequence numbers

func (Keeper) GetAllRateLimits

func (k Keeper) GetAllRateLimits(ctx sdk.Context) []types.RateLimit

Returns all rate limits stored

func (Keeper) GetAllWhitelistedAddressPairs

func (k Keeper) GetAllWhitelistedAddressPairs(ctx sdk.Context) []types.WhitelistedAddressPair

Get all the whitelisted addresses

func (Keeper) GetAppVersion

func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool)

GetAppVersion wraps IBC ChannelKeeper's GetAppVersion function

func (Keeper) GetChannelValue

func (k Keeper) GetChannelValue(ctx sdk.Context, denom string) sdkmath.Int

The total value on a given path (aka, the denominator in the percentage calculation) is the total supply of the given denom

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) types.Params

GetParams get all parameters as types.Params

func (Keeper) GetRateLimit

func (k Keeper) GetRateLimit(ctx sdk.Context, denom string, channelId string) (rateLimit types.RateLimit, found bool)

Grabs and returns a rate limit object from the store using denom and channel-id

func (Keeper) Hooks

func (k Keeper) Hooks() Hooks

func (Keeper) IsAddressPairWhitelisted

func (k Keeper) IsAddressPairWhitelisted(ctx sdk.Context, sender, receiver string) bool

Check if a sender/receiver address pair is currently whitelisted

func (Keeper) IsDenomBlacklisted

func (k Keeper) IsDenomBlacklisted(ctx sdk.Context, denom string) bool

Check if a denom is currently blacklisted

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

func (Keeper) RateLimit

Query a rate limit by denom and channelId

func (Keeper) RateLimitsByChainId

Query all rate limits for a given chain

func (Keeper) RateLimitsByChannelId

Query all rate limits for a given channel

func (Keeper) ReceiveRateLimitedPacket

func (k Keeper) ReceiveRateLimitedPacket(ctx sdk.Context, packet channeltypes.Packet) error

Middleware implementation for RecvPacket with rate limiting Checks whether the rate limit has been exceeded - and if it hasn't, allows the packet

func (Keeper) RemoveAllChannelPendingSendPackets

func (k Keeper) RemoveAllChannelPendingSendPackets(ctx sdk.Context, channelId string)

Remove all pending sequence numbers from the store This is executed when the quota resets

func (Keeper) RemoveDenomFromBlacklist

func (k Keeper) RemoveDenomFromBlacklist(ctx sdk.Context, denom string)

Removes a denom from a blacklist to re-enable IBC transfers for that denom

func (Keeper) RemovePendingSendPacket

func (k Keeper) RemovePendingSendPacket(ctx sdk.Context, channelId string, sequence uint64)

Remove a pending packet sequence number from the store Used after the ack or timeout for a packet has been received

func (Keeper) RemoveRateLimit

func (k Keeper) RemoveRateLimit(ctx sdk.Context, denom string, channelId string)

Removes a rate limit object from the store using denom and channel-id

func (Keeper) RemoveWhitelistedAddressPair

func (k Keeper) RemoveWhitelistedAddressPair(ctx sdk.Context, sender, receiver string)

Removes a whitelisted address pair so that it's transfers are counted in the quota

func (Keeper) ResetRateLimit

func (k Keeper) ResetRateLimit(ctx sdk.Context, denom string, channelId string) error

Reset the rate limit after expiration The inflow and outflow should get reset to 0, the channelValue should be updated, and all pending send packet sequence numbers should be removed

func (Keeper) SendPacket

func (k Keeper) SendPacket(
	ctx sdk.Context,
	channelCap *capabilitytypes.Capability,
	sourcePort string,
	sourceChannel string,
	timeoutHeight clienttypes.Height,
	timeoutTimestamp uint64,
	data []byte,
) (sequence uint64, err error)

SendPacket wraps IBC ChannelKeeper's SendPacket function If the packet does not get rate limited, it passes the packet to the IBC Channel keeper

func (Keeper) SendRateLimitedPacket

func (k Keeper) SendRateLimitedPacket(ctx sdk.Context, packet channeltypes.Packet) error

Middleware implementation for SendPacket with rate limiting Checks whether the rate limit has been exceeded - and if it hasn't, sends the packet

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params types.Params)

SetParams set the params

func (Keeper) SetPendingSendPacket

func (k Keeper) SetPendingSendPacket(ctx sdk.Context, channelId string, sequence uint64)

Sets the sequence number of a packet that was just sent

func (Keeper) SetRateLimit

func (k Keeper) SetRateLimit(ctx sdk.Context, rateLimit types.RateLimit)

Stores/Updates a rate limit object in the store

func (Keeper) SetWhitelistedAddressPair

func (k Keeper) SetWhitelistedAddressPair(ctx sdk.Context, whitelist types.WhitelistedAddressPair)

Adds an pair of sender and receiver addresses to the whitelist to allow all IBC transfers between those addresses to skip all flow calculations

func (Keeper) TimeoutRateLimitedPacket

func (k Keeper) TimeoutRateLimitedPacket(ctx sdk.Context, packet channeltypes.Packet) error

Middleware implementation for OnAckPacket with rate limiting The Outflow should be decremented from the failed packet

func (Keeper) UndoSendPacket

func (k Keeper) UndoSendPacket(ctx sdk.Context, channelId string, sequence uint64, denom string, amount sdkmath.Int) error

If a SendPacket fails or times out, undo the outflow increment that happened during the send

func (Keeper) UpdateFlow

func (k Keeper) UpdateFlow(rateLimit types.RateLimit, direction types.PacketDirection, amount sdkmath.Int) error

Adds an amount to the flow in either the SEND or RECV direction

func (Keeper) WriteAcknowledgement

func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error

WriteAcknowledgement wraps IBC ChannelKeeper's WriteAcknowledgement function

type RateLimitedPacketInfo

type RateLimitedPacketInfo struct {
	ChannelID string
	Denom     string
	Amount    sdkmath.Int
	Sender    string
	Receiver  string
}

func ParsePacketInfo

func ParsePacketInfo(packet channeltypes.Packet, direction types.PacketDirection) (RateLimitedPacketInfo, error)

Parses the sender and channelId and denom for the corresponding RateLimit object, and the sender/receiver/transfer amount

The Stride channelID should always be used as the key for the RateLimit object (not the counterparty channelID) For a SEND packet, the Stride channelID is the SOURCE channel For a RECEIVE packet, the Stride channelID is the DESTINATION channel

The Source and Desination are defined from the perspective of a packet recipient Meaning, when a send packet lands on a the host chain, the "Source" will be the Stride Channel, and the "Destination" will be the Host Channel And, when a receive packet lands on a Stride, the "Source" will be the host zone's channel, and the "Destination" will be the Stride Channel

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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