chainlib

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: Apache-2.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TendermintStatusQuery  = "status"
	ChainFetcherHeaderName = "X-LAVA-Provider"
)
View Source
const (
	ContextUserValueKeyDappID = "dappID"
	RetryListeningInterval    = 10 // seconds

)

Variables

This section is empty.

Functions

func CreateChainLibMocks

func CreateChainLibMocks(ctx context.Context, specIndex string, apiInterface string, serverCallback http.HandlerFunc, getToTopMostPath string) (cpar ChainParser, cprox ChainProxy, cfetc chaintracker.ChainFetcher, closeServer func(), errRet error)

generates a chain parser, a chain fetcher messages based on it apiInterface can either be an ApiInterface string as in spectypes.ApiInterfaceXXX or a number for an index in the apiCollections

func FormatResponseForParsing

func FormatResponseForParsing(reply *pairingtypes.RelayReply, chainMessage ChainMessageForSend) (parsable parser.RPCInput, err error)

func GetListenerWithRetryGrpc

func GetListenerWithRetryGrpc(protocol string, addr string) net.Listener

func ListenWithRetry

func ListenWithRetry(app *fiber.App, address string)

Types

type ApiContainer

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

type ApiKey

type ApiKey struct {
	Name           string
	ConnectionType string
}

type BaseChainParser

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

func (*BaseChainParser) Construct

func (bcp *BaseChainParser) Construct(spec spectypes.Spec, taggedApis map[spectypes.FUNCTION_TAG]TaggedContainer, serverApis map[ApiKey]ApiContainer, apiCollections map[CollectionKey]*spectypes.ApiCollection, headers map[ApiKey]*spectypes.Header)

func (*BaseChainParser) GetParsingByTag

func (bcp *BaseChainParser) GetParsingByTag(tag spectypes.FUNCTION_TAG) (parsing *spectypes.ParseDirective, collectionData *spectypes.CollectionData, existed bool)

func (*BaseChainParser) HandleHeaders

func (bcp *BaseChainParser) HandleHeaders(metadata []pairingtypes.Metadata, apiCollection *spectypes.ApiCollection, headersDirection spectypes.Header_HeaderType) (filteredHeaders []pairingtypes.Metadata, overwriteRequestedBlock string, ignoredMetadata []pairingtypes.Metadata)

type BaseChainProxy

type BaseChainProxy struct {
	ErrorHandler

	NodeUrl common.NodeUrl
	// contains filtered or unexported fields
}

type ChainFetcher

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

func NewChainFetcher

func NewChainFetcher(ctx context.Context, chainProxy ChainProxy, chainParser ChainParser, endpoint *lavasession.RPCProviderEndpoint) *ChainFetcher

func (*ChainFetcher) ChainFetcherMetadata

func (cf *ChainFetcher) ChainFetcherMetadata() []pairingtypes.Metadata

func (*ChainFetcher) FetchBlockHashByNum

func (cf *ChainFetcher) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)

func (*ChainFetcher) FetchChainID added in v0.20.0

func (cf *ChainFetcher) FetchChainID(ctx context.Context) (string, string, error)

func (*ChainFetcher) FetchEndpoint

func (cf *ChainFetcher) FetchEndpoint() lavasession.RPCProviderEndpoint

func (*ChainFetcher) FetchLatestBlockNum

func (cf *ChainFetcher) FetchLatestBlockNum(ctx context.Context) (int64, error)

func (*ChainFetcher) Validate

func (cf *ChainFetcher) Validate(ctx context.Context) error

type ChainFetcherIf

type ChainFetcherIf interface {
	FetchLatestBlockNum(ctx context.Context) (int64, error)
	FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)
	FetchEndpoint() lavasession.RPCProviderEndpoint
	Validate(ctx context.Context) error
}

type ChainListener

type ChainListener interface {
	Serve(ctx context.Context)
}

func NewChainListener

func NewChainListener(
	ctx context.Context,
	listenEndpoint *lavasession.RPCEndpoint,
	relaySender RelaySender,
	rpcConsumerLogs *metrics.RPCConsumerLogs,
	chainParser ChainParser,
) (ChainListener, error)

type ChainMessage

