types

package
v0.0.0-...-a766bce Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EventTypeSourceCallback is the event type for a source callback
	EventTypeSourceCallback = "ibc_src_callback"
	// EventTypeDestinationCallback is the event type for a destination callback
	EventTypeDestinationCallback = "ibc_dest_callback"

	// AttributeKeyCallbackType denotes the condition that the callback is executed on:
	//   "acknowledgement": the callback is executed on the acknowledgement of the packet
	//   "timeout": the callback is executed on the timeout of the packet
	//   "recv_packet": the callback is executed on the reception of the packet
	AttributeKeyCallbackType = "callback_type"
	// AttributeKeyCallbackAddress denotes the callback address
	AttributeKeyCallbackAddress = "callback_address"
	// AttributeKeyCallbackResult denotes the callback result:
	//   AttributeValueCallbackSuccess: the callback is successfully executed
	//   AttributeValueCallbackFailure: the callback has failed to execute
	AttributeKeyCallbackResult = "callback_result"
	// AttributeKeyCallbackError denotes the callback error message
	// if no error is returned, then this key will not be included in the event
	AttributeKeyCallbackError = "callback_error"
	// AttributeKeyCallbackGasLimit denotes the custom gas limit for the callback execution
	// if custom gas limit is not in effect, then this key will not be included in the event
	AttributeKeyCallbackGasLimit = "callback_exec_gas_limit"
	// AttributeKeyCallbackCommitGasLimit denotes the gas needed to commit the callback even
	// if the callback execution fails due to out of gas.
	AttributeKeyCallbackCommitGasLimit = "callback_commit_gas_limit"
	// AttributeKeyCallbackSourcePortID denotes the source port ID of the packet
	AttributeKeyCallbackSourcePortID = "packet_src_port"
	// AttributeKeyCallbackSourceChannelID denotes the source channel ID of the packet
	AttributeKeyCallbackSourceChannelID = "packet_src_channel"
	// AttributeKeyCallbackDestPortID denotes the destination port ID of the packet
	AttributeKeyCallbackDestPortID = "packet_dest_port"
	// AttributeKeyCallbackDestChannelID denotes the destination channel ID of the packet
	AttributeKeyCallbackDestChannelID = "packet_dest_channel"
	// AttributeKeyCallbackSequence denotes the sequence of the packet
	AttributeKeyCallbackSequence = "packet_sequence"
	// AttributeKeyCallbackBaseApplicationVersion denotes the callback base application version
	AttributeKeyCallbackBaseApplicationVersion = "callback_base_application_version"
	// AttributeValueCallbackSuccess denotes that the callback is successfully executed
	AttributeValueCallbackSuccess = "success"
	// AttributeValueCallbackFailure denotes that the callback has failed to execute
	AttributeValueCallbackFailure = "failure"
)
View Source
const (
	ModuleName = "ibccallbacks"

	CallbackTypeSendPacket            CallbackType = "send_packet"
	CallbackTypeAcknowledgementPacket CallbackType = "acknowledgement_packet"
	CallbackTypeTimeoutPacket         CallbackType = "timeout_packet"
	CallbackTypeReceivePacket         CallbackType = "receive_packet"

	// Source callback packet data is set inside the underlying packet data using the this key.
	// ICS20 and ICS27 will store the callback packet data in the memo field as a json object.
	// The expected format is as follows:
	// {"src_callback": { ... }}
	SourceCallbackKey = "src_callback"
	// Destination callback packet data is set inside the underlying packet data using the this key.
	// ICS20 and ICS27 will store the callback packet data in the memo field as a json object.
	// The expected format is as follows:
	// {"dest_callback": { ... }}
	DestinationCallbackKey = "dest_callback"
	// Callbacks' packet data is expected to contain the callback address under this key.
	// The expected format for ICS20 and ICS27 memo field is as follows:
	// { "{callbackKey}": { "address": {stringCallbackAddress}}
	CallbackAddressKey = "address"
	// Callbacks' packet data is expected to specify the user defined gas limit under this key.
	// The expected format for ICS20 and ICS27 memo field is as follows:
	// { "{callbackKey}": { ... , "gas_limit": {stringForCallback} }
	UserDefinedGasLimitKey = "gas_limit"
)

