chainproxy

package
v0.8.0-RC1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2023 License: Apache-2.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout            = 10 * time.Second
	TimePerCU                 = uint64(100 * time.Millisecond)
	ContextUserValueKeyDappID = "dappID"
	MinimumTimePerRelayDelay  = time.Second
	AverageWorldLatency       = 200 * time.Millisecond
	LavaErrorCode             = 555
	InternalErrorString       = "Internal Error"
)
View Source
const (
	DialTimeout                                = 500 * time.Millisecond
	ParallelConnectionsFlag                    = "parallel-connections"
	MaximumNumberOfParallelConnectionsAttempts = 10
)
View Source
const (
	RefererHeaderKey = "Referer"
)
View Source
const TendermintProviderHttpEndpoint = "tendermint-http-endpoint"

Variables

View Source
var ErrFailedToConvertMessage = sdkerrors.New("RPC error", 1000, "failed to convert a message")
View Source
var NumberOfParallelConnections uint = 10
View Source
var ReturnMaskedErrors = "false"

Functions

func ExtractDappIDFromFiberContext

func ExtractDappIDFromFiberContext(c *fiber.Ctx) (dappID string)

func ExtractDappIDFromWebsocketConnection

func ExtractDappIDFromWebsocketConnection(c *websocket.Conn) string

func ParseSymbol

func ParseSymbol(svcAndMethod string) (string, string)

func ReflectionSupport

func ReflectionSupport(err error) error

func SendRelay

func SendRelay(
	ctx context.Context,
	cp ChainProxy,
	privKey *btcec.PrivateKey,
	url string,
	req string,
	connectionType string,
	dappID string,
	analytics *metrics.RelayMetrics,
) (*pairingtypes.RelayReply, *pairingtypes.Relayer_RelaySubscribeClient, error)

Client requests and queries

func VerifyRelayReply

func VerifyRelayReply(reply *pairingtypes.RelayReply, relayRequest *pairingtypes.RelayRequest, addr string, comparesHashes bool) error

Types

type ChainProxy

type ChainProxy interface {
	Start(context.Context) error
	GetSentry() *sentry.Sentry
	ParseMsg(string, []byte, string) (NodeMessage, error)
	PortalStart(context.Context, *btcec.PrivateKey, string)
	FetchLatestBlockNum(ctx context.Context) (int64, error)
	FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)
	GetConsumerSessionManager() *lavasession.ConsumerSessionManager
	SetCache(*performance.Cache)
	GetCache() *performance.Cache
}

func GetChainProxy

func GetChainProxy(nodeUrl string, nConns uint, sentry *sentry.Sentry, pLogs *PortalLogs, flagSet *pflag.FlagSet) (ChainProxy, error)

func NewGrpcChainProxy

func NewGrpcChainProxy(nodeUrl string, nConns uint, sentry *sentry.Sentry, csm *lavasession.ConsumerSessionManager, pLogs *PortalLogs) ChainProxy

func NewJrpcChainProxy

func NewJrpcChainProxy(nodeUrl string, nConns uint, sentry *sentry.Sentry, csm *lavasession.ConsumerSessionManager, pLogs *PortalLogs) ChainProxy

func NewRestChainProxy

func NewRestChainProxy(nodeUrl string, sentry *sentry.Sentry, csm *lavasession.ConsumerSessionManager, pLogs *PortalLogs) ChainProxy

func NewtendermintRpcChainProxy

func NewtendermintRpcChainProxy(nodeUrl string, nConns uint, sentry *sentry.Sentry, csm *lavasession.ConsumerSessionManager, pLogs *PortalLogs, flagSet *pflag.FlagSet) ChainProxy

type Connector

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

func NewConnector

func NewConnector(ctx context.Context, nConns uint, addr string) *Connector

func (*Connector) Close

func (connector *Connector) Close()

func (*Connector) GetRpc

func (connector *Connector) GetRpc(ctx context.Context, block bool) (*rpcclient.Client, error)

func (*Connector) ReturnRpc

func (connector *Connector) ReturnRpc(rpc *rpcclient.Client)

type GRPCConnector

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

func NewGRPCConnector

func NewGRPCConnector(ctx context.Context, nConns uint, addr string) *GRPCConnector

func (*GRPCConnector) Close

func (connector *GRPCConnector) Close()

func (*GRPCConnector) GetRpc

func (connector *GRPCConnector) GetRpc(ctx context.Context, block bool) (*grpc.ClientConn, error)

