diff --git a/server/v2/cometbft/abci.go b/server/v2/cometbft/abci.go index 372886792ee7..7519b3d8c732 100644 --- a/server/v2/cometbft/abci.go +++ b/server/v2/cometbft/abci.go @@ -74,6 +74,7 @@ func NewConsensus[T transaction.Tx]( store types.Store, cfg Config, txCodec transaction.Codec[T], + chainId string, ) *Consensus[T] { return &Consensus[T]{ appName: appName, @@ -93,7 +94,7 @@ func NewConsensus[T transaction.Tx]( processProposalHandler: nil, verifyVoteExt: nil, extendVote: nil, - chainID: "", + chainID: chainId, indexedEvents: indexedEvents, initialHeight: 0, } diff --git a/server/v2/cometbft/go.sum b/server/v2/cometbft/go.sum index 99756515738a..66182dd031fe 100644 --- a/server/v2/cometbft/go.sum +++ b/server/v2/cometbft/go.sum @@ -321,6 +321,8 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= +github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g= github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index c85a241566e2..c06c56c9be9e 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -5,6 +5,7 @@ import ( "crypto/sha256" "encoding/json" "fmt" + "os" "path/filepath" abciserver "github.com/cometbft/cometbft/abci/server" @@ -68,6 +69,21 @@ func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger l AppTomlConfig: appTomlConfig, } + chainID := v.GetString(FlagChainID) + if chainID == "" { + // fallback to genesis chain-id + reader, err := os.Open(filepath.Join(v.GetString(serverv2.FlagHome), "config", "genesis.json")) + if err != nil { + panic(err) + } + defer reader.Close() + + chainID, err = genutiltypes.ParseChainIDFromGenesis(reader) + if err != nil { + panic(fmt.Errorf("failed to parse chain-id from genesis file: %w", err)) + } + } + indexEvents := make(map[string]struct{}, len(s.config.AppTomlConfig.IndexEvents)) for _, e := range s.config.AppTomlConfig.IndexEvents { indexEvents[e] = struct{}{} @@ -86,6 +102,7 @@ func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger l store, s.config, s.initTxCodec, + chainID, ) consensus.prepareProposalHandler = s.serverOptions.PrepareProposalHandler consensus.processProposalHandler = s.serverOptions.ProcessProposalHandler diff --git a/server/v2/config.go b/server/v2/config.go index 57cce302bd74..7ce73fe88a9a 100644 --- a/server/v2/config.go +++ b/server/v2/config.go @@ -2,7 +2,6 @@ package serverv2 import ( "fmt" - "strings" "github.com/mitchellh/mapstructure" "github.com/spf13/viper" @@ -34,8 +33,9 @@ func ReadConfig(configPath string) (*viper.Viper, error) { func UnmarshalSubConfig(v *viper.Viper, subName string, target any) error { var sub any for k, val := range v.AllSettings() { - if strings.HasPrefix(k, subName) { + if k == subName { sub = val + break } } diff --git a/server/v2/config_test.go b/server/v2/config_test.go index 24eb28bb7522..a24cd4cf3d2e 100644 --- a/server/v2/config_test.go +++ b/server/v2/config_test.go @@ -9,6 +9,7 @@ import ( serverv2 "cosmossdk.io/server/v2" grpc "cosmossdk.io/server/v2/api/grpc" + store "cosmossdk.io/server/v2/store" ) func TestReadConfig(t *testing.T) { @@ -20,6 +21,7 @@ func TestReadConfig(t *testing.T) { require.NoError(t, err) require.Equal(t, v.GetString("grpc.address"), grpc.DefaultConfig().Address) + require.Equal(t, v.GetString("store.app-db-backend"), store.DefaultConfig().AppDBBackend) } func TestUnmarshalSubConfig(t *testing.T) { @@ -36,4 +38,9 @@ func TestUnmarshalSubConfig(t *testing.T) { require.True(t, grpc.DefaultConfig().Enable) require.False(t, grpcConfig.Enable) + + storeConfig := store.Config{} + err = serverv2.UnmarshalSubConfig(v, "store", &storeConfig) + require.NoError(t, err) + require.Equal(t, *store.DefaultConfig(), storeConfig) } diff --git a/server/v2/store/server.go b/server/v2/store/server.go index c7a1f9035d10..78c4cd759cd9 100644 --- a/server/v2/store/server.go +++ b/server/v2/store/server.go @@ -25,7 +25,7 @@ func New[T transaction.Tx]() *StoreComponent[T] { func (s *StoreComponent[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logger) error { cfg := DefaultConfig() if v != nil { - if err := v.Sub(s.Name()).Unmarshal(&cfg); err != nil { + if err := serverv2.UnmarshalSubConfig(v, s.Name(), &cfg); err != nil { return fmt.Errorf("failed to unmarshal config: %w", err) } } diff --git a/server/v2/testdata/app.toml b/server/v2/testdata/app.toml index 20482ac44282..ec7d77995d41 100644 --- a/server/v2/testdata/app.toml +++ b/server/v2/testdata/app.toml @@ -10,6 +10,36 @@ max-recv-msg-size = 10485760 # The default value is math.MaxInt32. max-send-msg-size = 2147483647 +[store] +# The type of database for application and snapshots databases. +app-db-backend = 'goleveldb' + +[store.options] +# State storage database type. Currently we support: 0 for SQLite, 1 for Pebble +ss-type = 0 +# State commitment database type. Currently we support:0 for iavl, 1 for iavl v2 +sc-type = 0 + +# Pruning options for state storage +[store.options.ss-pruning-option] +# Number of recent heights to keep on disk. +keep-recent = 2 +# Height interval at which pruned heights are removed from disk. +interval = 1 + +# Pruning options for state commitment +[store.options.sc-pruning-option] +# Number of recent heights to keep on disk. +keep-recent = 2 +# Height interval at which pruned heights are removed from disk. +interval = 1 + +[store.options.iavl-config] +# CacheSize set the size of the iavl tree cache. +cache-size = 100000 +# If true, the tree will work like no fast storage and always not upgrade fast storage. +skip-fast-storage-upgrade = true + [mock-server-1] # Mock field mock_field = 'default'