relayer

package
v3.0.0-...-9121f9c Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ProcessorEvents string = "events"
	ProcessorLegacy string = "legacy"
)

Variables

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

Functions

func AddMessagesForInterqueries

func AddMessagesForInterqueries(ctx context.Context, queries []interquerytypes.Interquery, src, dst *Chain, srch, dsth int64, msgs *[]provider.RelayerMessage) error

AddMessagesForInterqueries performs a query for each pending interquery from src on dst chain and then constructs an interquery submit message with the query results for the src chain.

func AddMessagesForSequences

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 CastClientStateToTMType

func CastClientStateToTMType(cs *codectypes.Any) (*tmclient.ClientState, error)

CastClientStateToTMType casts client state to tendermint type

func CreateClient

func CreateClient(ctx context.Context, src, dst *Chain, srcUpdateHeader, dstUpdateHeader ibcexported.Header, allowUpdateAfterExpiry, allowUpdateAfterMisbehaviour, override bool, memo string) (bool, error)

func GetIBCUpdateHeaders

func GetIBCUpdateHeaders(ctx context.Context, srch, dsth int64, src, dst provider.ChainProvider, srcClientID, dstClientID string) (srcHeader, dstHeader ibcexported.Header, err error)

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

func GetLightSignedHeadersAtHeights

func GetLightSignedHeadersAtHeights(ctx context.Context, src, dst *Chain, srch, dsth int64) (srcUpdateHeader, dstUpdateHeader ibcexported.Header, err error)

func MustGetHeight

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 PathsSet

func PathsSet(chains ...*Chain) bool

PathsSet checks if the chains have their paths set

func PrependUpdateClientMsg

func PrependUpdateClientMsg(ctx context.Context, msgs *[]provider.RelayerMessage, src, dst *Chain, srch int64) error

PrependUpdateClientMsg adds an UpdateClient msg to the front of non-empty msg lists

func QueryChannel

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

func QueryChannelPair

func QueryChannelPair(ctx context.Context, src, dst *Chain, srcH, dstH int64, srcChanID, dstChanID, srcPortID, dstPortID string) (srcChan, dstChan *chantypes.QueryChannelResponse, err error)

QueryChannelPair returns a pair of channel responses

func QueryConnectionPair

func QueryConnectionPair(ctx context.Context, src, dst *Chain, srcH, dstH int64) (srcConn, dstConn *conntypes.QueryConnectionResponse, err error)

QueryConnectionPair returns a pair of connection responses

func QueryLatestHeights

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

QueryLatestHeights returns the heights of multiple chains at once

func QueryPortChannel

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 RelayInterqueries

func RelayInterqueries(ctx context.Context, src, dst *Chain, iqs []interquerytypes.Interquery, maxTxSize, maxMsgLength uint64) error

RelayInterqueries creates transactions to relay packets 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 StartRelayer

func StartRelayer(
	ctx context.Context,
	log *zap.Logger,
	src, dst *Chain,
	interquery bool,
	filter ChannelFilter,
	maxTxSize, maxMsgLength uint64,
	memo string,
	processorType string,
	initialBlockHistory uint64,
) chan error

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

func StringFromOrder

func StringFromOrder(order chantypes.Order) string

StringFromOrder returns the string representation of a channel order.

func UnrelayedInterqueries

func UnrelayedInterqueries(ctx context.Context, src, dst *Chain) ([]interquerytypes.Interquery, error)

UnrelayedInterqueries returns the unsubmitted/incomplete interqueries for the client-id specified in each interquery

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

func ValidatePaths

func ValidatePaths(src, dst *Chain) error

ValidatePaths takes two chains and validates their paths

Types

type ActiveChannel

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

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

func UnmarshalChain

func UnmarshalChain(pe PathEnd) *Chain

UnmarshalChain returns Marshalled 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,
) 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, memo string) (bool, 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,
) 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,
) (modified bool, err 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) (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

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) QueryTMClientState

func (c *Chain) QueryTMClientState(ctx context.Context, height int64) (*tmclient.ClientState, error)

QueryTMClientState retrieves the latest consensus state for a client in state at a given height and unpacks/cast it to tendermint clientstate

func (*Chain) SendTransferMsg

func (c *Chain) SendTransferMsg(ctx context.Context, log *zap.Logger, dst *Chain, amount sdk.Coin, dstAddr 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

func (*Chain) UpdateClients

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

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

func (*Chain) UpgradeClients

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

UpgradeClients upgrades the client on src after dst chain has undergone an upgrade.

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

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

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

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

type IBCdata

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 Interquery

type Interquery struct {
	Query bool `yaml:"query" json:"query"`
}

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"`
	Interquery Interquery    `yaml:"interquery" json:"interquery"`
}

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

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 MarshalChain

func MarshalChain(c *Chain) PathEnd

MarshalChain is PathEnd

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 RelayInterqueryMsgs

type RelayInterqueryMsgs struct {
	Msgs         []provider.RelayerMessage `json:"msgs"`
	MaxTxSize    uint64                    `json:"max_tx_size"`    // maximum permitted size of the msgs in a bundled relay transaction
	MaxMsgLength uint64                    `json:"max_msg_length"` // maximum amount of messages in a bundled relay transaction

	Last      bool `json:"last"`
	Succeeded bool `json:"success"`
}

RelayInterqueryMsgs contains the msgs that need to be sent to src chain with query results from the dst chain

func (*RelayInterqueryMsgs) IsMaxTx

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

func (*RelayInterqueryMsgs) Ready

func (r *RelayInterqueryMsgs) Ready() bool

Ready returns true if there are messages to relay

func (*RelayInterqueryMsgs) Send

func (r *RelayInterqueryMsgs) Send(ctx context.Context, src, dst *Chain)

func (*RelayInterqueryMsgs) Success

func (r *RelayInterqueryMsgs) Success() bool

Success returns the success var

type RelayMsgSender

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

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"`
	MaxTxSize    uint64                    `json:"max_tx_size"`    // maximum permitted size of the msgs in a bundled relay transaction
	MaxMsgLength uint64                    `json:"max_msg_length"` // maximum amount of messages in a bundled relay transaction
}

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) 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

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

func (r SendMsgsResult) Error() error

Error returns any accumulated erors that occurred while sending messages.

func (SendMsgsResult) MarshalLogObject

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

func (r SendMsgsResult) PartiallySent() bool

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

Directories

Path Synopsis
chains

Jump to

Keyboard shortcuts

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