type ChainMessage interface {
	RequestedBlock() int64
	UpdateLatestBlockInMessage(latestBlock int64, modifyContent bool) (modified bool)
	AppendHeader(metadata []pairingtypes.Metadata)
	ChainMessageForSend
}

type ChainMessageForSend

type ChainMessageForSend interface {
	GetApi() *spectypes.Api
	GetRPCMessage() parser.RPCInput
	GetApiCollection() *spectypes.ApiCollection
}

func CraftChainMessage

func CraftChainMessage(parsing *spectypes.ParseDirective, connectionType string, chainParser ChainParser, craftData *CraftData, metadata []pairingtypes.Metadata) (ChainMessageForSend, error)

type ChainParser

type ChainParser interface {
	ParseMsg(url string, data []byte, connectionType string, metadata []pairingtypes.Metadata) (ChainMessage, error)
	SetSpec(spec spectypes.Spec)
	DataReliabilityParams() (enabled bool, dataReliabilityThreshold uint32)
	ChainBlockStats() (allowedBlockLagForQosSync int64, averageBlockTime time.Duration, blockDistanceForFinalizedData uint32, blocksInFinalizationProof uint32)
	GetParsingByTag(tag spectypes.FUNCTION_TAG) (parsing *spectypes.ParseDirective, collectionData *spectypes.CollectionData, existed bool)
	CraftMessage(parser *spectypes.ParseDirective, connectionType string, craftData *CraftData, metadata []pairingtypes.Metadata) (ChainMessageForSend, error)
	HandleHeaders(metadata []pairingtypes.Metadata, apiCollection *spectypes.ApiCollection, headersDirection spectypes.Header_HeaderType) (filtered []pairingtypes.Metadata, overwriteReqBlock string, ignoredMetadata []pairingtypes.Metadata)
}

func NewChainParser

func NewChainParser(apiInterface string) (chainParser ChainParser, err error)

type ChainProxy

type ChainProxy interface {
	SendNodeMsg(ctx context.Context, ch chan interface{}, chainMessage ChainMessageForSend) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error) // has to be thread safe, reuse code within ParseMsg as common functionality
}

func GetChainProxy added in v0.5.0

func GetChainProxy(ctx context.Context, nConns uint, rpcProviderEndpoint *lavasession.RPCProviderEndpoint, chainParser ChainParser) (ChainProxy, error)

func NewGrpcChainProxy

func NewGrpcChainProxy(ctx context.Context, nConns uint, rpcProviderEndpoint *lavasession.RPCProviderEndpoint, averageBlockTime time.Duration, parser ChainParser) (ChainProxy, error)

func NewJrpcChainProxy

func NewJrpcChainProxy(ctx context.Context, nConns uint, rpcProviderEndpoint *lavasession.RPCProviderEndpoint, averageBlockTime time.Duration, chainParser ChainParser) (ChainProxy, error)

func NewRestChainProxy

func NewRestChainProxy(ctx context.Context, nConns uint, rpcProviderEndpoint *lavasession.RPCProviderEndpoint, averageBlockTime time.Duration) (ChainProxy, error)

func NewtendermintRpcChainProxy

func NewtendermintRpcChainProxy(ctx context.Context, nConns uint, rpcProviderEndpoint *lavasession.RPCProviderEndpoint, averageBlockTime time.Duration) (ChainProxy, error)

type CollectionKey

type CollectionKey struct {
	ConnectionType string
	InternalPath   string
	Addon          string
}

type CraftData

type CraftData struct {
	Path           string
	Data           []byte
	ConnectionType string
}

type DummyChainFetcher

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

func NewDummyChainFetcher added in v0.15.0

func NewDummyChainFetcher(ctx context.Context, endpoint *lavasession.RPCProviderEndpoint) *DummyChainFetcher

func (*DummyChainFetcher) FetchBlockHashByNum

func (cf *DummyChainFetcher) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)

func (*DummyChainFetcher) FetchEndpoint added in v0.15.0

func (*DummyChainFetcher) FetchLatestBlockNum

func (cf *DummyChainFetcher) FetchLatestBlockNum(ctx context.Context) (int64, error)

func (*DummyChainFetcher) Validate

func (cf *DummyChainFetcher) Validate(ctx context.Context) error

type ErrorHandler

type ErrorHandler interface {
	HandleNodeError(context.Context, error) error
}

