solana

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package solana provides a DataExtractor implementation for Solana blockchain.

The SolanaDataExtractor knows how to extract quality data from Solana JSON-RPC responses:

  • Block height from getEpochInfo responses
  • Health status from getHealth responses
  • Cluster (chain) info from getClusterNodes or getVersion responses

Solana uses JSON-RPC 2.0 for all RPC calls, similar to EVM chains.

solana package provides the support required for interacting with the Solana blockchain through the gateway.

Index

Constants

View Source
const QoSType = "solana"

QoSType is the QoS type for the Solana blockchain.

Variables

This section is empty.

Functions

This section is empty.

Types

type EndpointStore

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

EndpointStore maintains QoS data on the set of available endpoints for the Solana blockchain service. It performs several tasks: - Endpoint selection based on the quality data available - Application of endpoints' observations to update the data on endpoints.

func (*EndpointStore) CheckWebsocketConnection

func (es *EndpointStore) CheckWebsocketConnection() bool

TODO_TECHDEBT(@commoddity): Update Solana QoS to support Websocket connection checks. CheckWebsocketConnection returns true if the endpoint supports Websocket connections.

func (*EndpointStore) GetRequiredQualityChecks

func (es *EndpointStore) GetRequiredQualityChecks(_ protocol.EndpointAddr) []gateway.RequestQoSContext

TODO_IMPROVE(@commoddity): implement QoS check expiry functionality and use protocol.EndpointAddr to filter out checks for any endpoint which has acurrently valid QoS data point.

func (*EndpointStore) Select

func (es *EndpointStore) Select(allAvailableEndpoints protocol.EndpointAddrList) (protocol.EndpointAddr, error)

Select returns a random endpoint address from the list of valid endpoints. Valid endpoints are determined by filtering the available endpoints based on their validity criteria.

func (*EndpointStore) SelectMultiple

func (es *EndpointStore) SelectMultiple(
	allAvailableEndpoints protocol.EndpointAddrList,
	numEndpoints uint,
) (protocol.EndpointAddrList, error)

SelectMultiple returns multiple endpoint addresses from the list of valid endpoints. Valid endpoints are determined by filtering the available endpoints based on their validity criteria. If numEndpoints is 0, it defaults to 1.

func (*EndpointStore) UpdateEndpointsFromObservations

func (es *EndpointStore) UpdateEndpointsFromObservations(
	solanaObservations *qosobservations.SolanaRequestObservations,
) map[protocol.EndpointAddr]endpoint

UpdateEndpointsFromObservations CRUDs endpoint entries in the store based on the supplied observations. It returns the set of created/updated endpoints.

type QoS

type QoS struct {
	*EndpointStore
	*ServiceState
	// contains filtered or unexported fields
}

QoS implements ServiceQoS for Solana-based chains. It handles chain-specific:

  • Request parsing
  • Response building
  • Endpoint validation and selection

func NewSimpleQoSInstance added in v1.0.10

func NewSimpleQoSInstance(logger polylog.Logger, serviceID protocol.ServiceID) *QoS

NewSimpleQoSInstance creates a minimal Solana QoS instance without chain-specific validation. Validation is now handled by active health checks. This constructor only requires the service ID and provides JSON-RPC request parsing.

func (*QoS) ApplyObservations

func (q *QoS) ApplyObservations(observations *qosobservations.Observations) error

ApplyObservations updates the stored endpoints and the perceived blockchain state using the supplied observations. Implements the gateway.QoSService interface.

func (*QoS) GetPerceivedBlockNumber added in v1.0.12

func (q *QoS) GetPerceivedBlockNumber() uint64

GetPerceivedBlockNumber returns the perceived current block height. Used by health checks for block height validation. Returns 0 if no block height has been observed yet.

Implements gateway.QoSService interface.

func (QoS) HydrateDisqualifiedEndpointsResponse

func (QoS) HydrateDisqualifiedEndpointsResponse(_ protocol.ServiceID, _ *devtools.DisqualifiedEndpointResponse)

HydrateDisqualifiedEndpointsResponse is a no-op for the Solana QoS. TODO_TECHDEBT(@commoddity): implement this for Solana to enable debugging QoS results.

func (*QoS) ParseHTTPRequest

func (qos *QoS) ParseHTTPRequest(_ context.Context, req *http.Request, detectedRPCType sharedtypes.RPCType) (gateway.RequestQoSContext, bool)

ParseHTTPRequest builds a request context from the provided HTTP request. It returns an error if the HTTP request cannot be parsed as a JSONRPC request.

Implements the gateway.QoSService interface. Fallback logic for Solana: header → jsonrpc (Solana only supports JSON-RPC)

func (*QoS) ParseWebsocketRequest

func (qos *QoS) ParseWebsocketRequest(_ context.Context) (gateway.RequestQoSContext, bool)

ParseWebsocketRequest builds a request context from the provided Websocket request. Websocket connection requests do not have a body, so we don't need to parse it.

This method implements the gateway.QoSService interface.

func (*QoS) UpdateFromExtractedData added in v1.0.10

func (q *QoS) UpdateFromExtractedData(endpointAddr protocol.EndpointAddr, data *qostypes.ExtractedData) error

