collactor

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: Apache-2.0 Imports: 70 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChainTypeWeelink = "weelink"
	ChainTypeCosmos  = "cosmos"
)

Variables

View Source
var (
	AllowUpdateAfterExpiry       = true
	AllowUpdateAfterMisbehaviour = true
)
View Source
var (
	ErrDatabase = errors.New("database failure")

	// ErrLightNotInitialized returns the canonical error for a an uninitialized light client
	ErrLightNotInitialized = errors.New("light client is not initialized")
)
View Source
var (

	// DefaultUpgradePath is the default IBC upgrade path set for an on-chain light client
	DefaultUpgradePath = []string{"upgrade", "upgradedIBCState"}
)

Functions

func AutoUpdateClient

func AutoUpdateClient(src, dst *Chain, thresholdTime time.Duration) (time.Duration, error)

AutoUpdateClient update client automatically to prevent expiry

func CastClientStateToTMType

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

CastClientStateToTMType casts client state to tendermint type

func DefaultChainLogger

func DefaultChainLogger() log.Logger

func ExecuteChannelStep

func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err error)

ExecuteChannelStep executes the next channel step based on the states of two channel ends specified by the relayer configuration file. The booleans return indicate if the message was successfully executed and if this was the last handshake step.

func ExecuteConnectionStep

func ExecuteConnectionStep(src, dst *Chain) (success, last, modified bool, err error)

ExecuteConnectionStep executes the next connection step based on the states of two connection ends specified by the relayer configuration file. The booleans return indicate if the message was successfully executed and if this was the last handshake step.

func FindMatchingChannel

func FindMatchingChannel(source, counterparty *Chain) (string, bool)

FindMatchingChannel will determine if there already exists a channel between source and counterparty that matches the parameters set in the relayer configs.

func FindMatchingClient

func FindMatchingClient(source, counterparty *Chain, clientState *ibctmtypes.ClientState) (string, bool)

FindMatchingClient will determine if there exists a client with identical client and consensus states to the client which would have been created. Source is the chain that would be adding a client which would track the counterparty. Therefore we query source for the existing clients and check if any match the counterparty. The counterparty must have a matching consensus state to the latest consensus state of a potential match. The provided client state is the client state that will be created if there exist no matches.

func FindMatchingConnection

func FindMatchingConnection(source, counterparty *Chain) (string, bool)

FindMatchingConnection will determine if there already exists a connection between source and counterparty that matches the parameters set in the relayer configs.

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GetIBCCreateClientHeaders

func GetIBCCreateClientHeaders(src, dst *Chain) (srcHeader, dstHeader *tmclient.Header, err error)

GetIBCCreateClientHeaders returns the IBC TM header which will create an on-chain light client. The headers do not have trusted headers (ie trusted validators and trusted height)

func GetIBCUpdateHeaders

func GetIBCUpdateHeaders(src, dst *Chain) (srcHeader, dstHeader *tmclient.Header, err error)

GetIBCUpdateHeaders return the IBC TM Header which will update an on-chain light client. A header for the source and destination chain is returned.

func GetLatestLightHeights

func GetLatestLightHeights(src, dst *Chain) (srch int64, dsth int64, err error)

GetLatestLightHeights returns both the src and dst latest height in the local client

func InitializeChannel

func InitializeChannel(src, dst *Chain) (success, modified bool, err error)

InitializeChannel creates a new channel on either the source or destination chain . The identifiers set in the PathEnd's are used to determine which channel ends need to be initialized. The PathEnds are updated upon a successful transaction. NOTE: This function may need to be called twice if neither channel exists.

func InitializeConnection

func InitializeConnection(src, dst *Chain) (success, modified bool, err error)

InitializeConnection creates a new connection on either the source or destination chain . The identifiers set in the PathEnd's are used to determine which connection ends need to be initialized. The PathEnds are updated upon a successful transaction. NOTE: This function may need to be called twice if neither connection exists.

func IsConnectionFound

func IsConnectionFound(connectionHops []string, connectionID string) bool

IsConnectionFound determines if given connectionId is present in channel connectionHops list

func IsMatchingChannel

func IsMatchingChannel(source, counterparty *Chain, channel *chantypes.IdentifiedChannel) bool

IsMatchingChannel determines if given channel matches required conditions

func IsMatchingClient

func IsMatchingClient(clientStateA, clientStateB ibctmtypes.ClientState) bool