type GRPCErrorHandler

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

func (*GRPCErrorHandler) HandleNodeError

func (geh *GRPCErrorHandler) HandleNodeError(ctx context.Context, nodeError error) error

type GrpcChainListener

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

func NewGrpcChainListener

func NewGrpcChainListener(
	ctx context.Context,
	listenEndpoint *lavasession.RPCEndpoint,
	relaySender RelaySender,
	rpcConsumerLogs *metrics.RPCConsumerLogs,
	chainParser ChainParser) (chainListener *GrpcChainListener)

func (*GrpcChainListener) Serve

func (apil *GrpcChainListener) Serve(ctx context.Context)

Serve http server for GrpcChainListener

type GrpcChainParser

type GrpcChainParser struct {
	BaseChainParser
	// contains filtered or unexported fields
}

func NewGrpcChainParser

func NewGrpcChainParser() (chainParser *GrpcChainParser, err error)

NewGrpcChainParser creates a new instance of GrpcChainParser

func (*GrpcChainParser) ChainBlockStats

func (apip *GrpcChainParser) ChainBlockStats() (allowedBlockLagForQosSync int64, averageBlockTime time.Duration, blockDistanceForFinalizedData uint32, blocksInFinalizationProof uint32)

ChainBlockStats returns block stats from spec (spec.AllowedBlockLagForQosSync, spec.AverageBlockTime, spec.BlockDistanceForFinalizedData)

func (*GrpcChainParser) CraftMessage

func (apip *GrpcChainParser) CraftMessage(parsing *spectypes.ParseDirective, connectionType string, craftData *CraftData, metadata []pairingtypes.Metadata) (ChainMessageForSend, error)

func (*GrpcChainParser) DataReliabilityParams

func (apip *GrpcChainParser) DataReliabilityParams() (enabled bool, dataReliabilityThreshold uint32)

DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)

func (*GrpcChainParser) ParseMsg

func (apip *GrpcChainParser) ParseMsg(url string, data []byte, connectionType string, metadata []pairingtypes.Metadata) (ChainMessage, error)

ParseMsg parses message data into chain message object

func (*GrpcChainParser) SetSpec

func (apip *GrpcChainParser) SetSpec(spec spectypes.Spec)

SetSpec sets the spec for the GrpcChainParser

type GrpcChainProxy

type GrpcChainProxy struct {
	BaseChainProxy
	// contains filtered or unexported fields
}

func (*GrpcChainProxy) SendNodeMsg

func (cp *GrpcChainProxy) SendNodeMsg(ctx context.Context, ch chan interface{}, chainMessage ChainMessageForSend) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)

type GrpcNodeErrorResponse

type GrpcNodeErrorResponse struct {
	ErrorMessage string `json:"error_message"`
	ErrorCode    uint32 `json:"error_code"`
}

type JrpcChainProxy

type JrpcChainProxy struct {
	BaseChainProxy
	// contains filtered or unexported fields
}

func (*JrpcChainProxy) SendNodeMsg

func (cp *JrpcChainProxy) SendNodeMsg(ctx context.Context, ch chan interface{}, chainMessage ChainMessageForSend) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)

type JsonRPCChainListener

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

func NewJrpcChainListener

func NewJrpcChainListener(ctx context.Context, listenEndpoint *lavasession.RPCEndpoint, relaySender RelaySender, rpcConsumerLogs *metrics.RPCConsumerLogs) (chainListener *JsonRPCChainListener)

NewJrpcChainListener creates a new instance of JsonRPCChainListener

func (*JsonRPCChainListener) Serve

func (apil *JsonRPCChainListener) Serve(ctx context.Context)

Serve http server for JsonRPCChainListener

type JsonRPCChainParser

type JsonRPCChainParser struct {
	BaseChainParser
}

func NewJrpcChainParser

func NewJrpcChainParser() (chainParser *JsonRPCChainParser, err error)

NewJrpcChainParser creates a new instance of JsonRPCChainParser

func (*JsonRPCChainParser) ChainBlockStats

func (apip *JsonRPCChainParser) ChainBlockStats() (allowedBlockLagForQosSync int64, averageBlockTime time.Duration, blockDistanceForFinalizedData uint32, blocksInFinalizationProof uint32)