Variables

View Source
var (
	ErrCannotUnmarshalPacketData = errorsmod.Register(ModuleName, 2, "cannot unmarshal packet data")
	ErrNotPacketDataProvider     = errorsmod.Register(ModuleName, 3, "packet is not a PacketDataProvider")
	ErrCallbackKeyNotFound       = errorsmod.Register(ModuleName, 4, "callback key not found in packet data")
	ErrCallbackAddressNotFound   = errorsmod.Register(ModuleName, 5, "callback address not found in packet data")
	ErrCallbackOutOfGas          = errorsmod.Register(ModuleName, 6, "callback out of gas")
	ErrCallbackPanic             = errorsmod.Register(ModuleName, 7, "callback panic")
)

Functions

func EmitCallbackEvent

func EmitCallbackEvent(
	ctx sdk.Context,
	portID,
	channelID string,
	sequence uint64,
	callbackType CallbackType,
	callbackData CallbackData,
	err error,
)

EmitCallbackEvent emits an event for a callback

Types

type CallbackData

type CallbackData struct {
	// CallbackAddress is the address of the callback actor.
	CallbackAddress string
	// ExecutionGasLimit is the gas limit which will be used for the callback execution.
	ExecutionGasLimit uint64
	// SenderAddress is the sender of the packet. This is passed to the contract keeper
	// to verify that the packet sender is the same as the callback address if desired.
	// This address is empty during destination callback execution.
	// This address may be empty if the sender is unknown or undefined.
	SenderAddress string
	// CommitGasLimit is the gas needed to commit the callback even if the callback
	// execution fails due to out of gas.
	// This parameter is only used in event emissions, or logging.
	CommitGasLimit uint64
	// ApplicationVersion is the base application version.
	ApplicationVersion string
}

CallbackData is the callback data parsed from the packet.

func GetDestCallbackData

func GetDestCallbackData(
	ctx sdk.Context,
	packetDataUnmarshaler porttypes.PacketDataUnmarshaler,
	packet channeltypes.Packet, maxGas uint64,
) (CallbackData, error)

GetDestCallbackData parses the packet data and returns the destination callback data.

func GetSourceCallbackData

func GetSourceCallbackData(
	ctx sdk.Context,
	packetDataUnmarshaler porttypes.PacketDataUnmarshaler,
	packet channeltypes.Packet,
	maxGas uint64,
) (CallbackData, error)

GetSourceCallbackData parses the packet data and returns the source callback data.

func (CallbackData) AllowRetry

func (c CallbackData) AllowRetry() bool

AllowRetry returns true if the callback execution gas limit is less than the commit gas limit.

type CallbackType

type CallbackType string

type CallbacksCompatibleModule

type CallbacksCompatibleModule interface {
	porttypes.IBCModule
	porttypes.PacketDataUnmarshaler
}

CallbacksCompatibleModule is an interface that combines the IBCModule and PacketDataUnmarshaler interfaces to assert that the underlying application supports both.

type ContractKeeper