IsMatchingClient determines if the two provided clients match in all fields except latest height. They are assumed to be IBC tendermint light clients. NOTE: we don't pass in a pointer so upstream references don't have a modified latest height set to zero.

func IsMatchingConnection

func IsMatchingConnection(source, counterparty *Chain, connection *conntypes.IdentifiedConnection) bool

IsMatchingConnection determines if given connection matches required conditions

func IsMatchingConsensusState

func IsMatchingConsensusState(consensusStateA, consensusStateB *ibctmtypes.ConsensusState) bool

IsMatchingConsensusState determines if the two provided consensus states are identical. They are assumed to be IBC tendermint light clients.

func KeysDir

func KeysDir(home, chainID string) string

KeysDir returns the path to the keys for this chain

func Link(src, dst *Chain, retries uint64, to time.Duration) 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 sdk.StringEvents) (string, error)

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

func ParseClientIDFromEvents

func ParseClientIDFromEvents(events sdk.StringEvents) (string, error)

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

func ParseConnectionIDFromEvents

func ParseConnectionIDFromEvents(events sdk.StringEvents) (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 QueryChannelPair

func QueryChannelPair(src, dst *Chain, srcH, dstH int64) (srcChan, dstChan *chantypes.QueryChannelResponse, err error)

QueryChannelPair returns a pair of channel responses

func QueryConnectionPair

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

QueryConnectionPair returns a pair of connection responses

func RandLowerCaseLetterString

func RandLowerCaseLetterString(length int) string

RandLowerCaseLetterString returns a lowercase letter string of given length

func RunStrategy

func RunStrategy(src, dst *Chain, strategy Strategy) (func(), error)

RunStrategy runs a given strategy

func UpdateLightClients

func UpdateLightClients(src, dst *Chain) (srcLB, dstLB *tmtypes.LightBlock, err error)

UpdateLightClients updates the off-chain tendermint light clients concurrently.

func ValidateChannelParams

func ValidateChannelParams(src, dst *Chain) error

ValidateChannelParams takes two chains and validates their respective channel params

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 Chain

type Chain struct {
	//Key            string  `yaml:"key" json:"key"`
	ChainID        string  `yaml:"chain-id" json:"chain-id"`
	RPCAddr        string  `yaml:"rpc-addr" json:"rpc-addr"`
	RESTAddr       string  `yaml:"rest-addr" json:"rest-addr"`
	AccountPrefix  string  `yaml:"account-prefix" json:"account-prefix"`
	GasAdjustment  float64 `yaml:"gas-adjustment" json:"gas-adjustment"`
	GasPrices      string  `yaml:"gas-prices" json:"gas-prices"`
	TrustingPeriod string  `yaml:"trusting-period" json:"trusting-period"`
	PrivateKey     string  `yaml:"private-key" json:"-"` //json返回值除去private-key
	ChainType      string  `yaml:"chain-type" json:"chain-type"`

	// TODO: make these private
	HomePath string           `yaml:"-" json:"-"`
	PathEnd  *PathEnd         `yaml:"-" json:"-"`
	Keybase  keys.Keyring     `yaml:"-" json:"-"`
	Client   rpcclient.Client `yaml:"-" json:"-"`

	Encoding       types2.EncodingConfig `yaml:"-" json:"-"`
	CosmosEncoding params.EncodingConfig `yaml:"-" json:"-"`
	// contains filtered or unexported fields
}

Chain represents the necessary data for connecting to and indentifying a chain and its counterparites

func (*Chain) AddPath

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

AddPath takes the elements of a path and validates then, setting that path to the chain

func (*Chain) CLIContext

func (c *Chain) CLIContext(height int64) sdkCtx.Context

CLIContext returns an instance of client.Context derived from Chain

func (*Chain) CLICosmosContext

func (c *Chain) CLICosmosContext(height int64) cosmosSdkCtx.Context

CLIContext returns an instance of client.Context derived from Chain

func (*Chain) ChanAck

func (c *Chain) ChanAck(
	counterparty *Chain,
) ([]sdk.Msg, error)

ChanAck creates a MsgChannelOpenAck

func (*Chain) ChanConfirm

func (c *Chain) ChanConfirm(counterparty *Chain) ([]sdk.Msg, error)

ChanConfirm creates a MsgChannelOpenConfirm

func (*Chain) ChanInit

func (c *Chain) ChanInit(counterparty *Chain) ([]sdk.Msg, error)

ChanInit creates a MsgChannelOpenInit

func (*Chain) ChanTry

func (c *Chain) ChanTry(
	counterparty *Chain,
) ([]sdk.Msg, error)

ChanTry creates a MsgChannelOpenTry

func (*Chain) ConnAck

func (c *Chain) ConnAck(
	counterparty *Chain,
) ([]sdk.Msg, error)

ConnAck creates a MsgConnectionOpenAck

func (*Chain) ConnConfirm

func (c *Chain) ConnConfirm(counterparty *Chain) ([]sdk.Msg, error)

ConnConfirm creates a MsgConnectionOpenConfirm

func (*Chain) ConnInit

func (c *Chain) ConnInit(counterparty *Chain) ([]sdk.Msg, error)

ConnInit creates a MsgConnectionOpenInit

func (*Chain) ConnTry

func (c *Chain) ConnTry(
	counterparty *Chain,
) ([]sdk.Msg, error)

ConnTry creates a MsgConnectionOpenTry

func (*Chain) CreateClient

func (c *Chain) CreateClient(

	clientState *tmclient.ClientState,
	dstHeader *tmclient.Header) sdk.Msg

CreateClient creates an sdk.Msg to update the client on src with consensus state from dst

func (*Chain) CreateClients

func (c *Chain) CreateClients(dst *Chain) (modified bool, err error)

CreateClients creates clients for src on dst and dst on src if the client ids are unspecified. TODO: de-duplicate code

func (*Chain) CreateOpenChannels

func (c *Chain) CreateOpenChannels(dst *Chain, maxRetries uint64, to time.Duration) (modified bool, err error)

CreateOpenChannels runs the channel creation messages on timeout until they pass

func (*Chain) CreateOpenConnections

func (c *Chain) CreateOpenConnections(dst *Chain, maxRetries uint64, to time.Duration) (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) DeleteLightDB

func (c *Chain) DeleteLightDB() error

DeleteLightDB removes the light client database on disk, forcing re-initialization

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

func (c *Chain) Error(err error)

Error takes an error, wraps it in the chainID and logs the error

func (*Chain) GenerateConnHandshakeProof

func (c *Chain) GenerateConnHandshakeProof(height uint64) (clientState ibcexported.ClientState,
	clientStateProof []byte, consensusProof []byte, connectionProof []byte,
	connectionProofHeight clienttypes.Height, err error)

GenerateConnHandshakeProof generates all the proofs needed to prove the existence of the connection state on this chain. A counterparty should use these generated proofs.

func (*Chain) GetAddress

func (c *Chain) GetAddress() (sdk.AccAddress, error)

GetAddress returns the sdk.AccAddress associated with the configred key

func (*Chain) GetAddressString

func (c *Chain) GetAddressString() (string, error)

func (*Chain) GetIBCCreateClientHeader

func (c *Chain) GetIBCCreateClientHeader() (*tmclient.Header, error)

GetIBCCreateClientHeader updates the off chain tendermint light client on source and returns an IBC Update Header which can be used to create an on-chain light client on counterparty chain.

func (*Chain) GetIBCUpdateHeader

func (c *Chain) GetIBCUpdateHeader(dst *Chain) (*tmclient.Header, error)

GetIBCUpdateHeader updates the off chain tendermint light client and returns an IBC Update Header which can be used to update an on chain light client on the destination chain. The source is used to construct the header data.

func (*Chain) GetLatestLightHeader

func (c *Chain) GetLatestLightHeader() (*tmclient.Header, error)

GetLatestLightHeader returns the header to be used for client creation

func (*Chain) GetLatestLightHeight

func (c *Chain) GetLatestLightHeight() (int64, error)

GetLatestLightHeight returns the latest height of the light client.

func (*Chain) GetLightSignedHeaderAtHeight

func (c *Chain) GetLightSignedHeaderAtHeight(height int64) (*tmclient.Header, error)

GetLightSignedHeaderAtHeight returns a signed header at a particular height (0 - the latest).

func (*Chain) GetTrustingPeriod

func (c *Chain) GetTrustingPeriod() time.Duration

GetTrustingPeriod returns the trusting period for the chain

func (*Chain) HealthCheck

func (c *Chain) HealthCheck() error

func (*Chain) ImportKey

func (c *Chain) ImportKey() error

func (*Chain) Init

func (c *Chain) Init(homePath string, timeout time.Duration, logger log.Logger, debug bool) error

Init initializes the pieces of a chain that aren't set when it parses a configs NOTE: All validation of the chain should happen here.

func (*Chain) InjectTrustedFields

func (c *Chain) InjectTrustedFields(dst *Chain, header *tmclient.Header) (*tmclient.Header, error)

InjectTrustedFields injects the necessary trusted fields for a header to update a light client stored on the destination chain, using the information provided by the source chain. TrustedHeight is the latest height of the IBC client on dst TrustedValidators is the validator set of srcChain at the TrustedHeight InjectTrustedFields returns a copy of the header with TrustedFields modified

func (*Chain) KeyExists

func (c *Chain) KeyExists(name string) bool

KeyExists returns true if there is a specified key in chain's keybase

func (*Chain) LightClient

func (c *Chain) LightClient(db dbm.DB) (*light.Client, error)

LightClient initializes the light client for a given chain from the trusted store in the database this should be call for all other light client usage

func (*Chain) LightClientWithoutTrust

func (c *Chain) LightClientWithoutTrust(db dbm.DB) (*light.Client, error)

LightClientWithoutTrust querys the latest header from the chain and initializes a new light client database using that header. This should only be called when first initializing the light client

func (*Chain) LightHTTP

func (c *Chain) LightHTTP() lightp.Provider

LightHTTP returns the http client for light clients

func (*Chain) Log

func (c *Chain) Log(s string)

Log takes a string and logs the data

func (*Chain) LogFailedTx

func (c *Chain) LogFailedTx(res *sdk.TxResponse, err error, msgs []sdk.Msg)

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

func (*Chain) LogSuccessTx

func (c *Chain) LogSuccessTx(res *sdk.TxResponse, msgs []sdk.Msg)

LogSuccessTx take the transaction and the messages to create it and logs the appropriate data

func (*Chain) MakeCosmosEncodingConfig

func (c *Chain) MakeCosmosEncodingConfig() params.EncodingConfig

MakeEncodingConfig returns the encoding txConfig for the chain

func (*Chain) MakeEncodingConfig

func (c *Chain) MakeEncodingConfig() types2.EncodingConfig

func (*Chain) MsgRelayRecvPacket

func (c *Chain) MsgRelayRecvPacket(counterparty *Chain, packet *relayMsgRecvPacket) (msgs []sdk.Msg, err error)

MsgRelayRecvPacket constructs the MsgRecvPacket which is to be sent to the receiving chain. The counterparty represents the sending chain where the packet commitment would be stored.

func (*Chain) MsgRelayTimeout

func (c *Chain) MsgRelayTimeout(counterparty *Chain, packet *relayMsgTimeout) (msgs []sdk.Msg, err error)

MsgRelayTimeout constructs the MsgTimeout which is to be sent to the sending chain. The counterparty represents the receiving chain where the receipts would have been stored.

func (*Chain) MsgTransfer

func (c *Chain) MsgTransfer(dst *PathEnd, amount sdk.Coin, dstAddr string,
	timeoutHeight, timeoutTimestamp uint64) sdk.Msg

MsgTransfer creates a new transfer message

func (*Chain) MustGetAddress

func (c *Chain) MustGetAddress() sdk.AccAddress

MustGetAddress used for brevity

func (*Chain) MustGetAddressString

func (c *Chain) MustGetAddressString() string

func (*Chain) MustGetLatestLightHeight

func (c *Chain) MustGetLatestLightHeight() uint64

MustGetLatestLightHeight returns the latest height of the light client. If an error occurs due to a database failure, we keep trying with a delayed re-attempt. Otherwise, we panic.

func (*Chain) NewLightDB

func (c *Chain) NewLightDB() (db *dbm.GoLevelDB, df func(), err error)

NewLightDB returns a new instance of the lightclient database connection CONTRACT: must close the database connection when done with it (defer df())

func (*Chain) NewProtoCodec

func (c *Chain) NewProtoCodec(interfaceRegistry types.InterfaceRegistry, accountPrefix string) *ProtoCodec

NewProtoCodec returns a reference to a new ProtoCodec

func (*Chain) PathSet

func (c *Chain) PathSet() bool

PathSet check if the chain has a path set

func (*Chain) Print

func (c *Chain) Print(toPrint interface{}, text, indent bool) error

Print fmt.Printlns the json or yaml representation of whatever is passed in CONTRACT: The cmd calling this function needs to have the "json" and "indent" flags set TODO: better "text" printing here would be a nice to have TODO: fix indenting all over the code base

func (*Chain) QueryBalanceWithAddress

func (c *Chain) QueryBalanceWithAddress(address sdk.AccAddress) (sdk.Coins, error)

QueryBalanceWithAddress returns the amount of coins in the relayer account with address as input

func (*Chain) QueryChannel

func (c *Chain) QueryChannel(height int64) (chanRes *chantypes.QueryChannelResponse, err error)

QueryChannel returns the channel associated with a channelID

func (*Chain) QueryChannels

func (c *Chain) QueryChannels(offset, limit uint64) (*chantypes.QueryChannelsResponse, error)

QueryChannels returns all the channels that are registered on a chain

func (*Chain) QueryClientConsensusState

func (c *Chain) QueryClientConsensusState(
	height int64, dstClientConsHeight ibcexported.Height) (*clienttypes.QueryConsensusStateResponse, error)

QueryClientConsensusState retrevies the latest consensus state for a client in state at a given height

func (*Chain) QueryClientState

func (c *Chain) QueryClientState(height int64) (*clienttypes.QueryClientStateResponse, error)

QueryClientState retrevies the latest consensus state for a client in state at a given height

func (*Chain) QueryClients

func (c *Chain) QueryClients(offset, limit uint64) (*clienttypes.QueryClientStatesResponse, error)

QueryClients queries all the clients!

func (*Chain) QueryConnection

func (c *Chain) QueryConnection(height int64) (*conntypes.QueryConnectionResponse, error)

QueryConnection returns the remote end of a given connection

func (*Chain) QueryConnections

func (c *Chain) QueryConnections(
	offset, limit uint64) (*conntypes.QueryConnectionsResponse, error)

QueryConnections gets any connections on a chain

func (*Chain) QueryDenomTraces

func (c *Chain) QueryDenomTraces(offset, limit uint64, height int64) (*transfertypes.QueryDenomTracesResponse, error)

QueryDenomTraces returns all the denom traces from a given chain

func (*Chain) QueryLatestHeight

func (c *Chain) QueryLatestHeight() (int64, error)

QueryLatestHeight queries the chain for the latest height and returns it

func (*Chain) QueryNonce

func (c *Chain) QueryNonce() (uint64, error)

func (*Chain) QueryPacketAcknowledgement

func (c *Chain) QueryPacketAcknowledgement(height int64,
	seq uint64) (ackRes *chantypes.QueryPacketAcknowledgementResponse, err error)

QueryPacketAcknowledgement returns the packet ack proof at a given height

func (*Chain) QueryPacketCommitment

func (c *Chain) QueryPacketCommitment(
	height int64, seq uint64) (comRes *chantypes.QueryPacketCommitmentResponse, err error)

QueryPacketCommitment returns the packet commitment proof at a given height

func (*Chain) QueryPacketCommitments

func (c *Chain) QueryPacketCommitments(
	offset, limit, height uint64) (comRes *chantypes.QueryPacketCommitmentsResponse, err error)

QueryPacketCommitments returns an array of packet commitments

func (*Chain) QueryPacketReceipt

func (c *Chain) QueryPacketReceipt(height int64, seq uint64) (recRes *chantypes.QueryPacketReceiptResponse, err error)

QueryPacketReceipt returns the packet receipt proof at a given height

func (*Chain) QueryTxs

func (c *Chain) QueryTxs(height uint64, page, limit int, events []string) ([]*ctypes.ResultTx, error)

QueryTxs returns an array of transactions given a tag

func (*Chain) QueryUnbondingPeriod

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

QueryUnbondingPeriod returns the unbonding period of the chain

func (*Chain) QueryUnreceivedPackets

func (c *Chain) QueryUnreceivedPackets(height uint64, seqs []uint64) ([]uint64, error)

QueryUnreceivedPackets returns a list of unrelayed packet commitments

func (*Chain) SendMsg

func (c *Chain) SendMsg(datagram sdk.Msg) (*sdk.TxResponse, bool, error)

SendMsg wraps the msg in a stdtx, signs and sends it

func (*Chain) SendMsgs

func (c *Chain) SendMsgs(msgs []sdk.Msg) (*sdk.TxResponse, bool, error)

SendMsgs wraps the msgs in a StdTx, signs and sends it. An error is returned if there was an issue sending the transaction. A successfully sent, but failed transaction will not return an error. If a transaction is successfully sent, the result of the execution of that transaction will be logged. A boolean indicating if a transaction was successfully sent and executed successfully is returned.

func (*Chain) SendTransferMsg

func (c *Chain) SendTransferMsg(dst *Chain, amount sdk.Coin, dstAddr string, toHeightOffset uint64, toTimeOffset time.Duration) error

SendTransferMsg initiates an ibs20 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

func (*Chain) Start

func (c *Chain) Start() error

Start the client service

func (*Chain) Subscribe

func (c *Chain) Subscribe(query string) (<-chan ctypes.ResultEvent, context.CancelFunc, error)

Subscribe returns channel of events given a query

func (*Chain) TxFactory

func (c *Chain) TxFactory(height int64) tx.Factory

TxFactory returns an instance of tx.Factory derived from

func (*Chain) UnknownError

func (c *Chain) UnknownError(errorStr string)

Error takes an error, wraps it in the chainID and logs the error

func (*Chain) Update

func (c *Chain) Update(key, value string) (out *Chain, err error)

Update returns a new chain with updated values

func (*Chain) UpdateClient

func (c *Chain) UpdateClient(dst *Chain) (sdk.Msg, error)

UpdateClient creates an sdk.Msg to update the client on src with data pulled from dst at the request height..

func (*Chain) UpdateClient2

func (c *Chain) UpdateClient2(dst *Chain) (sdk.Msg, int64, error)

func (*Chain) UpdateClients

func (c *Chain) UpdateClients(dst *Chain) (err error)

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

func (*Chain) UpdateLightClient

func (c *Chain) UpdateLightClient() (*tmtypes.LightBlock, error)

UpdateLightClient updates the tendermint light client by verifying the current header against a trusted header.

func (*Chain) UseSDKContext

func (c *Chain) UseSDKContext() func()

func (*Chain) ValidateLightInitialized

func (c *Chain) ValidateLightInitialized() error

ValidateLightInitialized returns an error if the light client isn't initialized or there is a problem interacting with the light client.

type Chains

type Chains []*Chain

Chains is a collection of Chain

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

type NaiveStrategy

type NaiveStrategy struct {
	Ordered      bool
	MaxTxSize    uint64 // maximum permitted size of the msgs in a bundled relay transaction
	MaxMsgLength uint64 // maximum amount of messages in a bundled relay transaction
}

NaiveStrategy is an implementation of Strategy.

func (*NaiveStrategy) GetType

func (nrs *NaiveStrategy) GetType() string

GetType implements Strategy

func (*NaiveStrategy) HandleEvents

func (nrs *NaiveStrategy) HandleEvents(src, dst *Chain, events map[string][]string)

func (*NaiveStrategy) RelayAcknowledgements

func (nrs *NaiveStrategy) RelayAcknowledgements(src, dst *Chain, sp *RelaySequences) error

func (*NaiveStrategy) RelayPackets

func (nrs *NaiveStrategy) RelayPackets(src, dst *Chain, sp *RelaySequences) error

func (*NaiveStrategy) UnrelayedAcknowledgements

func (nrs *NaiveStrategy) UnrelayedAcknowledgements(src, dst *Chain) (*RelaySequences, error)

func (*NaiveStrategy) UnrelayedSequences

func (nrs *NaiveStrategy) UnrelayedSequences(src, dst *Chain) (*RelaySequences, error)

type Path

type Path struct {
	Src      *PathEnd     `yaml:"src" json:"src"`
	Dst      *PathEnd     `yaml:"dst" json:"dst"`
	Strategy *StrategyCfg `yaml:"strategy" json:"strategy"`
}

Path represents a pair of chains and the identifiers needed to relay over them

func (*Path) End

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

End returns the proper end given a chainID

func (*Path) GenDstChanID

func (p *Path) GenDstChanID()

GenDstChanID generates the specififed identifier

func (*Path) GenDstClientID

func (p *Path) GenDstClientID()

GenDstClientID generates the specififed identifier

func (*Path) GenDstConnID

func (p *Path) GenDstConnID()

GenDstConnID generates the specififed identifier

func (*Path) GenSrcChanID

func (p *Path) GenSrcChanID()

GenSrcChanID generates the specififed identifier

func (*Path) GenSrcClientID

func (p *Path) GenSrcClientID()

GenSrcClientID generates the specififed identifier

func (*Path) GenSrcConnID

func (p *Path) GenSrcConnID()

GenSrcConnID generates the specififed identifier

func (*Path) GetStrategy

func (p *Path) GetStrategy() (Strategy, error)

GetStrategy the strategy defined in the relay messages

func (*Path) MustGetStrategy

func (p *Path) MustGetStrategy() Strategy

MustGetStrategy returns the strategy and panics on error

func (*Path) MustYAML

func (p *Path) MustYAML() string

MustYAML returns the yaml string representation of the Path

func (*Path) Ordered

func (p *Path) Ordered() bool

Ordered returns true if the path is ordered and false if otherwise

func (*Path) QueryPathStatus

func (p *Path) QueryPathStatus(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) Validate

func (p *Path) Validate() (err error)

Validate checks that a path is valid

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"`
	ChannelID    string `yaml:"channel-id,omitempty" json:"channel-id,omitempty"`
	PortID       string `yaml:"port-id,omitempty" json:"port-id,omitempty"`
	Order        string `yaml:"order,omitempty" json:"order,omitempty"`
	Version      string `yaml:"version,omitempty" json:"version,omitempty"`
}

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

