rpcsmartrouter

package
v5.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: Apache-2.0 Imports: 54 Imported by: 0

README

RPC Smart Router (Enterprise Mode)

The RPC Smart Router is Lava's centralized RPC gateway designed for enterprises with known provider infrastructure. It routes requests to pre-configured static and backup providers without requiring blockchain pairing, making it ideal for controlled environments.

When to Use RPC Smart Router

Use rpcsmartrouter when you want:

  • Known provider infrastructure - You control or trust specific RPC endpoints
  • Simple setup - No blockchain wallet or pairing required
  • Predictable routing - Providers don't change based on blockchain epochs
  • Enterprise control - Full control over which providers are used
  • Backup failover - Configure primary and backup provider tiers
  • Performance optimization - QoS-based routing without blockchain overhead

For decentralized/trustless operation with on-chain provider discovery, use rpcconsumer instead.

Key Features

Static Provider Configuration
  • Pre-configured Providers: Define your trusted RPC endpoints in config
  • Backup Providers: Automatic failover to backup tier when primaries fail
  • No Blockchain Dependency: Runs without on-chain pairing (specs can be static)
  • Multi-provider Support: Mix Alchemy, Infura, self-hosted, and other providers
Intelligent Routing
  • QoS-based Selection: Routes to best-performing providers
  • Automatic Failover: Seamlessly switches to backups on provider failure
  • Health Monitoring: Continuous provider health checks
  • Strategy Options: Multiple routing strategies (latency, balanced, etc.)
Enterprise Features
  • Smart Caching: Two-layer caching reduces provider load
  • Transaction Broadcasting: Sends transactions to all providers for faster propagation
  • WebSocket Support: Full support for subscription-based APIs
  • Metrics & Monitoring: Prometheus metrics and health endpoints
  • Analytics Integration: Kafka support for detailed analytics

Installation

# Clone the repository
git clone https://github.com/lavanet/lava.git
cd lava

# Install all binaries
make install-all

Configuration

Create a configuration file (e.g., rpcsmartrouter.yml):

endpoints:
  - chain-id: ETH1
    api-interface: jsonrpc
    network-address: 127.0.0.1:3333
  - chain-id: OSMOSIS
    api-interface: rest
    network-address: 127.0.0.1:3334

static-providers:
  # Primary providers (used first)
  - name: alchemy-eth-mainnet
    chain-id: ETH1
    api-interface: jsonrpc
    node-urls:
      - url: https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
  
  - name: infura-eth-mainnet
    chain-id: ETH1
    api-interface: jsonrpc
    node-urls:
      - url: https://mainnet.infura.io/v3/YOUR_KEY
  
  - name: self-hosted-osmosis
    chain-id: OSMOSIS
    api-interface: rest
    node-urls:
      - url: http://osmosis-node-1.internal:1317

backup-providers:
  # Backup providers (used when primaries fail)
  - name: backup-alchemy
    chain-id: ETH1
    api-interface: jsonrpc
    node-urls:
      - url: https://eth-mainnet.g.alchemy.com/v2/YOUR_BACKUP_KEY
  
  - name: backup-osmosis
    chain-id: OSMOSIS
    api-interface: rest
    node-urls:
      - url: http://osmosis-node-2.internal:1317
Configuration Fields
Endpoints
  • chain-id: Blockchain identifier
  • api-interface: API type (jsonrpc, rest, tendermintrpc, grpc)
  • network-address: IP:PORT where smart router listens
