gateway

package
v1.36.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: Apache-2.0, MIT Imports: 51 Imported by: 8

Documentation

Index

Constants

View Source
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

View Source
var ErrTooManyFilters = errors.New("too many subscriptions and filters per connection")
View Source
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)

func (*CORSHandler) Shutdown added in v1.33.1

func (h *CORSHandler) Shutdown(ctx context.Context) error

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 (*EthSubHandler) EthSubscription added in v1.20.0

func (e *EthSubHandler) EthSubscription(ctx context.Context, r jsonrpc.RawParams) error

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)

func (*LoggingHandler) Shutdown added in v1.33.1

func (h *LoggingHandler) Shutdown(ctx context.Context) error

type Node

type Node struct {
	// contains filtered or unexported fields
}

func NewNode

func NewNode(v1 v1api.FullNode, v2 v2api.FullNode, opts ...Option) *Node

NewNode creates a new gateway node.

func (*Node) V1ReverseProxy added in v1.33.0

func (gw *Node) V1ReverseProxy() api.Gateway

func (*Node) V2ReverseProxy added in v1.33.0

func (gw *Node) V2ReverseProxy() v2api.Gateway

type Option added in v1.29.0

type Option func(*options)

func WithEthMaxFiltersPerConn added in v1.29.0

func WithEthMaxFiltersPerConn(ethMaxFiltersPerConn int) Option

WithEthMaxFiltersPerConn sets the maximum number of Ethereum filters and subscriptions that can be maintained per websocket connection.

func WithEthTraceFilterMaxBlockRange added in v1.35.1

func WithEthTraceFilterMaxBlockRange(maxBlockRange int64) Option

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

func WithMaxLookbackDuration(maxLookbackDuration time.Duration) Option

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

func WithRateLimit(rateLimit int) Option

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

func WithRateLimitTimeout(rateLimitTimeout time.Duration) Option

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)

func (*RateLimitHandler) Shutdown added in v1.29.0

func (h *RateLimitHandler) Shutdown(ctx context.Context) error

type ShutdownHandler added in v1.29.0

type ShutdownHandler interface {
	http.Handler

	Shutdown(ctx context.Context) error
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL