feat(server/v2/cometbft): config (#20989)

This commit is contained in:
Julien Robert
2024-07-22 09:36:35 +00:00
committed by GitHub
parent 4b3a0b0afe
commit 8484dc50e2
24 changed files with 469 additions and 340 deletions
+43 -43
View File
@@ -32,46 +32,6 @@ import (
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)
var _ transaction.Codec[transaction.Tx] = &temporaryTxDecoder[transaction.Tx]{}
type temporaryTxDecoder[T transaction.Tx] struct {
txConfig client.TxConfig
}
// Decode implements transaction.Codec.
func (t *temporaryTxDecoder[T]) Decode(bz []byte) (T, error) {
var out T
tx, err := t.txConfig.TxDecoder()(bz)
if err != nil {
return out, err
}
var ok bool
out, ok = tx.(T)
if !ok {
return out, errors.New("unexpected Tx type")
}
return out, nil
}
// DecodeJSON implements transaction.Codec.
func (t *temporaryTxDecoder[T]) DecodeJSON(bz []byte) (T, error) {
var out T
tx, err := t.txConfig.TxJSONDecoder()(bz)
if err != nil {
return out, err
}
var ok bool
out, ok = tx.(T)
if !ok {
return out, errors.New("unexpected Tx type")
}
return out, nil
}
func newApp[T transaction.Tx](
logger log.Logger, viper *viper.Viper,
) serverv2.AppI[T] {
@@ -102,19 +62,19 @@ func initRootCmd[T transaction.Tx](
// add keybase, auxiliary RPC, query, genesis, and tx child commands
rootCmd.AddCommand(
genesisCommand[T](moduleManager, appExport[T]),
genesisCommand(moduleManager, appExport[T]),
queryCommand(),
txCommand(),
keys.Commands(),
offchain.OffChain(),
)
// Add empty server struct here for writing default config
// wire server commands
if err = serverv2.AddCommands(
rootCmd,
newApp,
logger,
cometbft.New[T](&temporaryTxDecoder[T]{txConfig}, cometbft.DefaultServerOptions[T]()),
cometbft.New(&genericTxDecoder[T]{txConfig}, cometbft.DefaultServerOptions[T]()),
grpc.New[T](),
); err != nil {
panic(err)
@@ -220,3 +180,43 @@ func appExport[T transaction.Tx](
return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
}
var _ transaction.Codec[transaction.Tx] = &genericTxDecoder[transaction.Tx]{}
type genericTxDecoder[T transaction.Tx] struct {
txConfig client.TxConfig
}
// Decode implements transaction.Codec.
func (t *genericTxDecoder[T]) Decode(bz []byte) (T, error) {
var out T
tx, err := t.txConfig.TxDecoder()(bz)
if err != nil {
return out, err
}
var ok bool
out, ok = tx.(T)
if !ok {
return out, errors.New("unexpected Tx type")
}
return out, nil
}
// DecodeJSON implements transaction.Codec.
func (t *genericTxDecoder[T]) DecodeJSON(bz []byte) (T, error) {
var out T
tx, err := t.txConfig.TxJSONDecoder()(bz)
if err != nil {
return out, err
}
var ok bool
out, ok = tx.(T)
if !ok {
return out, errors.New("unexpected Tx type")
}
return out, nil
}
+8 -3
View File
@@ -40,6 +40,7 @@ import (
)
var (
flagMinGasPrices = "min-gas-prices"
flagNodeDirPrefix = "node-dir-prefix"
flagNumValidators = "validator-count"
flagOutputDir = "output-dir"
@@ -70,7 +71,7 @@ func addTestnetFlagsToCmd(cmd *cobra.Command) {
cmd.Flags().IntP(flagNumValidators, "n", 4, "Number of validators to initialize the testnet with")
cmd.Flags().StringP(flagOutputDir, "o", "./.testnets", "Directory to store initialization data for the testnet")
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.Flags().String(cometbft.FlagMinGasPrices, fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photino,0.001stake)")
cmd.Flags().String(flagMinGasPrices, fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photino,0.001stake)")
cmd.Flags().String(flags.FlagKeyType, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for")
// support old flags name for backwards compatibility
@@ -127,7 +128,7 @@ Example:
args.outputDir, _ = cmd.Flags().GetString(flagOutputDir)
args.keyringBackend, _ = cmd.Flags().GetString(flags.FlagKeyringBackend)
args.chainID, _ = cmd.Flags().GetString(flags.FlagChainID)
args.minGasPrices, _ = cmd.Flags().GetString(cometbft.FlagMinGasPrices)
args.minGasPrices, _ = cmd.Flags().GetString(flagMinGasPrices)
args.nodeDirPrefix, _ = cmd.Flags().GetString(flagNodeDirPrefix)
args.nodeDaemonHome, _ = cmd.Flags().GetString(flagNodeDaemonHome)
args.startingIPAddress, _ = cmd.Flags().GetString(flagStartingIPAddress)
@@ -336,7 +337,11 @@ func initTestnetFiles[T transaction.Tx](
}
// Write server config
cometServer := cometbft.New[T](&temporaryTxDecoder[T]{clientCtx.TxConfig}, cometbft.ServerOptions[T]{}, cometbft.OverwriteDefaultCometConfig(nodeConfig))
cometServer := cometbft.New[T](
&genericTxDecoder[T]{clientCtx.TxConfig},
cometbft.ServerOptions[T]{},
cometbft.OverwriteDefaultConfigTomlConfig(nodeConfig),
)
grpcServer := grpc.New[T](grpc.OverwriteDefaultConfig(grpcConfig))
server := serverv2.NewServer(coretesting.NewNopLogger(), cometServer, grpcServer)
err = server.WriteConfig(filepath.Join(nodeDir, "config"))