Static Providers (Primary)
  • name: Unique identifier for this provider
  • chain-id: Which blockchain this provider serves
  • api-interface: API type
  • node-urls: List of RPC endpoint URLs
    • url: The actual RPC endpoint (http://, https://, ws://)
    • addons: Optional extensions (e.g., archive, debug, trace)
Backup Providers (Failover)
  • Same format as static providers
  • Used automatically when all static providers fail
  • Optional but highly recommended for production

Usage

Basic Usage
lavap rpcsmartrouter rpcsmartrouter.yml \
  --geolocation 1
Required Flags
  • --geolocation: Your geographic location code (for metrics/routing)
Common Options
lavap rpcsmartrouter rpcsmartrouter.yml \
  --geolocation 1 \
  --cache-be "127.0.0.1:7778" \
  --strategy latency \
  --metrics-listen-address ":7779" \
  --log_level debug
Strategy Options

Choose provider selection strategy with --strategy:

  • balanced (default) - Balance between latency and reliability
  • latency - Prioritize fastest providers
  • sync-freshness - Prioritize most up-to-date providers
  • cost - Optimize for lower cost (if configured)
  • privacy - Maximize privacy distribution
  • distributed - Distribute load across many providers
Advanced Flags
# Enable caching
--cache-be "127.0.0.1:7778"

# Prometheus metrics
--metrics-listen-address ":7779"

# Kafka analytics
--relay-kafka-addr "localhost:9092"
--relay-kafka-topic "lava-relay-metrics"

# Performance tuning
--max-concurrent-providers 5

# Debug options
--debug-relays
--log_level trace

# Load static spec (no blockchain needed)
--use-static-spec-file "./specs/eth.json"

Example Requests

After starting the smart router, make RPC requests to configured endpoints:

# JSON-RPC request (routed to best ETH provider)
curl -X POST http://127.0.0.1:3333 \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_blockNumber",
    "params": [],
    "id": 1
  }'

# REST API request (routed to best Osmosis provider)
curl http://127.0.0.1:3334/cosmos/base/tendermint/v1beta1/blocks/latest

# With failover - if primary fails, automatically uses backup
curl http://127.0.0.1:3333 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x123...",  "latest"],"id":1}'

How It Works

  1. Configuration Loading: Reads static and backup providers from config
  2. Provider Initialization: Connects to all configured providers
  3. Health Monitoring: Continuously monitors provider health
  4. Request Routing: Routes requests to best available provider
  5. QoS Tracking: Tracks latency, errors, and success rates
  6. Automatic Failover: Switches to backup providers on failure
  7. Load Balancing: Distributes load based on QoS scores

Architecture

User Request → Smart Router → Provider Selection (QoS-based)
                     ↓
              Try Static Providers
                     ↓
              [If all fail] → Try Backup Providers
                     ↓
              Cache Response (optional)
                     ↓
              Return to User

Multi-Provider Example

Configure multiple providers for high availability:

static-providers:
  # Mix of different provider types
  - name: alchemy-primary
    chain-id: ETH1
    api-interface: jsonrpc
    node-urls:
      - url: https://eth-mainnet.g.alchemy.com/v2/PRIMARY_KEY

  - name: infura-primary
    chain-id: ETH1
    api-interface: jsonrpc
    node-urls:
      - url: https://mainnet.infura.io/v3/PRIMARY_KEY
  
  - name: quicknode-primary
    chain-id: ETH1
    api-interface: jsonrpc
    node-urls:
      - url: https://your-endpoint.quiknode.pro/YOUR_KEY

  - name: self-hosted-archive
    chain-id: ETH1
    api-interface: jsonrpc
    node-urls:
      - url: http://archive-node.internal:8545
        addons: ["archive", "debug", "trace"]

backup-providers:
  - name: alchemy-backup
    chain-id: ETH1
    api-interface: jsonrpc
    node-urls:
      - url: https://eth-mainnet.g.alchemy.com/v2/BACKUP_KEY

vs. RPC Consumer

Feature RPC Smart Router (Centralized) RPC Consumer (Decentralized)
Provider Discovery Static configuration On-chain blockchain pairing
Setup Complexity Simple (just config) Medium (requires wallet)
Trust Model Trust known providers Trustless (blockchain verified)
Provider Selection QoS only Stake-weighted + QoS
Data Validation Basic validation Conflict detection + consensus
Blockchain Dependency Optional (only for specs) Required
Backup Providers ✅ Built-in failover ❌ Not applicable
Best For Enterprises, known infra Public networks, trustless

Backup Provider Failover

The smart router automatically fails over to backup providers:

  1. Primary Attempt: Tries static providers first (best QoS selected)
  2. Failure Detection: Detects errors, timeouts, or unavailability
  3. Automatic Failover: Switches to backup providers transparently
  4. Recovery: Monitors primary providers and switches back when healthy
  5. Logging: All failover events are logged for monitoring

