forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inspect: resurrect the inspect command (#9655)
resurrect the inspect command from #6785 Co-authored-by: Sam Kleinman <garen@tychoish.com> Co-authored-by: Thane Thomson <connect@thanethomson.com> Co-authored-by: Callum Waters <cmwaters19@gmail.com>
- Loading branch information
1 parent
ac48630
commit 3324f49
Showing
53 changed files
with
1,506 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
cfg "github.com/tendermint/tendermint/config" | ||
"github.com/tendermint/tendermint/inspect" | ||
"github.com/tendermint/tendermint/state" | ||
"github.com/tendermint/tendermint/state/indexer/block" | ||
"github.com/tendermint/tendermint/store" | ||
"github.com/tendermint/tendermint/types" | ||
) | ||
|
||
// InspectCmd is the command for starting an inspect server. | ||
var InspectCmd = &cobra.Command{ | ||
Use: "inspect", | ||
Short: "Run an inspect server for investigating Tendermint state", | ||
Long: ` | ||
inspect runs a subset of Tendermint's RPC endpoints that are useful for debugging | ||
issues with Tendermint. | ||
When the Tendermint consensus engine detects inconsistent state, it will crash the | ||
Tendermint process. Tendermint will not start up while in this inconsistent state. | ||
The inspect command can be used to query the block and state store using Tendermint | ||
RPC calls to debug issues of inconsistent state. | ||
`, | ||
|
||
RunE: runInspect, | ||
} | ||
|
||
func init() { | ||
InspectCmd.Flags(). | ||
String("rpc.laddr", | ||
config.RPC.ListenAddress, "RPC listenener address. Port required") | ||
InspectCmd.Flags(). | ||
String("db-backend", | ||
config.DBBackend, "database backend: goleveldb | cleveldb | boltdb | rocksdb | badgerdb") | ||
InspectCmd.Flags(). | ||
String("db-dir", config.DBPath, "database directory") | ||
} | ||
|
||
func runInspect(cmd *cobra.Command, args []string) error { | ||
ctx, cancel := context.WithCancel(cmd.Context()) | ||
defer cancel() | ||
|
||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT) | ||
go func() { | ||
<-c | ||
cancel() | ||
}() | ||
|
||
blockStoreDB, err := cfg.DefaultDBProvider(&cfg.DBContext{ID: "blockstore", Config: config}) | ||
if err != nil { | ||
return err | ||
} | ||
blockStore := store.NewBlockStore(blockStoreDB) | ||
defer blockStore.Close() | ||
|
||
stateDB, err := cfg.DefaultDBProvider(&cfg.DBContext{ID: "state", Config: config}) | ||
if err != nil { | ||
return err | ||
} | ||
stateStore := state.NewStore(stateDB, state.StoreOptions{DiscardABCIResponses: false}) | ||
defer stateStore.Close() | ||
|
||
genDoc, err := types.GenesisDocFromFile(config.GenesisFile()) | ||
if err != nil { | ||
return err | ||
} | ||
txIndexer, blockIndexer, err := block.IndexerFromConfig(config, cfg.DefaultDBProvider, genDoc.ChainID) | ||
if err != nil { | ||
return err | ||
} | ||
ins := inspect.New(config.RPC, blockStore, stateStore, txIndexer, blockIndexer, logger) | ||
|
||
logger.Info("starting inspect server") | ||
if err := ins.Run(ctx); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
|
||
dbm "github.com/tendermint/tm-db" | ||
|
||
"github.com/tendermint/tendermint/libs/log" | ||
"github.com/tendermint/tendermint/libs/service" | ||
) | ||
|
||
// ServiceProvider takes a config and a logger and returns a ready to go Node. | ||
type ServiceProvider func(context.Context, *Config, log.Logger) (service.Service, error) | ||
|
||
// DBContext specifies config information for loading a new DB. | ||
type DBContext struct { | ||
ID string | ||
Config *Config | ||
} | ||
|
||
// DBProvider takes a DBContext and returns an instantiated DB. | ||
type DBProvider func(*DBContext) (dbm.DB, error) | ||
|
||
// DefaultDBProvider returns a database using the DBBackend and DBDir | ||
// specified in the Config. | ||
func DefaultDBProvider(ctx *DBContext) (dbm.DB, error) { | ||
dbType := dbm.BackendType(ctx.Config.DBBackend) | ||
|
||
return dbm.NewDB(ctx.ID, dbType, ctx.Config.DBDir()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Package inspect provides a tool for investigating the state of a | ||
failed Tendermint node. | ||
This package provides the Inspector type. The Inspector type runs a subset of the Tendermint | ||
RPC endpoints that are useful for debugging issues with Tendermint consensus. | ||
When a node running the Tendermint consensus engine detects an inconsistent consensus state, | ||
the entire node will crash. The Tendermint consensus engine cannot run in this | ||
inconsistent state so the node will not be able to start up again. | ||
The RPC endpoints provided by the Inspector type allow for a node operator to inspect | ||
the block store and state store to better understand what may have caused the inconsistent state. | ||
The Inspector type's lifecycle is controlled by a context.Context | ||
ins := inspect.NewFromConfig(rpcConfig) | ||
ctx, cancelFunc:= context.WithCancel(context.Background()) | ||
// Run blocks until the Inspector server is shut down. | ||
go ins.Run(ctx) | ||
... | ||
// calling the cancel function will stop the running inspect server | ||
cancelFunc() | ||
Inspector serves its RPC endpoints on the address configured in the RPC configuration | ||
rpcConfig.ListenAddress = "tcp://127.0.0.1:26657" | ||
ins := inspect.NewFromConfig(rpcConfig) | ||
go ins.Run(ctx) | ||
The list of available RPC endpoints can then be viewed by navigating to | ||
http://127.0.0.1:26657/ in the web browser. | ||
*/ | ||
package inspect |
Oops, something went wrong.