Documentation
¶
Index ¶
Constants ¶
const ( // DefaultMaxBufferSize is the default maximum number of messages that the provider // will buffer at any given time. DefaultMaxBufferSize = 1024 // DefaultReconnectionTimeout is the default timeout for the provider to attempt // to reconnect to the websocket endpoint. DefaultReconnectionTimeout = 10 * time.Second // DefaultPostConnectionTimeout is the default timeout for the provider to wait // after a connection is established before sending messages. DefaultPostConnectionTimeout = 1 * time.Second // DefaultReadBufferSize is the default I/O read buffer size. If a buffer size of // 0 is specified, then a default buffer size is used i.e. the buffers allocated // by the HTTP server. DefaultReadBufferSize = 0 // DefaultWriteBufferSize is the default I/O write buffer size. If a buffer size of // 0 is specified, then a default buffer size is used i.e. the buffers allocated // by the HTTP server. DefaultWriteBufferSize = 0 // DefaultHandshakeTimeout is the default duration for the handshake to complete. DefaultHandshakeTimeout = 10 * time.Second // DefaultEnableCompression is the default value for whether the client should // attempt to negotiate per message compression (RFC 7692). DefaultEnableCompression = false // DefaultReadTimeout is the default read deadline on the underlying network // connection. DefaultReadTimeout = 10 * time.Second // DefaultWriteTimeout is the default write deadline on the underlying network // connection. DefaultWriteTimeout = 5 * time.Second // DefaultPingInterval is the default interval at which the provider should send // ping messages to the server. DefaultPingInterval = 0 * time.Second // DefaultWriteInterval is the default interval at which the provider should send // write messages to the server. DefaultWriteInterval = 100 * time.Millisecond // DefaultMaxReadErrorCount is the default maximum number of read errors that // the provider will tolerate before closing the connection and attempting to // reconnect. This default value utilized by the gorilla/websocket package is // 1000, but we set it to a lower value to allow the provider to reconnect // faster. DefaultMaxReadErrorCount = 100 // DefaultMaxSubscriptionsPerConnection is the default maximum subscriptions // a provider can handle per-connection. When this value is 0, one connection // will handle all subscriptions. DefaultMaxSubscriptionsPerConnection = 0 // DefaultMaxSubscriptionsPerBatch is the default maximum number of subscriptions // that can be assigned to a single batch/write/message. DefaultMaxSubscriptionsPerBatch = 1 )
const ( // DefaultConfigTemplate should be utilized in the app.toml file. // This template configures the application to connect to the // oracle sidecar and exposes instrumentation for the oracle client // and the interaction between the oracle and the app. DefaultConfigTemplate = `` /* 1700-byte string literal not displayed */ )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type APIConfig ¶
type APIConfig struct {
// Enabled is a flag that indicates whether the provider is API based.
Enabled bool `json:"enabled"`
// Timeout is the amount of time the provider should wait for a response from
// its API before timing out.
Timeout time.Duration `json:"timeout"`
// Interval is the interval at which the provider should update the prices.
Interval time.Duration `json:"interval"`
// ReconnectTimeout is the amount of time the provider should wait before
// reconnecting to the API.
ReconnectTimeout time.Duration `json:"reconnectTimeout"`
// MaxQueries is the maximum number of concurrent queries that the provider will make
// within the interval.
MaxQueries int `json:"maxQueries"`
// Atomic is a flag that indicates whether the provider can fulfill its queries
// in a single request.
Atomic bool `json:"atomic"`
// Endpoints is a list of endpoints that the provider can query.
Endpoints []Endpoint `json:"endpoints"`
// BatchSize is the maximum number of IDs that the provider can query in a single
// request. This parameter must be 0 for atomic providers. Otherwise, the effective
// value will be max(1, BatchSize). Notice, if numCPs > batchSize * maxQueries then
// some currency-pairs may not be fetched each interval.
BatchSize int `json:"batchSize"`
// Name is the name of the provider that corresponds to this config.
Name string `json:"name"`
// MaxBlockHeightAge is the oldest an update from an on-chain data source can be without having its
// block height incremented. In the case where a data source has exceeded this limit and the block
// height is not increasing, price reporting will be skipped until the block height increases.
MaxBlockHeightAge time.Duration `json:"maxBlockHeightAge"`
}
APIConfig defines a config for an API based data provider.
func (*APIConfig) ValidateBasic ¶
ValidateBasic performs basic validation of the API config.
type AppConfig ¶
type AppConfig struct {
// Enabled indicates whether the oracle is enabled.
Enabled bool `mapstructure:"enabled" toml:"enabled"`
// OracleAddress is the URL of the out of process oracle sidecar. This is
// used to connect to the oracle sidecar.
OracleAddress string `mapstructure:"oracle_address" toml:"oracle_address"`
// ClientTimeout is the time that the client is willing to wait for responses
// from the oracle before timing out.
ClientTimeout time.Duration `mapstructure:"client_timeout" toml:"client_timeout"`
// MetricsEnabled is a flag that determines whether oracle metrics are enabled.
MetricsEnabled bool `mapstructure:"metrics_enabled" toml:"metrics_enabled"`
// PriceTTL is the maximum age of the latest price response before it is considered
// stale.
PriceTTL time.Duration `mapstructure:"price_ttl" toml:"price_ttl"`
// Interval is the time between each price update request.
Interval time.Duration `mapstructure:"interval" toml:"interval"`
}
AppConfig contains the application side oracle configurations that must be set in the app.toml file.
func NewDefaultAppConfig ¶
func NewDefaultAppConfig() AppConfig
NewDefaultAppConfig returns a default application side oracle configuration.
func ReadConfigFromAppOpts ¶
func ReadConfigFromAppOpts(opts servertypes.AppOptions) (AppConfig, error)
ReadConfigFromAppOpts reads the config parameters from the AppOptions and returns the config.
func (*AppConfig) ValidateBasic ¶
ValidateBasic performs basic validation of the app config.
type Authentication ¶
type Authentication struct {
// HTTPHeaderAPIKey is the API-key that will be set under the X-Api-Key header
APIKey string `json:"apiKey"`
// APIKeyHeader is the header that will be used to set the API key.
APIKeyHeader string `json:"apiKeyHeader"`
}
Authentication holds all data necessary for an API provider to authenticate with an endpoint.
func (Authentication) Enabled ¶
func (a Authentication) Enabled() bool
Enabled returns true if the authentication is enabled.
func (Authentication) ValidateBasic ¶
func (a Authentication) ValidateBasic() error
ValidateBasic performs basic validation of the API authentication. Specifically, the APIKey + APIKeyHeader must be set atomically.
type Endpoint ¶
type Endpoint struct {
// URL is the URL that is used to fetch data from the API.
URL string `json:"url"`
// Authentication holds all data necessary for an API provider to authenticate with
// an endpoint.
Authentication Authentication `json:"authentication"`
}
Endpoint holds all data necessary for an API provider to connect to a given endpoint i.e. URL, headers, authentication, etc.
func (Endpoint) ValidateBasic ¶
ValidateBasic performs basic validation of the API endpoint.
type MetricsConfig ¶
type MetricsConfig struct {
// PrometheusServerAddress is the address of the prometheus server that the oracle will expose
// metrics to.
PrometheusServerAddress string `json:"prometheusServerAddress"`
// Enabled indicates whether metrics should be enabled.
Enabled bool `json:"enabled"`
}
MetricsConfig is the metrics configurations for the oracle. This configuration object specifically exposes metrics pertaining to the oracle sidecar. To enable app side metrics, please see the app configuration.
func (*MetricsConfig) ValidateBasic ¶
func (c *MetricsConfig) ValidateBasic() error
ValidateBasic performs basic validation of the config.
type OracleConfig ¶
type OracleConfig struct {
// UpdateInterval is the interval at which the oracle will fetch prices from providers.
UpdateInterval time.Duration `json:"updateInterval"`
// MaxPriceAge is the maximum age of a price that the oracle will consider valid. If a
// price is older than this, the oracle will not consider it valid and will not return it in /prices
// requests.
MaxPriceAge time.Duration `json:"maxPriceAge"`
// Providers is the list of providers that the oracle will fetch prices from.
Providers map[string]ProviderConfig `json:"providers"`
// Metrics is the metrics configurations for the oracle.
Metrics MetricsConfig `json:"metrics"`
// Host is the host that the oracle will listen on.
Host string `json:"host"`
// Port is the port that the oracle will listen on.
Port string `json:"port"`
}
OracleConfig is the over-arching config for the oracle sidecar and instrumentation. The oracle is configured via a set of data providers (i.e. coinbase, binance, etc.) and a set of currency pairs (i.e. BTC/USD, ETH/USD, etc.). The oracle will fetch prices from the data providers for the currency pairs at the specified update interval.
func ReadOracleConfigFromFile ¶
func ReadOracleConfigFromFile(path string) (OracleConfig, error)
ReadOracleConfigFromFile reads a config from a file and returns the config.
func (*OracleConfig) ValidateBasic ¶
func (c *OracleConfig) ValidateBasic() error
ValidateBasic performs basic validation on the oracle config.
type ProviderConfig ¶
type ProviderConfig struct {
// Name identifies which provider this config is for.
Name string `json:"name"`
// API is the config for the API based data provider. If the provider does not
// support API based fetching, this field should be omitted.
API APIConfig `json:"api"`
// WebSocket is the config for the websocket based data provider. If the provider
// does not support websocket based fetching, this field should be omitted.
WebSocket WebSocketConfig `json:"webSocket"`
// Type is the type of the provider (i.e. price, market map, other). This is used
// to determine how to construct the provider.
Type string `json:"type"`
}
ProviderConfig defines a config for a provider. To add a new provider, add the provider config to the oracle configuration.
func (*ProviderConfig) ValidateBasic ¶
func (c *ProviderConfig) ValidateBasic() error
type WebSocketConfig ¶
type WebSocketConfig struct {
// Enabled is a flag that indicates whether the provider is websocket based.
Enabled bool `json:"enabled"`
// MaxBufferSize is the maximum number of messages that the provider will buffer
// at any given time. If the provider receives more messages than this, it will
// block receiving messages until the buffer is cleared.
MaxBufferSize int `json:"maxBufferSize"`
// ReconnectionTimeout is the timeout for the provider to attempt to reconnect
// to the websocket endpoint.
ReconnectionTimeout time.Duration `json:"reconnectionTimeout"`
// PostConnectionTimeout is the timeout for the provider to wait after a connection
// is established before sending messages.
PostConnectionTimeout time.Duration `json:"postConnectionTimeout"`
// Endpoints are the websocket endpoints for the provider. At least one endpoint
// must be specified.
Endpoints []Endpoint `json:"endpoints"`
// Name is the name of the provider that corresponds to this config.
Name string `json:"name"`
// ReadBufferSize specifies the I/O read buffer size. if a buffer size of 0 is
// specified, then a default buffer size is used.
ReadBufferSize int `json:"readBufferSize"`
// WriteBufferSize specifies the I/O write buffer size. if a buffer size of 0 is
// specified, then a default buffer size is used.
WriteBufferSize int `json:"writeBufferSize"`
// HandshakeTimeout specifies the duration for the handshake to complete.
HandshakeTimeout time.Duration `json:"handshakeTimeout"`
// EnableCompression specifies if the client should attempt to negotiate per
// message compression (RFC 7692). Setting this value to true does not guarantee
// that compression will be supported. Note that enabling compression may
EnableCompression bool `json:"enableCompression"`
// ReadTimeout sets the read deadline on the underlying network connection.
// After a read has timed out, the websocket connection state is corrupt and
// all future reads will return an error. A zero value for t means reads will
// not time out.
ReadTimeout time.Duration `json:"readTimeout"`
// WriteTimeout sets the write deadline on the underlying network
// connection. After a write has timed out, the websocket state is corrupt and
// all future writes will return an error. A zero value for t means writes will
// not time out.
WriteTimeout time.Duration `json:"writeTimeout"`
// PingInterval is the interval to ping the server. Note that a ping interval
// of 0 disables pings.
PingInterval time.Duration `json:"pingInterval"`
// WriteInterval is the interval at which the provider should wait before sending
// consecutive write messages to the server.
WriteInterval time.Duration `json:"writeInterval"`
// MaxReadErrorCount is the maximum number of read errors that the provider
// will tolerate before closing the connection and attempting to reconnect.
MaxReadErrorCount int `json:"maxReadErrorCount"`
// MaxSubscriptionsPerConnection is the maximum amount of subscriptions that
// can be assigned to a single connection for this provider. The null value (0),
// indicates that there is no limit per connection.
MaxSubscriptionsPerConnection int `json:"maxSubscriptionsPerConnection"`
// MaxSubscriptionsPerBatch is the maximum number of subscription messages that the
// provider will send in a single batch/write.
MaxSubscriptionsPerBatch int `json:"maxSubscriptionsPerBatch"`
}
WebSocketConfig defines a config for a websocket based data provider.
func (*WebSocketConfig) ValidateBasic ¶
func (c *WebSocketConfig) ValidateBasic() error
ValidateBasic performs basic validation of the websocket config.