relayer

package
v2.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 29 Imported by: 6

Documentation

Index

Constants

View Source
const (
	ProcessorEvents              string = "events"
	ProcessorLegacy                     = "legacy"
	DefaultClientUpdateThreshold        = 0 * time.Millisecond
	DefaultFlushInterval                = 5 * time.Minute
	DefaultMaxMsgLength                 = 5
	TwoMB                               = 2 * 1024 * 1024
)
View Source
const (
	Expired = "EXPIRED"
)

Variables

View Source
var (
	RtyAttNum = uint(5)
	RtyAtt    = retry.Attempts(RtyAttNum)
	RtyDel    = retry.Delay(time.Millisecond * 400)
	RtyErr    = retry.LastErrorOnly(true)
)

Functions

func AddMessagesForSequences added in v2.1.0

func AddMessagesForSequences(
	ctx context.Context,
	sequences []uint64,
	src, dst *Chain,
	srch, dsth int64,
	srcMsgs, dstMsgs *[]provider.RelayerMessage,
	srcChanID, srcPortID, dstChanID, dstPortID string,
	order chantypes.Order,
) error

AddMessagesForSequences constructs RecvMsgs and TimeoutMsgs from sequence numbers on a src chain and adds them to the appropriate queue of msgs for both src and dst

func CreateClient added in v2.1.0

func CreateClient(
	ctx context.Context,
	src, dst *Chain,
	srcUpdateHeader, dstUpdateHeader provider.IBCHeader,
	allowUpdateAfterExpiry,
	allowUpdateAfterMisbehaviour,
	override bool,
	customClientTrustingPeriod,
	overrideUnbondingPeriod,
	maxClockDrift time.Duration,
	customClientTrustingPeriodPercentage int64,
	memo string) (string, error)

CreateClient creates client tracking dst on src.

func MsgUpdateClient added in v2.1.0

func MsgUpdateClient(
	ctx context.Context,
	src, dst *Chain,
	srch, dsth int64,
) (provider.RelayerMessage, error)

MsgUpdateClient queries for the current client state on dst, then queries for the latest and trusted headers on src in order to build a MsgUpdateClient message for dst.

func MustGetHeight added in v2.1.0

func MustGetHeight(h ibcexported.Height) clienttypes.Height

MustGetHeight takes the height inteface and returns the actual height

func OrderFromString

func OrderFromString(order string) chantypes.Order

OrderFromString parses a string into a channel order byte

func ParseChannelIDFromEvents

func ParseChannelIDFromEvents(events []provider.RelayerEvent) (string, error)

ParseChannelIDFromEvents parses events emitted from a MsgChannelOpenInit or MsgChannelOpenTry and returns the channel identifier.

func ParseClientIDFromEvents

func ParseClientIDFromEvents(events []provider.RelayerEvent) (string, error)

ParseClientIDFromEvents parses events emitted from a MsgCreateClient and returns the client identifier.

func ParseConnectionIDFromEvents

func ParseConnectionIDFromEvents(events []provider.RelayerEvent) (string, error)

ParseConnectionIDFromEvents parses events emitted from a MsgConnectionOpenInit or MsgConnectionOpenTry and returns the connection identifier.

func QueryBalance added in v2.1.0

func QueryBalance(ctx context.Context, chain *Chain, address string, showDenoms bool) (sdk.Coins, error)

QueryBalance is a helper function for query balance

func QueryChannel added in v2.1.0

func QueryChannel(ctx context.Context, src *Chain, channelID string) (*chantypes.IdentifiedChannel, error)

func QueryClientStates added in v2.1.0

func QueryClientStates(ctx context.Context,
	srch, dsth int64,
	src, dst *Chain,
) (ibcexported.ClientState, ibcexported.ClientState, error)

QueryClientStates queries the client state of multiple chains at once

func QueryIBCHeaders added in v2.1.0