Example log output:

INF Configured backup providers for endpoint chainID=ETH1 apiInterface=jsonrpc backupCount=2
WRN Primary provider failed, trying backup provider=alchemy-eth-mainnet error="connection timeout"
INF Successfully failed over to backup provider=backup-alchemy-eth

Monitoring & Metrics

Smart Router exposes Prometheus metrics:

# View metrics
curl http://localhost:7779/metrics

# Key metrics:
# - lava_smart_router_requests_total
# - lava_smart_router_provider_qos_score
# - lava_smart_router_failover_events_total
# - lava_smart_router_cache_hit_rate
# - lava_smart_router_provider_latency_seconds

Health Checks

Built-in health monitoring:

# Enable health checks (enabled by default)
--relays-health-enable=true
--relay-health-interval=5m

# Health check logs
DBG Health check sent to provider provider=alchemy-primary success=true latency=45ms

Troubleshooting

"No static providers configured"
  • Check static-providers section in config
  • Ensure chain-id matches endpoint chain-id
  • Verify api-interface matches endpoint api-interface
All Providers Failing
  • Check provider URLs are accessible
  • Verify API keys are valid
  • Check network connectivity
  • Review backup provider configuration
Performance Issues
  • Enable caching: --cache-be "127.0.0.1:7778"
  • Increase concurrent providers: --max-concurrent-providers 5
  • Use latency strategy: --strategy latency
  • Check provider QoS metrics
Backup Providers Not Working
  • Ensure backup providers are configured
  • Verify backup URLs are different from static
  • Check logs for failover events

Configuration Examples

See config/consumer_examples/ directory:

  • lava_consumer_static_with_backup.yml - Full example with backups
  • lava_consumer_static_peers.yml - Simple static provider setup

Production Deployment

# Production configuration with redundancy
endpoints:
  - chain-id: ETH1
    api-interface: jsonrpc
    network-address: 0.0.0.0:3333  # Bind to all interfaces

static-providers:
  # Use multiple providers for redundancy
  - name: provider-1
    chain-id: ETH1
    api-interface: jsonrpc
    node-urls:
      - url: https://provider1.example.com/v1/YOUR_KEY

  - name: provider-2
    chain-id: ETH1
    api-interface: jsonrpc
    node-urls:
      - url: https://provider2.example.com/v1/YOUR_KEY

backup-providers:
  # Different provider for true failover
  - name: backup-provider
    chain-id: ETH1
    api-interface: jsonrpc
    node-urls:
      - url: https://backup.example.com/v1/YOUR_KEY
Production Flags
lavap rpcsmartrouter config.yml \
  --geolocation 1 \
  --cache-be "redis:7778" \
  --metrics-listen-address "0.0.0.0:7779" \
  --relay-kafka-addr "kafka:9092" \
  --log_level info \
  --max-concurrent-providers 5 \
  --strategy balanced

More Information

Documentation

Overview

Package rpcconsumer is a generated GoMock package.

Package rpcsmartrouter provides a centralized RPC routing solution for the Lava protocol.

Architecture Overview

The smart router is designed for centralized deployments where providers are statically configured rather than dynamically discovered through blockchain pairing. This is useful for:

  • Enterprise deployments with known provider infrastructure
  • Testing and development environments
  • Use cases requiring predictable provider routing

Key Differences from rpcconsumer

rpcsmartrouter (centralized):

  • Uses pre-configured static providers from configuration files
  • No blockchain state tracking required
  • Provider selection based on configured weights (static providers get 10x multiplier)
  • No epoch management or on-chain pairing updates

rpcconsumer (decentralized):

  • Discovers providers dynamically through blockchain pairing
  • Tracks blockchain state, epochs, and provider stake
  • Provider selection weighted by actual on-chain stake
  • Includes conflict detection and finalization consensus

Provider Selection

Static providers are configured in YAML files and automatically receive a 10x weight multiplier compared to blockchain providers. This ensures static providers are preferred in routing decisions. See StaticProviderDummyCoin for implementation details.

Index

Constants