func (*GRPCConnector) ReturnRpc

func (connector *GRPCConnector) ReturnRpc(rpc *grpc.ClientConn)

type GrpcChainProxy

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

func (*GrpcChainProxy) FetchBlockHashByNum

func (cp *GrpcChainProxy) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)

func (*GrpcChainProxy) FetchLatestBlockNum

func (cp *GrpcChainProxy) FetchLatestBlockNum(ctx context.Context) (int64, error)

func (*GrpcChainProxy) GetCache

func (cp *GrpcChainProxy) GetCache() *performance.Cache

func (*GrpcChainProxy) GetConsumerSessionManager

func (cp *GrpcChainProxy) GetConsumerSessionManager() *lavasession.ConsumerSessionManager

func (*GrpcChainProxy) GetSentry

func (cp *GrpcChainProxy) GetSentry() *sentry.Sentry

func (*GrpcChainProxy) NewMessage

func (cp *GrpcChainProxy) NewMessage(path string, data []byte, connectionType string) (*GrpcMessage, error)

func (*GrpcChainProxy) ParseMsg

func (cp *GrpcChainProxy) ParseMsg(path string, data []byte, connectionType string) (NodeMessage, error)

func (*GrpcChainProxy) PortalStart

func (cp *GrpcChainProxy) PortalStart(ctx context.Context, privKey *btcec.PrivateKey, listenAddr string)

func (*GrpcChainProxy) SetCache

func (cp *GrpcChainProxy) SetCache(cache *performance.Cache)

func (*GrpcChainProxy) Start

func (cp *GrpcChainProxy) Start(ctx context.Context) error

type GrpcMessage

type GrpcMessage struct {
	Result json.RawMessage
	// contains filtered or unexported fields
}

func (*GrpcMessage) GetExtraContextTimeout added in v0.6.0

func (r *GrpcMessage) GetExtraContextTimeout() time.Duration

func (*GrpcMessage) GetInterface

func (nm *GrpcMessage) GetInterface() *spectypes.ApiInterface

func (*GrpcMessage) GetMsg

func (r *GrpcMessage) GetMsg() interface{}

func (GrpcMessage) GetParams

func (m GrpcMessage) GetParams() interface{}

func (GrpcMessage) GetResult

func (m GrpcMessage) GetResult() json.RawMessage

func (*GrpcMessage) GetServiceApi

func (nm *GrpcMessage) GetServiceApi() *spectypes.ServiceApi

func (GrpcMessage) ParseBlock

func (m GrpcMessage) ParseBlock(inp string) (int64, error)

func (*GrpcMessage) RequestedBlock

func (nm *GrpcMessage) RequestedBlock() int64

func (*GrpcMessage) Send

func (nm *GrpcMessage) Send(ctx context.Context, ch chan interface{}) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)

type JSONRPCIntID added in v0.5.0

type JSONRPCIntID int

JSONRPCIntID a wrapper for JSON-RPC integer IDs

func (JSONRPCIntID) String added in v0.5.0

func (id JSONRPCIntID) String() string

type JSONRPCStringID added in v0.5.0

type JSONRPCStringID string

JSONRPCStringID a wrapper for JSON-RPC string IDs

func (JSONRPCStringID) String added in v0.5.0

func (id JSONRPCStringID) String() string

type JrpcChainProxy

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

func (*JrpcChainProxy) FetchBlockHashByNum

func (cp *JrpcChainProxy) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)

func (*JrpcChainProxy) FetchLatestBlockNum

func (cp *JrpcChainProxy) FetchLatestBlockNum(ctx context.Context) (int64, error)

func (*JrpcChainProxy) GetCache

func (cp *JrpcChainProxy) GetCache() *performance.Cache

func (*JrpcChainProxy) GetConsumerSessionManager

func (cp *JrpcChainProxy) GetConsumerSessionManager() *lavasession.ConsumerSessionManager

func (*JrpcChainProxy) GetSentry

func (cp *JrpcChainProxy) GetSentry() *sentry.Sentry

func (*JrpcChainProxy) NewMessage

func (cp *JrpcChainProxy) NewMessage(serviceApi *spectypes.ServiceApi, requestedBlock int64, params []interface{}) (*JrpcMessage, error)

func (*JrpcChainProxy) ParseMsg

func (cp *JrpcChainProxy) ParseMsg(path string, data []byte, connectionType string) (NodeMessage, error)