ChainBlockStats returns block stats from spec (spec.AllowedBlockLagForQosSync, spec.AverageBlockTime, spec.BlockDistanceForFinalizedData)

func (*JsonRPCChainParser) CraftMessage

func (apip *JsonRPCChainParser) CraftMessage(parsing *spectypes.ParseDirective, connectionType string, craftData *CraftData, metadata []pairingtypes.Metadata) (ChainMessageForSend, error)

func (*JsonRPCChainParser) DataReliabilityParams

func (apip *JsonRPCChainParser) DataReliabilityParams() (enabled bool, dataReliabilityThreshold uint32)

DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)

func (*JsonRPCChainParser) GetInternalPaths

func (apip *JsonRPCChainParser) GetInternalPaths() map[string]struct{}

func (*JsonRPCChainParser) ParseMsg

func (apip *JsonRPCChainParser) ParseMsg(url string, data []byte, connectionType string, metadata []pairingtypes.Metadata) (ChainMessage, error)

this func parses message data into chain message object

func (*JsonRPCChainParser) SetSpec

func (apip *JsonRPCChainParser) SetSpec(spec spectypes.Spec)

SetSpec sets the spec for the JsonRPCChainParser

type JsonRPCErrorHandler

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

func (*JsonRPCErrorHandler) HandleNodeError

func (jeh *JsonRPCErrorHandler) HandleNodeError(ctx context.Context, nodeError error) error

type LavaChainFetcher

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

func NewLavaChainFetcher

func NewLavaChainFetcher(ctx context.Context, clientCtx client.Context) *LavaChainFetcher

func (*LavaChainFetcher) FetchBlockHashByNum

func (lcf *LavaChainFetcher) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)

func (*LavaChainFetcher) FetchChainID

func (lcf *LavaChainFetcher) FetchChainID(ctx context.Context) (string, string, error)

func (*LavaChainFetcher) FetchEndpoint

func (lcf *LavaChainFetcher) FetchEndpoint() lavasession.RPCProviderEndpoint

func (*LavaChainFetcher) FetchLatestBlockNum

func (lcf *LavaChainFetcher) FetchLatestBlockNum(ctx context.Context) (int64, error)

type RelaySender

type RelaySender interface {
	SendRelay(
		ctx context.Context,
		url string,
		req string,
		connectionType string,
		dappID string,
		analytics *metrics.RelayMetrics,
		metadataValues []pairingtypes.Metadata,
	) (*pairingtypes.RelayReply, *pairingtypes.Relayer_RelaySubscribeClient, error)
}

type RestChainListener

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

func NewRestChainListener

func NewRestChainListener(ctx context.Context, listenEndpoint *lavasession.RPCEndpoint, relaySender RelaySender, rpcConsumerLogs *metrics.RPCConsumerLogs) (chainListener *RestChainListener)

NewRestChainListener creates a new instance of RestChainListener

func (*RestChainListener) Serve

func (apil *RestChainListener) Serve(ctx context.Context)

Serve http server for RestChainListener

type RestChainParser

type RestChainParser struct {
	BaseChainParser
}

func NewRestChainParser

func NewRestChainParser() (chainParser *RestChainParser, err error)

NewRestChainParser creates a new instance of RestChainParser

func (*RestChainParser) ChainBlockStats

func (apip *RestChainParser) ChainBlockStats() (allowedBlockLagForQosSync int64, averageBlockTime time.Duration, blockDistanceForFinalizedData uint32, blocksInFinalizationProof uint32)

ChainBlockStats returns block stats from spec (spec.AllowedBlockLagForQosSync, spec.AverageBlockTime, spec.BlockDistanceForFinalizedData)

func (*RestChainParser) CraftMessage

func (apip *RestChainParser) CraftMessage(parsing *spectypes.ParseDirective, connectionType string, craftData *CraftData, metadata []pairingtypes.Metadata) (ChainMessageForSend, error)

func (*RestChainParser) DataReliabilityParams

func (apip *RestChainParser) DataReliabilityParams() (enabled bool, dataReliabilityThreshold uint32)

DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)

func (*RestChainParser) ParseMsg

func (apip *RestChainParser) ParseMsg(url string, data []byte, connectionType string, metadata []pairingtypes.Metadata) (ChainMessage, error)

