processor

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: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RuleAllowList = "allowlist"
	RuleDenyList  = "denylist"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainProcessor

type ChainProcessor interface {
	// Run starts the query loop for the chain which will gather applicable ibc messages and push events out to the relevant PathProcessors.
	// The initialBlockHistory parameter determines how many historical blocks should be fetched and processed before continuing with current blocks.
	// ChainProcessors should obey the context and return upon context cancellation.
	Run(ctx context.Context, initialBlockHistory uint64) error

	// Provider returns the ChainProvider, which provides the methods for querying, assembling IBC messages, and sending transactions.
	Provider() provider.ChainProvider

	// Set the PathProcessors that this ChainProcessor should publish relevant IBC events to.
	// ChainProcessors need reference to their PathProcessors and vice-versa, handled by EventProcessorBuilder.Build().
	SetPathProcessors(pathProcessors PathProcessors)
}

The ChainProcessor interface is reponsible for polling blocks and emitting IBC message events to the PathProcessors. It is also responsible for tracking open channels and not sending messages to the PathProcessors for closed channels.

type ChainProcessorCacheData

type ChainProcessorCacheData struct {
	IBCMessagesCache     IBCMessagesCache
	InSync               bool
	ClientState          provider.ClientState
	ConnectionStateCache ConnectionStateCache
	ChannelStateCache    ChannelStateCache
	LatestBlock          provider.LatestBlock
	LatestHeader         provider.IBCHeader
	IBCHeaderCache       IBCHeaderCache
}

ChainProcessorCacheData is the data sent from the ChainProcessors to the PathProcessors to keep the PathProcessors up to date with the latest info from the chains.

type ChainProcessors

type ChainProcessors []ChainProcessor

ChainProcessors is a slice of ChainProcessor instances.

type ChannelKey

type ChannelKey struct {
	ChannelID             string
	PortID                string
	CounterpartyChannelID string
	CounterpartyPortID    string
}

ChannelKey is the key used for identifying channels between ChainProcessor and PathProcessor.

func ChannelInfoChannelKey

func ChannelInfoChannelKey(info provider.ChannelInfo) ChannelKey

ChannelInfoChannelKey returns the applicable ChannelKey for ChannelInfo.

func PacketInfoChannelKey

func PacketInfoChannelKey(eventType string, info provider.PacketInfo) (ChannelKey, error)

PacketInfoChannelKey returns the applicable ChannelKey for the chain based on the eventType.

func (ChannelKey) Counterparty

func (k ChannelKey) Counterparty() ChannelKey

Counterparty flips a ChannelKey for the perspective of the counterparty chain

func (ChannelKey) MarshalLogObject

func (k ChannelKey) MarshalLogObject(enc zapcore.ObjectEncoder) error

type ChannelMessage

type ChannelMessage struct {
	ChainID   string
	EventType string
	Info      provider.ChannelInfo
}

type ChannelMessageCache

type ChannelMessageCache map[ChannelKey]provider.ChannelInfo

ChannelMessageCache is used for caching channel handshake IBC messages for a given IBC channel.

func (ChannelMessageCache) Merge

Merge merges another ChannelMessageCache into this one.

type ChannelMessageLifecycle

type ChannelMessageLifecycle struct {
	Initial     *ChannelMessage
	Termination *ChannelMessage
}

ChannelMessageLifecycle is used as a stop condition for the PathProcessor. It will send the Initial channel message (if non-nil), then stop once it observes the termination channel message (if non-nil).

type ChannelMessagesCache

type ChannelMessagesCache map[string]ChannelMessageCache

ChannelMessagesCache is used for caching a ChannelMessageCache for a given IBC message type.

func (ChannelMessagesCache) DeleteMessages

func (c ChannelMessagesCache) DeleteMessages(toDelete ...map[string][]ChannelKey)

func (ChannelMessagesCache) Merge

Merge merges another ChannelMessagesCache into this one.

func (ChannelMessagesCache) Retain

Retain assumes creates cache path if it doesn't exist, then caches message.

type ChannelPacketMessagesCache

type ChannelPacketMessagesCache map[ChannelKey]PacketMessagesCache