func (*JrpcChainProxy) PortalStart

func (cp *JrpcChainProxy) PortalStart(ctx context.Context, privKey *btcec.PrivateKey, listenAddr string)

func (*JrpcChainProxy) SetCache

func (cp *JrpcChainProxy) SetCache(cache *performance.Cache)

func (*JrpcChainProxy) Start

func (cp *JrpcChainProxy) Start(ctx context.Context) error

type JrpcMessage

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

func (*JrpcMessage) GetExtraContextTimeout added in v0.6.0

func (r *JrpcMessage) GetExtraContextTimeout() time.Duration

func (*JrpcMessage) GetInterface

func (nm *JrpcMessage) GetInterface() *spectypes.ApiInterface

func (*JrpcMessage) GetMsg

func (j *JrpcMessage) GetMsg() interface{}

func (*JrpcMessage) GetServiceApi

func (nm *JrpcMessage) GetServiceApi() *spectypes.ServiceApi

func (*JrpcMessage) RequestedBlock

func (nm *JrpcMessage) RequestedBlock() int64

func (*JrpcMessage) Send

func (nm *JrpcMessage) Send(ctx context.Context, ch chan interface{}) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)

type JsonrpcMessage

type JsonrpcMessage struct {
	Version string               `json:"jsonrpc,omitempty"`
	ID      json.RawMessage      `json:"id,omitempty"`
	Method  string               `json:"method,omitempty"`
	Params  interface{}          `json:"params,omitempty"`
	Error   *rpcclient.JsonError `json:"error,omitempty"`
	Result  json.RawMessage      `json:"result,omitempty"`
}

func (JsonrpcMessage) GetParams

func (cp JsonrpcMessage) GetParams() interface{}

func (JsonrpcMessage) GetResult

func (cp JsonrpcMessage) GetResult() json.RawMessage

func (JsonrpcMessage) ParseBlock

func (cp JsonrpcMessage) ParseBlock(inp string) (int64, error)

type NodeMessage

type NodeMessage interface {
	GetServiceApi() *spectypes.ServiceApi
	GetInterface() *spectypes.ApiInterface
	Send(ctx context.Context, ch chan interface{}) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)
	RequestedBlock() int64
	GetMsg() interface{}
	GetExtraContextTimeout() time.Duration
}

type PortalLogs

type PortalLogs struct {
	MetricService   *metrics.MetricService
	StoreMetricData bool
	// contains filtered or unexported fields
}

func NewPortalLogs

func NewPortalLogs() (*PortalLogs, error)

func (*PortalLogs) AddMetricForGrpc added in v0.6.0

func (pl *PortalLogs) AddMetricForGrpc(data *metrics.RelayMetrics, err error, metadataValues *metadata.MD)

func (*PortalLogs) AddMetricForHttp added in v0.6.0

func (pl *PortalLogs) AddMetricForHttp(data *metrics.RelayMetrics, err error, headers map[string]string)

func (*PortalLogs) AddMetricForWebSocket added in v0.6.0

func (pl *PortalLogs) AddMetricForWebSocket(data *metrics.RelayMetrics, err error, c *websocket.Conn)

func (*PortalLogs) AnalyzeWebSocketErrorAndWriteMessage

func (pl *PortalLogs) AnalyzeWebSocketErrorAndWriteMessage(c *websocket.Conn, mt int, err error, msgSeed string, msg []byte, rpcType string)

Websocket healthy disconnections throw "websocket: close 1005 (no status)" error, We dont want to alert error monitoring for that purpses.

func (*PortalLogs) GetMessageSeed

func (pl *PortalLogs) GetMessageSeed() string

func (*PortalLogs) GetUniqueGuidResponseForError

func (pl *PortalLogs) GetUniqueGuidResponseForError(responseError error, msgSeed string) string

Input will be masked with a random GUID if returnMaskedErrors is set to true

func (*PortalLogs) LogRequestAndResponse

func (pl *PortalLogs) LogRequestAndResponse(module string, hasError bool, method string, path string, req string, resp string, msgSeed string, err error)

func (*PortalLogs) LogStartTransaction

func (pl *PortalLogs) LogStartTransaction(name string)

type RPCResponse added in v0.5.0

type RPCResponse struct {
	JSONRPC string                    `json:"jsonrpc"`
	ID      jsonrpcId                 `json:"id,omitempty"`
	Result  json.RawMessage           `json:"result,omitempty"`
	Error   *tenderminttypes.RPCError `json:"error,omitempty"`
}