func QueryIBCHeaders(ctx context.Context, src, dst *Chain, srch, dsth int64) (srcUpdateHeader, dstUpdateHeader provider.IBCHeader, err error)

func QueryIBCUpdateHeaders added in v2.1.0

func QueryIBCUpdateHeaders(
	ctx context.Context,
	srcClientID, dstClientID string,
	src, dst provider.ChainProvider,
	srch, dsth int64,
	srcTrustedH, dstTrustedH int64,
) (srcHeader, dstHeader, srcTrustedHeader, dstTrustedHeader provider.IBCHeader, err error)

QueryIBCUpdateHeaders returns a pair of IBC update headers which can be used to update an on chain light client

func QueryLatestHeights

func QueryLatestHeights(ctx context.Context, src, dst *Chain) (srch, dsth int64, err error)

QueryLatestHeights queries the heights of multiple chains at once

func QueryPortChannel added in v2.1.0

func QueryPortChannel(ctx context.Context, src *Chain, portID string) (*chantypes.IdentifiedChannel, error)

func RelayAcknowledgements

func RelayAcknowledgements(ctx context.Context, log *zap.Logger, src, dst *Chain, sp RelaySequences, maxTxSize, maxMsgLength uint64, memo string, srcChannel *chantypes.IdentifiedChannel) error

RelayAcknowledgements creates transactions to relay acknowledgements from src to dst and from dst to src

func RelayPackets

func RelayPackets(ctx context.Context, log *zap.Logger, src, dst *Chain, sp RelaySequences, maxTxSize, maxMsgLength uint64, memo string, srcChannel *chantypes.IdentifiedChannel) error

RelayPackets creates transactions to relay packets from src to dst and from dst to src

func SPrintClientExpiration added in v2.3.0

func SPrintClientExpiration(chain *Chain, expiration time.Time, clientInfo ClientStateInfo) string

func SPrintClientExpirationJson added in v2.4.2

func SPrintClientExpirationJson(chain *Chain, expiration time.Time, clientInfo ClientStateInfo) string

Returns clientExpiration data in JSON format.

func StartRelayer

func StartRelayer(
	ctx context.Context,
	log *zap.Logger,
	chains map[string]*Chain,
	paths []NamedPath,
	maxMsgLength uint64,
	maxReceiverSize,
	memoLimit int,
	memo string,
	clientUpdateThresholdTime time.Duration,
	flushInterval time.Duration,
	messageLifecycle processor.MessageLifecycle,
	processorType string,
	initialBlockHistory uint64,
	metrics *processor.PrometheusMetrics,
	stuckPacket *processor.StuckPacket,
) chan error

StartRelayer starts the main relaying loop and returns a channel that will contain any control-flow related errors.

func StringFromOrder added in v2.1.0

func StringFromOrder(order chantypes.Order) string

StringFromOrder returns the string representation of a channel order.

func UpdateClients added in v2.1.0

func UpdateClients(
	ctx context.Context,
	src, dst *Chain,
	memo string,
) error

UpdateClients updates clients for src on dst and dst on src given the configured paths.

func UpgradeClient added in v2.1.0

func UpgradeClient(
	ctx context.Context,
	src, dst *Chain,
	height int64,
	memo string,
) error

UpgradeClient upgrades the client on dst after src chain has undergone an upgrade. If height is zero, will use the latest height of the source chain. If height is non-zero, it will be used for queries on the source chain.

func ValidateChannelParams

func ValidateChannelParams(srcPortID, dstPortID, order string) error

ValidateChannelParams validates a set of port-ids as well as the order.

func ValidateClientPaths

func ValidateClientPaths(src, dst *Chain) error

ValidateClientPaths takes two chains and validates their clients

func ValidateConnectionPaths

func ValidateConnectionPaths(src, dst *Chain) error

ValidateConnectionPaths takes two chains and validates the connections and underlying client identifiers

Types

type ActiveChannel added in v2.1.0

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