ChannelPacketMessagesCache is used for caching a PacketMessagesCache for a given IBC channel.

func (ChannelPacketMessagesCache) Merge

Merge merges another ChannelPacketMessagesCache into this one.

func (ChannelPacketMessagesCache) Retain

Retain assumes the packet is applicable to the channels for a path processor that is subscribed to this chain processor. It creates cache path if it doesn't exist, then caches message.

func (ChannelPacketMessagesCache) ShouldRetainSequence

func (c ChannelPacketMessagesCache) ShouldRetainSequence(p PathProcessors, k ChannelKey, chainID string, m string, seq uint64) bool

ShouldRetainSequence returns true if packet is applicable to the channels for path processors that are subscribed to this chain processor

type ChannelStateCache

type ChannelStateCache map[ChannelKey]bool

ChannelStateCache maintains channel open state for multiple channels.

func (ChannelStateCache) FilterForClient

func (c ChannelStateCache) FilterForClient(clientID string, channelConnections map[string]string, connectionClients map[string]string) ChannelStateCache

FilterForClient returns a filtered copy of channels on top of an underlying clientID so it can be used by other goroutines.

func (ChannelStateCache) Merge

func (c ChannelStateCache) Merge(other ChannelStateCache)

Merge merges another ChannelStateCache into this one, appending messages and updating the Open state.

type ConnectionKey

type ConnectionKey struct {
	ClientID             string
	ConnectionID         string
	CounterpartyClientID string
	CounterpartyConnID   string
}

ConnectionKey is the key used for identifying connections between ChainProcessor and PathProcessor.

func ConnectionInfoConnectionKey

func ConnectionInfoConnectionKey(info provider.ConnectionInfo) ConnectionKey

ConnectionInfoConnectionKey returns the applicable ConnectionKey for ConnectionInfo.

func (ConnectionKey) Counterparty

func (connectionKey ConnectionKey) Counterparty() ConnectionKey

Counterparty flips a ConnectionKey for the perspective of the counterparty chain

func (ConnectionKey) MarshalLogObject

func (k ConnectionKey) MarshalLogObject(enc zapcore.ObjectEncoder) error

type ConnectionMessage

type ConnectionMessage struct {
	ChainID   string
	EventType string
	Info      provider.ConnectionInfo
}

type ConnectionMessageCache

type ConnectionMessageCache map[ConnectionKey]provider.ConnectionInfo

ConnectionMessageCache is used for caching connection handshake IBC messages for a given IBC connection.

func (ConnectionMessageCache) Merge

Merge merges another ConnectionMessageCache into this one.

type ConnectionMessageLifecycle

type ConnectionMessageLifecycle struct {
	Initial     *ConnectionMessage
	Termination *ConnectionMessage
}

ConnectionMessageLifecycle is used as a stop condition for the PathProcessor. It will send the Initial connection message (if non-nil), then stop once it observes the termination connection message (if non-nil).

type ConnectionMessagesCache

type ConnectionMessagesCache map[string]ConnectionMessageCache

ConnectionMessagesCache is used for caching a ConnectionMessageCache for a given IBC message type.

func (ConnectionMessagesCache) DeleteMessages

func (c ConnectionMessagesCache) DeleteMessages(toDelete ...map[string][]ConnectionKey)

func (ConnectionMessagesCache) Merge

Merge merges another ConnectionMessagesCache into this one.

func (ConnectionMessagesCache) Retain

Retain assumes creates cache path if it doesn't exist, then caches message.

type ConnectionStateCache

type ConnectionStateCache map[ConnectionKey]bool

ConnectionStateCache maintains connection open state for multiple connections.

func (ConnectionStateCache) FilterForClient

func (c ConnectionStateCache) FilterForClient(clientID string) ConnectionStateCache

FilterForClient makes a filtered copy of the ConnectionStateCache for a single client ID so it can be used by other goroutines.

func (ConnectionStateCache) Merge

Merge merges another ChannelStateCache into this one, appending messages and updating the Open state.

type EventProcessor

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

EventProcessor is a built instance that is ready to be executed with Run(ctx).

func (EventProcessor) Run

func (ep EventProcessor) Run(ctx context.Context) error