func (*PathEnd) GetOrder

func (pe *PathEnd) GetOrder() chantypes.Order

GetOrder returns the channel order for the path end

func (PathEnd) String

func (pe PathEnd) String() string

func (*PathEnd) ValidateBasic

func (pe *PathEnd) ValidateBasic() error

ValidateBasic validates fields that cannot be empty such as the port and channel order.

func (*PathEnd) ValidateFull

func (pe *PathEnd) ValidateFull() error

ValidateFull returns errors about invalid identifiers as well as unset path variables for the appropriate type

func (*PathEnd) Vchan

func (pe *PathEnd) Vchan() error

Vchan validates the channel identifier in the path

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

func (*PathEnd) Vport

func (pe *PathEnd) Vport() error

Vport validates the port identifier in the path

func (*PathEnd) Vversion

func (pe *PathEnd) Vversion() error

Vversion validates the version 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"`
	Channel    bool `yaml:"channel" json:"channel"`
}

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

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

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

AddForce ignores existing paths and overwrites an existing path with that 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 configs between two chains

type ProtoCodec

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

ProtoCodec defines a codec that utilizes Protobuf for both binary and JSON encoding.

func (*ProtoCodec) InterfaceRegistry

func (pc *ProtoCodec) InterfaceRegistry() types.InterfaceRegistry