View Source
const (
	DefaultRPCSmartRouterFileName = "rpcsmartrouter.yml"
	DebugRelaysFlagName           = "debug-relays"
	DebugProbesFlagName           = "debug-probes"
)
View Source
const (
	// maximum number of retries to send due to the ticker, if we didn't get a response after 10 different attempts then just wait.
	MaximumNumberOfTickerRelayRetries = 10
	MaxRelayRetries                   = 6
	SendRelayAttempts                 = 3

	// Subscription and pairing management constants
	MaxSubscriptionMapSizeWarningThreshold = 5000
	SubscriptionCleanupInterval            = 1 * time.Minute
	PairingInitializationTimeout           = 30 * time.Second
	PairingCheckInterval                   = 1 * time.Second
	BlockGapWarningThreshold               = 1000
	RelayRetryBackoffDuration              = 2 * time.Millisecond
)

Variables

View Source
var (
	Yaml_config_properties         = []string{"network-address", "chain-id", "api-interface"}
	RelaysHealthEnableFlagDefault  = true
	RelayHealthIntervalFlagDefault = 5 * time.Minute

	// StaticProviderDummyCoin is used for type compatibility in provider sessions.
	// Static providers don't use blockchain stake for selection; they automatically
	// receive a 10x weight multiplier in CalcWeightsByStake (see lavasession package).
	// The coin value is ignored but the object must exist to avoid nil pointer errors.
	StaticProviderDummyCoin = sdk.NewCoin("ulava", sdk.NewInt(1))
)
View Source
var NoResponseTimeout = protocolerrors.NoResponseTimeout

NoResponseTimeout is imported from protocolerrors to avoid duplicate error code registration

Functions

func CreateRPCSmartRouterCobraCommand

func CreateRPCSmartRouterCobraCommand() *cobra.Command

func CreateTestRPCSmartRouterCobraCommand

func CreateTestRPCSmartRouterCobraCommand() *cobra.Command

func ParseEndpoints

func ParseEndpoints(viper_endpoints *viper.Viper, geolocation uint64) (endpoints []*lavasession.RPCEndpoint, err error)

Types

type AnalyticsServerAddresses

type AnalyticsServerAddresses struct {
	AddApiMethodCallsMetrics bool
	MetricsListenAddress     string
	RelayServerAddress       string
	RelayKafkaAddress        string
	RelayKafkaTopic          string
	RelayKafkaUsername       string
	RelayKafkaPassword       string
	RelayKafkaMechanism      string
	RelayKafkaTLSEnabled     bool
	RelayKafkaTLSInsecure    bool
	ReportsAddressFlag       string
	OptimizerQoSAddress      string
	OptimizerQoSListen       bool
}

type CancelableContextHolder

type CancelableContextHolder struct {
	Ctx        context.Context
	CancelFunc context.CancelFunc
}

type MinimalStateTrackerInf

type MinimalStateTrackerInf interface {
	GetLatestVirtualEpoch() uint64
}

MinimalStateTrackerInf is a minimal interface for smart router state tracking

type MockMinimalStateTrackerInf

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

MockMinimalStateTrackerInf is a mock of MinimalStateTrackerInf interface.

func NewMockMinimalStateTrackerInf

func NewMockMinimalStateTrackerInf(ctrl *gomock.Controller) *MockMinimalStateTrackerInf

NewMockMinimalStateTrackerInf creates a new mock instance.

func (*MockMinimalStateTrackerInf) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockMinimalStateTrackerInf) GetLatestVirtualEpoch

func (m *MockMinimalStateTrackerInf) GetLatestVirtualEpoch() uint64

GetLatestVirtualEpoch mocks base method.

type MockMinimalStateTrackerInfMockRecorder

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

MockMinimalStateTrackerInfMockRecorder is the mock recorder for MockMinimalStateTrackerInf.

func (*MockMinimalStateTrackerInfMockRecorder) GetLatestVirtualEpoch

func (mr *MockMinimalStateTrackerInfMockRecorder) GetLatestVirtualEpoch() *gomock.Call

GetLatestVirtualEpoch indicates an expected call of GetLatestVirtualEpoch.

type MockRelayerClient

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

MockRelayerClient is a mock of RelayerClient interface.

func NewMockRelayerClient

func NewMockRelayerClient(ctrl *gomock.Controller) *MockRelayerClient

NewMockRelayerClient creates a new mock instance.

func (*MockRelayerClient) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockRelayerClient) Probe

Probe mocks base method.

func (*MockRelayerClient) Relay

Relay mocks base method.

func (*MockRelayerClient) RelaySubscribe

RelaySubscribe mocks base method.

type MockRelayerClientMockRecorder

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

MockRelayerClientMockRecorder is the mock recorder for MockRelayerClient.

func (*MockRelayerClientMockRecorder) Probe

func (mr *MockRelayerClientMockRecorder) Probe(ctx, in any, opts ...any) *gomock.Call

Probe indicates an expected call of Probe.

func (*MockRelayerClientMockRecorder) Relay

func (mr *MockRelayerClientMockRecorder) Relay(ctx, in any, opts ...any) *gomock.Call

Relay indicates an expected call of Relay.

func (*MockRelayerClientMockRecorder) RelaySubscribe

func (mr *MockRelayerClientMockRecorder) RelaySubscribe(ctx, in any, opts ...any) *gomock.Call

RelaySubscribe indicates an expected call of RelaySubscribe.

type MockRelayerServer

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

MockRelayerServer is a mock of RelayerServer interface.

func NewMockRelayerServer

func NewMockRelayerServer(ctrl *gomock.Controller) *MockRelayerServer

NewMockRelayerServer creates a new mock instance.

func (*MockRelayerServer) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockRelayerServer) Probe

Probe mocks base method.

func (*MockRelayerServer) Relay

Relay mocks base method.

func (*MockRelayerServer) RelaySubscribe

RelaySubscribe mocks base method.

type MockRelayerServerMockRecorder

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

MockRelayerServerMockRecorder is the mock recorder for MockRelayerServer.

func (*MockRelayerServerMockRecorder) Probe

func (mr *MockRelayerServerMockRecorder) Probe(arg0, arg1 any) *gomock.Call

Probe indicates an expected call of Probe.

func (*MockRelayerServerMockRecorder) Relay

func (mr *MockRelayerServerMockRecorder) Relay(arg0, arg1 any) *gomock.Call

Relay indicates an expected call of Relay.

func (*MockRelayerServerMockRecorder) RelaySubscribe

func (mr *MockRelayerServerMockRecorder) RelaySubscribe(arg0, arg1 any) *gomock.Call

RelaySubscribe indicates an expected call of RelaySubscribe.

type MockRelayer_RelaySubscribeClient

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

MockRelayer_RelaySubscribeClient is a mock of Relayer_RelaySubscribeClient interface.

func NewMockRelayer_RelaySubscribeClient

func NewMockRelayer_RelaySubscribeClient(ctrl *gomock.Controller) *MockRelayer_RelaySubscribeClient

NewMockRelayer_RelaySubscribeClient creates a new mock instance.

func (*MockRelayer_RelaySubscribeClient) CloseSend

func (m *MockRelayer_RelaySubscribeClient) CloseSend() error

CloseSend mocks base method.

func (*MockRelayer_RelaySubscribeClient) Context

Context mocks base method.

func (*MockRelayer_RelaySubscribeClient) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockRelayer_RelaySubscribeClient) Header

Header mocks base method.

func (*MockRelayer_RelaySubscribeClient) Recv

Recv mocks base method.

func (*MockRelayer_RelaySubscribeClient) RecvMsg

func (m_2 *MockRelayer_RelaySubscribeClient) RecvMsg(m any) error

RecvMsg mocks base method.

func (*MockRelayer_RelaySubscribeClient) SendMsg

func (m_2 *MockRelayer_RelaySubscribeClient) SendMsg(m any) error

SendMsg mocks base method.

func (*MockRelayer_RelaySubscribeClient) Trailer

Trailer mocks base method.

type MockRelayer_RelaySubscribeClientMockRecorder

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

MockRelayer_RelaySubscribeClientMockRecorder is the mock recorder for MockRelayer_RelaySubscribeClient.