Run is a blocking call that launches all provided PathProcessors and ChainProcessors in parallel. It will return once all PathProcessors and ChainProcessors have stopped running due to context cancellation, or if a critical error has occurred within one of the ChainProcessors.

type EventProcessorBuilder

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

EventProcessorBuilder is a configuration type with .With functions used for building an EventProcessor.

func NewEventProcessor

func NewEventProcessor() EventProcessorBuilder

NewEventProcessor creates a builder than can be used to construct a multi-ChainProcessor, multi-PathProcessor topology for the relayer.

func (EventProcessorBuilder) Build

Build links the relevant ChainProcessors and PathProcessors, then returns an EventProcessor that can be used to run the ChainProcessors and PathProcessors.

func (EventProcessorBuilder) WithChainProcessors

func (ep EventProcessorBuilder) WithChainProcessors(chainProcessors ...ChainProcessor) EventProcessorBuilder

WithChainProcessors adds to the list of ChainProcessors to be used if the chain name has not already been added.

func (EventProcessorBuilder) WithInitialBlockHistory

func (ep EventProcessorBuilder) WithInitialBlockHistory(initialBlockHistory uint64) EventProcessorBuilder

WithInitialBlockHistory sets the initial block history to query for the ChainProcessors.

func (EventProcessorBuilder) WithMessageLifecycle

func (ep EventProcessorBuilder) WithMessageLifecycle(messageLifecycle MessageLifecycle) EventProcessorBuilder

WithMessageLifecycle sets the message that should be sent to a chain once in sync, and also the message that should stop the EventProcessor once observed.

func (EventProcessorBuilder) WithPathProcessors

func (ep EventProcessorBuilder) WithPathProcessors(pathProcessors ...*PathProcessor) EventProcessorBuilder

WithPathProcessors adds to the list of PathProcessors to be used.

type IBCHeaderCache

type IBCHeaderCache map[uint64]provider.IBCHeader

IBCHeaderCache holds a mapping of IBCHeaders for their block height.

func (IBCHeaderCache) Merge

func (c IBCHeaderCache) Merge(other IBCHeaderCache)

Merge merges another IBCHeaderCache into this one.

func (IBCHeaderCache) Prune

func (c IBCHeaderCache) Prune(keep int)

Prune deletes all map entries except for the most recent (keep).

type IBCMessagesCache

type IBCMessagesCache struct {
	PacketFlow          ChannelPacketMessagesCache
	ConnectionHandshake ConnectionMessagesCache
	ChannelHandshake    ChannelMessagesCache
}

IBCMessagesCache holds cached messages for packet flows, connection handshakes, and channel handshakes. The PathProcessors use this for message correlation to determine when messages should be sent and are pruned when flows/handshakes are complete. ChainProcessors construct this for new IBC messages and pass it to the PathProcessors which will retain relevant messages for each PathProcessor.

func NewIBCMessagesCache

func NewIBCMessagesCache() IBCMessagesCache

NewIBCMessagesCache returns an empty IBCMessagesCache.

type MessageLifecycle

type MessageLifecycle interface {
	// contains filtered or unexported methods
}

MessageLifecycle is used to send an initial IBC message to a chain once the chains are in sync for the PathProcessor. It also allows setting a stop condition for the PathProcessor. PathProcessor will stop if it observes a message that matches the MessageLifecycle's Termination message.

type PacketMessage

type PacketMessage struct {
	ChainID   string
	EventType string
	Info      provider.PacketInfo
}

type PacketMessageLifecycle

type PacketMessageLifecycle struct {
	Initial     *PacketMessage
	Termination *PacketMessage
}

PacketMessageLifecycle is used as a stop condition for the PathProcessor. It will send the Initial packet message (if non-nil), then stop once it observes the Termination packet message (if non-nil).

type PacketMessagesCache

type PacketMessagesCache map[string]PacketSequenceCache

PacketMessagesCache is used for caching a PacketSequenceCache for a given IBC message type.

func (PacketMessagesCache) Clone

Clone creates a deep copy of a PacketMessagesCache.

func (PacketMessagesCache) DeleteMessages