InterfaceRegistry returns the ProtoCodec interfaceRegistry

func (*ProtoCodec) MarshalBinaryBare

func (pc *ProtoCodec) MarshalBinaryBare(o codec.ProtoMarshaler) ([]byte, error)

MarshalBinaryBare implements BinaryMarshaler.MarshalBinaryBare method.

func (*ProtoCodec) MarshalBinaryLengthPrefixed

func (pc *ProtoCodec) MarshalBinaryLengthPrefixed(o codec.ProtoMarshaler) ([]byte, error)

MarshalBinaryLengthPrefixed implements BinaryMarshaler.MarshalBinaryLengthPrefixed method.

func (*ProtoCodec) MarshalInterface

func (pc *ProtoCodec) MarshalInterface(i proto.Message) ([]byte, error)

MarshalInterface is a convenience function for proto marshalling interfaces. It packs the provided value, which must be an interface, in an Any and then marshals it to bytes. NOTE: to marshal a concrete type, you should use MarshalBinaryBare instead

func (*ProtoCodec) MarshalInterfaceJSON

func (pc *ProtoCodec) MarshalInterfaceJSON(x proto.Message) ([]byte, error)

MarshalInterfaceJSON is a convenience function for proto marshalling interfaces. It packs the provided value in an Any and then marshals it to bytes. NOTE: to marshal a concrete type, you should use MarshalJSON instead