ParseMsg parses message data into chain message object

func (*RestChainParser) SetSpec

func (apip *RestChainParser) SetSpec(spec spectypes.Spec)

SetSpec sets the spec for the TendermintChainParser

type RestChainProxy

type RestChainProxy struct {
	BaseChainProxy
}

func (*RestChainProxy) SendNodeMsg

func (rcp *RestChainProxy) SendNodeMsg(ctx context.Context, ch chan interface{}, chainMessage ChainMessageForSend) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)

type RestErrorHandler

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

func (*RestErrorHandler) HandleNodeError

func (rne *RestErrorHandler) HandleNodeError(ctx context.Context, nodeError error) error

Validating if the error is related to the provider connection or not returning nil if its not one of the expected connectivity error types

type TaggedContainer

type TaggedContainer struct {
	Parsing       *spectypes.ParseDirective
	ApiCollection *spectypes.ApiCollection
}

type TendermintChainParser

type TendermintChainParser struct {
	BaseChainParser
}

func NewTendermintRpcChainParser

func NewTendermintRpcChainParser() (chainParser *TendermintChainParser, err error)

NewTendermintRpcChainParser creates a new instance of TendermintChainParser

func (*TendermintChainParser) ChainBlockStats

func (apip *TendermintChainParser) ChainBlockStats() (allowedBlockLagForQosSync int64, averageBlockTime time.Duration, blockDistanceForFinalizedData uint32, blocksInFinalizationProof uint32)

ChainBlockStats returns block stats from spec (spec.AllowedBlockLagForQosSync, spec.AverageBlockTime, spec.BlockDistanceForFinalizedData, spec.BlocksInFinalizationProof)

func (*TendermintChainParser) CraftMessage

func (apip *TendermintChainParser) CraftMessage(parsing *spectypes.ParseDirective, connectionType string, craftData *CraftData, metadata []pairingtypes.Metadata) (ChainMessageForSend, error)

func (*TendermintChainParser) DataReliabilityParams

func (apip *TendermintChainParser) DataReliabilityParams() (enabled bool, dataReliabilityThreshold uint32)

DataReliabilityParams returns data reliability params from spec (spec.enabled and spec.dataReliabilityThreshold)

func (*TendermintChainParser) ParseMsg

func (apip *TendermintChainParser) ParseMsg(url string, data []byte, connectionType string, metadata []pairingtypes.Metadata) (ChainMessage, error)

ParseMsg parses message data into chain message object

func (*TendermintChainParser) SetSpec

func (apip *TendermintChainParser) SetSpec(spec spectypes.Spec)

SetSpec sets the spec for the TendermintChainParser

type TendermintRPCErrorHandler

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

func (*TendermintRPCErrorHandler) HandleNodeError

func (tendermintErrorHandler *TendermintRPCErrorHandler) HandleNodeError(ctx context.Context, nodeError error) error

type TendermintRpcChainListener

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

func NewTendermintRpcChainListener

func NewTendermintRpcChainListener(ctx context.Context, listenEndpoint *lavasession.RPCEndpoint, relaySender RelaySender, rpcConsumerLogs *metrics.RPCConsumerLogs) (chainListener *TendermintRpcChainListener)

NewTendermintRpcChainListener creates a new instance of TendermintRpcChainListener

func (*TendermintRpcChainListener) Serve

func (apil *TendermintRpcChainListener) Serve(ctx context.Context)

Serve http server for TendermintRpcChainListener

type TestStruct

type TestStruct struct {
	Ctx       context.Context
	Keepers   *keepertest.Keepers
	Servers   *keepertest.Servers
	Providers []testcommon.Account
	Spec      spectypes.Spec
	Plan      plantypes.Plan
	Consumer  testcommon.Account
}

func SetupForTests

func SetupForTests(t *testing.T, numOfProviders int, specID string, getToTopMostPath string) TestStruct

Directories

Path Synopsis
rpcclient
package rpcclient implements bi-directional JSON-RPC 2.0 on multiple transports.
package rpcclient implements bi-directional JSON-RPC 2.0 on multiple transports.
testproto
Package testproto is a reverse proxy.
Package testproto is a reverse proxy.

Jump to

Keyboard shortcuts

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