update comments for the inspect server

This commit is contained in:
William Banfield
2021-08-11 20:36:23 -04:00
parent c6077076d4
commit 557326c2f4
2 changed files with 27 additions and 13 deletions

View File

@@ -20,8 +20,8 @@ import (
)
// Inspect manages an RPC service that exports methods to debug a failed node.
// After a node shuts down due to a consensus failure,, it will no longer start
// up and cannot easily be inspected. A Inspect value provides a similar interface
// After a node shuts down due to a consensus failure, it will no longer start
// up its state cannot easily be inspected. An Inspect value provides a similar interface
// to the node, using the underlying Tendermint data stores, without bringing up
// any other components. A caller can query the Inspect service to inspect the
// persisted state and debug the failure.
@@ -33,6 +33,17 @@ type Inspect struct {
logger log.Logger
}
// New constructs a new Inspect from the passed in parameters.
func New(rpcConfig *cfg.RPCConfig, blockStore sm.BlockStore, stateStore sm.Store, eventSinks []indexer.EventSink, logger log.Logger) *Inspect {
routes := inspect_rpc.Routes(stateStore, blockStore, eventSinks)
return &Inspect{
routes: routes,
rpcConfig: rpcConfig,
logger: logger,
}
}
// NewFromConfig constructs an Inspect using the values defined in the passed in config.
func NewFromConfig(config *cfg.Config) (*Inspect, error) {
blockStoreDB, err := cfg.DefaultDBProvider(&cfg.DBContext{ID: "blockstore", Config: config})
if err != nil {
@@ -56,15 +67,7 @@ func NewFromConfig(config *cfg.Config) (*Inspect, error) {
return New(config.RPC, blockStore, stateStore, sinks, l), nil
}
func New(rpcConfig *cfg.RPCConfig, blockStore sm.BlockStore, stateStore sm.Store, eventSinks []indexer.EventSink, logger log.Logger) *Inspect {
routes := inspect_rpc.Routes(stateStore, blockStore, eventSinks)
return &Inspect{
routes: routes,
rpcConfig: rpcConfig,
logger: logger,
}
}
// NewDefault constructs a new Inspect using the default values.
func NewDefault() (*Inspect, error) {
config := cfg.Config{
BaseConfig: cfg.DefaultBaseConfig(),
@@ -74,6 +77,8 @@ func NewDefault() (*Inspect, error) {
return NewFromConfig(&config)
}
// Run starts the Inspect servers and blocks until the servers shut down. The passed
// in context is used to control the lifecycle of the servers.
func (inspect *Inspect) Run(ctx context.Context) error {
return startRPCServers(ctx, inspect.rpcConfig, inspect.logger, inspect.routes)
}

View File

@@ -18,6 +18,7 @@ import (
"github.com/tendermint/tendermint/types"
)
// Server defines parameters for running an Inspect rpc server.
type Server struct {
Addr string // TCP address to listen on, ":http" if empty
Handler http.Handler
@@ -25,6 +26,7 @@ type Server struct {
Config *config.RPCConfig
}
// Routes returns the set of routes used by the Inspect server.
func Routes(store state.Store, blockStore state.BlockStore, eventSinks []indexer.EventSink) rpccore.RoutesMap {
env := &core.Environment{
EventSinks: eventSinks,
@@ -45,6 +47,9 @@ func Routes(store state.Store, blockStore state.BlockStore, eventSinks []indexer
}
}
// Handler returns the http.Handler configured for use with an Inspect server. Handler
// registers the routes on the http.Handler and also registers the websocket handler
// and the CORS handler if specified by the configuration options.
func Handler(rpcConfig *config.RPCConfig, routes rpccore.RoutesMap, logger log.Logger) http.Handler {
mux := http.NewServeMux()
wmLogger := logger.With("protocol", "websocket")
@@ -81,7 +86,9 @@ func addCORSHandler(rpcConfig *config.RPCConfig, h http.Handler) http.Handler {
return h
}
func (r *Server) ListenAndServe(ctx context.Context) error {
// ListenAndServe listens on the address specified in srv.Addr and handles any
// incoming requests over HTTP using the Inspect rpc handler specified on the server.
func (srv *Server) ListenAndServe(ctx context.Context) error {
listener, err := rpcserver.Listen(r.Addr, r.Config.MaxOpenConnections)
if err != nil {
return err
@@ -93,7 +100,9 @@ func (r *Server) ListenAndServe(ctx context.Context) error {
return rpcserver.Serve(listener, r.Handler, r.Logger, serverRPCConfig(r.Config))
}
func (r *Server) ListenAndServeTLS(ctx context.Context, certFile, keyFile string) error {
// ListenAndServeTLS listens on the address specified in srv.Addr. ListenAndServeTLS handles
// incoming requests over HTTPS using the Inspect rpc handler specified on the server.
func (srv *Server) ListenAndServeTLS(ctx context.Context, certFile, keyFile string) error {
listener, err := rpcserver.Listen(r.Addr, r.Config.MaxOpenConnections)
if err != nil {
return err