refactor: rename to CometBFT (#14914)

This commit is contained in:
Julien Robert
2023-02-06 18:11:14 +00:00
committed by GitHub
parent 88909d6f2b
commit 80dd55f79b
274 changed files with 1506 additions and 1514 deletions
+8 -8
View File
@@ -93,13 +93,13 @@ func New(clientCtx client.Context, logger log.Logger, grpcSrv *grpc.Server) *Ser
func (s *Server) Start(cfg config.Config) error {
s.mtx.Lock()
tmCfg := tmrpcserver.DefaultConfig()
tmCfg.MaxOpenConnections = int(cfg.API.MaxOpenConnections)
tmCfg.ReadTimeout = time.Duration(cfg.API.RPCReadTimeout) * time.Second
tmCfg.WriteTimeout = time.Duration(cfg.API.RPCWriteTimeout) * time.Second
tmCfg.MaxBodyBytes = int64(cfg.API.RPCMaxBodyBytes)
cmtCfg := tmrpcserver.DefaultConfig()
cmtCfg.MaxOpenConnections = int(cfg.API.MaxOpenConnections)
cmtCfg.ReadTimeout = time.Duration(cfg.API.RPCReadTimeout) * time.Second
cmtCfg.WriteTimeout = time.Duration(cfg.API.RPCWriteTimeout) * time.Second
cmtCfg.MaxBodyBytes = int64(cfg.API.RPCMaxBodyBytes)
listener, err := tmrpcserver.Listen(cfg.API.Address, tmCfg)
listener, err := tmrpcserver.Listen(cfg.API.Address, cmtCfg)
if err != nil {
s.mtx.Unlock()
return err
@@ -137,10 +137,10 @@ func (s *Server) Start(cfg config.Config) error {
s.logger.Info("starting API server...")
if cfg.API.EnableUnsafeCORS {
allowAllCORS := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}))
return tmrpcserver.Serve(s.listener, allowAllCORS(s.Router), s.logger, tmCfg)
return tmrpcserver.Serve(s.listener, allowAllCORS(s.Router), s.logger, cmtCfg)
}
return tmrpcserver.Serve(s.listener, s.Router, s.logger, tmCfg)
return tmrpcserver.Serve(s.listener, s.Router, s.logger, cmtCfg)
}
// Close closes the API server.
+6 -6
View File
@@ -3,8 +3,8 @@ package cmd
import (
"context"
tmcfg "github.com/cometbft/cometbft/config"
tmcli "github.com/cometbft/cometbft/libs/cli"
cmtcfg "github.com/cometbft/cometbft/config"
cmtcli "github.com/cometbft/cometbft/libs/cli"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
@@ -20,15 +20,15 @@ func Execute(rootCmd *cobra.Command, envPrefix string, defaultHome string) error
// Create and set a client.Context on the command's Context. During the pre-run
// of the root command, a default initialized client.Context is provided to
// seed child command execution with values such as AccountRetriever, Keyring,
// and a Tendermint RPC. This requires the use of a pointer reference when
// and a CometBFT RPC. This requires the use of a pointer reference when
// getting and setting the client.Context. Ideally, we utilize
// https://github.com/spf13/cobra/pull/1118.
ctx := CreateExecuteContext(context.Background())
rootCmd.PersistentFlags().String(flags.FlagLogLevel, tmcfg.DefaultLogLevel, "The logging level (trace|debug|info|warn|error|fatal|panic)")
rootCmd.PersistentFlags().String(flags.FlagLogFormat, tmcfg.LogFormatPlain, "The logging format (json|plain)")
rootCmd.PersistentFlags().String(flags.FlagLogLevel, cmtcfg.DefaultLogLevel, "The logging level (trace|debug|info|warn|error|fatal|panic)")
rootCmd.PersistentFlags().String(flags.FlagLogFormat, cmtcfg.LogFormatPlain, "The logging format (json|plain)")
executor := tmcli.PrepareBaseCmd(rootCmd, envPrefix, defaultHome)
executor := cmtcli.PrepareBaseCmd(rootCmd, envPrefix, defaultHome)
return executor.ExecuteContext(ctx)
}
+6 -6
View File
@@ -14,7 +14,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// ShowNodeIDCmd - ported from Tendermint, dump node ID to stdout
// ShowNodeIDCmd - ported from CometBFT, dump node ID to stdout
func ShowNodeIDCmd() *cobra.Command {
return &cobra.Command{
Use: "show-node-id",
@@ -34,11 +34,11 @@ func ShowNodeIDCmd() *cobra.Command {
}
}
// ShowValidatorCmd - ported from Tendermint, show this node's validator info
// ShowValidatorCmd - ported from CometBFT, show this node's validator info
func ShowValidatorCmd() *cobra.Command {
cmd := cobra.Command{
Use: "show-validator",
Short: "Show this node's tendermint validator info",
Short: "Show this node's CometBFT validator info",
RunE: func(cmd *cobra.Command, args []string) error {
serverCtx := GetServerContextFromCmd(cmd)
cfg := serverCtx.Config
@@ -72,7 +72,7 @@ func ShowValidatorCmd() *cobra.Command {
func ShowAddressCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "show-address",
Short: "Shows this node's tendermint validator consensus address",
Short: "Shows this node's CometBFT validator consensus address",
RunE: func(cmd *cobra.Command, args []string) error {
serverCtx := GetServerContextFromCmd(cmd)
cfg := serverCtx.Config
@@ -88,11 +88,11 @@ func ShowAddressCmd() *cobra.Command {
return cmd
}
// VersionCmd prints tendermint and ABCI version numbers.
// VersionCmd prints CometBFT and ABCI version numbers.
func VersionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Print tendermint libraries' version",
Short: "Print CometBFT libraries' version",
Long: "Print protocols' and libraries' version numbers against which this app has been compiled.",
RunE: func(cmd *cobra.Command, args []string) error {
bs, err := yaml.Marshal(&struct {
+8 -8
View File
@@ -61,15 +61,15 @@ type BaseConfig struct {
// MinRetainBlocks defines the minimum block height offset from the current
// block being committed, such that blocks past this offset may be pruned
// from Tendermint. It is used as part of the process of determining the
// from CometBFT. It is used as part of the process of determining the
// ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates
// that no blocks should be pruned.
//
// This configuration value is only responsible for pruning Tendermint blocks.
// This configuration value is only responsible for pruning CometBFT blocks.
// It has no bearing on application state pruning which is determined by the
// "pruning-*" configurations.
//
// Note: Tendermint block pruning is dependant on this parameter in conjunction
// Note: CometBFT block pruning is dependant on this parameter in conjunction
// with the unbonding (safety threshold) period, state pruning and state sync
// snapshot parameters to determine the correct minimum value of
// ResponseCommit.RetainHeight.
@@ -79,7 +79,7 @@ type BaseConfig struct {
InterBlockCache bool `mapstructure:"inter-block-cache"`
// IndexEvents defines the set of events in the form {eventType}.{attributeKey},
// which informs Tendermint what to index. If empty, all events will be indexed.
// which informs CometBFT what to index. If empty, all events will be indexed.
IndexEvents []string `mapstructure:"index-events"`
// IavlCacheSize set the size of the iavl tree cache.
@@ -92,7 +92,7 @@ type BaseConfig struct {
IAVLLazyLoading bool `mapstructure:"iavl-lazy-loading"`
// AppDBBackend defines the type of Database to use for the application and snapshots databases.
// An empty string indicates that the Tendermint config's DBBackend value should be used.
// An empty string indicates that the CometBFT config's DBBackend value should be used.
AppDBBackend string `mapstructure:"app-db-backend"`
}
@@ -113,13 +113,13 @@ type APIConfig struct {
// MaxOpenConnections defines the number of maximum open connections
MaxOpenConnections uint `mapstructure:"max-open-connections"`
// RPCReadTimeout defines the Tendermint RPC read timeout (in seconds)
// RPCReadTimeout defines the CometBFT RPC read timeout (in seconds)
RPCReadTimeout uint `mapstructure:"rpc-read-timeout"`
// RPCWriteTimeout defines the Tendermint RPC write timeout (in seconds)
// RPCWriteTimeout defines the CometBFT RPC write timeout (in seconds)
RPCWriteTimeout uint `mapstructure:"rpc-write-timeout"`
// RPCMaxBodyBytes defines the Tendermint maximum response body (in bytes)
// RPCMaxBodyBytes defines the CometBFT maximum response body (in bytes)
RPCMaxBodyBytes uint `mapstructure:"rpc-max-body-bytes"`
// TODO: TLS/Proxy configuration.
+8 -8
View File
@@ -46,15 +46,15 @@ halt-time = {{ .BaseConfig.HaltTime }}
# MinRetainBlocks defines the minimum block height offset from the current
# block being committed, such that all blocks past this offset are pruned
# from Tendermint. It is used as part of the process of determining the
# from CometBFT. It is used as part of the process of determining the
# ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates
# that no blocks should be pruned.
#
# This configuration value is only responsible for pruning Tendermint blocks.
# This configuration value is only responsible for pruning CometBFT blocks.
# It has no bearing on application state pruning which is determined by the
# "pruning-*" configurations.
#
# Note: Tendermint block pruning is dependant on this parameter in conjunction
# Note: CometBFT block pruning is dependant on this parameter in conjunction
# with the unbonding (safety threshold) period, state pruning and state sync
# snapshot parameters to determine the correct minimum value of
# ResponseCommit.RetainHeight.
@@ -64,7 +64,7 @@ min-retain-blocks = {{ .BaseConfig.MinRetainBlocks }}
inter-block-cache = {{ .BaseConfig.InterBlockCache }}
# IndexEvents defines the set of events in the form {eventType}.{attributeKey},
# which informs Tendermint what to index. If empty, all events will be indexed.
# which informs CometBFT what to index. If empty, all events will be indexed.
#
# Example:
# ["message.sender", "message.recipient"]
@@ -84,7 +84,7 @@ iavl-lazy-loading = {{ .BaseConfig.IAVLLazyLoading }}
# AppDBBackend defines the database backend type to use for the application and snapshots DBs.
# An empty string indicates that a fallback will be used.
# First fallback is the deprecated compile-time types.DBBackend value.
# Second fallback (if the types.DBBackend also isn't set), is the db-backend value set in Tendermint's config.toml.
# Second fallback (if the types.DBBackend also isn't set), is the db-backend value set in CometBFT's config.toml.
app-db-backend = "{{ .BaseConfig.AppDBBackend }}"
###############################################################################
@@ -140,13 +140,13 @@ address = "{{ .API.Address }}"
# MaxOpenConnections defines the number of maximum open connections.
max-open-connections = {{ .API.MaxOpenConnections }}
# RPCReadTimeout defines the Tendermint RPC read timeout (in seconds).
# RPCReadTimeout defines the CometBFT RPC read timeout (in seconds).
rpc-read-timeout = {{ .API.RPCReadTimeout }}
# RPCWriteTimeout defines the Tendermint RPC write timeout (in seconds).
# RPCWriteTimeout defines the CometBFT RPC write timeout (in seconds).
rpc-write-timeout = {{ .API.RPCWriteTimeout }}
# RPCMaxBodyBytes defines the Tendermint maximum response body (in bytes).
# RPCMaxBodyBytes defines the CometBFT maximum response body (in bytes).
rpc-max-body-bytes = {{ .API.RPCMaxBodyBytes }}
# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk).
+11 -11
View File
@@ -4,8 +4,8 @@ import (
"fmt"
"os"
tmjson "github.com/cometbft/cometbft/libs/json"
tmtypes "github.com/cometbft/cometbft/types"
cmtjson "github.com/cometbft/cometbft/libs/json"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client/flags"
@@ -73,7 +73,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
return fmt.Errorf("error exporting state: %v", err)
}
doc, err := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile())
doc, err := cmttypes.GenesisDocFromFile(serverCtx.Config.GenesisFile())
if err != nil {
return err
}
@@ -81,25 +81,25 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
doc.AppState = exported.AppState
doc.Validators = exported.Validators
doc.InitialHeight = exported.Height
doc.ConsensusParams = &tmtypes.ConsensusParams{
Block: tmtypes.BlockParams{
doc.ConsensusParams = &cmttypes.ConsensusParams{
Block: cmttypes.BlockParams{
MaxBytes: exported.ConsensusParams.Block.MaxBytes,
MaxGas: exported.ConsensusParams.Block.MaxGas,
},
Evidence: tmtypes.EvidenceParams{
Evidence: cmttypes.EvidenceParams{
MaxAgeNumBlocks: exported.ConsensusParams.Evidence.MaxAgeNumBlocks,
MaxAgeDuration: exported.ConsensusParams.Evidence.MaxAgeDuration,
MaxBytes: exported.ConsensusParams.Evidence.MaxBytes,
},
Validator: tmtypes.ValidatorParams{
Validator: cmttypes.ValidatorParams{
PubKeyTypes: exported.ConsensusParams.Validator.PubKeyTypes,
},
}
// NOTE: Tendermint uses a custom JSON decoder for GenesisDoc
// NOTE: CometBFT uses a custom JSON decoder for GenesisDoc
// (except for stuff inside AppState). Inside AppState, we're free
// to encode as protobuf or amino.
encoded, err := tmjson.Marshal(doc)
encoded, err := cmtjson.Marshal(doc)
if err != nil {
return err
}
@@ -113,8 +113,8 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
return nil
}
var exportedGenDoc tmtypes.GenesisDoc
if err = tmjson.Unmarshal(out, &exportedGenDoc); err != nil {
var exportedGenDoc cmttypes.GenesisDoc
if err = cmtjson.Unmarshal(out, &exportedGenDoc); err != nil {
return err
}
if err = exportedGenDoc.SaveAs(outputDocument); err != nil {
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"time"
abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cometbft/cometbft/types"
"github.com/stretchr/testify/require"
@@ -58,7 +58,7 @@ func TestDeliverTx(t *testing.T) {
tx := NewTx(key, value, randomAccounts[0].Address)
txBytes := tx.GetSignBytes()
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{
app.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{
AppHash: []byte("apphash"),
Height: 1,
}})
+4 -4
View File
@@ -6,17 +6,17 @@ import (
"testing"
abci "github.com/cometbft/cometbft/abci/types"
tmlog "github.com/cometbft/cometbft/libs/log"
cmtlog "github.com/cometbft/cometbft/libs/log"
)
// SetupApp returns an application as well as a clean-up function to be used to
// quickly setup a test case with an app.
func SetupApp() (abci.Application, func(), error) {
var logger tmlog.Logger
var logger cmtlog.Logger
if testing.Verbose() {
logger = tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout)).With("module", "mock")
logger = cmtlog.NewTMLogger(cmtlog.NewSyncWriter(os.Stdout)).With("module", "mock")
} else {
logger = tmlog.NewNopLogger()
logger = cmtlog.NewNopLogger()
}
rootDir, err := os.MkdirTemp("", "mock-sdk")
+8 -8
View File
@@ -3,25 +3,25 @@ package server
import (
"fmt"
tmcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server/types"
"github.com/spf13/cobra"
)
// NewRollbackCmd creates a command to rollback tendermint and multistore state by one height.
// NewRollbackCmd creates a command to rollback CometBFT and multistore state by one height.
func NewRollbackCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command {
var removeBlock bool
cmd := &cobra.Command{
Use: "rollback",
Short: "rollback cosmos-sdk and tendermint state by one height",
Short: "rollback Cosmos SDK and CometBFT state by one height",
Long: `
A state rollback is performed to recover from an incorrect application state transition,
when Tendermint has persisted an incorrect app hash and is thus unable to make
when CometBFT has persisted an incorrect app hash and is thus unable to make
progress. Rollback overwrites a state at height n with the state at height n - 1.
The application also rolls back to height n - 1. No blocks are removed, so upon
restarting Tendermint the transactions in block n will be re-executed against the
restarting CometBFT the transactions in block n will be re-executed against the
application.
`,
RunE: func(cmd *cobra.Command, args []string) error {
@@ -33,10 +33,10 @@ application.
return err
}
app := appCreator(ctx.Logger, db, nil, ctx.Viper)
// rollback tendermint state
height, hash, err := tmcmd.RollbackState(ctx.Config, removeBlock)
// rollback CometBFT state
height, hash, err := cmtcmd.RollbackState(ctx.Config, removeBlock)
if err != nil {
return fmt.Errorf("failed to rollback tendermint state: %w", err)
return fmt.Errorf("failed to rollback cometbft state: %w", err)
}
// rollback the multistore
+17 -17
View File
@@ -32,7 +32,7 @@ import (
)
const (
// Tendermint full-node start flags
// CometBFT full-node start flags
flagWithTendermint = "with-tendermint"
flagAddress = "address"
flagTransport = "transport"
@@ -80,13 +80,13 @@ const (
)
// StartCmd runs the service passed in, either stand-alone or in-process with
// Tendermint.
// CometBFT.
func StartCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "Run the full node",
Long: `Run the full node application with Tendermint in or out of process. By
default, the application will run with Tendermint in process.
Long: `Run the full node application with CometBFT in or out of process. By
default, the application will run with CometBFT in process.
Pruning options can be provided via the '--pruning' flag or alternatively with '--pruning-keep-recent', and
'pruning-interval' together.
@@ -108,7 +108,7 @@ For profiling and benchmarking purposes, CPU profiling can be enabled via the '-
which accepts a path for the resulting pprof file.
The node may be started in a 'query only' mode where only the gRPC and JSON HTTP
API services are enabled via the 'grpc-only' flag. In this mode, Tendermint is
API services are enabled via the 'grpc-only' flag. In this mode, CometBFT is
bypassed and can be used when legacy queries are needed after an on-chain upgrade
is performed. Note, when enabled, gRPC will also be automatically enabled.
`,
@@ -133,7 +133,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled.
withTM, _ := cmd.Flags().GetBool(flagWithTendermint)
if !withTM {
serverCtx.Logger.Info("starting ABCI without Tendermint")
serverCtx.Logger.Info("starting ABCI without CometBFT")
return startStandAlone(serverCtx, appCreator)
}
@@ -150,7 +150,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled.
}
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().Bool(flagWithTendermint, true, "Run abci app embedded in-process with tendermint")
cmd.Flags().Bool(flagWithTendermint, true, "Run abci app embedded in-process with CometBFT")
cmd.Flags().String(flagAddress, "tcp://0.0.0.0:26658", "Listen address")
cmd.Flags().String(flagTransport, "socket", "Transport protocol: socket, grpc")
cmd.Flags().String(flagTraceStore, "", "Enable KVStore tracing to an output file")
@@ -165,18 +165,18 @@ is performed. Note, when enabled, gRPC will also be automatically enabled.
cmd.Flags().Uint64(FlagPruningKeepRecent, 0, "Number of recent heights to keep on disk (ignored if pruning is not 'custom')")
cmd.Flags().Uint64(FlagPruningInterval, 0, "Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom')")
cmd.Flags().Uint(FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks")
cmd.Flags().Uint64(FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune Tendermint blocks")
cmd.Flags().Uint64(FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune CometBFT blocks")
cmd.Flags().Bool(FlagAPIEnable, false, "Define if the API server should be enabled")
cmd.Flags().Bool(FlagAPISwagger, false, "Define if swagger documentation should automatically be registered (Note: the API must also be enabled)")
cmd.Flags().String(FlagAPIAddress, serverconfig.DefaultAPIAddress, "the API server address to listen on")
cmd.Flags().Uint(FlagAPIMaxOpenConnections, 1000, "Define the number of maximum open connections")
cmd.Flags().Uint(FlagRPCReadTimeout, 10, "Define the Tendermint RPC read timeout (in seconds)")
cmd.Flags().Uint(FlagRPCWriteTimeout, 0, "Define the Tendermint RPC write timeout (in seconds)")
cmd.Flags().Uint(FlagRPCMaxBodyBytes, 1000000, "Define the Tendermint maximum response body (in bytes)")
cmd.Flags().Uint(FlagRPCReadTimeout, 10, "Define the CometBFT RPC read timeout (in seconds)")
cmd.Flags().Uint(FlagRPCWriteTimeout, 0, "Define the CometBFT RPC write timeout (in seconds)")
cmd.Flags().Uint(FlagRPCMaxBodyBytes, 1000000, "Define the CometBFT maximum response body (in bytes)")
cmd.Flags().Bool(FlagAPIEnableUnsafeCORS, false, "Define if CORS should be enabled (unsafe - use it at your own risk)")
cmd.Flags().Bool(flagGRPCOnly, false, "Start the node in gRPC query only mode (no Tendermint process is started)")
cmd.Flags().Bool(flagGRPCOnly, false, "Start the node in gRPC query only mode (no CometBFT process is started)")
cmd.Flags().Bool(flagGRPCEnable, true, "Define if the gRPC server should be enabled")
cmd.Flags().String(flagGRPCAddress, serverconfig.DefaultGRPCAddress, "the gRPC server address to listen on")
@@ -189,7 +189,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled.
cmd.Flags().Int(FlagMempoolMaxTxs, mempool.DefaultMaxTx, "Sets MaxTx value for the app-side mempool")
// add support for all Tendermint-specific command line options
// add support for all CometBFT-specific command line options
tcmd.AddNodeFlags(cmd)
return cmd
}
@@ -321,10 +321,10 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
)
if gRPCOnly {
ctx.Logger.Info("starting node in gRPC only mode; Tendermint is disabled")
ctx.Logger.Info("starting node in gRPC only mode; CometBFT is disabled")
config.GRPC.Enable = true
} else {
ctx.Logger.Info("starting node with ABCI Tendermint in-process")
ctx.Logger.Info("starting node with ABCI CometBFT in-process")
tmNode, err = node.NewNode(
cfg,
@@ -347,7 +347,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
// Add the tx service to the gRPC router. We only need to register this
// service if API or gRPC is enabled, and avoid doing so in the general
// case, because it spawns a new local tendermint RPC client.
// case, because it spawns a new local CometBFT RPC client.
if (config.API.Enable || config.GRPC.Enable) && tmNode != nil {
// re-assign for making the client available below
// do not use := to avoid shadowing clientCtx
@@ -453,7 +453,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
}
// At this point it is safe to block the process if we're in gRPC only mode as
// we do not need to handle any Tendermint related processes.
// we do not need to handle any CometBFT related processes.
if gRPCOnly {
// wait for signal capture and gracefully return
return WaitForQuitSignals()
+5 -5
View File
@@ -9,8 +9,8 @@ import (
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/gogoproto/grpc"
"github.com/spf13/cobra"
@@ -53,7 +53,7 @@ type (
// simulation, fetching txs by hash...).
RegisterTxService(client.Context)
// RegisterTendermintService registers the gRPC Query service for tendermint queries.
// RegisterTendermintService registers the gRPC Query service for CometBFT queries.
RegisterTendermintService(client.Context)
// RegisterNodeService registers the node gRPC Query service.
@@ -76,11 +76,11 @@ type (
// AppState is the application state as JSON.
AppState json.RawMessage
// Validators is the exported validator set.
Validators []tmtypes.GenesisValidator
Validators []cmttypes.GenesisValidator
// Height is the app's latest block height.
Height int64
// ConsensusParams are the exported consensus params for ABCI.
ConsensusParams *tmproto.ConsensusParams
ConsensusParams *cmtproto.ConsensusParams
}
// AppExporter is a function that dumps all app state to
+42 -41
View File
@@ -16,11 +16,11 @@ import (
dbm "github.com/cosmos/cosmos-db"
tmcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
tmcfg "github.com/cometbft/cometbft/config"
tmcli "github.com/cometbft/cometbft/libs/cli"
tmflags "github.com/cometbft/cometbft/libs/cli/flags"
tmlog "github.com/cometbft/cometbft/libs/log"
cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
cmtcfg "github.com/cometbft/cometbft/config"
cmtcli "github.com/cometbft/cometbft/libs/cli"
cmtflags "github.com/cometbft/cometbft/libs/cli/flags"
cmtlog "github.com/cometbft/cometbft/libs/log"
"github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
@@ -47,8 +47,8 @@ const ServerContextKey = sdk.ContextKey("server.context")
// server context
type Context struct {
Viper *viper.Viper
Config *tmcfg.Config
Logger tmlog.Logger
Config *cmtcfg.Config
Logger cmtlog.Logger
}
// ErrorCode contains the exit code for server exit.
@@ -63,12 +63,12 @@ func (e ErrorCode) Error() string {
func NewDefaultContext() *Context {
return NewContext(
viper.New(),
tmcfg.DefaultConfig(),
tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout)),
cmtcfg.DefaultConfig(),
cmtlog.NewTMLogger(cmtlog.NewSyncWriter(os.Stdout)),
)
}
func NewContext(v *viper.Viper, config *tmcfg.Config, logger tmlog.Logger) *Context {
func NewContext(v *viper.Viper, config *cmtcfg.Config, logger cmtlog.Logger) *Context {
return &Context{v, config, logger}
}
@@ -108,15 +108,15 @@ func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error)
// InterceptConfigsPreRunHandler performs a pre-run function for the root daemon
// application command. It will create a Viper literal and a default server
// Context. The server Tendermint configuration will either be read and parsed
// Context. The server CometBFT configuration will either be read and parsed
// or created and saved to disk, where the server Context is updated to reflect
// the Tendermint configuration. It takes custom app config template and config
// settings to create a custom Tendermint configuration. If the custom template
// the CometBFT configuration. It takes custom app config template and config
// settings to create a custom CometBFT configuration. If the custom template
// is empty, it uses default-template provided by the server. The Viper literal
// is used to read and parse the application configuration. Command handlers can
// fetch the server Context to get the Tendermint configuration or to get access
// fetch the server Context to get the CometBFT configuration or to get access
// to Viper.
func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}, tmConfig *tmcfg.Config) error {
func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}, cmtConfig *cmtcfg.Config) error {
serverCtx := NewDefaultContext()
// Get the executable name and configure the viper instance so that environmental
@@ -142,32 +142,32 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate s
serverCtx.Viper.AutomaticEnv()
// intercept configuration files, using both Viper instances separately
config, err := interceptConfigs(serverCtx.Viper, customAppConfigTemplate, customAppConfig, tmConfig)
config, err := interceptConfigs(serverCtx.Viper, customAppConfigTemplate, customAppConfig, cmtConfig)
if err != nil {
return err
}
// return value is a tendermint configuration object
// return value is a CometBFT configuration object
serverCtx.Config = config
if err = bindFlags(basename, cmd, serverCtx.Viper); err != nil {
return err
}
var logger tmlog.Logger
if serverCtx.Viper.GetString(flags.FlagLogFormat) == tmcfg.LogFormatJSON {
logger = tmlog.NewTMJSONLogger(tmlog.NewSyncWriter(os.Stdout))
var logger cmtlog.Logger
if serverCtx.Viper.GetString(flags.FlagLogFormat) == cmtcfg.LogFormatJSON {
logger = cmtlog.NewTMJSONLogger(cmtlog.NewSyncWriter(os.Stdout))
} else {
logger = tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout))
logger = cmtlog.NewTMLogger(cmtlog.NewSyncWriter(os.Stdout))
}
logger, err = tmflags.ParseLogLevel(config.LogLevel, logger, tmcfg.DefaultLogLevel)
logger, err = cmtflags.ParseLogLevel(config.LogLevel, logger, cmtcfg.DefaultLogLevel)
if err != nil {
return err
}
// Check if the tendermint flag for trace logging is set if it is then setup
// Check if the CometBFT flag for trace logging is set if it is then setup
// a tracing logger in this app as well.
if serverCtx.Viper.GetBool(tmcli.TraceFlag) {
logger = tmlog.NewTracingLogger(logger)
if serverCtx.Viper.GetBool(cmtcli.TraceFlag) {
logger = cmtlog.NewTracingLogger(logger)
}
serverCtx.Logger = logger.With("module", "server")
@@ -199,21 +199,21 @@ func SetCmdServerContext(cmd *cobra.Command, serverCtx *Context) error {
return nil
}
// interceptConfigs parses and updates a Tendermint configuration file or
// interceptConfigs parses and updates a CometBFT configuration file or
// creates a new one and saves it. It also parses and saves the application
// configuration file. The Tendermint configuration file is parsed given a root
// configuration file. The CometBFT configuration file is parsed given a root
// Viper object, whereas the application is parsed with the private package-aware
// viperCfg object.
func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customConfig interface{}, tmConfig *tmcfg.Config) (*tmcfg.Config, error) {
func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customConfig interface{}, cmtConfig *cmtcfg.Config) (*cmtcfg.Config, error) {
rootDir := rootViper.GetString(flags.FlagHome)
configPath := filepath.Join(rootDir, "config")
tmCfgFile := filepath.Join(configPath, "config.toml")
cmtCfgFile := filepath.Join(configPath, "config.toml")
conf := tmConfig
conf := cmtConfig
switch _, err := os.Stat(tmCfgFile); {
switch _, err := os.Stat(cmtCfgFile); {
case os.IsNotExist(err):
tmcfg.EnsureRoot(rootDir)
cmtcfg.EnsureRoot(rootDir)
if err = conf.ValidateBasic(); err != nil {
return nil, fmt.Errorf("error in config file: %w", err)
@@ -223,7 +223,7 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo
conf.P2P.RecvRate = 5120000
conf.P2P.SendRate = 5120000
conf.Consensus.TimeoutCommit = 5 * time.Second
tmcfg.WriteConfigFile(tmCfgFile, conf)
cmtcfg.WriteConfigFile(cmtCfgFile, conf)
case err != nil:
return nil, err
@@ -234,7 +234,7 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo
rootViper.AddConfigPath(configPath)
if err := rootViper.ReadInConfig(); err != nil {
return nil, fmt.Errorf("failed to read in %s: %w", tmCfgFile, err)
return nil, fmt.Errorf("failed to read in %s: %w", cmtCfgFile, err)
}
}
@@ -280,18 +280,19 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo
// add server commands
func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, addStartFlags types.ModuleInitFlags) {
tendermintCmd := &cobra.Command{
Use: "tendermint",
Short: "Tendermint subcommands",
cometCmd := &cobra.Command{
Use: "comet",
Aliases: []string{"cmt", "cometbft", "tendermint"},
Short: "CometBFT subcommands",
}
tendermintCmd.AddCommand(
cometCmd.AddCommand(
ShowNodeIDCmd(),
ShowValidatorCmd(),
ShowAddressCmd(),
VersionCmd(),
tmcmd.ResetAllCmd,
tmcmd.ResetStateCmd,
cmtcmd.ResetAllCmd,
cmtcmd.ResetStateCmd,
)
startCmd := StartCmd(appCreator, defaultNodeHome)
@@ -299,7 +300,7 @@ func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator type
rootCmd.AddCommand(
startCmd,
tendermintCmd,
cometCmd,
ExportCmd(appExport, defaultNodeHome),
version.NewVersionCommand(),
NewRollbackCmd(appCreator, defaultNodeHome),
+3 -3
View File
@@ -10,7 +10,7 @@ import (
"strings"
"testing"
tmcfg "github.com/cometbft/cometbft/config"
cmtcfg "github.com/cometbft/cometbft/config"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
@@ -30,7 +30,7 @@ var errCanceledInPreRun = errors.New("canceled in prerun")
// Used in each test to run the function under test via Cobra
// but to always halt the command
func preRunETestImpl(cmd *cobra.Command, args []string) error {
err := server.InterceptConfigsPreRunHandler(cmd, "", nil, tmcfg.DefaultConfig())
err := server.InterceptConfigsPreRunHandler(cmd, "", nil, cmtcfg.DefaultConfig())
if err != nil {
return err
}
@@ -435,7 +435,7 @@ func TestEmptyMinGasPrices(t *testing.T) {
// Run StartCmd.
cmd = server.StartCmd(nil, tempDir)
cmd.PreRunE = func(cmd *cobra.Command, _ []string) error {
return server.InterceptConfigsPreRunHandler(cmd, "", nil, tmcfg.DefaultConfig())
return server.InterceptConfigsPreRunHandler(cmd, "", nil, cmtcfg.DefaultConfig())
}
err = cmd.ExecuteContext(ctx)
require.Errorf(t, err, sdkerrors.ErrAppConfig.Error())