UpdateFromExtractedData updates QoS state from extracted observation data. Called by the observation pipeline after async parsing completes. This updates the perceived block height and stores the endpoint's block height observation.

Implements gateway.QoSService interface.

type ServiceQoSConfig

type ServiceQoSConfig interface {
	GetServiceID() protocol.ServiceID
	GetServiceQoSType() string
}

ServiceQoSConfig defines the base interface for service QoS configurations. This avoids circular dependency with the config package.

type ServiceState

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

ServiceState keeps the expected current state of the Solana blockchain based on the endpoints' responses to different requests.

func (*ServiceState) UpdateFromEndpoints

func (s *ServiceState) UpdateFromEndpoints(updatedEndpoints map[protocol.EndpointAddr]endpoint) error

UpdateFromObservations updates the service state using estimation(s) derived from the set of updated endpoints. NOTE: This only includes the set of endpoints for which an observation was received.

func (*ServiceState) ValidateEndpoint

func (s *ServiceState) ValidateEndpoint(endpoint endpoint) error

TODO_FUTURE: add an endpoint ranking method which can be used to assign a rank/score to a valid endpoint to guide endpoint selection.

ValidateEndpoint returns an error if the supplied endpoint is not valid based on the perceived state of Solana blockchain.

type SolanaDataExtractor added in v1.0.10

type SolanaDataExtractor struct{}

SolanaDataExtractor extracts quality data from Solana JSON-RPC responses.

func NewSolanaDataExtractor added in v1.0.10

func NewSolanaDataExtractor() *SolanaDataExtractor

NewSolanaDataExtractor creates a new Solana data extractor.

func (*SolanaDataExtractor) ExtractBlockHeight added in v1.0.10

func (e *SolanaDataExtractor) ExtractBlockHeight(response []byte) (int64, error)

ExtractBlockHeight extracts the block height from a getEpochInfo response. Solana's block height comes from the epochInfo result's blockHeight field.

Expected response format:

{"jsonrpc":"2.0","id":1,"result":{"blockHeight":123456789,"epoch":100,...}}

Returns:

  • Block height as int64
  • Error if extraction fails or response doesn't contain block height

func (*SolanaDataExtractor) ExtractChainID added in v1.0.10

func (e *SolanaDataExtractor) ExtractChainID(response []byte) (string, error)

ExtractChainID extracts the cluster identifier from a Solana response. Solana doesn't have a traditional chain ID like EVM chains. Instead, it uses cluster names (mainnet-beta, devnet, testnet) or genesis hash.

This method attempts to extract cluster info from getClusterNodes or getVersion responses, or from the feature set in getEpochInfo.

Note: For Solana, chain identification is typically done via the genesis hash or by querying getClusterNodes. This returns an empty string with an error for responses that don't contain cluster information.

Returns:

  • Cluster identifier as string (e.g., feature set version)
  • Error if extraction fails

func (*SolanaDataExtractor) IsArchival added in v1.0.10

func (e *SolanaDataExtractor) IsArchival(response []byte) (bool, error)

IsArchival determines if the endpoint supports archival queries. For Solana, archival nodes store all transaction and block data. Non-archival nodes only keep recent data (typically ~2 epochs).

This is checked by querying historical slot data. An archival node will return data for old slots, while a non-archival node will return an error.

Returns:

  • true if endpoint is archival (historical query succeeded)
  • false if endpoint is not archival (historical query failed)
  • Error if archival status cannot be determined

func (*SolanaDataExtractor) IsSyncing added in v1.0.10

func (e *SolanaDataExtractor) IsSyncing(response []byte) (bool, error)

IsSyncing determines if the endpoint is currently syncing. Uses the getHealth response to determine health status.

getHealth returns:

  • "ok" when the node is healthy and not syncing
  • An error response when the node is unhealthy or syncing

Expected response format (healthy):

{"jsonrpc":"2.0","id":1,"result":"ok"}

Expected response format (unhealthy/syncing):

{"jsonrpc":"2.0","id":1,"error":{"code":-32005,"message":"Node is behind by 42 slots"}}

Returns:

  • true if endpoint is syncing/unhealthy
  • false if endpoint is healthy (not syncing)
  • Error if sync status cannot be determined

func (*SolanaDataExtractor) IsValidResponse added in v1.0.10

func (e *SolanaDataExtractor) IsValidResponse(response []byte) (bool, error)

IsValidResponse checks if the response is a valid JSON-RPC 2.0 response. This performs basic structural validation without extracting specific data.

Returns:

  • true if response is valid JSON-RPC with result
  • false if response is malformed or contains error
  • Error if validation fails unexpectedly

type SolanaServiceQoSConfig

type SolanaServiceQoSConfig interface {
	ServiceQoSConfig // Using locally defined interface to avoid circular dependency
	// contains filtered or unexported methods
}

SolanaServiceQoSConfig is the configuration for the Solana service QoS.

func NewSolanaServiceQoSConfig

func NewSolanaServiceQoSConfig(
	serviceID protocol.ServiceID,
	chainID string,
) SolanaServiceQoSConfig

NewSolanaServiceQoSConfig creates a new Solana service configuration.

Jump to

Keyboard shortcuts

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