Documentation
¶
Overview ¶
The package protocol defines the basic concepts of any protocol that can be used by a gateway for serving user requests as relays. It is also a container for all implementations of the gateway.Protocol interface.
Index ¶
Constants ¶
const ( GatewayModeCentralized = "centralized" GatewayModeDelegated = "delegated" GatewayModePermissionless = "permissionless" )
Variables ¶
ErrEndpointUnavailable indicates that a selected endpoint is no longer available. This can happen due to: - Session rollover between endpoint selection and context building - Endpoint filtered out (low reputation) due to an observation while selection logic was running - Race condition between endpoint listing and selection
Callers should handle this error by re-selecting from available endpoints.
Functions ¶
This section is empty.
Types ¶
type Endpoint ¶
type Endpoint interface {
// Addr is used to uniquely identify an endpoint.
// Defining this as an interface allows Shannon to
// define its own service endpoint address scheme.
// See the comment on EndpointAddr type for more details.
Addr() EndpointAddr
// PublicURL is the publically exposed/accessible URL to which relay requests can be sent.
PublicURL() string
// WebsocketURL is the URL of the endpoint for websocket RPC type requests.
// Returns an error if the endpoint does not support websocket RPC type requests.
WebsocketURL() (string, error)
}
Endpoint represents an entity which serves relay requests.
type EndpointAddr ¶
type EndpointAddr string
EndpointAddr is used as the unique identifier for a service endpoint. operator address and the endpoint's URL, separated by a "-" character.
For example:
- "pokt1ggdpwj5stslx2e567qcm50wyntlym5c4n0dst8-https://im.oldgreg.org"
func (EndpointAddr) GetAddress ¶
func (e EndpointAddr) GetAddress() (string, error)
GetAddress returns the address of the endpoint. For example: - Given the endpoint address "pokt1eetcwfv2agdl2nvpf4cprhe89rdq3cxdf037wq-https://relayminer.shannon-mainnet.eu.nodefleet.net" - Would return "pokt1eetcwfv2agdl2nvpf4cprhe89rdq3cxdf037wq"
func (EndpointAddr) GetURL ¶
func (e EndpointAddr) GetURL() (string, error)
GetURL returns the effective TLD+1 domain of the endpoint address. For example: - Given the endpoint address "pokt1eetcwfv2agdl2nvpf4cprhe89rdq3cxdf037wq-https://relayminer.shannon-mainnet.eu.nodefleet.net" - Would return "https://relayminer.shannon-mainnet.eu.nodefleet.net"
func (EndpointAddr) String ¶
func (e EndpointAddr) String() string
type EndpointAddrList ¶
type EndpointAddrList []EndpointAddr
func (EndpointAddrList) String ¶
func (e EndpointAddrList) String() string
type EndpointArchival ¶ added in v1.0.15
type EndpointArchival struct {
// IsArchival indicates if the endpoint supports archival requests
IsArchival bool `json:"is_archival"`
// ExpiresAt indicates when the archival status needs re-validation
ExpiresAt string `json:"expires_at,omitempty"`
}
EndpointArchival contains archival capability information.
type EndpointDetails ¶ added in v1.0.15
type EndpointDetails struct {
// Address is the unique identifier for this endpoint (supplier-url format)
Address string `json:"address"`
// SupplierAddress is the on-chain address of the supplier
SupplierAddress string `json:"supplier_address"`
// URL is the public URL of the endpoint
URL string `json:"url"`
// IsFallback indicates whether this is a fallback (non-protocol) endpoint
IsFallback bool `json:"is_fallback"`
// Reputation contains the endpoint's reputation metrics
Reputation *EndpointReputation `json:"reputation,omitempty"`
// Archival contains archival capability information (EVM services only)
Archival *EndpointArchival `json:"archival,omitempty"`
// RPCTypes lists the supported RPC types for this endpoint
RPCTypes []string `json:"rpc_types,omitempty"`
// Tier indicates the current reputation tier (1=highest, 2=medium, 3=lowest)
Tier int `json:"tier,omitempty"`
// InCooldown indicates if the endpoint is currently in cooldown
InCooldown bool `json:"in_cooldown,omitempty"`
// CooldownRemaining is the remaining cooldown time if in cooldown
CooldownRemaining string `json:"cooldown_remaining,omitempty"`
}
EndpointDetails contains detailed information about a single endpoint.
type EndpointLatency ¶ added in v1.0.15
type EndpointLatency struct {
// AvgLatencyMs is the average response latency in milliseconds
AvgLatencyMs float64 `json:"avg_latency_ms"`
// MinLatencyMs is the minimum observed latency in milliseconds
MinLatencyMs float64 `json:"min_latency_ms"`
// MaxLatencyMs is the maximum observed latency in milliseconds
MaxLatencyMs float64 `json:"max_latency_ms"`
// LastLatencyMs is the most recent latency sample in milliseconds
LastLatencyMs float64 `json:"last_latency_ms"`
// SampleCount is the number of latency samples collected
SampleCount int64 `json:"sample_count"`
}
EndpointLatency contains latency metrics for an endpoint.
type EndpointReputation ¶ added in v1.0.15
type EndpointReputation struct {
// Score is the current reputation score (0-100)
Score float64 `json:"score"`
// SuccessCount is the total number of successful requests
SuccessCount int64 `json:"success_count"`
// ErrorCount is the total number of failed requests
ErrorCount int64 `json:"error_count"`
// LastUpdated is when the score was last modified
LastUpdated string `json:"last_updated,omitempty"`
// Latency contains latency metrics for the endpoint
Latency *EndpointLatency `json:"latency,omitempty"`
// CriticalStrikes is the current strike count
CriticalStrikes int `json:"critical_strikes,omitempty"`
}
EndpointReputation contains reputation metrics for an endpoint.
type EndpointSelector ¶
type EndpointSelector interface {
Select(EndpointAddrList) (EndpointAddr, error)
SelectMultiple(EndpointAddrList, uint) (EndpointAddrList, error)
// SelectMultipleWithArchival selects multiple endpoints with optional archival filtering.
// When requiresArchival is true, only endpoints that have passed archival capability checks
// are considered. When false, all valid endpoints are considered (same as SelectMultiple).
// This enables archival requests to be routed only to archival-capable endpoints.
SelectMultipleWithArchival(EndpointAddrList, uint, bool) (EndpointAddrList, error)
}
EndpointSelector defines the functionality that the user of a protocol needs to provide. E.g. selecting an endpoint, from the list of available ones, to which the relay will be sent.
type GatewayMode ¶
type GatewayMode string
TODO_MVP(@adshmh): add a README based on the following notion doc: https://www.notion.so/buildwithgrove/Different-Modes-of-Operation-PATH-LocalNet-Discussions-122a36edfff6805e9090c9a14f72f3b5
GatewayMode represents the operation mode of the gateway that is using a relaying protcol for serving user requests. It is defined in the `protocol` package for: a. Consistency: protocol package defines all key concepts related to a relaying protocol. b. Clarity: make it clear that is a protocol-level concern to be addressed by all protocol implementations.
As of now, the GatewayMode can be one of the following (see the comment attached to each mode for details). 1. Centralized 2. Delegated 3. Permissionless
type Payload ¶
type Payload struct {
Data string
Method string
Path string
Headers map[string]string
// RPCType indicates the type of RPC protocol for routing to appropriate backend ports:
// - RPCType_REST: Cosmos SDK REST API (typically port 1317)
// - RPCType_COMET_BFT: CometBFT RPC (typically port 26657)
// - RPCType_JSON_RPC: EVM JSON-RPC (typically port 8545)
RPCType sharedtypes.RPCType
// OriginalRPCType preserves the RPC type detected from the request before any
// fallback was applied. When COMET_BFT falls back to JSON_RPC for routing
// (because no suppliers stake comet_bft endpoints), this field retains
// COMET_BFT so downstream analysis (e.g., heuristic error detection) can
// make protocol-aware decisions.
// Zero value (UNKNOWN_RPC) means no fallback occurred — use RPCType directly.
OriginalRPCType sharedtypes.RPCType
// JSONRPCMethod is the JSON-RPC method name (e.g., "eth_blockNumber", "eth_getLogs").
// Set at QoS request parsing time. Used by the heuristic analyzer for method-aware
// response validation (e.g., "result":[] is valid for eth_getLogs but not eth_blockNumber).
// Empty for non-JSON-RPC requests (REST, WebSocket).
JSONRPCMethod string
}
Payload represents the HTTP(s) requests proxied between clients and backend services. TODO_DOCUMENT(@adshmh): Add more examples (e.g. for RESTful services) TODO_IMPROVE(@adshmh): Use an interface here that returns the serialized form of the request.
func EmptyErrorPayload ¶
func EmptyErrorPayload() Payload
EmptyPayload returns an empty payload struct. It should only be used when an error is encountered and the actual request cannot be proxied, parsed or otherwise processed.
func (Payload) EffectiveRPCType ¶ added in v1.0.15
func (p Payload) EffectiveRPCType() sharedtypes.RPCType
EffectiveRPCType returns the most specific RPC type for protocol-aware analysis. If OriginalRPCType is set (fallback occurred), returns that; otherwise returns RPCType.
type RelayMetadata ¶ added in v1.0.15
type RelayMetadata struct {
// AppAddress is the application address used to sign/authorize the relay.
AppAddress string
// SupplierAddress is the supplier/operator address of the endpoint that served the relay.
SupplierAddress string
// SessionID is the session identifier from which the supplier was selected.
SessionID string
}
RelayMetadata contains metadata about a relay for debugging and transparency. This information is exposed via HTTP response headers to help clients understand which infrastructure served their request.
type Response ¶
type Response struct {
// Bytes is the response to a relay received from an endpoint.
// An endpoint is the backend server servicing an onchain service.
// This can be the serialized response to any type of RPC (gRPC, HTTP, etc.)
Bytes []byte
// HTTPStatusCode is the HTTP status returned by an endpoint in response to a relay request.
HTTPStatusCode int
// EndpointAddr is the address of the endpoint which returned the response.
EndpointAddr
// Metadata contains relay-specific information for debugging/transparency.
// Used to populate response headers like X-Supplier-Address, X-App-Address, X-Session-ID.
Metadata RelayMetadata
// RequestID is the JSON-RPC request ID that this response corresponds to.
// Used for batch request processing to ensure error responses have the correct ID.
// For non-JSON-RPC requests or when ID extraction fails, this may be empty.
RequestID string
}
Response is a general purpose struct for capturing the response to a relay, received from an endpoint. TODO_FUTURE(@adshmh): It only supports HTTP responses for now; add support for others.
type ServiceID ¶
type ServiceID string
ServiceID represents a unique onchain ID for a service. It is defined in the `protocol` package and not the `qos` package because: A. Protocols (i.e. Shannon) define and maintain onchain entities, including service IDs. B. The `qos` package handles offchain specs & details. C. This allows the `gateway` package to map multiple Service IDs to a single qos implementation, e.g. all EVM blockchain services can be handled by `qos/evm`.