ActiveChannel represents an IBC channel and whether there is an active goroutine relaying packets against it.

type Chain

type Chain struct {
	ChainProvider provider.ChainProvider
	Chainid       string `yaml:"chain-id" json:"chain-id"`
	RPCAddr       string `yaml:"rpc-addr" json:"rpc-addr"`

	PathEnd *PathEnd `yaml:"-" json:"-"`
	// contains filtered or unexported fields
}

Chain represents the necessary data for connecting to and identifying a chain and its counterparties TODO revise Chain struct

func NewChain added in v2.1.0

func NewChain(log *zap.Logger, prov provider.ChainProvider, debug bool) *Chain

func (*Chain) AddPath

func (c *Chain) AddPath(clientID, connectionID string) error

AddPath takes the client and connection identifiers for a Path, and if they are initialized, validates them before setting the PathEnd on the Chain. NOTE: if the Path is blank (i.e. the identifiers are not set) validation is skipped.

func (*Chain) ChainID

func (c *Chain) ChainID() string

func (*Chain) ClientID

func (c *Chain) ClientID() string

func (*Chain) CloseChannel

func (c *Chain) CloseChannel(
	ctx context.Context,
	dst *Chain,
	maxRetries uint64,
	timeout time.Duration,
	srcChanID,
	srcPortID string,
	memo string,
	pathName string,
) error

CloseChannel runs the channel closing messages on timeout until they pass.

func (*Chain) ConnectionID

func (c *Chain) ConnectionID() string

func (*Chain) CreateClients

func (c *Chain) CreateClients(ctx context.Context,
	dst *Chain,
	allowUpdateAfterExpiry,
	allowUpdateAfterMisbehaviour,
	override bool,
	customClientTrustingPeriod,
	maxClockDrift time.Duration,
	customClientTrustingPeriodPercentage int64,
	memo string) (string, string, error)

CreateClients creates clients for src on dst and dst on src if the client ids are unspecified.

func (*Chain) CreateOpenChannels

func (c *Chain) CreateOpenChannels(
	ctx context.Context,
	dst *Chain,
	maxRetries uint64,
	timeout time.Duration,
	srcPortID, dstPortID, order, version string,
	override bool,
	memo string,
	pathName string,
) error

CreateOpenChannels runs the channel creation messages on timeout until they pass.

func (*Chain) CreateOpenConnections

func (c *Chain) CreateOpenConnections(
	ctx context.Context,
	dst *Chain,
	maxRetries uint64,
	timeout time.Duration,
	memo string,
	initialBlockHistory uint64,
	pathName string,
) (string, string, error)

CreateOpenConnections runs the connection creation messages on timeout until they pass. The returned boolean indicates that the path end has been modified.

func (*Chain) CreateTestKey

func (c *Chain) CreateTestKey() error

CreateTestKey creates a key for test chain

func (*Chain) ErrCantSetPath

func (c *Chain) ErrCantSetPath(err error) error

ErrCantSetPath returns an error if the path doesn't set properly

func (*Chain) ErrPathNotSet

func (c *Chain) ErrPathNotSet() error

ErrPathNotSet returns information what identifiers are needed to relay

func (*Chain) GetRPCPort

func (c *Chain) GetRPCPort() string

GetRPCPort returns the port configured for the chain

func (*Chain) GetSelfVersion

func (c *Chain) GetSelfVersion() uint64

GetSelfVersion returns the version of the given chain

func (*Chain) GetTimeout

func (c *Chain) GetTimeout() (time.Duration, error)

GetTimeout returns the chain's configured timeout

func (*Chain) GetTrustingPeriod

func (c *Chain) GetTrustingPeriod(ctx context.Context, overrideUnbondingPeriod time.Duration, percentage int64) (time.Duration, error)

GetTrustingPeriod returns the trusting period for the chain

func (*Chain) LogFailedTx

func (c *Chain) LogFailedTx(res *provider.RelayerTxResponse, err error, msgs []provider.RelayerMessage)