func (*ProtoCodec) MarshalJSON

func (pc *ProtoCodec) MarshalJSON(o proto.Message) ([]byte, error)

MarshalJSON implements JSONMarshaler.MarshalJSON method, it marshals to JSON using proto codec.

func (*ProtoCodec) MustMarshalBinaryBare

func (pc *ProtoCodec) MustMarshalBinaryBare(o codec.ProtoMarshaler) []byte

MustMarshalBinaryBare implements BinaryMarshaler.MustMarshalBinaryBare method.

func (*ProtoCodec) MustMarshalBinaryLengthPrefixed

func (pc *ProtoCodec) MustMarshalBinaryLengthPrefixed(o codec.ProtoMarshaler) []byte

MustMarshalBinaryLengthPrefixed implements BinaryMarshaler.MustMarshalBinaryLengthPrefixed method.

func (*ProtoCodec) MustMarshalJSON

func (pc *ProtoCodec) MustMarshalJSON(o proto.Message) []byte

MustMarshalJSON implements JSONMarshaler.MustMarshalJSON method, it executes MarshalJSON except it panics upon failure.

func (*ProtoCodec) MustUnmarshalBinaryBare

func (pc *ProtoCodec) MustUnmarshalBinaryBare(bz []byte, ptr codec.ProtoMarshaler)

