Documentation
¶
Index ¶
- Constants
- Variables
- type CORSHandler
- type EthSubHandler
- type HandlerOption
- type LoggingHandler
- type Node
- type Option
- func WithEthMaxFiltersPerConn(ethMaxFiltersPerConn int) Option
- func WithEthTraceFilterMaxBlockRange(maxBlockRange int64) Option
- func WithMaxLookbackDuration(maxLookbackDuration time.Duration) Option
- func WithMaxMessageLookbackEpochs(maxMessageLookbackEpochs abi.ChainEpoch) Option
- func WithRateLimit(rateLimit int) Option
- func WithRateLimitTimeout(rateLimitTimeout time.Duration) Option
- func WithV1EthSubHandler(subHandler *EthSubHandler) Option
- func WithV2EthSubHandler(subHandler *EthSubHandler) Option
- type RateLimitHandler
- type ShutdownHandler
Constants ¶
const ( DefaultMaxLookbackDuration = time.Hour * 24 // Default duration that a gateway request can look back in chain history DefaultMaxMessageLookbackEpochs = abi.ChainEpoch(20) // Default number of epochs that a gateway message lookup can look back in chain history DefaultRateLimitTimeout = time.Second * 5 // Default timeout for rate limiting requests; where a request would take longer to wait than this value, it will be rejected DefaultEthMaxFiltersPerConn = 16 // Default maximum number of ETH filters and subscriptions per websocket connection DefaultEthTraceFilterMaxBlockRange = int64(100) // Default maximum block range for EthTraceFilter on the gateway MaxRateLimitTokens = stateRateLimitTokens // Number of tokens consumed for the most expensive types of operations )
Variables ¶
var ErrTooManyFilters = errors.New("too many subscriptions and filters per connection")
var EthFeeHistoryMaxBlockCount = 128 // this seems to be expensive; todo: figure out what is a good number that works with everything
Functions ¶
This section is empty.
Types ¶
type CORSHandler ¶ added in v1.33.1
type CORSHandler struct {
// contains filtered or unexported fields
}
CORSHandler handles CORS headers for cross-origin requests.
func NewCORSHandler ¶ added in v1.33.1
func NewCORSHandler(next http.Handler) *CORSHandler
NewCORSHandler creates a new CORSHandler that wraps the provided handler and adds appropriate CORS headers to allow cross-origin requests from web browsers.
func (*CORSHandler) ServeHTTP ¶ added in v1.33.1
func (h *CORSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type EthSubHandler ¶ added in v1.20.0
type EthSubHandler struct {
// contains filtered or unexported fields
}
func NewEthSubHandler ¶ added in v1.20.0
func NewEthSubHandler() *EthSubHandler
func (*EthSubHandler) AddSub ¶ added in v1.20.0
func (e *EthSubHandler) AddSub(ctx context.Context, id ethtypes.EthSubscriptionID, sink func(context.Context, *ethtypes.EthSubscriptionResponse) error) error
func (*EthSubHandler) EthSubscription ¶ added in v1.20.0
func (*EthSubHandler) RemoveSub ¶ added in v1.20.0
func (e *EthSubHandler) RemoveSub(id ethtypes.EthSubscriptionID)
type HandlerOption ¶ added in v1.29.0
type HandlerOption func(*handlerOptions)
HandlerOption is a functional option for configuring the Handler.
func WithCORS ¶ added in v1.33.1
func WithCORS(enable bool) HandlerOption
WithCORS sets whether to enable CORS headers to allow cross-origin requests from web browsers.
func WithJsonrpcServerOptions ¶ added in v1.29.0
func WithJsonrpcServerOptions(options ...jsonrpc.ServerOption) HandlerOption
WithJsonrpcServerOptions sets the JSON-RPC server options.
func WithPerConnectionAPIRateLimit ¶ added in v1.29.0
func WithPerConnectionAPIRateLimit(limit int) HandlerOption
WithPerConnectionAPIRateLimit sets the per connection API rate limit.
The handler will limit the number of API calls per minute within a single WebSocket connection (where API calls are weighted by their relative expense), and the number of connections per minute from a single host.
func WithPerHostConnectionsPerMinute ¶ added in v1.29.0
func WithPerHostConnectionsPerMinute(limit int) HandlerOption
WithPerHostConnectionsPerMinute sets the per host connections per minute limit.
Connection limiting is a hard limit that will reject requests with a http.StatusTooManyRequests status code if the limit is exceeded. API call limiting is a soft limit that will delay requests if the limit is exceeded.
func WithRequestLogging ¶ added in v1.33.1
func WithRequestLogging(enable bool) HandlerOption
WithRequestLogging sets whether to enable request logging.
type LoggingHandler ¶ added in v1.33.1
type LoggingHandler struct {
// contains filtered or unexported fields
}
LoggingHandler logs incoming HTTP requests with details
func NewLoggingHandler ¶ added in v1.33.1
func NewLoggingHandler(next http.Handler) *LoggingHandler
NewLoggingHandler creates a new LoggingHandler that logs request details
func (*LoggingHandler) ServeHTTP ¶ added in v1.33.1
func (h *LoggingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func (*Node) V1ReverseProxy ¶ added in v1.33.0
func (*Node) V2ReverseProxy ¶ added in v1.33.0
type Option ¶ added in v1.29.0
type Option func(*options)
func WithEthMaxFiltersPerConn ¶ added in v1.29.0
WithEthMaxFiltersPerConn sets the maximum number of Ethereum filters and subscriptions that can be maintained per websocket connection.
func WithEthTraceFilterMaxBlockRange ¶ added in v1.35.1
WithEthTraceFilterMaxBlockRange sets the maximum block range allowed for EthTraceFilter requests on the gateway. This is typically tighter than the node-level MaxFilterHeightRange because trace replay is significantly more expensive than log lookups.
func WithMaxLookbackDuration ¶ added in v1.29.0
WithMaxLookbackDuration sets the maximum lookback duration (time) for state queries.
func WithMaxMessageLookbackEpochs ¶ added in v1.29.0
func WithMaxMessageLookbackEpochs(maxMessageLookbackEpochs abi.ChainEpoch) Option
WithMaxMessageLookbackEpochs sets the maximum lookback (epochs) for state queries.
func WithRateLimit ¶ added in v1.29.0
WithRateLimit sets the maximum number of requests per second globally that will be allowed before the gateway starts to rate limit requests.
func WithRateLimitTimeout ¶ added in v1.29.0
WithRateLimitTimeout sets the timeout for rate limiting requests such that when rate limiting is being applied, if the timeout is reached the request will be allowed.
func WithV1EthSubHandler ¶ added in v1.33.0
func WithV1EthSubHandler(subHandler *EthSubHandler) Option
WithV1EthSubHandler sets the Ethereum subscription handler for the gateway node. This is used for the RPC reverse handler for EthSubscribe calls.
func WithV2EthSubHandler ¶ added in v1.33.0
func WithV2EthSubHandler(subHandler *EthSubHandler) Option
WithV2EthSubHandler sets the Ethereum subscription handler for the gateway node. This is used for the RPC reverse handler for EthSubscribe calls.
type RateLimitHandler ¶ added in v1.29.0
type RateLimitHandler struct {
// contains filtered or unexported fields
}
func NewRateLimitHandler ¶ added in v1.29.0
func NewRateLimitHandler( next http.Handler, perConnectionAPIRateLimit int, perHostConnectionsPerMinute int, cleanupInterval time.Duration, ) *RateLimitHandler
NewRateLimitHandler creates a new RateLimitHandler that wraps the provided handler and limits the number of API calls per minute within a single WebSocket connection (where API calls are weighted by their relative expense), and the number of connections per minute from a single host. The cleanupInterval determines how often the handler will check for unused limiters to clean up.
func (*RateLimitHandler) ServeHTTP ¶ added in v1.29.0
func (h *RateLimitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ShutdownHandler ¶ added in v1.29.0
ShutdownHandler is an http.Handler that can be gracefully shutdown.
func Handler ¶
func Handler(gateway *Node, options ...HandlerOption) (ShutdownHandler, error)
Handler returns a gateway http.Handler, to be mounted as-is on the server. The handler is returned as a ShutdownHandler which allows for graceful shutdown of the handler via its Shutdown method.