LogFailedTx takes the transaction and the messages to create it and logs the appropriate data

func (*Chain) LogRetryGetIBCUpdateHeader added in v2.1.0

func (c *Chain) LogRetryGetIBCUpdateHeader(n uint, err error)

func (*Chain) PathSet

func (c *Chain) PathSet() bool

PathSet check if the chain has a path set

func (*Chain) SendTransferMsg

func (c *Chain) SendTransferMsg(
	ctx context.Context,
	log *zap.Logger,
	dst *Chain,
	amount sdk.Coin,
	dstAddr, memo string,
	toHeightOffset uint64,
	toTimeOffset time.Duration,
	srcChannel *chantypes.IdentifiedChannel,
) error

SendTransferMsg initiates an ics20 transfer from src to dst with the specified args.

func (*Chain) SetPath

func (c *Chain) SetPath(p *PathEnd) error

SetPath sets the path and validates the identifiers if they are initialized.

func (*Chain) String

func (c *Chain) String() string

type Chains

type Chains map[string]*Chain

Chains is a collection of Chain (mapped by chain_name)

func (Chains) Get

func (c Chains) Get(chainID string) (*Chain, error)

Get returns the configuration for a given chain

func (Chains) Gets

func (c Chains) Gets(chainIDs ...string) (map[string]*Chain, error)

Gets returns a map chainIDs to their chains

func (Chains) MustGet

func (c Chains) MustGet(chainID string) *Chain

MustGet returns the chain and panics on any error

type ChannelFilter added in v2.1.0

type ChannelFilter struct {
	Rule        string   `yaml:"rule" json:"rule"`
	ChannelList []string `yaml:"channel-list" json:"channel-list"`
}

ChannelFilter provides the means for either creating an allowlist or a denylist of channels on the src chain which will be used to narrow down the list of channels a user wants to relay on.

func (*ChannelFilter) InChannelList added in v2.1.0

func (cf *ChannelFilter) InChannelList(channelID string) bool

InChannelList returns true if the channelID argument is in the ChannelFilter's ChannelList or false otherwise.

type ClientStateInfo added in v2.3.0

type ClientStateInfo struct {
	ChainID        string
	TrustingPeriod time.Duration
	LatestHeight   ibcexported.Height
	UnbondingTime  time.Duration
}

func ClientInfoFromClientState added in v2.3.0

func ClientInfoFromClientState(clientState *codectypes.Any) (ClientStateInfo, error)

func QueryClientExpiration added in v2.3.0

func QueryClientExpiration(ctx context.Context, src, dst *Chain) (time.Time, ClientStateInfo, error)

type IBCdata added in v2.1.0

type IBCdata struct {
	Schema string `json:"$schema"`
	Chain1 struct {
		ChainName    string `json:"chain_name"`
		ClientID     string `json:"client_id"`
		ConnectionID string `json:"connection_id"`
	} `json:"chain_1"`
	Chain2 struct {
		ChainName    string `json:"chain_name"`
		ClientID     string `json:"client_id"`
		ConnectionID string `json:"connection_id"`
	} `json:"chain_2"`
	Channels []struct {
		Chain1 struct {
			ChannelID string `json:"channel_id"`
			PortID    string `json:"port_id"`
		} `json:"chain_1"`
		Chain2 struct {
			ChannelID string `json:"channel_id"`
			PortID    string `json:"port_id"`
		} `json:"chain_2"`
		Ordering string `json:"ordering"`
		Version  string `json:"version"`
		Tags     struct {
			Status     string `json:"status"`
			Preferred  bool   `json:"preferred"`
			Dex        string `json:"dex"`
			Properties string `json:"properties"`
		} `json:"tags,omitempty"`
	} `json:"channels"`
}

type NamedPath added in v2.1.0

type NamedPath struct {
	Name string
	Path *Path
}

Named path wraps a Path with its name.