MustUnmarshalBinaryBare implements BinaryMarshaler.MustUnmarshalBinaryBare method.

func (*ProtoCodec) MustUnmarshalBinaryLengthPrefixed

func (pc *ProtoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr codec.ProtoMarshaler)

MustUnmarshalBinaryLengthPrefixed implements BinaryMarshaler.MustUnmarshalBinaryLengthPrefixed method.

func (*ProtoCodec) MustUnmarshalJSON

func (pc *ProtoCodec) MustUnmarshalJSON(bz []byte, ptr proto.Message)

MustUnmarshalJSON implements JSONMarshaler.MustUnmarshalJSON method, it executes UnmarshalJSON except it panics upon failure.

func (*ProtoCodec) UnmarshalBinaryBare

func (pc *ProtoCodec) UnmarshalBinaryBare(bz []byte, ptr codec.ProtoMarshaler) error

UnmarshalBinaryBare implements BinaryMarshaler.UnmarshalBinaryBare method.

func (*ProtoCodec) UnmarshalBinaryLengthPrefixed

func (pc *ProtoCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr codec.ProtoMarshaler) error

UnmarshalBinaryLengthPrefixed implements BinaryMarshaler.UnmarshalBinaryLengthPrefixed method.

func (*ProtoCodec) UnmarshalInterface

