feat(server/v2/cometbft): wire mempool config (#21741)

This commit is contained in:
Julien Robert
2024-09-16 18:45:21 +00:00
committed by GitHub
parent f348d84c1a
commit 52ba264c80
9 changed files with 80 additions and 27 deletions
+6
View File
@@ -2,6 +2,8 @@ package cometbft
import (
cmtcfg "github.com/cometbft/cometbft/config"
"cosmossdk.io/server/v2/cometbft/mempool"
)
// Config is the configuration for the CometBFT application
@@ -20,6 +22,7 @@ func DefaultAppTomlConfig() *AppTomlConfig {
Transport: "socket",
Trace: false,
Standalone: false,
Mempool: mempool.DefaultConfig(),
}
}
@@ -32,6 +35,9 @@ type AppTomlConfig struct {
Transport string `mapstructure:"transport" toml:"transport" comment:"transport defines the CometBFT RPC server transport protocol: socket, grpc"`
Trace bool `mapstructure:"trace" toml:"trace" comment:"trace enables the CometBFT RPC server to output trace information about its internal operations."`
Standalone bool `mapstructure:"standalone" toml:"standalone" comment:"standalone starts the application without the CometBFT node. The node should be started separately."`
// Sub configs
Mempool mempool.Config `mapstructure:"mempool" toml:"mempool" comment:"mempool defines the configuration for the SDK built-in app-side mempool implementations."`
}
// CfgOption is a function that allows to overwrite the default server configuration.
+7 -6
View File
@@ -51,10 +51,11 @@ func prefix(f string) string {
// Server flags
var (
Standalone = prefix("standalone")
FlagAddress = prefix("address")
FlagTransport = prefix("transport")
FlagHaltHeight = prefix("halt-height")
FlagHaltTime = prefix("halt-time")
FlagTrace = prefix("trace")
Standalone = prefix("standalone")
FlagAddress = prefix("address")
FlagTransport = prefix("transport")
FlagHaltHeight = prefix("halt-height")
FlagHaltTime = prefix("halt-time")
FlagTrace = prefix("trace")
FlagMempoolMaxTxs = prefix("mempool.max-txs")
)
+12 -7
View File
@@ -1,11 +1,16 @@
package mempool
// Config defines the configurations for the SDK built-in app-side mempool
// implementations.
var DefaultMaxTx = -1
// Config defines the configurations for the SDK built-in app-side mempool implementations.
type Config struct {
// MaxTxs defines the behavior of the mempool. A negative value indicates
// the mempool is disabled entirely, zero indicates that the mempool is
// unbounded in how many txs it may contain, and a positive value indicates
// the maximum amount of txs it may contain.
MaxTxs int `mapstructure:"max-txs"`
// MaxTxs defines the maximum number of transactions that can be in the mempool.
MaxTxs int `mapstructure:"max-txs" toml:"max-txs" comment:"max-txs defines the maximum number of transactions that can be in the mempool. A value of 0 indicates an unbounded mempool, a negative value disables the app-side mempool."`
}
// DefaultConfig returns a default configuration for the SDK built-in app-side mempool implementations.
func DefaultConfig() Config {
return Config{
MaxTxs: DefaultMaxTx,
}
}
+1 -5
View File
@@ -1,6 +1,2 @@
/*
The mempool package defines a few mempool services which can be used in conjunction with your consensus implementation
*/
// Package mempool defines a few mempool services which can be used in conjunction with your consensus implementation.
package mempool
+5 -4
View File
@@ -9,14 +9,15 @@ import (
)
// ServerOptions defines the options for the CometBFT server.
// When an option takes a map[string]any, it can access the app.tom's cometbft section and the config.toml config.
type ServerOptions[T transaction.Tx] struct {
Mempool mempool.Mempool[T]
PrepareProposalHandler handlers.PrepareHandler[T]
ProcessProposalHandler handlers.ProcessHandler[T]
VerifyVoteExtensionHandler handlers.VerifyVoteExtensionhandler
ExtendVoteHandler handlers.ExtendVoteHandler
SnapshotOptions snapshots.SnapshotOptions
Mempool func(cfg map[string]any) mempool.Mempool[T]
SnapshotOptions func(cfg map[string]any) snapshots.SnapshotOptions
AddrPeerFilter types.PeerFilter // filter peers by address and port
IdPeerFilter types.PeerFilter // filter peers by node ID
@@ -26,12 +27,12 @@ type ServerOptions[T transaction.Tx] struct {
// It defaults to a NoOpMempool and NoOp handlers.
func DefaultServerOptions[T transaction.Tx]() ServerOptions[T] {
return ServerOptions[T]{
Mempool: mempool.NoOpMempool[T]{},
PrepareProposalHandler: handlers.NoOpPrepareProposal[T](),
ProcessProposalHandler: handlers.NoOpProcessProposal[T](),
VerifyVoteExtensionHandler: handlers.NoOpVerifyVoteExtensionHandler(),
ExtendVoteHandler: handlers.NoOpExtendVote(),
SnapshotOptions: snapshots.NewSnapshotOptions(0, 0),
Mempool: func(cfg map[string]any) mempool.Mempool[T] { return mempool.NoOpMempool[T]{} },
SnapshotOptions: func(cfg map[string]any) snapshots.SnapshotOptions { return snapshots.NewSnapshotOptions(0, 0) },
AddrPeerFilter: nil,
IdPeerFilter: nil,
}
+4 -2
View File
@@ -24,6 +24,7 @@ import (
"cosmossdk.io/log"
serverv2 "cosmossdk.io/server/v2"
cometlog "cosmossdk.io/server/v2/cometbft/log"
"cosmossdk.io/server/v2/cometbft/mempool"
"cosmossdk.io/server/v2/cometbft/types"
"cosmossdk.io/store/v2/snapshots"
@@ -105,7 +106,7 @@ func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logg
appI.Name(),
appI.GetConsensusAuthority(),
appI.GetAppManager(),
s.serverOptions.Mempool,
s.serverOptions.Mempool(cfg),
indexEvents,
appI.GetGPRCMethodsToMessageMap(),
store,
@@ -127,7 +128,7 @@ func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logg
if err != nil {
return err
}
consensus.snapshotManager = snapshots.NewManager(snapshotStore, s.serverOptions.SnapshotOptions, sc, ss, nil, s.logger)
consensus.snapshotManager = snapshots.NewManager(snapshotStore, s.serverOptions.SnapshotOptions(cfg), sc, ss, nil, s.logger)
s.Consensus = consensus
@@ -240,6 +241,7 @@ func (s *CometBFTServer[T]) StartCmdFlags() *pflag.FlagSet {
flags.Uint64(FlagHaltTime, 0, "Minimum block time (in Unix seconds) at which to gracefully halt the chain and shutdown the node")
flags.Bool(FlagTrace, false, "Provide full stack traces for errors in ABCI Log")
flags.Bool(Standalone, false, "Run app without CometBFT")
flags.Int(FlagMempoolMaxTxs, mempool.DefaultMaxTx, "Sets MaxTx value for the app-side mempool")
// add comet flags, we use an empty command to avoid duplicating CometBFT's AddNodeFlags.
// we can then merge the flag sets.
+2 -2
View File
@@ -38,14 +38,14 @@ func AddCommands[T transaction.Tx](
rootCmd *cobra.Command,
newApp AppCreator[T],
logger log.Logger,
serverCfg ServerConfig,
globalServerCfg ServerConfig,
components ...ServerComponent[T],
) error {
if len(components) == 0 {
return errors.New("no components provided")
}
server := NewServer(logger, serverCfg, components...)
server := NewServer(logger, globalServerCfg, components...)
originalPersistentPreRunE := rootCmd.PersistentPreRunE
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
// set the default command outputs