type ContractKeeper interface {
	// IBCSendPacketCallback is called in the source chain when a PacketSend is executed. The
	// packetSenderAddress is determined by the underlying module, and may be empty if the sender is
	// unknown or undefined. The contract is expected to handle the callback within the user defined
	// gas limit, and handle any errors, or panics gracefully.
	// This entry point is called with a cached context. If an error is returned, then the changes in
	// this context will not be persisted, and the error will be propagated to the underlying IBC
	// application, resulting in a packet send failure.
	//
	// Implementations are provided with the packetSenderAddress and MAY choose to use this to perform
	// validation on the origin of a given packet. It is recommended to perform the same validation
	// on all source chain callbacks (SendPacket, AcknowledgementPacket, TimeoutPacket). This
	// defensively guards against exploits due to incorrectly wired SendPacket ordering in IBC stacks.
	//
	// The version provided is the base application version for the given packet send. This allows
	// contracts to determine how to unmarshal the packetData.
	IBCSendPacketCallback(
		cachedCtx sdk.Context,
		sourcePort string,
		sourceChannel string,
		timeoutHeight clienttypes.Height,
		timeoutTimestamp uint64,
		packetData []byte,
		contractAddress,
		packetSenderAddress string,
		version string,
	) error
	// IBCOnAcknowledgementPacketCallback is called in the source chain when a packet acknowledgement
	// is received. The packetSenderAddress is determined by the underlying module, and may be empty if
	// the sender is unknown or undefined. The contract is expected to handle the callback within the
	// user defined gas limit, and handle any errors, or panics gracefully.
	// This entry point is called with a cached context. If an error is returned, then the changes in
	// this context will not be persisted, but the packet lifecycle will not be blocked.
	//
	// Implementations are provided with the packetSenderAddress and MAY choose to use this to perform
	// validation on the origin of a given packet. It is recommended to perform the same validation
	// on all source chain callbacks (SendPacket, AcknowledgementPacket, TimeoutPacket). This
	// defensively guards against exploits due to incorrectly wired SendPacket ordering in IBC stacks.
	//
	// The version provided is the base application version for the given packet send. This allows
	// contracts to determine how to unmarshal the packetData.
	IBCOnAcknowledgementPacketCallback(
		cachedCtx sdk.Context,
		packet channeltypes.Packet,
		acknowledgement []byte,
		relayer sdk.AccAddress,
		contractAddress,
		packetSenderAddress string,
		version string,
	) error
	// IBCOnTimeoutPacketCallback is called in the source chain when a packet is not received before
	// the timeout height. The packetSenderAddress is determined by the underlying module, and may be
	// empty if the sender is unknown or undefined. The contract is expected to handle the callback
	// within the user defined gas limit, and handle any error, out of gas, or panics gracefully.
	// This entry point is called with a cached context. If an error is returned, then the changes in
	// this context will not be persisted, but the packet lifecycle will not be blocked.
	//
	// Implementations are provided with the packetSenderAddress and MAY choose to use this to perform
	// validation on the origin of a given packet. It is recommended to perform the same validation
	// on all source chain callbacks (SendPacket, AcknowledgementPacket, TimeoutPacket). This
	// defensively guards against exploits due to incorrectly wired SendPacket ordering in IBC stacks.
	//
	// The version provided is the base application version for the given packet send. This allows
	// contracts to determine how to unmarshal the packetData.
	IBCOnTimeoutPacketCallback(
		cachedCtx sdk.Context,
		packet channeltypes.Packet,
		relayer sdk.AccAddress,
		contractAddress,
		packetSenderAddress string,
		version string,
	) error
	// IBCReceivePacketCallback is called in the destination chain when a packet acknowledgement is written.
	// The contract is expected to handle the callback within the user defined gas limit, and handle any errors,
	// out of gas, or panics gracefully.
	// This entry point is called with a cached context. If an error is returned, then the changes in
	// this context will not be persisted, but the packet lifecycle will not be blocked.
	//
	// The version provided is the base application version for the given packet send. This allows
	// contracts to determine how to unmarshal the packetData.
	IBCReceivePacketCallback(
		cachedCtx sdk.Context,
		packet ibcexported.PacketI,
		ack ibcexported.Acknowledgement,
		contractAddress string,
		version string,
	) error
}

ContractKeeper defines the entry points exposed to the VM module which invokes a smart contract

Jump to

Keyboard shortcuts

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