func (pc *ProtoCodec) UnmarshalInterface(bz []byte, ptr interface{}) error

UnmarshalInterface is a convenience function for proto unmarshaling interfaces. It unmarshals an Any from bz bytes and then unpacks it to the `ptr`, which must be a pointer to a non empty interface with registered implementations. NOTE: to unmarshal a concrete type, you should use UnmarshalBinaryBare instead

Example:

var x MyInterface
err := cdc.UnmarshalInterface(bz, &x)

func (*ProtoCodec) UnmarshalInterfaceJSON

func (pc *ProtoCodec) UnmarshalInterfaceJSON(bz []byte, iface interface{}) error

UnmarshalInterfaceJSON is a convenience function for proto unmarshaling interfaces. It unmarshals an Any from bz bytes and then unpacks it to the `iface`, which must be a pointer to a non empty interface, implementing proto.Message with registered implementations. NOTE: to unmarshal a concrete type, you should use UnmarshalJSON instead

Example:

var x MyInterface  // must implement proto.Message
err := cdc.UnmarshalInterfaceJSON(&x, bz)

func (*ProtoCodec) UnmarshalJSON

func (pc *ProtoCodec) UnmarshalJSON(bz []byte, ptr proto.Message) error

UnmarshalJSON implements JSONMarshaler.UnmarshalJSON method, it unmarshals from JSON using proto codec.

