github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/bft/mempool/config/config.go (about) 1 package config 2 3 import "github.com/gnolang/gno/tm2/pkg/errors" 4 5 // ----------------------------------------------------------------------------- 6 // MempoolConfig 7 8 // MempoolConfig defines the configuration options for the Tendermint mempool 9 type MempoolConfig struct { 10 RootDir string `toml:"home"` 11 Recheck bool `toml:"recheck"` 12 Broadcast bool `toml:"broadcast"` 13 WalPath string `toml:"wal_dir"` 14 Size int `toml:"size" comment:"Maximum number of transactions in the mempool"` 15 MaxPendingTxsBytes int64 `toml:"max_pending_txs_bytes" comment:"Limit the total size of all txs in the mempool.\n This only accounts for raw transactions (e.g. given 1MB transactions and\n max_txs_bytes=5MB, mempool will only accept 5 transactions)."` 16 CacheSize int `toml:"cache_size" comment:"Size of the cache (used to filter transactions we saw earlier) in transactions"` 17 } 18 19 // DefaultMempoolConfig returns a default configuration for the Tendermint mempool 20 func DefaultMempoolConfig() *MempoolConfig { 21 return &MempoolConfig{ 22 Recheck: true, 23 Broadcast: true, 24 WalPath: "", 25 // Each signature verification takes .5ms, Size reduced until we implement 26 // ABCI Recheck 27 Size: 5000, 28 MaxPendingTxsBytes: 1024 * 1024 * 1024, // 1GB 29 CacheSize: 10000, 30 } 31 } 32 33 // TestMempoolConfig returns a configuration for testing the Tendermint mempool 34 func TestMempoolConfig() *MempoolConfig { 35 cfg := DefaultMempoolConfig() 36 cfg.CacheSize = 1000 37 return cfg 38 } 39 40 // WalDir returns the full path to the mempool's write-ahead log 41 func (cfg *MempoolConfig) WalDir() string { 42 return join(cfg.RootDir, cfg.WalPath) 43 } 44 45 // WalEnabled returns true if the WAL is enabled. 46 func (cfg *MempoolConfig) WalEnabled() bool { 47 return cfg.WalPath != "" 48 } 49 50 // ValidateBasic performs basic validation (checking param bounds, etc.) and 51 // returns an error if any check fails. 52 func (cfg *MempoolConfig) ValidateBasic() error { 53 if cfg.Size < 0 { 54 return errors.New("size can't be negative") 55 } 56 if cfg.MaxPendingTxsBytes < 0 { 57 return errors.New("max_txs_bytes can't be negative") 58 } 59 if cfg.CacheSize < 0 { 60 return errors.New("cache_size can't be negative") 61 } 62 return nil 63 }