type Path

type Path struct {
	Src    *PathEnd      `yaml:"src" json:"src"`
	Dst    *PathEnd      `yaml:"dst" json:"dst"`
	Filter ChannelFilter `yaml:"src-channel-filter" json:"src-channel-filter"`
}

Path represents a pair of chains and the identifiers needed to relay over them along with a channel filter list. A Memo can optionally be provided for identification in relayed messages.

func GenPath

func GenPath(srcChainID, dstChainID string) *Path

GenPath generates a path with unspecified client, connection and channel identifiers given chainIDs and portIDs.

func (*Path) End

func (p *Path) End(chainID string) *PathEnd

End returns the proper end given a chainID.

func (*Path) MustYAML

func (p *Path) MustYAML() string

MustYAML returns the yaml string representation of the Path

func (*Path) QueryPathStatus

func (p *Path) QueryPathStatus(ctx context.Context, src, dst *Chain) *PathWithStatus

QueryPathStatus returns an instance of the path struct with some attached data about the current status of the path

func (*Path) String

func (p *Path) String() string

func (*Path) ValidateChannelFilterRule added in v2.1.0

func (p *Path) ValidateChannelFilterRule() error

ValidateChannelFilterRule verifies that the configured ChannelFilter rule is set to an appropriate value.

type PathAction

type PathAction struct {
	*Path
	Type string `json:"type"`
}

PathAction is struct

type PathEnd

type PathEnd struct {
	ChainID      string `yaml:"chain-id,omitempty" json:"chain-id,omitempty"`
	ClientID     string `yaml:"client-id,omitempty" json:"client-id,omitempty"`
	ConnectionID string `yaml:"connection-id,omitempty" json:"connection-id,omitempty"`
}

PathEnd represents the local connection identifiers for a relay path The path is set on the chain before performing operations

func (PathEnd) String

func (pe PathEnd) String() string

func (*PathEnd) ValidateFull

func (pe *PathEnd) ValidateFull() error

ValidateFull returns errors about invalid client and connection identifiers.

func (*PathEnd) Vclient

func (pe *PathEnd) Vclient() error

Vclient validates the client identifier in the path

func (*PathEnd) Vconn

func (pe *PathEnd) Vconn() error

Vconn validates the connection identifier in the path

type PathStatus

type PathStatus struct {
	Chains     bool `yaml:"chains" json:"chains"`
	Clients    bool `yaml:"clients" json:"clients"`
	Connection bool `yaml:"connection" json:"connection"`
}

PathStatus holds the status of the primitives in the path

type PathWithStatus

type PathWithStatus struct {
	Path   *Path      `yaml:"path" json:"chains"`
	Status PathStatus `yaml:"status" json:"status"`
}

PathWithStatus is used for showing the status of the path

func (*PathWithStatus) PrintString

func (ps *PathWithStatus) PrintString(name string) string

PrintString prints a string representations of the path status

type Paths

type Paths map[string]*Path

Paths represent connection paths between chains

func (Paths) Add

func (p Paths) Add(name string, path *Path) error

Add adds a path by its name

func (Paths) Get

func (p Paths) Get(name string) (path *Path, err error)

Get returns the configuration for a given path

func (Paths) MustGet

func (p Paths) MustGet(name string) *Path

MustGet panics if path is not found

func (Paths) MustYAML

func (p Paths) MustYAML() string

MustYAML returns the yaml string representation of the Paths

func (Paths) PathsFromChains

func (p Paths) PathsFromChains(src, dst string) (Paths, error)

PathsFromChains returns a path from the config between two chains

type RelayMsgSender added in v2.1.0

type RelayMsgSender struct {
	ChainID string

	// SendMessages is a function matching the signature of the same method
	// on the ChainProvider interface.
	//
	// Accepting this narrow subset of the interface greatly simplifies testing.
	SendMessages func(context.Context, []provider.RelayerMessage, string) (*provider.RelayerTxResponse, bool, error)
}

