Documentation ¶
Index ¶
- func EmitTransferDeniedEvent(ctx sdk.Context, reason, denom, channelId string, ...)
- func GetRateLimitItemKey(denom string, channelId string) []byte
- func ParseDenomFromRecvPacket(packet channeltypes.Packet, packetData transfertypes.FungibleTokenPacketData) (denom string)
- func ParseDenomFromSendPacket(packet transfertypes.FungibleTokenPacketData) (denom string)
- type Hooks
- type Keeper
- func (k Keeper) AcknowledgeRateLimitedPacket(ctx sdk.Context, packet channeltypes.Packet, acknowledgement []byte) error
- func (k Keeper) AddDenomToBlacklist(ctx sdk.Context, denom string)
- func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochInfo epochstypes.EpochInfo)
- func (k Keeper) AllBlacklistedDenoms(c context.Context, req *types.QueryAllBlacklistedDenomsRequest) (*types.QueryAllBlacklistedDenomsResponse, error)
- func (k Keeper) AllRateLimits(c context.Context, req *types.QueryAllRateLimitsRequest) (*types.QueryAllRateLimitsResponse, error)
- func (k Keeper) AllWhitelistedAddresses(c context.Context, req *types.QueryAllWhitelistedAddressesRequest) (*types.QueryAllWhitelistedAddressesResponse, error)
- func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochInfo epochstypes.EpochInfo)
- func (k Keeper) CheckPacketSentDuringCurrentQuota(ctx sdk.Context, channelId string, sequence uint64) bool
- func (k Keeper) CheckRateLimitAndUpdateFlow(ctx sdk.Context, direction types.PacketDirection, ...) (updatedFlow bool, err error)
- func (k Keeper) GetAllBlacklistedDenoms(ctx sdk.Context) []string
- func (k Keeper) GetAllPendingSendPackets(ctx sdk.Context) []string
- func (k Keeper) GetAllRateLimits(ctx sdk.Context) []types.RateLimit
- func (k Keeper) GetAllWhitelistedAddressPairs(ctx sdk.Context) []types.WhitelistedAddressPair
- func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool)
- func (k Keeper) GetChannelValue(ctx sdk.Context, denom string) sdkmath.Int
- func (k Keeper) GetParams(ctx sdk.Context) types.Params
- func (k Keeper) GetRateLimit(ctx sdk.Context, denom string, channelId string) (rateLimit types.RateLimit, found bool)
- func (k Keeper) Hooks() Hooks
- func (k Keeper) IsAddressPairWhitelisted(ctx sdk.Context, sender, receiver string) bool
- func (k Keeper) IsDenomBlacklisted(ctx sdk.Context, denom string) bool
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) RateLimit(c context.Context, req *types.QueryRateLimitRequest) (*types.QueryRateLimitResponse, error)
- func (k Keeper) RateLimitsByChainId(c context.Context, req *types.QueryRateLimitsByChainIdRequest) (*types.QueryRateLimitsByChainIdResponse, error)
- func (k Keeper) RateLimitsByChannelId(c context.Context, req *types.QueryRateLimitsByChannelIdRequest) (*types.QueryRateLimitsByChannelIdResponse, error)
- func (k Keeper) ReceiveRateLimitedPacket(ctx sdk.Context, packet channeltypes.Packet) error
- func (k Keeper) RemoveAllChannelPendingSendPackets(ctx sdk.Context, channelId string)
- func (k Keeper) RemoveDenomFromBlacklist(ctx sdk.Context, denom string)
- func (k Keeper) RemovePendingSendPacket(ctx sdk.Context, channelId string, sequence uint64)
- func (k Keeper) RemoveRateLimit(ctx sdk.Context, denom string, channelId string)
- func (k Keeper) RemoveWhitelistedAddressPair(ctx sdk.Context, sender, receiver string)
- func (k Keeper) ResetRateLimit(ctx sdk.Context, denom string, channelId string) error
- func (k Keeper) SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort string, ...) (sequence uint64, err error)
- func (k Keeper) SendRateLimitedPacket(ctx sdk.Context, packet channeltypes.Packet) error
- func (k Keeper) SetParams(ctx sdk.Context, params types.Params)
- func (k Keeper) SetPendingSendPacket(ctx sdk.Context, channelId string, sequence uint64)
- func (k Keeper) SetRateLimit(ctx sdk.Context, rateLimit types.RateLimit)
- func (k Keeper) SetWhitelistedAddressPair(ctx sdk.Context, whitelist types.WhitelistedAddressPair)
- func (k Keeper) TimeoutRateLimitedPacket(ctx sdk.Context, packet channeltypes.Packet) error
- func (k Keeper) UndoSendPacket(ctx sdk.Context, channelId string, sequence uint64, denom string, ...) error
- func (k Keeper) UpdateFlow(rateLimit types.RateLimit, direction types.PacketDirection, amount sdkmath.Int) error
- func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, ...) error
- type RateLimitedPacketInfo
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 ¶
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 ¶
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 ¶
func (k Keeper) AllBlacklistedDenoms(c context.Context, req *types.QueryAllBlacklistedDenomsRequest) (*types.QueryAllBlacklistedDenomsResponse, error)
Query all blacklisted denoms
func (Keeper) AllRateLimits ¶
func (k Keeper) AllRateLimits(c context.Context, req *types.QueryAllRateLimitsRequest) (*types.QueryAllRateLimitsResponse, error)
Query all rate limits
func (Keeper) AllWhitelistedAddresses ¶
func (k Keeper) AllWhitelistedAddresses(c context.Context, req *types.QueryAllWhitelistedAddressesRequest) (*types.QueryAllWhitelistedAddressesResponse, error)
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 ¶
Get all the blacklisted denoms
func (Keeper) GetAllPendingSendPackets ¶
Get all pending packet sequence numbers
func (Keeper) GetAllRateLimits ¶
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 ¶
GetAppVersion wraps IBC ChannelKeeper's GetAppVersion function
func (Keeper) GetChannelValue ¶
The total value on a given path (aka, the denominator in the percentage calculation) is the total supply of the given denom
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) IsAddressPairWhitelisted ¶
Check if a sender/receiver address pair is currently whitelisted
func (Keeper) IsDenomBlacklisted ¶
Check if a denom is currently blacklisted
func (Keeper) RateLimit ¶
func (k Keeper) RateLimit(c context.Context, req *types.QueryRateLimitRequest) (*types.QueryRateLimitResponse, error)
Query a rate limit by denom and channelId
func (Keeper) RateLimitsByChainId ¶
func (k Keeper) RateLimitsByChainId(c context.Context, req *types.QueryRateLimitsByChainIdRequest) (*types.QueryRateLimitsByChainIdResponse, error)
Query all rate limits for a given chain
func (Keeper) RateLimitsByChannelId ¶
func (k Keeper) RateLimitsByChannelId(c context.Context, req *types.QueryRateLimitsByChannelIdRequest) (*types.QueryRateLimitsByChannelIdResponse, error)
Query all rate limits for a given channel
func (Keeper) ReceiveRateLimitedPacket ¶
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 ¶
Remove all pending sequence numbers from the store This is executed when the quota resets
func (Keeper) RemoveDenomFromBlacklist ¶
Removes a denom from a blacklist to re-enable IBC transfers for that denom
func (Keeper) RemovePendingSendPacket ¶
Remove a pending packet sequence number from the store Used after the ack or timeout for a packet has been received
func (Keeper) RemoveRateLimit ¶
Removes a rate limit object from the store using denom and channel-id
func (Keeper) RemoveWhitelistedAddressPair ¶
Removes a whitelisted address pair so that it's transfers are counted in the quota
func (Keeper) ResetRateLimit ¶
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 ¶
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) SetPendingSendPacket ¶
Sets the sequence number of a packet that was just sent
func (Keeper) SetRateLimit ¶
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 ¶
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