Documentation
¶
Index ¶
- Variables
- func BuildServiceBackendRequest(relayRequest *types.RelayRequest, ...) (*http.Request, error)
- func CaptureGRPCCallDuration(component, method string, startTime time.Time)
- func CaptureRelayDuration(serviceId string, startTime time.Time, statusCode int)
- func CaptureRequestPreparationDuration(serviceId string, startTime time.Time)
- func CaptureResponsePreparationDuration(serviceId string, startTime time.Time)
- func CaptureServiceDuration(serviceId string, startTime time.Time, statusCode int)
- func ForwardPocketHeaders(header *http.Header, meta types.RelayRequestMetadata)
- func NewRelayMiner(ctx context.Context, deps depinject.Config) (*relayMiner, error)
- type MinedRelay
- type MinedRelaysObservable
- type Miner
- type MinerOption
- type RelayAuthenticator
- type RelayAuthenticatorOption
- type RelayMeter
- type RelayServer
- type RelayServers
- type RelayerProxy
- type RelayerProxyOption
- type RelayerSessionsManager
- type RelayerSessionsManagerOption
- type RelaysObservable
- type SessionTree
Constants ¶
This section is empty.
Variables ¶
var ( // RelaysTotal is a Counter metric for the total requests processed by the relay miner. // It increments to track proxy requests and is labeled by 'service_id', // essential for monitoring load and traffic on different proxies and services. // // Usage: // - Monitor total request load. // - Compare requests across services or proxies. RelaysTotal = prometheus.NewCounterFrom(stdprometheus.CounterOpts{ Subsystem: relayMinerProcess, Name: requestsTotal, Help: "Total number of requests processed, labeled by service ID.", }, []string{"service_id", "supplier_operator_address"}) // RelaysErrorsTotal is a Counter for total error events in the relay miner. // It increments with each error, labeled by 'service_id', // crucial for pinpointing error-prone areas for reliability improvement. // // Usage: // - Track and analyze error types and distribution. // - Compare error rates for reliability analysis. RelaysErrorsTotal = prometheus.NewCounterFrom(stdprometheus.CounterOpts{ Subsystem: relayMinerProcess, Name: requestsErrorsTotal, Help: "Total number of error events.", }, []string{"service_id"}) // RelaysSuccessTotal is a Counter metric for successful requests in the relay miner. // It increments with each successful request, labeled by 'service_id'. RelaysSuccessTotal = prometheus.NewCounterFrom(stdprometheus.CounterOpts{ Subsystem: relayMinerProcess, Name: requestsSuccessTotal, Help: "Total number of successful requests processed, labeled by service ID.", }, []string{"service_id"}) // RelaysDurationSeconds observes the end-to-end duration of the request in the relay miner. // // It includes the duration of the request to the backend service/data node AS WELL AS // the duration of the RelayMiner's internal overhead. // // Usage: // - Analyze typical response times and long-tail latency issues. // - Compare performance across services or environments. RelaysDurationSeconds = prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ Subsystem: relayMinerProcess, Name: relayDurationSeconds, Help: "Histogram of request durations for performance analysis.", Buckets: defaultBuckets, }, []string{"service_id", "status_code"}) // ServiceDurationSeconds observes the duration of the request to the backend service/data node outside of the RelayMiner. // // This histogram, labeled by 'service_id' and 'status_code', measures response times, // vital for performance analysis under different loads. // // It is a complementary metric to RelaysDurationSeconds allowing to isolate the // performance of the data node and the overhead of the RelayMiner's internal processing. // // Usage: // - Analyze typical response times and long-tail latency issues. // - Compare performance across services or environments. ServiceDurationSeconds = prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ Subsystem: relayMinerProcess, Name: serviceDurationSeconds, Help: "Histogram of service call durations for performance analysis.", Buckets: defaultBuckets, }, []string{"service_id", "status_code"}) // TODO_TECHDEBT: Remove those metrics once the session rollover issue is resolved. // RelayRequestPreparationDurationSeconds observes the duration of preparing // a relay request from an HTTP request. // // This histogram, labeled by 'service_id', measures the time taken to prepare // a relay request, which includes unmarshaling the request body and preparing // the RelayRequest structure. // Usage: // - Analyze the time taken to prepare relay requests. // - Identify potential bottlenecks in request preparation. RelayRequestPreparationDurationSeconds = prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ Subsystem: relayMinerProcess, Name: requestPreparationDurationSeconds, Help: "Histogram of relay request preparation durations in seconds.", Buckets: defaultBuckets, }, []string{"service_id"}) // TODO_TECHDEBT: Remove those metrics once the session rollover issue is resolved. // RelayResponsePreparationDurationSeconds observes the duration of preparing // a relay response from the the service's HTTP response. // // This histogram, labeled by 'service_id', measures the time taken to prepare // a relay response, which includes marshaling the response body and preparing // the RelayResponse structure. // Usage: // - Analyze the time taken to prepare relay responses. // - Identify potential bottlenecks in response preparation. RelayResponsePreparationDurationSeconds = prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ Subsystem: relayMinerProcess, Name: responsePreparationDurationSeconds, Help: "Histogram of relay response preparation durations in seconds.", Buckets: defaultBuckets, }, []string{"service_id"}) // FullNodeGRPCCallDurationSeconds is a histogram metric for measuring the duration of gRPC calls. // // It is labeled by 'component' (e.g., miner, proxy) and 'method', capturing the time taken for each call. // This metric is essential for performance monitoring and analysis of gRPC interactions. // Usage: // - Monitor gRPC call performance. // - Identify slow or problematic calls. FullNodeGRPCCallDurationSeconds = prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ Subsystem: relayMinerProcess, Name: fullNodeGRPCCallDurationSeconds, Help: "Histogram of gRPC call durations for performance analysis.", Buckets: defaultBuckets, }, []string{"component", "method"}) // RelayResponseSizeBytes is a histogram metric for observing response size distribution. // It counts responses in bytes, with buckets: // - 100 bytes to 50,000 bytes, capturing a range from small to large responses. // This data helps in accurately representing response size distribution and is vital // for performance tuning. // // TODO_TECHDEBT: Consider configuring bucket sizes externally for flexible adjustments // in response to different data patterns or deployment scenarios. RelayResponseSizeBytes = prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ Subsystem: relayMinerProcess, Name: responseSizeBytes, Help: "Histogram of response sizes in bytes for performance analysis.", Buckets: []float64{100, 500, 1000, 5000, 10000, 50000}, }, []string{"service_id"}) // RelayRequestSizeBytes is a histogram metric for observing request size distribution. // It counts requests in bytes, with buckets: // - 100 bytes to 50,000 bytes, capturing a range from small to large requests. // This data helps in accurately representing request size distribution and is vital // for performance tuning. RelayRequestSizeBytes = prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ Subsystem: relayMinerProcess, Name: requestSizeBytes, Help: "Histogram of request sizes in bytes for performance analysis.", Buckets: []float64{100, 500, 1000, 5000, 10000, 50000}, }, []string{"service_id"}) )
Functions ¶
func BuildServiceBackendRequest ¶ added in v0.0.13
func BuildServiceBackendRequest( relayRequest *types.RelayRequest, serviceConfig *config.RelayMinerSupplierServiceConfig, ) (*http.Request, error)
BuildServiceBackendRequest builds the service backend request from the relay request and the service configuration.
func CaptureGRPCCallDuration ¶ added in v0.1.28
CaptureGRPCCallDuration records the duration of a gRPC call. It is labeled by component (e.g., miner, proxy) and method, capturing the time taken for the call.
func CaptureRelayDuration ¶ added in v0.1.23
CaptureRelayDuration records the internal end-to-end duration of handling a relay which includes the network call to the backend data / service node. It calculates the elapsed time since the RelayMiner started processing the request BEFORE doing all of its internal processing.
func CaptureRequestPreparationDuration ¶ added in v0.1.28
CaptureRequestPreparationDuration records the duration of the request reading and preparation before sending it to the backend service/data node. It is labeled by service ID and captures the time taken to process the request.
func CaptureResponsePreparationDuration ¶ added in v0.1.28
CaptureResponsePreparationDuration records the duration of preparing the response after receiving it from the backend service/data node. It is labeled by service ID and captures the time taken to process the response.
func CaptureServiceDuration ¶ added in v0.1.23
CaptureServiceDuration records the duration of a request to the backend data / service node explicitly. It is labeled by service ID and HTTP status code. It calculates the elapsed time since the RelayMiner started the outbound network call AFTER doing all of its internal processing.
func ForwardPocketHeaders ¶ added in v0.1.12
func ForwardPocketHeaders(header *http.Header, meta types.RelayRequestMetadata)
ForwardPocketHeaders adds Pocket-specific identity headers from the relay metadata to the HTTP request header. This helps with tracking and authentication at the service backend level.
func NewRelayMiner ¶
NewRelayMiner creates a new Relayer instance with the given dependencies. It injects the dependencies into the Relayer instance and returns it.
Required dependencies:
- RelayerProxy
- Miner
- RelayerSessionsManager
Types ¶
type MinedRelay ¶
MinedRelay is a wrapper around a relay that has been serialized and hashed.
type MinedRelaysObservable ¶
type MinedRelaysObservable observable.Observable[*MinedRelay]
MinedRelaysObservable is an observable which is notified with MinedRelay values.
TODO_HACK: The purpose of this type is to work around gomock's lack of support for generic types. For the same reason, this type cannot be an alias (i.e. MinedRelaysObservable = observable.Observable[*MinedRelay]).
type Miner ¶
type Miner interface {
MinedRelays(
ctx context.Context,
servedRelayObs RelaysObservable,
) (minedRelaysObs MinedRelaysObservable)
}
Miner is responsible for observing servedRelayObs, hashing and checking the difficulty of each, finally publishing those with sufficient difficulty to minedRelayObs as they are applicable for relay volume.
type MinerOption ¶
type MinerOption func(Miner)
type RelayAuthenticator ¶ added in v0.0.13
type RelayAuthenticator interface {
// VerifyRelayRequest verifies the relay request signature and session validity.
VerifyRelayRequest(
ctx context.Context,
relayRequest *servicetypes.RelayRequest,
serviceId string,
) error
// CheckRelayRewardEligibility verifies the Relay Request is still reward eligible.
// This is done by:
// - Retrieving the session header of the relay request
// - Ensuring the current block height hasn't reached the beginning of the claim window
// Returns an error if the relay is no longer eligible for rewards.
CheckRelayRewardEligibility(ctx context.Context, relayRequest *servicetypes.RelayRequest) error
// SignRelayResponse signs the relay response given a supplier operator address.
SignRelayResponse(relayResponse *servicetypes.RelayResponse, supplierOperatorAddr string) error
// GetSupplierOperatorAddresses returns the supplier operator addresses that
// the relay authenticator can use to sign relay responses.
GetSupplierOperatorAddresses() []string
}
RelayAuthenticator is the interface that authenticates the relay requests and responses (i.e. verifies the relay request signature and session validity, and signs the relay response).
type RelayAuthenticatorOption ¶ added in v0.0.13
type RelayAuthenticatorOption func(RelayAuthenticator)
type RelayMeter ¶ added in v0.0.11
type RelayMeter interface {
// Start starts the relay meter.
Start(ctx context.Context) error
// IsOverServicing returns whether the relay would result in over-servicing the application.
IsOverServicing(ctx context.Context, relayRequestMeta servicetypes.RelayRequestMetadata) bool
// SetNonApplicableRelayReward updates the relay meter for the given relay request as
// non-applicable between a single Application and a single Supplier for a single session.
// The volume / reward applicability of the relay is unknown to the relay miner
// until the relay is served and the relay response signed.
SetNonApplicableRelayReward(ctx context.Context, relayRequestMeta servicetypes.RelayRequestMetadata)
// AllowOverServicing returns true if the relay meter is configured to allow over-servicing.
AllowOverServicing() bool
}
RelayMeter is an interface that keeps track of the amount of stake consumed between a single onchain Application and a single onchain Supplier over the course of a single session. It enables the RelayMiner to rate limit the number of requests handled offchain as a function of the optimistic onchain rate limits.
type RelayServer ¶
type RelayServer interface {
// Start starts the service server and returns an error if it fails.
Start(ctx context.Context) error
// Stop terminates the service server and returns an error if it fails.
Stop(ctx context.Context) error
// Ping tests the connection between the relay server and its backend URL.
Ping(ctx context.Context) error
}
RelayServer is the interface of the advertised relay servers provided by the RelayerProxy.
type RelayServers ¶ added in v0.0.14
type RelayServers []RelayServer
RelayServers aggregates a slice of RelayServer interface.
type RelayerProxy ¶
type RelayerProxy interface {
// Start starts all advertised relay servers and returns an error if any of them fail to start.
Start(ctx context.Context) error
// Stop stops all advertised relay servers and returns an error if any of them fail.
Stop(ctx context.Context) error
// ServedRelays returns an observable that notifies the miner about the relays that have been served.
// A served relay is one whose RelayRequest's signature and session have been verified,
// and its RelayResponse has been signed and successfully sent to the client.
ServedRelays() RelaysObservable
// PingAll tests the connectivity between all the managed relay servers and their respective backend URLs.
PingAll(ctx context.Context) error
}
RelayerProxy is the interface for the proxy that serves relays to the application. It is responsible for starting and stopping all supported RelayServers. While handling requests and responding in a closed loop, it also notifies the miner about the relays that have been served.
type RelayerProxyOption ¶
type RelayerProxyOption func(RelayerProxy)
type RelayerSessionsManager ¶
type RelayerSessionsManager interface {
// InsertRelays receives an observable of relays that should be included
// in their respective session's SMST (tree).
InsertRelays(minedRelaysObs MinedRelaysObservable)
// Start iterates over the session trees at the end of each, respective, session.
// The session trees are piped through a series of map operations which progress
// them through the claim/proof lifecycle, broadcasting transactions to the
// network as necessary.
Start(ctx context.Context) error
// Stop unsubscribes all observables from the InsertRelays observable which
// will close downstream observables as they drain.
//
// TODO_TECHDEBT: Either add a mechanism to wait for draining to complete
// and/or ensure that the state at each pipeline stage is persisted to disk
// and exit as early as possible.
Stop()
}
RelayerSessionsManager is responsible for managing the relayer's session lifecycles. It handles the creation and retrieval of SMSTs (trees) for a given session, as well as the respective and subsequent claim creation and proof submission. This is largely accomplished by pipelining observables of relays and sessions through a series of map operations.
TODO_TECHDEBT: add architecture diagrams covering observable flows throughout the relayer package.
type RelayerSessionsManagerOption ¶
type RelayerSessionsManagerOption func(RelayerSessionsManager)
type RelaysObservable ¶
type RelaysObservable observable.Observable[*servicetypes.Relay]
RelaysObservable is an observable which is notified with Relay values.
TODO_HACK: The purpose of this type is to work around gomock's lack of support for generic types. For the same reason, this type cannot be an alias (i.e. RelaysObservable = observable.Observable[*servicetypes.Relay]).
type SessionTree ¶
type SessionTree interface {
// GetSessionHeader returns the header of the session corresponding to the SMST.
GetSessionHeader() *sessiontypes.SessionHeader
// Update is a wrapper for the SMST's Update function. It updates the SMST with
// the given key, value, and weight.
// This function should be called when a Relay has been successfully served.
Update(key, value []byte, weight uint64) error
// ProveClosest is a wrapper for the SMST's ProveClosest function. It returns the
// proof for the given path.
// This function should be called several blocks after a session has been claimed and needs to be proven.
ProveClosest(path []byte) (proof *smt.SparseCompactMerkleClosestProof, err error)
// GetSMSTRoot returns the the current root hash of the SMST.
// It differs from GetClaimRoot in that it always returns the latest root hash
// of the SMST, while GetClaimRoot returns the root hash after the session tree
// has been flushed to create the claim.
GetSMSTRoot() smt.MerkleSumRoot
// GetClaimRoot returns the root hash of the SMST needed for creating the claim.
// It returns nil if the session tree has not been flushed yet.
GetClaimRoot() []byte
// GetProofBz returns the proof created by ProveClosest needed for submitting
// a proof in byte format.
GetProofBz() []byte
// Flush should be used to safely free up resources used by the SMST without risking rewards.
// Flush can be seen as a safe version of "Stop" which is explicitly not exposed by this interface.
//
// It does the following:
// 1. Gets the root hash of the SMST needed for submitting the claim.
// 2. Commits the entire tree to disk (if disk storage is used)
// 3. Stops the KVStore.
//
// It should be called before submitting the claim onchain.
// This function frees up the in-memory resources used by the SMST that are
// no longer needed while waiting for the proof submission window to open.
Flush() (SMSTRoot []byte, err error)
// TODO_DISCUSS: This function should not be part of the interface as it is an optimization
// aiming to free up KVStore resources after the proof is no longer needed.
// Delete deletes the SMST from the KVStore.
// WARNING: This function should be called only after the proof has been successfully
// submitted onchain and the servicer has confirmed that it has been rewarded.
Delete() error
// StartClaiming marks the session tree as being picked up for claiming,
// so it won't be picked up by the relayer again.
// It returns an error if it has already been marked as such.
StartClaiming() error
// GetSupplierOperatorAddress returns a stringified bech32 address of the supplier
// operator this sessionTree belongs to.
GetSupplierOperatorAddress() string
// GetTrieSpec returns the trie spec of the SMST.
GetTrieSpec() smt.TrieSpec
}
SessionTree is an interface that wraps an SMST (Sparse Merkle State Trie) and its corresponding session.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cmd provides the command-line interface for the RelayMiner.
|
Package cmd provides the command-line interface for the RelayMiner. |