RelayMsgSender is a narrow subset of a Chain, to simplify testing methods on RelayMsgs.

func AsRelayMsgSender added in v2.1.0

func AsRelayMsgSender(c *Chain) RelayMsgSender

AsRelayMsgSender converts c to a RelayMsgSender.

type RelayMsgs

type RelayMsgs struct {
	Src []provider.RelayerMessage `json:"src"`
	Dst []provider.RelayerMessage `json:"dst"`

	// maximum permitted size of the msgs in a bundled relay transaction
	MaxTxSize uint64 `json:"max_tx_size"`

	// maximum amount of messages in a bundled relay transaction
	MaxMsgLength uint64 `json:"max_msg_length"`
}

RelayMsgs contains the msgs that need to be sent to both a src and dst chain after a given relay round. MaxTxSize and MaxMsgLength are ignored if they are set to zero.

func (*RelayMsgs) IsMaxTx

func (r *RelayMsgs) IsMaxTx(msgLen, txSize uint64) bool

func (*RelayMsgs) PrependMsgUpdateClient added in v2.1.0

func (r *RelayMsgs) PrependMsgUpdateClient(
	ctx context.Context,
	src, dst *Chain,
	srch, dsth int64,
) error

func (*RelayMsgs) Ready

func (r *RelayMsgs) Ready() bool

Ready returns true if there are messages to relay

func (*RelayMsgs) Send

func (r *RelayMsgs) Send(
	ctx context.Context,
	log *zap.Logger,
	src, dst RelayMsgSender,
	memo string,
) SendMsgsResult

Send concurrently sends out r's messages to the corresponding RelayMsgSenders.

type RelaySequences

type RelaySequences struct {
	Src []uint64 `json:"src"`
	Dst []uint64 `json:"dst"`
}

RelaySequences represents unrelayed packets on src and dst

func UnrelayedAcknowledgements

func UnrelayedAcknowledgements(ctx context.Context, src, dst *Chain, srcChannel *chantypes.IdentifiedChannel) RelaySequences

UnrelayedAcknowledgements returns the unrelayed sequence numbers between two chains

func UnrelayedSequences

func UnrelayedSequences(ctx context.Context, src, dst *Chain, srcChannel *chantypes.IdentifiedChannel) RelaySequences

UnrelayedSequences returns the unrelayed sequence numbers between two chains

func (*RelaySequences) Empty

func (rs *RelaySequences) Empty() bool

type SendMsgsResult added in v2.1.0

type SendMsgsResult struct {
	// Count of successfully sent batches,
	// where "successful" means there was no error in sending the batch across the network,
	// and the remote end sent a response indicating success.
	SuccessfulSrcBatches, SuccessfulDstBatches int

	// Accumulation of errors encountered when sending to source or destination.
	// If multiple errors occurred, these will be multierr errors
	// which are displayed nicely through zap logging.
	SrcSendError, DstSendError error
}

SendMsgsResult is returned by (*RelayMsgs).Send. It contains details about the distinct results of sending messages to the corresponding chains.

func (SendMsgsResult) Error added in v2.1.0

func (r SendMsgsResult) Error() error

Error returns any accumulated erors that occurred while sending messages.

func (SendMsgsResult) MarshalLogObject added in v2.1.0

func (r SendMsgsResult) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject satisfies the zapcore.ObjectMarshaler interface so that you can use zap.Object("send_result", r) when logging. This is typically useful when logging details about a partially sent result.

func (SendMsgsResult) PartiallySent added in v2.1.0

func (r SendMsgsResult) PartiallySent() bool

PartiallySent reports the presence of both some successfully sent batches and some errors.

func (SendMsgsResult) SuccessfullySent added in v2.4.0

func (r SendMsgsResult) SuccessfullySent() bool

SuccessfullySent reports the presence successfully sent batches

Jump to

Keyboard shortcuts

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