type RestChainProxy

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

func (*RestChainProxy) FetchBlockHashByNum

func (cp *RestChainProxy) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)

func (*RestChainProxy) FetchLatestBlockNum

func (cp *RestChainProxy) FetchLatestBlockNum(ctx context.Context) (int64, error)

func (*RestChainProxy) GetCache

func (cp *RestChainProxy) GetCache() *performance.Cache

func (*RestChainProxy) GetConsumerSessionManager

func (cp *RestChainProxy) GetConsumerSessionManager() *lavasession.ConsumerSessionManager

func (*RestChainProxy) GetSentry

func (cp *RestChainProxy) GetSentry() *sentry.Sentry

func (*RestChainProxy) NewMessage

func (cp *RestChainProxy) NewMessage(path string, data []byte, connectionType string) (*RestMessage, error)

func (*RestChainProxy) ParseMsg

func (cp *RestChainProxy) ParseMsg(path string, data []byte, connectionType string) (NodeMessage, error)

func (*RestChainProxy) PortalStart

func (cp *RestChainProxy) PortalStart(ctx context.Context, privKey *btcec.PrivateKey, listenAddr string)

func (*RestChainProxy) SetCache

func (cp *RestChainProxy) SetCache(cache *performance.Cache)

func (*RestChainProxy) Start

func (cp *RestChainProxy) Start(context.Context) error

type RestMessage

type RestMessage struct {
	Result json.RawMessage
	// contains filtered or unexported fields
}

func (*RestMessage) GetExtraContextTimeout added in v0.6.0

func (r *RestMessage) GetExtraContextTimeout() time.Duration

func (*RestMessage) GetInterface

func (nm *RestMessage) GetInterface() *spectypes.ApiInterface

func (*RestMessage) GetMsg

func (r *RestMessage) GetMsg() interface{}

func (RestMessage) GetParams

func (m RestMessage) GetParams() interface{}

func (RestMessage) GetResult

func (m RestMessage) GetResult() json.RawMessage

func (*RestMessage) GetServiceApi

func (nm *RestMessage) GetServiceApi() *spectypes.ServiceApi

func (RestMessage) ParseBlock

func (m RestMessage) ParseBlock(inp string) (int64, error)

func (*RestMessage) RequestedBlock

func (nm *RestMessage) RequestedBlock() int64

func (*RestMessage) Send

func (nm *RestMessage) Send(ctx context.Context, ch chan interface{}) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)

type ServerSource

type ServerSource struct {
	Client *grpcreflect.Client
}

func (ServerSource) AllExtensionsForType

func (ss ServerSource) AllExtensionsForType(typeName string) ([]*desc.FieldDescriptor, error)

func (ServerSource) FindSymbol

func (ss ServerSource) FindSymbol(fullyQualifiedName string) (desc.Descriptor, error)

func (ServerSource) ListServices

func (ss ServerSource) ListServices() ([]string, error)

type TendemintRpcMessage

type TendemintRpcMessage struct {
	JrpcMessage
	// contains filtered or unexported fields
}

func (TendemintRpcMessage) GetParams

func (m TendemintRpcMessage) GetParams() interface{}

func (TendemintRpcMessage) GetResult

func (m TendemintRpcMessage) GetResult() json.RawMessage

func (TendemintRpcMessage) ParseBlock

func (m TendemintRpcMessage) ParseBlock(inp string) (int64, error)

func (*TendemintRpcMessage) Send

func (nm *TendemintRpcMessage) Send(ctx context.Context, ch chan interface{}) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)

Send sends either Tendermint RPC or URI call depending on the type

func (*TendemintRpcMessage) SendRPC added in v0.5.0

func (nm *TendemintRpcMessage) SendRPC(ctx context.Context, ch chan interface{}) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)

SendRPC sends Tendermint HTTP or WebSockets call

func (*TendemintRpcMessage) SendURI added in v0.5.0

func (nm *TendemintRpcMessage) SendURI(ctx context.Context, ch chan interface{}) (relayReply *pairingtypes.RelayReply, subscriptionID string, relayReplyServer *rpcclient.ClientSubscription, err error)

SendURI sends URI HTTP call

Directories

Path Synopsis
package rpcclient implements bi-directional JSON-RPC 2.0 on multiple transports.
package rpcclient implements bi-directional JSON-RPC 2.0 on multiple transports.

Jump to

Keyboard shortcuts

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