Documentation
¶
Index ¶
- Constants
- Variables
- func CloseBody(logger polylog.Logger, body io.ReadCloser)
- func NewHTTPServer(logger polylog.Logger, serverConfig *config.RelayMinerServerConfig, ...) relayer.RelayServer
- func NewRelayMeter(deps depinject.Config, enableOverServicing bool) (relayer.RelayMeter, error)
- func NewRelayerProxy(deps depinject.Config, opts ...relayer.RelayerProxyOption) (relayer.RelayerProxy, error)
- func SafeReadBody(logger polylog.Logger, body io.ReadCloser, maxSize int64) (bodyBytes []byte, cleanupFunc func(), err error)
- func SafeRequestReadBody(logger polylog.Logger, request *http.Request, maxSize int64) (bodyBytes []byte, cleanupFunc func(), err error)
- func SafeResponseReadBody(logger polylog.Logger, response *http.Response, maxSize int64) (bodyBytes []byte, cleanupFunc func(), err error)
- func SerializeHTTPResponse(logger polylog.Logger, response *http.Response, maxBodySize int64) (poktHTTPResponse *sdktypes.POKTHTTPResponse, poktHTTPResponseBz []byte, ...)
- func WithPingEnabled(pingEnabled bool) relayer.RelayerProxyOption
- func WithServedRelaysBufferSize(size int) relayer.RelayerProxyOption
- func WithServicesConfigMap(servicesConfigMap map[string]*config.RelayMinerServerConfig) relayer.RelayerProxyOption
- type ProxyRelayMeter
- func (rmtr *ProxyRelayMeter) AllowOverServicing() bool
- func (rmtr *ProxyRelayMeter) IsOverServicing(ctx context.Context, reqMeta servicetypes.RelayRequestMetadata) bool
- func (rmtr *ProxyRelayMeter) SetNonApplicableRelayReward(ctx context.Context, reqMeta servicetypes.RelayRequestMetadata)
- func (rmtr *ProxyRelayMeter) Start(ctx context.Context) error
Constants ¶
const ( UnknownServiceID = "unknown_service_id" UnknownSupplierOperatorAddress = "unknown_supplier_operator_address" )
UnknownServiceID and UnknownSupplierOperatorAddress are the default values used as a fallback when the actual service ID or supplier operator cannot be determined. This occurs during error scenarios before relay request validation, ensuring metrics labels and error responses always have a valid service ID value.
const RPCTypeHeader = "Rpc-Type"
rpcTypeHeader is the header key for the RPC type, provided by the client.
Variables ¶
var ( ErrRelayerProxyInvalidSession = sdkerrors.Register(codespace, 1, "invalid session in relayer request") ErrRelayerServicesConfigsUndefined = sdkerrors.Register(codespace, 2, "services configurations are undefined") ErrRelayerProxyServiceEndpointNotHandled = sdkerrors.Register(codespace, 3, "service endpoint not handled by relayer proxy") ErrRelayerProxyUnsupportedTransportType = sdkerrors.Register(codespace, 4, "unsupported proxy transport type") ErrRelayerProxyInternalError = sdkerrors.Register(codespace, 5, "internal error") ErrRelayerProxyUnknownSession = sdkerrors.Register(codespace, 6, "relayer proxy encountered unknown session") ErrRelayerProxyRateLimited = sdkerrors.Register(codespace, 7, "offchain rate limit hit by relayer proxy") ErrRelayerProxyCalculateRelayCost = sdkerrors.Register(codespace, 8, "failed to calculate relay cost") ErrRelayerProxySupplierNotReachable = sdkerrors.Register(codespace, 9, "supplier(s) not reachable") ErrRelayerProxyTimeout = sdkerrors.Register(codespace, 10, "relayer proxy request timed out") ErrRelayerProxyMaxBodyExceeded = sdkerrors.Register(codespace, 11, "max body size exceeded") ErrRelayerProxyResponseLimitExceeded = sdkerrors.Register(codespace, 12, "response limit exceed") ErrRelayerProxyRequestLimitExceeded = sdkerrors.Register(codespace, 13, "request limit exceed") ErrRelayerProxyUnmarshalingRelayRequest = sdkerrors.Register(codespace, 14, "failed to unmarshal relay request") )
Functions ¶
func CloseBody ¶ added in v0.1.27
func CloseBody(logger polylog.Logger, body io.ReadCloser)
CloseBody safely closes an io.ReadCloser with proper error handling and logging. It gracefully handles nil readers and logs any errors encountered during closure.
func NewHTTPServer ¶ added in v0.0.13
func NewHTTPServer( logger polylog.Logger, serverConfig *config.RelayMinerServerConfig, servedRelaysProducer chan<- *types.Relay, relayAuthenticator relayer.RelayAuthenticator, relayMeter relayer.RelayMeter, blockClient client.BlockClient, sharedQueryClient client.SharedQueryClient, sessionQueryClient client.SessionQueryClient, ) relayer.RelayServer
NewHTTPServer creates a new RelayServer that listens for incoming relay requests and forwards them to the corresponding proxied service endpoint. TODO_RESEARCH(#590): Currently, the communication between the Gateway and the RelayMiner uses HTTP. This could be changed to a more generic and performant one, such as QUIC or pure TCP.
func NewRelayMeter ¶ added in v0.0.11
func NewRelayerProxy ¶
func NewRelayerProxy( deps depinject.Config, opts ...relayer.RelayerProxyOption, ) (relayer.RelayerProxy, error)
NewRelayerProxy creates a new relayer proxy with the given dependencies or returns an error if the dependencies fail to resolve or the options are invalid.
Required dependencies:
- polylog.Logger
- client.BlockClient
- client.SupplierQueryClient
- client.SharedQueryClient
- client.SessionQueryClient
- relayer.RelayMeter
- relayer.RelayAuthenticator
Available options:
- WithServicesConfigMap
func SafeReadBody ¶ added in v0.1.23
func SafeReadBody( logger polylog.Logger, body io.ReadCloser, maxSize int64, ) (bodyBytes []byte, cleanupFunc func(), err error)
SafeReadBody reads the complete body from an io.ReadCloser with size limits and memory pooling. It automatically closes the reader, enforces maximum size constraints, and reuses buffers from a shared pool to minimize memory allocations.
Parameters:
- body: The io.ReadCloser to read from (will be closed automatically)
- maxSize: Maximum allowed body size in bytes (uses defaultMaxBodySize if <= 0)
- logger: Logger for error reporting
Returns the complete body as a byte slice or an error if reading fails or size limit is exceeded.
func SafeRequestReadBody ¶ added in v0.1.27
func SafeRequestReadBody( logger polylog.Logger, request *http.Request, maxSize int64, ) (bodyBytes []byte, cleanupFunc func(), err error)
SafeRequestReadBody reads the HTTP request body up to a specified size limit, enforcing safety and logging errors. Logs and wraps errors for size violations or reading issues, using the provided logger. Returns body as []byte or error.
func SafeResponseReadBody ¶ added in v0.1.27
func SafeResponseReadBody( logger polylog.Logger, response *http.Response, maxSize int64, ) (bodyBytes []byte, cleanupFunc func(), err error)
SafeResponseReadBody reads the HTTP response body up to a specified size limit, enforcing safety and logging errors. Logs and wraps errors for size violations or reading issues, using the provided logger. Returns body as []byte or error.
func SerializeHTTPResponse ¶ added in v0.1.23
func SerializeHTTPResponse( logger polylog.Logger, response *http.Response, maxBodySize int64, ) (poktHTTPResponse *sdktypes.POKTHTTPResponse, poktHTTPResponseBz []byte, err error)
TODO_TECHDEBT: Move this function back to the Shannon SDK. It was moved: 1. To ensure proper body closure 2. To avoid using io.ReadAll which doesn't implement size limits. 3. To iterate faster
SerializeHTTPResponse converts an http.Response into a protobuf-serialized byte slice.
The function:
- Safely reads the response body with size limits
- Preserves all HTTP headers (including multiple values per header key)
- Uses deterministic protobuf marshaling for consistent serialization
- Properly closes the response body
Parameters:
- response: The HTTP response to serialize
- logger: Logger for error reporting
Returns:
- poktHTTPResponse: The structured response object
- poktHTTPResponseBz: The serialized response as bytes
- err: Any error encountered during processing
func WithPingEnabled ¶ added in v0.1.18
func WithPingEnabled(pingEnabled bool) relayer.RelayerProxyOption
WithPingEnabled configures whether ping functionality is enabled for the RelayerProxy. When enabled, the proxy will perform health checks and connectivity tests to backend service endpoints.
func WithServedRelaysBufferSize ¶ added in v0.1.34
func WithServedRelaysBufferSize(size int) relayer.RelayerProxyOption
WithServedRelaysBufferSize sets the buffer size of the channel that forwards served, reward-eligible relays into the mining pipeline. When this buffer fills, relays are dropped from mining (served but unpaid), so high-throughput suppliers should raise it. A value <= 0 keeps the observable's default buffer size.
func WithServicesConfigMap ¶
func WithServicesConfigMap(servicesConfigMap map[string]*config.RelayMinerServerConfig) relayer.RelayerProxyOption
WithServicesConfigMap updates the configurations of all the services the RelayMiner proxies requests to. servicesConfigMap is a map of server endpoints to their respective parsed configurations.
Types ¶
type ProxyRelayMeter ¶ added in v0.0.11
type ProxyRelayMeter struct {
// contains filtered or unexported fields
}
ProxyRelayMeter is the offchain Supplier's rate limiter. It ensures that no Application is over-serviced by the Supplier per session. This is done by maintaining the max amount of stake the supplier can consume per session and the amount of stake consumed by mined relays. TODO_POST_MAINNET(@red-0ne): Consider making the relay meter a light client, since it's already receiving all committed blocks and events.
func (*ProxyRelayMeter) AllowOverServicing ¶ added in v0.1.18
func (rmtr *ProxyRelayMeter) AllowOverServicing() bool
AllowOverServicing returns true if the relay meter is configured to allow over-servicing.
Over-servicing allows the offchain relay miner to serve more relays than the amount of stake the onchain Application can pay the corresponding onchain Supplier at the end of the session.
func (*ProxyRelayMeter) IsOverServicing ¶ added in v0.1.18
func (rmtr *ProxyRelayMeter) IsOverServicing( ctx context.Context, reqMeta servicetypes.RelayRequestMetadata, ) bool
IsOverServicing returns whether the relay would result in over-servicing the application.
It returns true if serving this relay would exceed the application's allocated stake (serving beyond what the application can pay for), false if the relay is within limits. The function updates the relay meter with the given relay request metadata.
func (*ProxyRelayMeter) SetNonApplicableRelayReward ¶ added in v0.0.11
func (rmtr *ProxyRelayMeter) SetNonApplicableRelayReward(ctx context.Context, reqMeta servicetypes.RelayRequestMetadata)
SetNonApplicableRelayReward updates the relay meter to make the relay reward for the given relay request as non-applicable. This is used when the relay is not volume / reward applicable but was optimistically accounted for in the relay meter.