Documentation
ΒΆ
Overview ΒΆ
Package rpc provides robust RPC handler registration with retries, health checks, and clear debugging. Follows Go principles: fail fast with clear errors, single responsibility, minimal dependencies.
Index ΒΆ
- func IntegrationExample(ctx context.Context, chainID ids.ID, vm interface{}, server server.Server, ...) error
- func MinimalIntegration(ctx context.Context, chainID ids.ID, vm interface{}, server server.Server, ...) error
- func QuickDiagnose(nodeURL string, chainID ids.ID, alias string)
- type ChainHandlerRegistrar
- func (r *ChainHandlerRegistrar) GetAllRoutes() map[string]*RouteInfo
- func (r *ChainHandlerRegistrar) GetRouteInfo(chainID ids.ID) (*RouteInfo, bool)
- func (r *ChainHandlerRegistrar) HealthCheckAll() map[string]bool
- func (r *ChainHandlerRegistrar) RegisterChainHandlers(ctx context.Context, chainID ids.ID, vm interface{}) error
- func (r *ChainHandlerRegistrar) SetRetryConfig(maxRetries int, initialWait time.Duration)
- func (r *ChainHandlerRegistrar) ValidateEndpoint(chainID ids.ID, endpoint string) error
- type DebugTool
- type DiagnosticReport
- type HandlerManager
- func (m *HandlerManager) GetAllRoutes() map[string]*RouteInfo
- func (m *HandlerManager) GetRouteInfo(chainID ids.ID) (*RouteInfo, bool)
- func (m *HandlerManager) HealthCheckAll() map[string]bool
- func (m *HandlerManager) RegisterChainHandlers(ctx context.Context, chainID ids.ID, chainAlias string, ...) error
- func (m *HandlerManager) SetRetryConfig(maxRetries int, initialWait time.Duration)
- type RPCTest
- type RouteInfo
- type TestResult
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func IntegrationExample ΒΆ
func IntegrationExample( ctx context.Context, chainID ids.ID, vm interface{}, server server.Server, logger log.Logger, cChainID ids.ID, pChainID ids.ID, isDevMode bool, ) error
IntegrationExample shows how to modify the existing createChain function in manager.go. This replaces lines 941-990 with cleaner, more robust code.
Types ΒΆ
type ChainHandlerRegistrar ΒΆ
type ChainHandlerRegistrar struct {
// contains filtered or unexported fields
}
ChainHandlerRegistrar provides a clean interface for chain manager to register handlers. This replaces the inline registration logic with a more robust, testable solution.
func NewChainHandlerRegistrar ΒΆ
func NewChainHandlerRegistrar( server server.Server, logger log.Logger, cChainID ids.ID, pChainID ids.ID, ) *ChainHandlerRegistrar
NewChainHandlerRegistrar creates a registrar for chain handler registration. Encapsulates all the registration logic in one place.
func (*ChainHandlerRegistrar) GetAllRoutes ΒΆ
func (r *ChainHandlerRegistrar) GetAllRoutes() map[string]*RouteInfo
GetAllRoutes returns all registered routes across all chains. Complete visibility for monitoring and debugging.
func (*ChainHandlerRegistrar) GetRouteInfo ΒΆ
func (r *ChainHandlerRegistrar) GetRouteInfo(chainID ids.ID) (*RouteInfo, bool)
GetRouteInfo returns information about a specific chain's registered routes. Useful for debugging and operational visibility.
func (*ChainHandlerRegistrar) HealthCheckAll ΒΆ
func (r *ChainHandlerRegistrar) HealthCheckAll() map[string]bool
HealthCheckAll performs health checks on all registered routes. Returns a map of chainID -> healthy status.
func (*ChainHandlerRegistrar) RegisterChainHandlers ΒΆ
func (r *ChainHandlerRegistrar) RegisterChainHandlers( ctx context.Context, chainID ids.ID, vm interface{}, ) error
RegisterChainHandlers is the main entry point from chain manager. Handles all the complexity of VM type checking and handler extraction.
func (*ChainHandlerRegistrar) SetRetryConfig ΒΆ
func (r *ChainHandlerRegistrar) SetRetryConfig(maxRetries int, initialWait time.Duration)
SetRetryConfig allows tuning of retry behavior for different environments. Production might want more retries, dev might want faster failures.
func (*ChainHandlerRegistrar) ValidateEndpoint ΒΆ
func (r *ChainHandlerRegistrar) ValidateEndpoint( chainID ids.ID, endpoint string, ) error
ValidateEndpoint performs a test request against a specific endpoint. Useful for debugging specific handler issues.
type DebugTool ΒΆ
type DebugTool struct {
// contains filtered or unexported fields
}
DebugTool provides utilities for debugging RPC handler issues. Developer-friendly diagnostics with clear, actionable output.
func NewDebugTool ΒΆ
NewDebugTool creates a debug tool for RPC endpoint testing.
func (*DebugTool) DiagnoseEndpoint ΒΆ
func (d *DebugTool) DiagnoseEndpoint(chainID ids.ID, alias string) *DiagnosticReport
DiagnoseEndpoint performs comprehensive diagnostics on an RPC endpoint. Returns detailed information about what's working and what's not.
type DiagnosticReport ΒΆ
type DiagnosticReport struct {
ChainID ids.ID
Alias string
Timestamp time.Time
Tests []TestResult
RPCTests []RPCTest
}
DiagnosticReport contains comprehensive endpoint diagnostic information.
func (*DiagnosticReport) GetBestURL ΒΆ
func (r *DiagnosticReport) GetBestURL() string
GetBestURL returns the first working URL from the tests.
func (*DiagnosticReport) String ΒΆ
func (r *DiagnosticReport) String() string
String returns a human-readable report.
type HandlerManager ΒΆ
type HandlerManager struct {
// contains filtered or unexported fields
}
HandlerManager manages RPC handler registration with robust error handling and health checks. Single responsibility: reliable handler registration with observability.
func NewHandlerManager ΒΆ
func NewHandlerManager(server server.Server, logger log.Logger) *HandlerManager
NewHandlerManager creates a handler manager with sensible defaults. Simple factory, no magic.
func (*HandlerManager) GetAllRoutes ΒΆ
func (m *HandlerManager) GetAllRoutes() map[string]*RouteInfo
GetAllRoutes returns all registered route information. Complete visibility for operators.
func (*HandlerManager) GetRouteInfo ΒΆ
func (m *HandlerManager) GetRouteInfo(chainID ids.ID) (*RouteInfo, bool)
GetRouteInfo returns information about a registered chain's routes. Useful for debugging and monitoring.
func (*HandlerManager) HealthCheckAll ΒΆ
func (m *HandlerManager) HealthCheckAll() map[string]bool
HealthCheckAll performs health checks on all registered routes. Batch operation for monitoring systems.
func (*HandlerManager) RegisterChainHandlers ΒΆ
func (m *HandlerManager) RegisterChainHandlers( ctx context.Context, chainID ids.ID, chainAlias string, handlers map[string]http.Handler, ) error
RegisterChainHandlers registers all handlers for a chain with retry logic and health checks. This is the main entry point - handles everything needed for robust registration.
func (*HandlerManager) SetRetryConfig ΒΆ
func (m *HandlerManager) SetRetryConfig(maxRetries int, initialWait time.Duration)
SetRetryConfig allows customization of retry behavior. Flexibility for different deployment scenarios.
type RouteInfo ΒΆ
type RouteInfo struct {
ChainID ids.ID
ChainAlias string
Base string // e.g., "bc/C" or "bc/<chainID>"
Endpoints []string // e.g., ["/rpc", "/ws"]
Handler http.Handler
Healthy bool
LastCheck time.Time
}
RouteInfo contains complete information about a registered route. Everything needed for debugging in one place.