func (*MockRelayer_RelaySubscribeClientMockRecorder) CloseSend

CloseSend indicates an expected call of CloseSend.

func (*MockRelayer_RelaySubscribeClientMockRecorder) Context

Context indicates an expected call of Context.

func (*MockRelayer_RelaySubscribeClientMockRecorder) Header

Header indicates an expected call of Header.

func (*MockRelayer_RelaySubscribeClientMockRecorder) Recv

Recv indicates an expected call of Recv.

func (*MockRelayer_RelaySubscribeClientMockRecorder) RecvMsg

RecvMsg indicates an expected call of RecvMsg.

func (*MockRelayer_RelaySubscribeClientMockRecorder) SendMsg

SendMsg indicates an expected call of SendMsg.

func (*MockRelayer_RelaySubscribeClientMockRecorder) Trailer

Trailer indicates an expected call of Trailer.

type MockRelayer_RelaySubscribeServer

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

MockRelayer_RelaySubscribeServer is a mock of Relayer_RelaySubscribeServer interface.

func NewMockRelayer_RelaySubscribeServer

func NewMockRelayer_RelaySubscribeServer(ctrl *gomock.Controller) *MockRelayer_RelaySubscribeServer

NewMockRelayer_RelaySubscribeServer creates a new mock instance.

func (*MockRelayer_RelaySubscribeServer) Context

Context mocks base method.

func (*MockRelayer_RelaySubscribeServer) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockRelayer_RelaySubscribeServer) RecvMsg

func (m_2 *MockRelayer_RelaySubscribeServer) RecvMsg(m any) error

RecvMsg mocks base method.

func (*MockRelayer_RelaySubscribeServer) Send

Send mocks base method.

func (*MockRelayer_RelaySubscribeServer) SendHeader

func (m *MockRelayer_RelaySubscribeServer) SendHeader(arg0 metadata.MD) error

SendHeader mocks base method.

func (*MockRelayer_RelaySubscribeServer) SendMsg

func (m_2 *MockRelayer_RelaySubscribeServer) SendMsg(m any) error

SendMsg mocks base method.

func (*MockRelayer_RelaySubscribeServer) SetHeader

SetHeader mocks base method.

func (*MockRelayer_RelaySubscribeServer) SetTrailer

func (m *MockRelayer_RelaySubscribeServer) SetTrailer(arg0 metadata.MD)

SetTrailer mocks base method.

type MockRelayer_RelaySubscribeServerMockRecorder

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

MockRelayer_RelaySubscribeServerMockRecorder is the mock recorder for MockRelayer_RelaySubscribeServer.

func (*MockRelayer_RelaySubscribeServerMockRecorder) Context

Context indicates an expected call of Context.

func (*MockRelayer_RelaySubscribeServerMockRecorder) RecvMsg

RecvMsg indicates an expected call of RecvMsg.

func (*MockRelayer_RelaySubscribeServerMockRecorder) Send

Send indicates an expected call of Send.

func (*MockRelayer_RelaySubscribeServerMockRecorder) SendHeader

SendHeader indicates an expected call of SendHeader.

func (*MockRelayer_RelaySubscribeServerMockRecorder) SendMsg

SendMsg indicates an expected call of SendMsg.

func (*MockRelayer_RelaySubscribeServerMockRecorder) SetHeader

SetHeader indicates an expected call of SetHeader.

func (*MockRelayer_RelaySubscribeServerMockRecorder) SetTrailer

SetTrailer indicates an expected call of SetTrailer.

type RPCSmartRouter

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

func (*RPCSmartRouter) CreateSmartRouterEndpoint

func (rpsr *RPCSmartRouter) CreateSmartRouterEndpoint(
	ctx context.Context,
	rpcEndpoint *lavasession.RPCEndpoint,
	errCh chan error,
	optimizers *common.SafeSyncMap[string, *provideroptimizer.ProviderOptimizer],
	smartRouterConsistencies *common.SafeSyncMap[string, relaycore.Consistency],
	chainMutexes map[string]*sync.Mutex,
	options *rpcSmartRouterStartOptions,
	smartRouterIdentifier string,
	rpcSmartRouterMetrics *metrics.RPCConsumerLogs,
	smartRouterReportsManager *metrics.ConsumerReportsClient,
	smartRouterOptimizerQoSClient *metrics.ConsumerOptimizerQoSClient,
	smartRouterMetricsManager *metrics.ConsumerMetricsManager,
	relaysMonitorAggregator *metrics.RelaysMonitorAggregator,
) error

func (*RPCSmartRouter) Start

func (rpsr *RPCSmartRouter) Start(ctx context.Context, options *rpcSmartRouterStartOptions) (err error)

spawns a new RPCConsumer server with all it's processes and internals ready for communications

type RPCSmartRouterServer

type RPCSmartRouterServer struct {
	SmartRouterAddress sdk.AccAddress
	// contains filtered or unexported fields
}

implements Relay Sender interfaced and uses an ChainListener to get it called

func (*RPCSmartRouterServer) CancelSubscriptionContext

func (rpcss *RPCSmartRouterServer) CancelSubscriptionContext(subscriptionKey string)

func (*RPCSmartRouterServer) CreateDappKey

func (rpcss *RPCSmartRouterServer) CreateDappKey(userData common.UserData) string

func (*RPCSmartRouterServer) GetChainIdAndApiInterface

func (rpcss *RPCSmartRouterServer) GetChainIdAndApiInterface() (string, string)

func (*RPCSmartRouterServer) GetListeningAddress

func (rpcss *RPCSmartRouterServer) GetListeningAddress() string

func (*RPCSmartRouterServer) HandleDirectiveHeadersForMessage

func (rpcss *RPCSmartRouterServer) HandleDirectiveHeadersForMessage(chainMessage chainlib.ChainMessage, directiveHeaders map[string]string)

func (*RPCSmartRouterServer) IsHealthy

func (rpcss *RPCSmartRouterServer) IsHealthy() bool

func (*RPCSmartRouterServer) IsInitialized

func (rpcss *RPCSmartRouterServer) IsInitialized() bool

func (*RPCSmartRouterServer) LavaDirectiveHeaders

func (rpcss *RPCSmartRouterServer) LavaDirectiveHeaders(metadata []pairingtypes.Metadata) ([]pairingtypes.Metadata, map[string]string)

func (*RPCSmartRouterServer) ParseRelay

func (rpcss *RPCSmartRouterServer) ParseRelay(
	ctx context.Context,
	url string,
	req string,
	connectionType string,
	dappID string,
	consumerIp string,
	metadata []pairingtypes.Metadata,
) (protocolMessage chainlib.ProtocolMessage, err error)

func (*RPCSmartRouterServer) ProcessRelaySend

func (rpcss *RPCSmartRouterServer) ProcessRelaySend(ctx context.Context, protocolMessage chainlib.ProtocolMessage, analytics *metrics.RelayMetrics) (*relaycore.RelayProcessor, error)

func (*RPCSmartRouterServer) RoundTrip

func (rpcss *RPCSmartRouterServer) RoundTrip(req *http.Request) (*http.Response, error)

func (*RPCSmartRouterServer) SendParsedRelay

func (rpcss *RPCSmartRouterServer) SendParsedRelay(
	ctx context.Context,
	analytics *metrics.RelayMetrics,
	protocolMessage chainlib.ProtocolMessage,
) (relayResult *common.RelayResult, errRet error)

func (*RPCSmartRouterServer) SendRelay

func (rpcss *RPCSmartRouterServer) SendRelay(
	ctx context.Context,
	url string,
	req string,
	connectionType string,
	dappID string,
	consumerIp string,
	analytics *metrics.RelayMetrics,
	metadata []pairingtypes.Metadata,
) (relayResult *common.RelayResult, errRet error)

func (*RPCSmartRouterServer) ServeRPCRequests