func (*ProtoCodec) UnpackAny

func (pc *ProtoCodec) UnpackAny(any *types.Any, iface interface{}) error

UnpackAny implements AnyUnpacker.UnpackAny method, it unpacks the value in any to the interface pointer passed in as iface.

type RelayMsgs

type RelayMsgs struct {
	Src          []sdk.Msg `json:"src"`
	Dst          []sdk.Msg `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

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

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(src, dst *Chain)

Send sends the messages with appropriate output TODO: Parallelize? Maybe?

func (*RelayMsgs) SendWithController

func (r *RelayMsgs) SendWithController(src, dst *Chain, useController bool)

func (*RelayMsgs) Success

func (r *RelayMsgs) Success() bool

Success returns the success var

type RelaySequences

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

RelaySequences represents unrelayed packets on src and dst

type Strategy

type Strategy interface {
	GetType() string
	HandleEvents(src, dst *Chain, events map[string][]string)
	UnrelayedSequences(src, dst *Chain) (*RelaySequences, error)
	UnrelayedAcknowledgements(src, dst *Chain) (*RelaySequences, error)
	RelayPackets(src, dst *Chain, sp *RelaySequences) error
	RelayAcknowledgements(src, dst *Chain, sp *RelaySequences) error
}

Strategy defines

type StrategyCfg

type StrategyCfg struct {
	Type string `json:"type" yaml:"type"`
}

StrategyCfg defines which relaying strategy to take for a given path

func NewNaiveStrategy

func NewNaiveStrategy() *StrategyCfg

NewNaiveStrategy returns the proper configs for the NaiveStrategy

Jump to

Keyboard shortcuts

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