func (c PacketMessagesCache) DeleteMessages(toDelete ...map[string][]uint64)

func (PacketMessagesCache) Merge

Merge merges another PacketMessagesCache into this one.

type PacketSequenceCache

type PacketSequenceCache map[uint64]provider.PacketInfo

PacketSequenceCache is used for caching an IBC message for a given packet sequence.

func (PacketSequenceCache) Merge

Merge merges another PacketSequenceCache into this one.

type PathEnd

type PathEnd struct {
	ChainID  string
	ClientID string

	// Can be either "allowlist" or "denylist"
	Rule       string
	FilterList []ChannelKey // which channels to allow or deny
}

PathEnd references one chain involved in a path. A path is composed of two PathEnds.

func NewPathEnd

func NewPathEnd(chainID string, clientID string, rule string, filterList []ChannelKey) PathEnd

NewPathEnd constructs a PathEnd, validating initial parameters.

func (PathEnd) ShouldRelayChannel

func (pe PathEnd) ShouldRelayChannel(channelKey ChannelKey) bool

if port ID is empty on allowlist channel, allow all ports if port ID is non-empty on allowlist channel, allow only that specific port if port ID is empty on blocklist channel, block all ports if port ID is non-empty on blocklist channel, block only that specific port

type PathProcessor

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

PathProcessor is a process that handles incoming IBC messages from a pair of chains. It determines what messages need to be relayed, and sends them.

func NewPathProcessor

func NewPathProcessor(log *zap.Logger, pathEnd1 PathEnd, pathEnd2 PathEnd, memo string) *PathProcessor

func (*PathProcessor) HandleNewData

func (pp *PathProcessor) HandleNewData(chainID string, cacheData ChainProcessorCacheData)

ChainProcessors call this method when they have new IBC messages

func (*PathProcessor) IsRelayedChannel

func (pp *PathProcessor) IsRelayedChannel(chainID string, channelKey ChannelKey) bool

func (*PathProcessor) IsRelevantChannel

func (pp *PathProcessor) IsRelevantChannel(chainID string, channelID string) bool

func (*PathProcessor) IsRelevantClient

func (pp *PathProcessor) IsRelevantClient(chainID string, clientID string) bool

func (*PathProcessor) IsRelevantConnection

func (pp *PathProcessor) IsRelevantConnection(chainID string, connectionID string) bool

func (*PathProcessor) OnConnectionMessage

func (pp *PathProcessor) OnConnectionMessage(chainID string, eventType string, onMsg func(provider.ConnectionInfo))

OnConnectionMessage allows the caller to handle connection handshake messages with a callback.

func (*PathProcessor) PathEnd1Messages

func (pp *PathProcessor) PathEnd1Messages(channelKey ChannelKey, message string) PacketSequenceCache

TEST USE ONLY

func (*PathProcessor) PathEnd2Messages

func (pp *PathProcessor) PathEnd2Messages(channelKey ChannelKey, message string) PacketSequenceCache

TEST USE ONLY

func (*PathProcessor) ProcessBacklogIfReady

func (pp *PathProcessor) ProcessBacklogIfReady()

ProcessBacklogIfReady gives ChainProcessors a way to trigger the path processor process as soon as they are in sync for the first time, even if they do not have new messages.

func (*PathProcessor) RelevantClientID

func (pp *PathProcessor) RelevantClientID(chainID string) string

RelevantClientID returns the relevant client ID or panics

func (*PathProcessor) Run

func (pp *PathProcessor) Run(ctx context.Context, cancel func(), messageLifecycle MessageLifecycle)

Run executes the main path process.

func (*PathProcessor) SetChainProviderIfApplicable

func (pp *PathProcessor) SetChainProviderIfApplicable(chainProvider provider.ChainProvider) bool

Path Processors are constructed before ChainProcessors, so reference needs to be added afterwards This can be done inside the ChainProcessor constructor for simplification

type PathProcessors

type PathProcessors []*PathProcessor

PathProcessors is a slice of PathProcessor instances

func (PathProcessors) IsRelayedChannel

func (p PathProcessors) IsRelayedChannel(k ChannelKey, chainID string) bool

Jump to

Keyboard shortcuts

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