func (rpcss *RPCSmartRouterServer) ServeRPCRequests(
	ctx context.Context,
	listenEndpoint *lavasession.RPCEndpoint,
	chainParser chainlib.ChainParser,
	sessionManager *lavasession.ConsumerSessionManager,
	requiredResponses int,
	privKey *btcec.PrivateKey,
	lavaChainID string,
	cache *performance.Cache,
	rpcSmartRouterLogs *metrics.RPCConsumerLogs,
	smartRouterAddress sdk.AccAddress,
	smartRouterConsistency relaycore.Consistency,
	relaysMonitor *metrics.RelaysMonitor,
	cmdFlags common.ConsumerCmdFlags,
	sharedState bool,
	refererData *chainlib.RefererData,
	reporter metrics.Reporter,
	wsSubscriptionManager *chainlib.ConsumerWSSubscriptionManager,
) (err error)

func (*RPCSmartRouterServer) SetConsistencySeenBlock

func (rpcss *RPCSmartRouterServer) SetConsistencySeenBlock(blockSeen int64, key string)

type RelayProcessorForHeaders

type RelayProcessorForHeaders interface {
	GetQuorumParams() common.QuorumParams
	GetResultsData() ([]common.RelayResult, []common.RelayResult, []relaycore.RelayError)
	GetStatefulRelayTargets() []string
	GetUsedProviders() *lavasession.UsedProviders
	NodeErrors() (ret []common.RelayResult)
}

RelayProcessorForHeaders interface for methods used by appendHeadersToRelayResult

type RelayStateMachine

type RelayStateMachine = relaycore.RelayStateMachine

Using interfaces from relaycore

func NewSmartRouterRelayStateMachine

func NewSmartRouterRelayStateMachine(
	ctx context.Context,
	usedProviders *lavasession.UsedProviders,
	relaySender SmartRouterRelaySender,
	protocolMessage chainlib.ProtocolMessage,
	analytics *metrics.RelayMetrics,
	debugRelays bool,
	tickerMetricSetter tickerMetricSetterInf,
) RelayStateMachine

type RelayStateSendInstructions

type RelayStateSendInstructions = relaycore.RelayStateSendInstructions

Using RelayStateSendInstructions from relaycore

type ResultsCheckerInf

type ResultsCheckerInf = relaycore.ResultsCheckerInf

Using interfaces from relaycore

type SmartRouterRelaySender

type SmartRouterRelaySender interface {
	GetChainIdAndApiInterface() (string, string)
	ParseRelay(
		ctx context.Context,
		url string,
		req string,
		connectionType string,
		dappID string,
		consumerIp string,
		metadata []pairingtypes.Metadata,
	) (protocolMessage chainlib.ProtocolMessage, err error)
	// contains filtered or unexported methods
}

type SmartRouterRelayStateMachine

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

func (*SmartRouterRelayStateMachine) GetDebugState

func (srsm *SmartRouterRelayStateMachine) GetDebugState() bool

func (*SmartRouterRelayStateMachine) GetProtocolMessage

func (srsm *SmartRouterRelayStateMachine) GetProtocolMessage() chainlib.ProtocolMessage

func (*SmartRouterRelayStateMachine) GetRelayTaskChannel

func (srsm *SmartRouterRelayStateMachine) GetRelayTaskChannel() (chan RelayStateSendInstructions, error)

func (*SmartRouterRelayStateMachine) GetSelection

func (srsm *SmartRouterRelayStateMachine) GetSelection() relaycore.Selection

func (*SmartRouterRelayStateMachine) GetUsedProviders

func (srsm *SmartRouterRelayStateMachine) GetUsedProviders() *lavasession.UsedProviders

func (*SmartRouterRelayStateMachine) Initialized

func (srsm *SmartRouterRelayStateMachine) Initialized() bool

func (*SmartRouterRelayStateMachine) SetRelayRetriesManager

func (srsm *SmartRouterRelayStateMachine) SetRelayRetriesManager(relayRetriesManager *lavaprotocol.RelayRetriesManager)

func (*SmartRouterRelayStateMachine) SetResultsChecker

func (srsm *SmartRouterRelayStateMachine) SetResultsChecker(resultsChecker ResultsCheckerInf)

func (*SmartRouterRelayStateMachine) UpdateBatch

func (srsm *SmartRouterRelayStateMachine) UpdateBatch(err error)

Jump to

Keyboard shortcuts

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