From 7a6f8aa9fbf949917265c1e4a203eede0fe45a95 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Tue, 7 May 2024 15:52:27 +0700 Subject: [PATCH 01/29] simplify server ctx --- client/snapshot/export.go | 8 +- client/snapshot/restore.go | 7 +- core/context/server_context.go | 44 +++++ core/go.mod | 45 ++++- core/go.sum | 217 ++++++++++++++++++++++- server/cmt_cmds.go | 22 ++- server/rollback.go | 9 +- server/start.go | 34 +++- server/util.go | 90 +++++++--- server/util_test.go | 53 +++++- testutil/network/network.go | 5 +- testutil/network/util.go | 8 +- x/genutil/client/cli/collect.go | 10 +- x/genutil/client/cli/export.go | 12 +- x/genutil/client/cli/export_test.go | 4 +- x/genutil/client/cli/genaccount.go | 5 +- x/genutil/client/cli/genaccount_test.go | 4 +- x/genutil/client/cli/gentx.go | 7 +- x/genutil/client/cli/init.go | 9 +- x/genutil/client/cli/init_test.go | 26 +-- x/genutil/client/cli/validate_genesis.go | 6 +- x/genutil/client/testutil/helpers.go | 9 +- 22 files changed, 523 insertions(+), 111 deletions(-) create mode 100644 core/context/server_context.go diff --git a/client/snapshot/export.go b/client/snapshot/export.go index 61f1951bbafe..a43858deefa5 100644 --- a/client/snapshot/export.go +++ b/client/snapshot/export.go @@ -1,6 +1,8 @@ package snapshot import ( + "fmt" + "github.com/spf13/cobra" "cosmossdk.io/log" @@ -17,13 +19,17 @@ func ExportSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCrea Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { ctx := server.GetServerContextFromCmd(cmd) + cfg, ok := ctx.GetConfig().(server.CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } height, err := cmd.Flags().GetInt64("height") if err != nil { return err } - home := ctx.Config.RootDir + home := cfg.RootDir db, err := openDB(home, server.GetAppDBBackend(ctx.Viper)) if err != nil { return err diff --git a/client/snapshot/restore.go b/client/snapshot/restore.go index c1f5b21f214c..1c6df23ce764 100644 --- a/client/snapshot/restore.go +++ b/client/snapshot/restore.go @@ -1,6 +1,7 @@ package snapshot import ( + "fmt" "path/filepath" "strconv" @@ -22,6 +23,10 @@ func RestoreSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCre Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { ctx := server.GetServerContextFromCmd(cmd) + cfg, ok := ctx.GetConfig().(server.CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } height, err := strconv.ParseUint(args[0], 10, 64) if err != nil { @@ -32,7 +37,7 @@ func RestoreSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCre return err } - home := ctx.Config.RootDir + home := cfg.RootDir db, err := openDB(home, server.GetAppDBBackend(ctx.Viper)) if err != nil { return err diff --git a/core/context/server_context.go b/core/context/server_context.go new file mode 100644 index 000000000000..dbd71127e3e4 --- /dev/null +++ b/core/context/server_context.go @@ -0,0 +1,44 @@ +package context + +import ( + "fmt" + + "github.com/spf13/cobra" + "github.com/spf13/viper" + + "cosmossdk.io/log" +) + +type ContextKey string + +const ServerContextKey ContextKey = "server.context" + +type ServerContext interface { + GetLogger() log.Logger + GetViper() *viper.Viper + GetConfig() CometConfig +} + +type BaseConfig interface { + DBDir() string + GenesisFile() string + NodeKeyFile() string + PrivValidatorKeyFile() string + PrivValidatorStateFile() string +} + +type CometConfig interface { + BaseConfig + CheckDeprecated() []string + SetRoot(root string) CometConfig + ValidateBasic() error +} + +func GetServerContextFromCmd(cmd *cobra.Command) ServerContext { + if v := cmd.Context().Value(ServerContextKey); v != nil { + fmt.Println("serverCtxPtr", v) + serverCtxPtr := v.(ServerContext) + return serverCtxPtr + } + return nil +} diff --git a/core/go.mod b/core/go.mod index 61b40dacba8f..6f6e9c9b05dc 100644 --- a/core/go.mod +++ b/core/go.mod @@ -1,30 +1,67 @@ module cosmossdk.io/core -go 1.20 +go 1.21 + +toolchain go1.22.2 require ( cosmossdk.io/log v1.3.1 + github.com/cometbft/cometbft v0.38.7 github.com/cosmos/gogoproto v1.4.12 + github.com/spf13/cobra v1.8.0 + github.com/spf13/viper v1.18.2 github.com/stretchr/testify v1.9.0 google.golang.org/grpc v1.63.2 google.golang.org/protobuf v1.34.0 ) require ( - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/cespare/xxhash v1.1.0 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cometbft/cometbft-db v0.7.0 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/dgraph-io/badger/v2 v2.2007.4 // indirect + github.com/dgraph-io/ristretto v0.1.1 // indirect + github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect + github.com/dustin/go-humanize v1.0.1 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/go-kit/log v0.2.1 // indirect + github.com/go-logfmt/logfmt v0.6.0 // indirect + github.com/golang/glog v1.2.0 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/google/btree v1.1.2 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/kr/pretty v0.3.1 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/jmhodges/levigo v1.0.0 // indirect + github.com/klauspost/compress v1.17.0 // indirect + github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/rs/zerolog v1.32.0 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect + github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect + go.etcd.io/bbolt v1.3.6 // indirect + go.uber.org/multierr v1.10.0 // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect + gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/core/go.sum b/core/go.sum index 8806b62e64db..5aa67d98514a 100644 --- a/core/go.sum +++ b/core/go.sum @@ -1,14 +1,97 @@ cosmossdk.io/log v1.3.1 h1:UZx8nWIkfbbNEWusZqzAx3ZGvu54TZacWib3EzUYmGI= cosmossdk.io/log v1.3.1/go.mod h1:2/dIomt8mKdk6vl3OWJcPk2be3pGOS8OQaLUM/3/tCM= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= +github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= +github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cometbft/cometbft v0.38.7 h1:ULhIOJ9+LgSy6nLekhq9ae3juX3NnQUMMPyVdhZV6Hk= +github.com/cometbft/cometbft v0.38.7/go.mod h1:HIyf811dFMI73IE0F7RrnY/Fr+d1+HuJAgtkEpQjCMY= +github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo= +github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cosmos/gogoproto v1.4.12 h1:vB6Lbe/rtnYGjQuFxkPiPYiCybqFT8QvLipDZP8JpFE= github.com/cosmos/gogoproto v1.4.12/go.mod h1:LnZob1bXRdUoqMMtwYlcR3wjiElmlC+FkjaZRv1/eLY= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= +github.com/dgraph-io/badger/v2 v2.2007.4 h1:TRWBQg8UrlUhaFdco01nO2uXwzKS7zd+HVdwV/GHc4o= +github.com/dgraph-io/badger/v2 v2.2007.4/go.mod h1:vSw/ax2qojzbN6eXHIx6KPKtCSHJN/Uz0X0VPruTIhk= +github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= +github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8= +github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA= +github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y= +github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= +github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= +github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= +github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= +github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk= +github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= +github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= +github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= +github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= +github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= +github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U= +github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ= +github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= +github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM= +github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -16,45 +99,169 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 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/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae h1:FatpGJD2jmJfhZiFDElaC0QhZUDQnxUeAwTGkfAHN3I= +github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= +github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= +github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0= +github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= +github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= +github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= +github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= +github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzHWCjJB1zZfXPIAaDpzXIEJ0eS6B5Ok= +github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= +go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= +go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= +go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4= google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= +gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= diff --git a/server/cmt_cmds.go b/server/cmt_cmds.go index e4fdf1ed814c..8397ddb76cc5 100644 --- a/server/cmt_cmds.go +++ b/server/cmt_cmds.go @@ -74,7 +74,10 @@ func ShowNodeIDCmd() *cobra.Command { Short: "Show this node's ID", RunE: func(cmd *cobra.Command, args []string) error { serverCtx := GetServerContextFromCmd(cmd) - cfg := serverCtx.Config + cfg, ok := serverCtx.GetConfig().(CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } nodeKey, err := p2p.LoadNodeKey(cfg.NodeKeyFile()) if err != nil { @@ -94,7 +97,10 @@ func ShowValidatorCmd() *cobra.Command { Short: "Show this node's CometBFT validator info", RunE: func(cmd *cobra.Command, args []string) error { serverCtx := GetServerContextFromCmd(cmd) - cfg := serverCtx.Config + cfg, ok := serverCtx.GetConfig().(CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } privValidator := pvm.LoadFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()) pk, err := privValidator.GetPubKey() @@ -128,7 +134,10 @@ func ShowAddressCmd() *cobra.Command { Short: "Shows this node's CometBFT validator consensus address", RunE: func(cmd *cobra.Command, args []string) error { serverCtx := GetServerContextFromCmd(cmd) - cfg := serverCtx.Config + cfg, ok := serverCtx.GetConfig().(CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } privValidator := pvm.LoadFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()) @@ -364,7 +373,10 @@ func BootstrapStateCmd[T types.Application](appCreator types.AppCreator[T]) *cob RunE: func(cmd *cobra.Command, args []string) error { serverCtx := GetServerContextFromCmd(cmd) logger := log.NewLogger(cmd.OutOrStdout()) - cfg := serverCtx.Config + cfg, ok := serverCtx.GetConfig().(CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } height, err := cmd.Flags().GetInt64("height") if err != nil { @@ -381,7 +393,7 @@ func BootstrapStateCmd[T types.Application](appCreator types.AppCreator[T]) *cob height = app.CommitMultiStore().LastCommitID().Version } - return node.BootstrapState(cmd.Context(), cfg, cmtcfg.DefaultDBProvider, getGenDocProvider(cfg), uint64(height), nil) + return node.BootstrapState(cmd.Context(), cfg.Config, cmtcfg.DefaultDBProvider, getGenDocProvider(cfg.Config), uint64(height), nil) }, } diff --git a/server/rollback.go b/server/rollback.go index 7dd58bcedf64..e678edc2b1fb 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -27,13 +27,18 @@ application. RunE: func(cmd *cobra.Command, args []string) error { ctx := GetServerContextFromCmd(cmd) - db, err := OpenDB(ctx.Config.RootDir, GetAppDBBackend(ctx.Viper)) + config, ok := ctx.GetConfig().(CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } + + db, err := OpenDB(config.RootDir, GetAppDBBackend(ctx.Viper)) if err != nil { return err } app := appCreator(ctx.Logger, db, nil, ctx.Viper) // rollback CometBFT state - height, hash, err := cmtcmd.RollbackState(ctx.Config, removeBlock) + height, hash, err := cmtcmd.RollbackState(config.Config, removeBlock) if err != nil { return fmt.Errorf("failed to rollback CometBFT state: %w", err) } diff --git a/server/start.go b/server/start.go index ea0e43d31319..f6839e7d4a29 100644 --- a/server/start.go +++ b/server/start.go @@ -252,13 +252,18 @@ func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.C g, ctx := getCtx(svrCtx, false) + config, ok := svrCtx.GetConfig().(CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } + // 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 CometBFT RPC client. if svrCfg.API.Enable || svrCfg.GRPC.Enable { // create tendermint client // assumes the rpc listen address is where tendermint has its rpc server - rpcclient, err := rpchttp.New(svrCtx.Config.RPC.ListenAddress) + rpcclient, err := rpchttp.New(config.RPC.ListenAddress) if err != nil { return err } @@ -277,7 +282,7 @@ func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.C return err } - err = startAPIServer(ctx, g, svrCfg, clientCtx, svrCtx, app, svrCtx.Config.RootDir, grpcSrv, metrics) + err = startAPIServer(ctx, g, svrCfg, clientCtx, svrCtx, app, config.RootDir, grpcSrv, metrics) if err != nil { return err } @@ -307,7 +312,10 @@ func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.C func startInProcess[T types.Application](svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app T, metrics *telemetry.Metrics, opts StartCmdOptions[T], ) error { - cmtCfg := svrCtx.Config + cmtCfg, ok := svrCtx.GetConfig().(CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } gRPCOnly := svrCtx.Viper.GetBool(flagGRPCOnly) g, ctx := getCtx(svrCtx, true) @@ -318,7 +326,7 @@ func startInProcess[T types.Application](svrCtx *Context, svrCfg serverconfig.Co svrCfg.GRPC.Enable = true } else { svrCtx.Logger.Info("starting node with ABCI CometBFT in-process") - tmNode, cleanupFn, err := startCmtNode(ctx, cmtCfg, app, svrCtx) + tmNode, cleanupFn, err := startCmtNode(ctx, cmtCfg.Config, app, svrCtx) if err != nil { return err } @@ -627,7 +635,12 @@ func startApp[T types.Application](svrCtx *Context, appCreator types.AppCreator[ return app, traceCleanupFn, err } - home := svrCtx.Config.RootDir + cmtCfg, ok := svrCtx.GetConfig().(CometConfig) + if !ok { + return app, traceCleanupFn, fmt.Errorf("Can not convert cometbft config") + } + + home := cmtCfg.RootDir db, err := opts.DBOpener(home, GetAppDBBackend(svrCtx.Viper)) if err != nil { return app, traceCleanupFn, err @@ -754,7 +767,10 @@ you want to test the upgrade handler itself. // testnetify modifies both state and blockStore, allowing the provided operator address and local validator key to control the network // that the state in the data folder represents. The chainID of the local genesis file is modified to match the provided chainID. func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCreator[T], db dbm.DB, traceWriter io.WriteCloser) (*T, error) { - config := ctx.Config + config, ok := ctx.GetConfig().(CometConfig) + if !ok { + return nil, fmt.Errorf("Can not convert cometbft config") + } newChainID, ok := ctx.Viper.Get(KeyNewChainID).(string) if !ok { @@ -776,16 +792,16 @@ func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCr } // Load the comet genesis doc provider. - genDocProvider := node.DefaultGenesisDocProviderFunc(config) + genDocProvider := node.DefaultGenesisDocProviderFunc(config.Config) // Initialize blockStore and stateDB. - blockStoreDB, err := cmtcfg.DefaultDBProvider(&cmtcfg.DBContext{ID: "blockstore", Config: config}) + blockStoreDB, err := cmtcfg.DefaultDBProvider(&cmtcfg.DBContext{ID: "blockstore", Config: config.Config}) if err != nil { return nil, err } blockStore := store.NewBlockStore(blockStoreDB) - stateDB, err := cmtcfg.DefaultDBProvider(&cmtcfg.DBContext{ID: "state", Config: config}) + stateDB, err := cmtcfg.DefaultDBProvider(&cmtcfg.DBContext{ID: "state", Config: config.Config}) if err != nil { return nil, err } diff --git a/server/util.go b/server/util.go index 4262c288afd5..a3bdf148df99 100644 --- a/server/util.go +++ b/server/util.go @@ -29,12 +29,12 @@ import ( "cosmossdk.io/store/snapshots" snapshottypes "cosmossdk.io/store/snapshots/types" storetypes "cosmossdk.io/store/types" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/config" "github.com/cosmos/cosmos-sdk/server/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/mempool" "github.com/cosmos/cosmos-sdk/version" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" @@ -42,25 +42,71 @@ import ( // ServerContextKey defines the context key used to retrieve a server.Context from // a command's Context. -const ServerContextKey = sdk.ContextKey("server.context") +const ServerContextKey = corectx.ServerContextKey + +var _ corectx.ServerContext = &Context{} +var _ corectx.BaseConfig = cmtcfg.BaseConfig{} +var _ corectx.CometConfig = &CometConfig{} + +type CometConfig struct { + *cmtcfg.Config +} // Context server context type Context struct { Viper *viper.Viper - Config *cmtcfg.Config Logger log.Logger } +func (ctx *Context) GetConfig() corectx.CometConfig { + return GetCometConfigFromViper(ctx.Viper) +} + +func (ctx *Context) GetLogger() log.Logger { + return ctx.Logger +} + +func (ctx *Context) GetViper() *viper.Viper { + return ctx.Viper +} +// cfg.BaseConfig.RootDir = root +// cfg.RPC.RootDir = root +// cfg.P2P.RootDir = root +// cfg.Mempool.RootDir = root +// cfg.Consensus.RootDir = root + +// Apply change to viper when config root is changed +func (ctx *Context) SetRoot(rootDir string) { + v := ctx.GetViper() + v.Set("base_config.root_dir", rootDir) + v.Set("rpc.root_dir", rootDir) + v.Set("p2p.root_dir", rootDir) + v.Set("mempool.root_dir", rootDir) + v.Set("consensus.root_dir", rootDir) +} + +func (config CometConfig) SetRoot(root string) corectx.CometConfig { + return config.SetRoot(root) +} + +func GetCometConfigFromViper(v *viper.Viper) corectx.CometConfig { + conf := cmtcfg.DefaultConfig() + err := v.Unmarshal(conf) + if err != nil { + return CometConfig{cmtcfg.DefaultConfig()} + } + return CometConfig{conf} +} + func NewDefaultContext() *Context { return NewContext( viper.New(), - cmtcfg.DefaultConfig(), log.NewLogger(os.Stdout), ) } -func NewContext(v *viper.Viper, config *cmtcfg.Config, logger log.Logger) *Context { - return &Context{v, config, logger} +func NewContext(v *viper.Viper, logger log.Logger) *Context { + return &Context{v, logger} } func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) { @@ -152,13 +198,11 @@ func InterceptConfigsAndCreateContext(cmd *cobra.Command, customAppConfigTemplat serverCtx.Viper.AutomaticEnv() // intercept configuration files, using both Viper instances separately - config, err := interceptConfigs(serverCtx.Viper, customAppConfigTemplate, customAppConfig, cmtConfig) + err = interceptConfigs(serverCtx.Viper, customAppConfigTemplate, customAppConfig, cmtConfig) if err != nil { return nil, err } - // return value is a CometBFT configuration object - serverCtx.Config = config if err = bindFlags(basename, cmd, serverCtx.Viper); err != nil { return nil, err } @@ -233,7 +277,7 @@ func SetCmdServerContext(cmd *cobra.Command, serverCtx *Context) error { // 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{}, cmtConfig *cmtcfg.Config) (*cmtcfg.Config, error) { +func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customConfig interface{}, cmtConfig *cmtcfg.Config) error { rootDir := rootViper.GetString(flags.FlagHome) configPath := filepath.Join(rootDir, "config") cmtCfgFile := filepath.Join(configPath, "config.toml") @@ -245,7 +289,7 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo cmtcfg.EnsureRoot(rootDir) if err = conf.ValidateBasic(); err != nil { - return nil, fmt.Errorf("error in config file: %w", err) + return fmt.Errorf("error in config file: %w", err) } defaultCometCfg := cmtcfg.DefaultConfig() @@ -261,7 +305,7 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo cmtcfg.WriteConfigFile(cmtCfgFile, conf) case err != nil: - return nil, err + return err default: rootViper.SetConfigType("toml") @@ -269,7 +313,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", cmtCfgFile, err) + return fmt.Errorf("failed to read in %s: %w", cmtCfgFile, err) } } @@ -277,37 +321,35 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo // This may come from the configuration file above but also any of the other // sources viper uses. if err := rootViper.Unmarshal(conf); err != nil { - return nil, err + return err } - conf.SetRoot(rootDir) - appCfgFilePath := filepath.Join(configPath, "app.toml") if _, err := os.Stat(appCfgFilePath); os.IsNotExist(err) { if (customAppTemplate != "" && customConfig == nil) || (customAppTemplate == "" && customConfig != nil) { - return nil, fmt.Errorf("customAppTemplate and customConfig should be both nil or not nil") + return fmt.Errorf("customAppTemplate and customConfig should be both nil or not nil") } if customAppTemplate != "" { if err := config.SetConfigTemplate(customAppTemplate); err != nil { - return nil, fmt.Errorf("failed to set config template: %w", err) + return fmt.Errorf("failed to set config template: %w", err) } if err = rootViper.Unmarshal(&customConfig); err != nil { - return nil, fmt.Errorf("failed to parse %s: %w", appCfgFilePath, err) + return fmt.Errorf("failed to parse %s: %w", appCfgFilePath, err) } if err := config.WriteConfigFile(appCfgFilePath, customConfig); err != nil { - return nil, fmt.Errorf("failed to write %s: %w", appCfgFilePath, err) + return fmt.Errorf("failed to write %s: %w", appCfgFilePath, err) } } else { appConf, err := config.ParseConfig(rootViper) if err != nil { - return nil, fmt.Errorf("failed to parse %s: %w", appCfgFilePath, err) + return fmt.Errorf("failed to parse %s: %w", appCfgFilePath, err) } if err := config.WriteConfigFile(appCfgFilePath, appConf); err != nil { - return nil, fmt.Errorf("failed to write %s: %w", appCfgFilePath, err) + return fmt.Errorf("failed to write %s: %w", appCfgFilePath, err) } } } @@ -317,10 +359,10 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo rootViper.AddConfigPath(configPath) if err := rootViper.MergeInConfig(); err != nil { - return nil, fmt.Errorf("failed to merge configuration: %w", err) + return fmt.Errorf("failed to merge configuration: %w", err) } - return conf, nil + return nil } // AddCommands add server commands diff --git a/server/util_test.go b/server/util_test.go index 11f5cbb208c9..650b13e44878 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -83,7 +83,7 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T } // Test that CometBFT config is initialized - if serverCtx.Config == nil { + if serverCtx.GetConfig() == nil { t.Fatal("CometBFT config not created") } @@ -147,7 +147,12 @@ func TestInterceptConfigsPreRunHandlerReadsConfigToml(t *testing.T) { serverCtx = server.GetServerContextFromCmd(cmd) - if testDbBackend != serverCtx.Config.DBBackend { + config, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + t.Error("can not convert to cometbft config") + } + + if testDbBackend != config.DBBackend { t.Error("backend was not set from config.toml") } } @@ -217,7 +222,12 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { serverCtx = server.GetServerContextFromCmd(cmd) - if testAddr != serverCtx.Config.RPC.ListenAddress { + config, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + t.Error("can not convert to cometbft config") + } + + if testAddr != config.RPC.ListenAddress { t.Error("RPCListenAddress was not set from command flags") } } @@ -255,7 +265,12 @@ func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) { serverCtx = server.GetServerContextFromCmd(cmd) - if testAddr != serverCtx.Config.RPC.ListenAddress { + config, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + t.Error("can not convert to cometbft config") + } + + if testAddr != config.RPC.ListenAddress { t.Errorf("RPCListenAddress was not set from env. var. %q", envVarName) } } @@ -364,7 +379,12 @@ func TestInterceptConfigsPreRunHandlerPrecedenceFlag(t *testing.T) { serverCtx = server.GetServerContextFromCmd(testCommon.cmd) - if TestAddrExpected != serverCtx.Config.RPC.ListenAddress { + config, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + t.Error("can not convert to cometbft config") + } + + if TestAddrExpected != config.RPC.ListenAddress { t.Fatalf("RPCListenAddress was not set from flag %q", testCommon.flagName) } } @@ -382,7 +402,12 @@ func TestInterceptConfigsPreRunHandlerPrecedenceEnvVar(t *testing.T) { serverCtx = server.GetServerContextFromCmd(testCommon.cmd) - if TestAddrExpected != serverCtx.Config.RPC.ListenAddress { + config, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + t.Error("can not convert to cometbft config") + } + + if TestAddrExpected != config.RPC.ListenAddress { t.Errorf("RPCListenAddress was not set from env. var. %q", testCommon.envVarName) } } @@ -400,7 +425,12 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigFile(t *testing.T) { serverCtx = server.GetServerContextFromCmd(testCommon.cmd) - if TestAddrExpected != serverCtx.Config.RPC.ListenAddress { + config, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + t.Error("can not convert to cometbft config") + } + + if TestAddrExpected != config.RPC.ListenAddress { t.Errorf("RPCListenAddress was not read from file %q", testCommon.configTomlPath) } } @@ -418,7 +448,12 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigDefault(t *testing.T) { serverCtx = server.GetServerContextFromCmd(testCommon.cmd) - if serverCtx.Config.RPC.ListenAddress != "tcp://127.0.0.1:26657" { + config, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + t.Error("can not convert to cometbft config") + } + + if config.RPC.ListenAddress != "tcp://127.0.0.1:26657" { t.Error("RPCListenAddress is not using default") } } @@ -456,7 +491,7 @@ func TestEmptyMinGasPrices(t *testing.T) { // Run InitCmd to create necessary config files. clientCtx := client.Context{}.WithHomeDir(tempDir).WithCodec(encCfg.Codec) serverCtx := server.NewDefaultContext() - serverCtx.Config.SetRoot(tempDir) + serverCtx.SetRoot(tempDir) ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) cmd := genutilcli.InitCmd(module.NewManager()) diff --git a/testutil/network/network.go b/testutil/network/network.go index 1c867bd42521..251a0ade9e07 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -341,7 +341,8 @@ func New(l Logger, baseDir string, cfg Config) (NetworkI, error) { appCfg.Telemetry.Enabled = false ctx := server.NewDefaultContext() - cmtCfg := ctx.Config + cmtCfg, _ := ctx.GetConfig().(server.CometConfig) + cmtCfg.Consensus.TimeoutCommit = cfg.TimeoutCommit // Only allow the first validator to expose an RPC, API and gRPC @@ -437,7 +438,7 @@ func New(l Logger, baseDir string, cfg Config) (NetworkI, error) { mnemonic = cfg.Mnemonics[i] } - nodeID, pubKey, err := genutil.InitializeNodeValidatorFilesFromMnemonic(cmtCfg, mnemonic) + nodeID, pubKey, err := genutil.InitializeNodeValidatorFilesFromMnemonic(cmtCfg.Config, mnemonic) if err != nil { return nil, err } diff --git a/testutil/network/util.go b/testutil/network/util.go index e7746ec44086..9fc7e8844d76 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -32,7 +32,7 @@ import ( func startInProcess(cfg Config, val *Validator) error { logger := val.ctx.Logger - cmtCfg := val.ctx.Config + cmtCfg := val.ctx.GetConfig().(server.CometConfig) cmtCfg.Instrumentation.Prometheus = false if err := val.AppConfig.ValidateBasic(); err != nil { @@ -66,7 +66,7 @@ func startInProcess(cfg Config, val *Validator) error { cmtApp := server.NewCometABCIWrapper(app) tmNode, err := node.NewNode( //resleak:notresource context.TODO(), - cmtCfg, + cmtCfg.Config, pvm.LoadOrGenFilePV(cmtCfg.PrivValidatorKeyFile(), cmtCfg.PrivValidatorStateFile()), nodeKey, proxy.NewLocalClientCreator(cmtApp), @@ -140,7 +140,7 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { } for i := 0; i < cfg.NumValidators; i++ { - cmtCfg := vals[i].ctx.Config + cmtCfg := vals[i].ctx.GetConfig().(server.CometConfig) nodeDir := filepath.Join(outputDir, vals[i].moniker, "simd") gentxsDir := filepath.Join(outputDir, "gentxs") @@ -157,7 +157,7 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { } appState, err := genutil.GenAppStateFromConfig(cfg.Codec, cfg.TxConfig, - cmtCfg, initCfg, appGenesis, banktypes.GenesisBalancesIterator{}, genutiltypes.DefaultMessageValidator, + cmtCfg.Config, initCfg, appGenesis, banktypes.GenesisBalancesIterator{}, genutiltypes.DefaultMessageValidator, cfg.ValidatorAddressCodec, cfg.AddressCodec) if err != nil { return err diff --git a/x/genutil/client/cli/collect.go b/x/genutil/client/cli/collect.go index 3983a859b18e..e48dbaaf8536 100644 --- a/x/genutil/client/cli/collect.go +++ b/x/genutil/client/cli/collect.go @@ -2,6 +2,7 @@ package cli import ( "encoding/json" + "fmt" "path/filepath" "github.com/spf13/cobra" @@ -23,12 +24,15 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, validator ty Short: "Collect genesis txs and output a genesis.json file", RunE: func(cmd *cobra.Command, _ []string) error { serverCtx := server.GetServerContextFromCmd(cmd) - config := serverCtx.Config + config, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } clientCtx := client.GetClientContextFromCmd(cmd) cdc := clientCtx.Codec - nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(config) + nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(config.Config) if err != nil { return errors.Wrap(err, "failed to initialize node validator files") } @@ -47,7 +51,7 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, validator ty toPrint := newPrintInfo(config.Moniker, appGenesis.ChainID, nodeID, genTxsDir, json.RawMessage("")) initCfg := types.NewInitConfig(appGenesis.ChainID, genTxsDir, nodeID, valPubKey) - appMessage, err := genutil.GenAppStateFromConfig(cdc, clientCtx.TxConfig, config, initCfg, appGenesis, genBalIterator, validator, clientCtx.ValidatorAddressCodec, clientCtx.AddressCodec) + appMessage, err := genutil.GenAppStateFromConfig(cdc, clientCtx.TxConfig, config.Config, initCfg, appGenesis, genBalIterator, validator, clientCtx.ValidatorAddressCodec, clientCtx.AddressCodec) if err != nil { return errors.Wrap(err, "failed to get genesis app state from config") } diff --git a/x/genutil/client/cli/export.go b/x/genutil/client/cli/export.go index b59a17969b13..bd9c18c45289 100644 --- a/x/genutil/client/cli/export.go +++ b/x/genutil/client/cli/export.go @@ -32,12 +32,16 @@ func ExportCmd(appExporter servertypes.AppExporter) *cobra.Command { Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) error { serverCtx := server.GetServerContextFromCmd(cmd) + config, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } - if _, err := os.Stat(serverCtx.Config.GenesisFile()); os.IsNotExist(err) { + if _, err := os.Stat(config.GenesisFile()); os.IsNotExist(err) { return err } - db, err := server.OpenDB(serverCtx.Config.RootDir, server.GetAppDBBackend(serverCtx.Viper)) + db, err := server.OpenDB(config.RootDir, server.GetAppDBBackend(serverCtx.Viper)) if err != nil { return err } @@ -51,7 +55,7 @@ func ExportCmd(appExporter servertypes.AppExporter) *cobra.Command { // It is possible that the genesis file is large, // so we don't need to read it all into memory // before we stream it out. - f, err := os.OpenFile(serverCtx.Config.GenesisFile(), os.O_RDONLY, 0) + f, err := os.OpenFile(config.GenesisFile(), os.O_RDONLY, 0) if err != nil { return err } @@ -82,7 +86,7 @@ func ExportCmd(appExporter servertypes.AppExporter) *cobra.Command { return fmt.Errorf("error exporting state: %w", err) } - appGenesis, err := genutiltypes.AppGenesisFromFile(serverCtx.Config.GenesisFile()) + appGenesis, err := genutiltypes.AppGenesisFromFile(config.GenesisFile()) if err != nil { return err } diff --git a/x/genutil/client/cli/export_test.go b/x/genutil/client/cli/export_test.go index 8f58fc5e2eef..67224ecb228d 100644 --- a/x/genutil/client/cli/export_test.go +++ b/x/genutil/client/cli/export_test.go @@ -11,7 +11,6 @@ import ( "time" cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1" - cmtcfg "github.com/cometbft/cometbft/config" cmttypes "github.com/cometbft/cometbft/types" dbm "github.com/cosmos/cosmos-db" "github.com/rs/zerolog" @@ -67,10 +66,9 @@ func NewExportSystem(t *testing.T, exporter types.AppExporter) *ExportSystem { sCtx := server.NewContext( viper.New(), - cmtcfg.DefaultConfig(), log.NewCustomLogger(zerolog.New(tw)), ) - sCtx.Config.SetRoot(homeDir) + sCtx.SetRoot(homeDir) cCtx := (client.Context{}).WithHomeDir(homeDir) diff --git a/x/genutil/client/cli/genaccount.go b/x/genutil/client/cli/genaccount.go index 1cbb42b42379..71fc4ea33b36 100644 --- a/x/genutil/client/cli/genaccount.go +++ b/x/genutil/client/cli/genaccount.go @@ -39,7 +39,10 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) serverCtx := server.GetServerContextFromCmd(cmd) - config := serverCtx.Config + config, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } var kr keyring.Keyring addr, err := addressCodec.StringToBytes(args[0]) diff --git a/x/genutil/client/cli/genaccount_test.go b/x/genutil/client/cli/genaccount_test.go index 51cb42a3ac0e..0950a28cfb35 100644 --- a/x/genutil/client/cli/genaccount_test.go +++ b/x/genutil/client/cli/genaccount_test.go @@ -71,14 +71,12 @@ func TestAddGenesisAccountCmd(t *testing.T) { t.Run(tc.name, func(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() - cfg, err := genutiltest.CreateDefaultCometConfig(home) - require.NoError(t, err) appCodec := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}).Codec err = genutiltest.ExecInitCmd(testMbm, home, appCodec) require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), cfg, logger) + serverCtx := server.NewContext(viper.New(), logger) clientCtx := client.Context{}.WithCodec(appCodec).WithHomeDir(home).WithAddressCodec(ac) if tc.withKeyring { diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index 533c1ae0dfde..4997de337293 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -56,14 +56,17 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o ), RunE: func(cmd *cobra.Command, args []string) error { serverCtx := server.GetServerContextFromCmd(cmd) + config, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } cdc := clientCtx.Codec - config := serverCtx.Config - nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(serverCtx.Config) + nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(config.Config) if err != nil { return errors.Wrap(err, "failed to initialize node validator files") } diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index 2765eafc9acb..d509ac42da66 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -82,7 +82,10 @@ func InitCmd(mm *module.Manager) *cobra.Command { clientCtx := client.GetClientContextFromCmd(cmd) serverCtx := server.GetServerContextFromCmd(cmd) - config := serverCtx.Config + config, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } chainID, _ := cmd.Flags().GetString(flags.FlagChainID) switch { @@ -115,7 +118,7 @@ func InitCmd(mm *module.Manager) *cobra.Command { initHeight = 1 } - nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(config, mnemonic) + nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(config.Config, mnemonic) if err != nil { return err } @@ -177,7 +180,7 @@ func InitCmd(mm *module.Manager) *cobra.Command { toPrint := newPrintInfo(config.Moniker, chainID, nodeID, "", appState) - cfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config) + cfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config.Config) return displayInfo(toPrint) }, } diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index a958a47544e9..e683cd5fa4bd 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -63,10 +63,8 @@ func TestInitCmd(t *testing.T) { t.Run(tt.name, func(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() - cfg, err := genutiltest.CreateDefaultCometConfig(home) - require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), cfg, logger) + serverCtx := server.NewContext(viper.New(), logger) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -96,10 +94,8 @@ func TestInitCmd(t *testing.T) { func TestInitRecover(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() - cfg, err := genutiltest.CreateDefaultCometConfig(home) - require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), cfg, logger) + serverCtx := server.NewContext(viper.New(), logger) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -127,10 +123,8 @@ func TestInitRecover(t *testing.T) { func TestInitDefaultBondDenom(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() - cfg, err := genutiltest.CreateDefaultCometConfig(home) - require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), cfg, logger) + serverCtx := server.NewContext(viper.New(), logger) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -154,11 +148,9 @@ func TestInitDefaultBondDenom(t *testing.T) { func TestEmptyState(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() - cfg, err := genutiltest.CreateDefaultCometConfig(home) - require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), cfg, logger) - serverCtx.Config.SetRoot(home) + serverCtx := server.NewContext(viper.New(), logger) + serverCtx.SetRoot(home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -248,10 +240,8 @@ func TestInitNodeValidatorFiles(t *testing.T) { func TestInitConfig(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() - cfg, err := genutiltest.CreateDefaultCometConfig(home) - require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), cfg, logger) + serverCtx := server.NewContext(viper.New(), logger) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -297,7 +287,7 @@ func TestInitWithHeight(t *testing.T) { cfg, err := genutiltest.CreateDefaultCometConfig(home) require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), cfg, logger) + serverCtx := server.NewContext(viper.New(), logger) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -329,7 +319,7 @@ func TestInitWithNegativeHeight(t *testing.T) { cfg, err := genutiltest.CreateDefaultCometConfig(home) require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), cfg, logger) + serverCtx := server.NewContext(viper.New(), logger) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 232097cda5c0..397f091fa6cd 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -22,11 +22,15 @@ func ValidateGenesisCmd(mm *module.Manager) *cobra.Command { Short: "Validates the genesis file at the default location or at the location passed as an arg", RunE: func(cmd *cobra.Command, args []string) (err error) { serverCtx := server.GetServerContextFromCmd(cmd) + cfg, ok := serverCtx.GetConfig().(server.CometConfig) + if !ok { + return fmt.Errorf("Can not convert cometbft config") + } // Load default if passed no args, otherwise load passed file var genesis string if len(args) == 0 { - genesis = serverCtx.Config.GenesisFile() + genesis = cfg.GenesisFile() } else { genesis = args[0] } diff --git a/x/genutil/client/testutil/helpers.go b/x/genutil/client/testutil/helpers.go index e4fc09e9acff..79a2b5e6119c 100644 --- a/x/genutil/client/testutil/helpers.go +++ b/x/genutil/client/testutil/helpers.go @@ -19,14 +19,9 @@ import ( func ExecInitCmd(mm *module.Manager, home string, cdc codec.Codec) error { logger := log.NewNopLogger() - cfg, err := CreateDefaultCometConfig(home) - if err != nil { - return err - } - cmd := genutilcli.InitCmd(mm) - serverCtx := server.NewContext(viper.New(), cfg, logger) - serverCtx.Config.SetRoot(home) + serverCtx := server.NewContext(viper.New(), logger) + serverCtx.SetRoot(home) clientCtx := client.Context{}.WithCodec(cdc).WithHomeDir(home) _, out := testutil.ApplyMockIO(cmd) From 620509ec86cf25cd3128ef749bda83d45b29552c Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Tue, 7 May 2024 15:59:23 +0700 Subject: [PATCH 02/29] remove toolchain --- core/go.mod | 23 +------- core/go.sum | 165 ---------------------------------------------------- 2 files changed, 1 insertion(+), 187 deletions(-) diff --git a/core/go.mod b/core/go.mod index 6f6e9c9b05dc..c50a823e0999 100644 --- a/core/go.mod +++ b/core/go.mod @@ -1,12 +1,9 @@ module cosmossdk.io/core -go 1.21 - -toolchain go1.22.2 +go 1.20 require ( cosmossdk.io/log v1.3.1 - github.com/cometbft/cometbft v0.38.7 github.com/cosmos/gogoproto v1.4.12 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.2 @@ -16,26 +13,11 @@ require ( ) require ( - github.com/cespare/xxhash v1.1.0 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/cometbft/cometbft-db v0.7.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dgraph-io/badger/v2 v2.2007.4 // indirect - github.com/dgraph-io/ristretto v0.1.1 // indirect - github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect - github.com/dustin/go-humanize v1.0.1 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/go-kit/log v0.2.1 // indirect - github.com/go-logfmt/logfmt v0.6.0 // indirect - github.com/golang/glog v1.2.0 // indirect - github.com/golang/protobuf v1.5.4 // indirect - github.com/golang/snappy v0.0.4 // indirect - github.com/google/btree v1.1.2 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/jmhodges/levigo v1.0.0 // indirect - github.com/klauspost/compress v1.17.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -52,9 +34,6 @@ require ( github.com/spf13/cast v1.6.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.6.0 // indirect - github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect - github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect - go.etcd.io/bbolt v1.3.6 // indirect go.uber.org/multierr v1.10.0 // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/net v0.24.0 // indirect diff --git a/core/go.sum b/core/go.sum index 5aa67d98514a..32758fd7cd3c 100644 --- a/core/go.sum +++ b/core/go.sum @@ -1,105 +1,28 @@ cosmossdk.io/log v1.3.1 h1:UZx8nWIkfbbNEWusZqzAx3ZGvu54TZacWib3EzUYmGI= cosmossdk.io/log v1.3.1/go.mod h1:2/dIomt8mKdk6vl3OWJcPk2be3pGOS8OQaLUM/3/tCM= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= -github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= -github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cometbft/cometbft v0.38.7 h1:ULhIOJ9+LgSy6nLekhq9ae3juX3NnQUMMPyVdhZV6Hk= -github.com/cometbft/cometbft v0.38.7/go.mod h1:HIyf811dFMI73IE0F7RrnY/Fr+d1+HuJAgtkEpQjCMY= -github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo= -github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= -github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cosmos/gogoproto v1.4.12 h1:vB6Lbe/rtnYGjQuFxkPiPYiCybqFT8QvLipDZP8JpFE= github.com/cosmos/gogoproto v1.4.12/go.mod h1:LnZob1bXRdUoqMMtwYlcR3wjiElmlC+FkjaZRv1/eLY= -github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= -github.com/dgraph-io/badger/v2 v2.2007.4 h1:TRWBQg8UrlUhaFdco01nO2uXwzKS7zd+HVdwV/GHc4o= -github.com/dgraph-io/badger/v2 v2.2007.4/go.mod h1:vSw/ax2qojzbN6eXHIx6KPKtCSHJN/Uz0X0VPruTIhk= -github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= -github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8= -github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA= -github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y= -github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= -github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= -github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= -github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= -github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= -github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk= -github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= -github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= -github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= -github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= -github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= -github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= -github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= -github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= -github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= -github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U= -github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ= -github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= -github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM= -github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -108,27 +31,10 @@ 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/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae h1:FatpGJD2jmJfhZiFDElaC0QhZUDQnxUeAwTGkfAHN3I= -github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= -github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= -github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= -github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -139,40 +45,26 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= -github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= -github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0= -github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= -github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= -github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= -github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= -github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= @@ -180,88 +72,31 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= -github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= -github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzHWCjJB1zZfXPIAaDpzXIEJ0eS6B5Ok= -github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= -github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= -github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= -go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4= google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= -gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= From 67e13d1fc4018a98e590a99e0b80674584789fc3 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Tue, 7 May 2024 16:11:06 +0700 Subject: [PATCH 03/29] fix build simapp --- simapp/simd/cmd/testnet.go | 4 ++-- simapp/simd/cmd/testnet_test.go | 2 +- simapp/test_helpers.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 9ae538f00f36..8222e05ef9f5 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -141,7 +141,7 @@ Example: } serverCtx := server.GetServerContextFromCmd(cmd) - config := serverCtx.Config + config := serverCtx.GetConfig().(server.CometConfig) args := initArgs{} args.outputDir, _ = cmd.Flags().GetString(flagOutputDir) @@ -161,7 +161,7 @@ Example: return err } - return initTestnetFiles(clientCtx, cmd, config, mm, genBalIterator, args) + return initTestnetFiles(clientCtx, cmd, config.Config, mm, genBalIterator, args) }, } diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index 58e93e130d52..de253f3c870f 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -57,7 +57,7 @@ func Test_TestnetCmd(t *testing.T) { err = genutiltest.ExecInitCmd(moduleManager, home, encodingConfig.Codec) require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), cfg, logger) + serverCtx := server.NewContext(viper.New(), logger) clientCtx := client.Context{}. WithCodec(encodingConfig.Codec). WithHomeDir(home). diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 9db7b92bd354..21330c0c6fd2 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -229,7 +229,7 @@ func NewTestNetworkFixture() network.TestFixture { appCtr := func(val network.ValidatorI) servertypes.Application { return NewSimApp( val.GetCtx().Logger, dbm.NewMemDB(), nil, true, - simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().Config.RootDir), + simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().GetConfig().(server.CometConfig).RootDir), bam.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), bam.SetMinGasPrices(val.GetAppConfig().MinGasPrices), bam.SetChainID(val.GetCtx().Viper.GetString(flags.FlagChainID)), From 16c293b36e29c6acc53b58131e4cbed9f5790c50 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Tue, 7 May 2024 16:16:22 +0700 Subject: [PATCH 04/29] fix --- server/util.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/util.go b/server/util.go index a3bdf148df99..2b37295ed472 100644 --- a/server/util.go +++ b/server/util.go @@ -86,7 +86,8 @@ func (ctx *Context) SetRoot(rootDir string) { } func (config CometConfig) SetRoot(root string) corectx.CometConfig { - return config.SetRoot(root) + config.Config.SetRoot(root) + return config } func GetCometConfigFromViper(v *viper.Viper) corectx.CometConfig { From c46359d557194cc045bce64a3e8ad283eb82629f Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 8 May 2024 13:04:57 +0700 Subject: [PATCH 05/29] fix init test --- x/genutil/client/cli/init.go | 3 ++- x/genutil/client/cli/init_test.go | 23 +++++++++++++++-------- x/genutil/client/testutil/helpers.go | 26 +++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index d509ac42da66..7f8bb6abf246 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -15,6 +15,7 @@ import ( errorsmod "cosmossdk.io/errors" "cosmossdk.io/math/unsafe" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -81,7 +82,7 @@ func InitCmd(mm *module.Manager) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - serverCtx := server.GetServerContextFromCmd(cmd) + serverCtx := corectx.GetServerContextFromCmd(cmd) config, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { return fmt.Errorf("Can not convert cometbft config") diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index e683cd5fa4bd..abe300ce09da 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -13,6 +13,7 @@ import ( "github.com/spf13/viper" "github.com/stretchr/testify/require" + corectx "cosmossdk.io/core/context" "cosmossdk.io/log" "cosmossdk.io/x/staking" @@ -65,6 +66,7 @@ func TestInitCmd(t *testing.T) { logger := log.NewNopLogger() serverCtx := server.NewContext(viper.New(), logger) + genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -74,7 +76,7 @@ func TestInitCmd(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) cmd := genutilcli.InitCmd(testMbm) cmd.SetArgs( @@ -96,6 +98,7 @@ func TestInitRecover(t *testing.T) { logger := log.NewNopLogger() serverCtx := server.NewContext(viper.New(), logger) + genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -105,7 +108,7 @@ func TestInitRecover(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) cmd := genutilcli.InitCmd(testMbm) mockIn := testutil.ApplyMockIODiscardOutErr(cmd) @@ -125,6 +128,7 @@ func TestInitDefaultBondDenom(t *testing.T) { logger := log.NewNopLogger() serverCtx := server.NewContext(viper.New(), logger) + genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -134,7 +138,7 @@ func TestInitDefaultBondDenom(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) cmd := genutilcli.InitCmd(testMbm) @@ -150,7 +154,7 @@ func TestEmptyState(t *testing.T) { logger := log.NewNopLogger() serverCtx := server.NewContext(viper.New(), logger) - serverCtx.SetRoot(home) + genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -160,7 +164,7 @@ func TestEmptyState(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) cmd := genutilcli.InitCmd(testMbm) cmd.SetArgs([]string{"appnode-test"}) @@ -242,6 +246,7 @@ func TestInitConfig(t *testing.T) { logger := log.NewNopLogger() serverCtx := server.NewContext(viper.New(), logger) + genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -252,7 +257,7 @@ func TestInitConfig(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) cmd := genutilcli.InitCmd(testMbm) cmd.SetArgs([]string{"testnode"}) @@ -288,6 +293,7 @@ func TestInitWithHeight(t *testing.T) { require.NoError(t, err) serverCtx := server.NewContext(viper.New(), logger) + genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -298,7 +304,7 @@ func TestInitWithHeight(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) testInitialHeight := int64(333) @@ -320,6 +326,7 @@ func TestInitWithNegativeHeight(t *testing.T) { require.NoError(t, err) serverCtx := server.NewContext(viper.New(), logger) + genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -330,7 +337,7 @@ func TestInitWithNegativeHeight(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) testInitialHeight := int64(-333) diff --git a/x/genutil/client/testutil/helpers.go b/x/genutil/client/testutil/helpers.go index 79a2b5e6119c..265f3e805a72 100644 --- a/x/genutil/client/testutil/helpers.go +++ b/x/genutil/client/testutil/helpers.go @@ -3,13 +3,16 @@ package testutil import ( "context" "fmt" + "path/filepath" cmtcfg "github.com/cometbft/cometbft/config" "github.com/spf13/viper" + corectx "cosmossdk.io/core/context" "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/testutil" @@ -21,7 +24,7 @@ func ExecInitCmd(mm *module.Manager, home string, cdc codec.Codec) error { logger := log.NewNopLogger() cmd := genutilcli.InitCmd(mm) serverCtx := server.NewContext(viper.New(), logger) - serverCtx.SetRoot(home) + WriteAndTrackConfig(serverCtx.GetViper(), home) clientCtx := client.Context{}.WithCodec(cdc).WithHomeDir(home) _, out := testutil.ApplyMockIO(cmd) @@ -29,11 +32,13 @@ func ExecInitCmd(mm *module.Manager, home string, cdc codec.Codec) error { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) cmd.SetArgs([]string{"appnode-test"}) - return cmd.ExecuteContext(ctx) + err := cmd.ExecuteContext(ctx) + + return err } func CreateDefaultCometConfig(rootDir string) (*cmtcfg.Config, error) { @@ -47,3 +52,18 @@ func CreateDefaultCometConfig(rootDir string) (*cmtcfg.Config, error) { return conf, nil } + +func WriteAndTrackConfig(v *viper.Viper, home string) error { + cfg, err := CreateDefaultCometConfig(home) + if err != nil { + return err + } + + cmtcfg.WriteConfigFile(filepath.Join(home, "config", "config.toml"), cfg) + + v.Set(flags.FlagHome, home) + v.SetConfigType("toml") + v.SetConfigName("config") + v.AddConfigPath(filepath.Join(home, "config")) + return v.ReadInConfig() +} From 95b2c29c1c6182a0385107d50ff4e5414e48d4e0 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 8 May 2024 13:23:15 +0700 Subject: [PATCH 06/29] fix export tests --- x/genutil/client/cli/export_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/genutil/client/cli/export_test.go b/x/genutil/client/cli/export_test.go index 67224ecb228d..464add01169d 100644 --- a/x/genutil/client/cli/export_test.go +++ b/x/genutil/client/cli/export_test.go @@ -25,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/cmdtest" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + gentestutil "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -68,7 +69,7 @@ func NewExportSystem(t *testing.T, exporter types.AppExporter) *ExportSystem { viper.New(), log.NewCustomLogger(zerolog.New(tw)), ) - sCtx.SetRoot(homeDir) + gentestutil.WriteAndTrackConfig(sCtx.GetViper(), homeDir) cCtx := (client.Context{}).WithHomeDir(homeDir) From 467428ebf2baf69fe0912be40ce52a6f55b080c6 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 8 May 2024 14:36:14 +0700 Subject: [PATCH 07/29] network track config --- testutil/network/network.go | 3 +++ x/genutil/client/cli/export_test.go | 3 +-- x/genutil/client/cli/init_test.go | 19 ++++++++++++------- x/genutil/client/testutil/helpers.go | 10 +++------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/testutil/network/network.go b/testutil/network/network.go index 251a0ade9e07..4de152cc9c6c 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -57,6 +57,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/genutil" + gentestutil "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" ) // package-wide network lock to only allow one test network at a time @@ -433,6 +434,8 @@ func New(l Logger, baseDir string, cfg Config) (NetworkI, error) { cmtCfg.P2P.AddrBookStrict = false cmtCfg.P2P.AllowDuplicateIP = true + // write comet config file and track by viper + gentestutil.WriteAndTrackConfig(ctx.GetViper(), nodeDir, cmtCfg.Config) var mnemonic string if i < len(cfg.Mnemonics) { mnemonic = cfg.Mnemonics[i] diff --git a/x/genutil/client/cli/export_test.go b/x/genutil/client/cli/export_test.go index 464add01169d..c79d0d83173f 100644 --- a/x/genutil/client/cli/export_test.go +++ b/x/genutil/client/cli/export_test.go @@ -25,7 +25,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/cmdtest" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" - gentestutil "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -69,7 +68,7 @@ func NewExportSystem(t *testing.T, exporter types.AppExporter) *ExportSystem { viper.New(), log.NewCustomLogger(zerolog.New(tw)), ) - gentestutil.WriteAndTrackConfig(sCtx.GetViper(), homeDir) + writeAndTrackDefaultConfig(sCtx.GetViper(), homeDir) cCtx := (client.Context{}).WithHomeDir(homeDir) diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index abe300ce09da..42267453a1b0 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -66,7 +66,7 @@ func TestInitCmd(t *testing.T) { logger := log.NewNopLogger() serverCtx := server.NewContext(viper.New(), logger) - genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -98,7 +98,7 @@ func TestInitRecover(t *testing.T) { logger := log.NewNopLogger() serverCtx := server.NewContext(viper.New(), logger) - genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -128,7 +128,7 @@ func TestInitDefaultBondDenom(t *testing.T) { logger := log.NewNopLogger() serverCtx := server.NewContext(viper.New(), logger) - genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -154,7 +154,7 @@ func TestEmptyState(t *testing.T) { logger := log.NewNopLogger() serverCtx := server.NewContext(viper.New(), logger) - genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -246,7 +246,7 @@ func TestInitConfig(t *testing.T) { logger := log.NewNopLogger() serverCtx := server.NewContext(viper.New(), logger) - genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -293,7 +293,7 @@ func TestInitWithHeight(t *testing.T) { require.NoError(t, err) serverCtx := server.NewContext(viper.New(), logger) - genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -326,7 +326,7 @@ func TestInitWithNegativeHeight(t *testing.T) { require.NoError(t, err) serverCtx := server.NewContext(viper.New(), logger) - genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(serverCtx.GetViper(), home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -364,3 +364,8 @@ func makeCodec() codec.Codec { interfaceRegistry := types.NewInterfaceRegistry() return codec.NewProtoCodec(interfaceRegistry) } + +func writeAndTrackDefaultConfig(v *viper.Viper, home string) { + cfg, _ := genutiltest.CreateDefaultCometConfig(home) + genutiltest.WriteAndTrackConfig(v, home, cfg) +} diff --git a/x/genutil/client/testutil/helpers.go b/x/genutil/client/testutil/helpers.go index 265f3e805a72..23950e3743cb 100644 --- a/x/genutil/client/testutil/helpers.go +++ b/x/genutil/client/testutil/helpers.go @@ -24,7 +24,8 @@ func ExecInitCmd(mm *module.Manager, home string, cdc codec.Codec) error { logger := log.NewNopLogger() cmd := genutilcli.InitCmd(mm) serverCtx := server.NewContext(viper.New(), logger) - WriteAndTrackConfig(serverCtx.GetViper(), home) + cfg, _ := CreateDefaultCometConfig(home) + WriteAndTrackConfig(serverCtx.GetViper(), home, cfg) clientCtx := client.Context{}.WithCodec(cdc).WithHomeDir(home) _, out := testutil.ApplyMockIO(cmd) @@ -53,12 +54,7 @@ func CreateDefaultCometConfig(rootDir string) (*cmtcfg.Config, error) { return conf, nil } -func WriteAndTrackConfig(v *viper.Viper, home string) error { - cfg, err := CreateDefaultCometConfig(home) - if err != nil { - return err - } - +func WriteAndTrackConfig(v *viper.Viper, home string, cfg *cmtcfg.Config) error { cmtcfg.WriteConfigFile(filepath.Join(home, "config", "config.toml"), cfg) v.Set(flags.FlagHome, home) From b9a72782a2212cfd3649b69b61bc67a4f4abd7b5 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 8 May 2024 14:51:20 +0700 Subject: [PATCH 08/29] fix gen test --- simapp/simd/cmd/testnet_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index de253f3c870f..f9de7173373e 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -58,6 +58,8 @@ func Test_TestnetCmd(t *testing.T) { require.NoError(t, err) serverCtx := server.NewContext(viper.New(), logger) + err = genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home, cfg) + require.NoError(t, err) clientCtx := client.Context{}. WithCodec(encodingConfig.Codec). WithHomeDir(home). From e8d9242a95bbe6f6f593c0c1977db064f9e00bdf Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 8 May 2024 15:24:06 +0700 Subject: [PATCH 09/29] fix gen_acc test --- x/genutil/client/cli/genaccount_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/genutil/client/cli/genaccount_test.go b/x/genutil/client/cli/genaccount_test.go index 0950a28cfb35..3e3402f9c0cf 100644 --- a/x/genutil/client/cli/genaccount_test.go +++ b/x/genutil/client/cli/genaccount_test.go @@ -77,6 +77,7 @@ func TestAddGenesisAccountCmd(t *testing.T) { require.NoError(t, err) serverCtx := server.NewContext(viper.New(), logger) + writeAndTrackDefaultConfig(serverCtx.Viper, home) clientCtx := client.Context{}.WithCodec(appCodec).WithHomeDir(home).WithAddressCodec(ac) if tc.withKeyring { From 77c3bc1e150239b21c5b686bb4d922501ac62d5f Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 8 May 2024 21:23:11 +0700 Subject: [PATCH 10/29] fix e2e err --- tests/e2e/genutil/export_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/e2e/genutil/export_test.go b/tests/e2e/genutil/export_test.go index d60c40ff1f74..78b71d6c58a4 100644 --- a/tests/e2e/genutil/export_test.go +++ b/tests/e2e/genutil/export_test.go @@ -20,6 +20,7 @@ import ( "cosmossdk.io/log" "cosmossdk.io/simapp" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -27,8 +28,10 @@ import ( "github.com/cosmos/cosmos-sdk/server/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/x/genutil" + gentestutil "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + cmtcfg "github.com/cometbft/cometbft/config" ) func TestExportCmd_ConsensusParams(t *testing.T) { @@ -55,8 +58,8 @@ func TestExportCmd_ConsensusParams(t *testing.T) { func TestExportCmd_HomeDir(t *testing.T) { _, ctx, _, cmd := setupApp(t, t.TempDir()) - serverCtxPtr := ctx.Value(server.ServerContextKey) - serverCtxPtr.(*server.Context).Config.SetRoot("foobar") + serverCtxPtr := ctx.Value(corectx.ServerContextKey) + serverCtxPtr.(corectx.ServerContext).GetConfig().SetRoot("foobar") err := cmd.ExecuteContext(ctx) assert.ErrorContains(t, err, "stat foobar/config/genesis.json: no such file or directory") @@ -169,7 +172,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, ge assert.NilError(t, err) serverCtx := server.NewDefaultContext() - serverCtx.Config.RootDir = tempDir + gentestutil.WriteAndTrackConfig(serverCtx.GetViper(), tempDir, cmtcfg.DefaultConfig()) clientCtx := client.Context{}.WithCodec(app.AppCodec()) appGenesis := genutiltypes.AppGenesis{ @@ -181,7 +184,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, ge } // save genesis file - err = genutil.ExportGenesisFile(&appGenesis, serverCtx.Config.GenesisFile()) + err = genutil.ExportGenesisFile(&appGenesis, serverCtx.GetConfig().GenesisFile()) assert.NilError(t, err) _, err = app.InitChain(&abci.InitChainRequest{ From 0b8808ee675377741b01ce223fa64f839a9849cb Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 9 May 2024 01:52:14 +0700 Subject: [PATCH 11/29] rename --- core/context/context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/context/context.go b/core/context/context.go index 4c3ab156dd8a..6147dc7871ae 100644 --- a/core/context/context.go +++ b/core/context/context.go @@ -1,4 +1,4 @@ -package appmodule +package context // ExecMode defines the execution mode which can be set on a Context. type ExecMode uint8 From 6c9992df1f28fd4a7dc5c7197969d7d6e30fd7d3 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 9 May 2024 02:09:48 +0700 Subject: [PATCH 12/29] clean up --- client/snapshot/delete.go | 5 +- client/snapshot/dump.go | 5 +- client/snapshot/export.go | 7 +- client/snapshot/list.go | 5 +- client/snapshot/load.go | 5 +- client/snapshot/restore.go | 7 +- core/context/server_context.go | 3 - server/cmt_cmds.go | 15 +++-- server/rollback.go | 7 +- server/start.go | 85 ++++++++++++------------ server/util.go | 38 ++++------- server/util_test.go | 19 +++--- simapp/simd/cmd/testnet.go | 3 +- x/genutil/client/cli/collect.go | 3 +- x/genutil/client/cli/export.go | 9 +-- x/genutil/client/cli/genaccount.go | 3 +- x/genutil/client/cli/gentx.go | 3 +- x/genutil/client/cli/validate_genesis.go | 3 +- 18 files changed, 114 insertions(+), 111 deletions(-) diff --git a/client/snapshot/delete.go b/client/snapshot/delete.go index 3bf322982925..3b5a2d715f1d 100644 --- a/client/snapshot/delete.go +++ b/client/snapshot/delete.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/server" ) @@ -14,7 +15,7 @@ func DeleteSnapshotCmd() *cobra.Command { Short: "Delete a local snapshot", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - ctx := server.GetServerContextFromCmd(cmd) + ctx := corectx.GetServerContextFromCmd(cmd) height, err := strconv.ParseUint(args[0], 10, 64) if err != nil { @@ -25,7 +26,7 @@ func DeleteSnapshotCmd() *cobra.Command { return err } - snapshotStore, err := server.GetSnapshotStore(ctx.Viper) + snapshotStore, err := server.GetSnapshotStore(ctx.GetViper()) if err != nil { return err } diff --git a/client/snapshot/dump.go b/client/snapshot/dump.go index 098f5ee6b3f5..12bb4f570c9c 100644 --- a/client/snapshot/dump.go +++ b/client/snapshot/dump.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/cobra" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/server" ) @@ -21,8 +22,8 @@ func DumpArchiveCmd() *cobra.Command { Short: "Dump the snapshot as portable archive format", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - ctx := server.GetServerContextFromCmd(cmd) - snapshotStore, err := server.GetSnapshotStore(ctx.Viper) + ctx := corectx.GetServerContextFromCmd(cmd) + snapshotStore, err := server.GetSnapshotStore(ctx.GetViper()) if err != nil { return err } diff --git a/client/snapshot/export.go b/client/snapshot/export.go index a43858deefa5..20c2757beb98 100644 --- a/client/snapshot/export.go +++ b/client/snapshot/export.go @@ -7,6 +7,7 @@ import ( "cosmossdk.io/log" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" ) @@ -18,7 +19,7 @@ func ExportSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCrea Short: "Export app state to snapshot store", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - ctx := server.GetServerContextFromCmd(cmd) + ctx := corectx.GetServerContextFromCmd(cmd) cfg, ok := ctx.GetConfig().(server.CometConfig) if !ok { return fmt.Errorf("Can not convert cometbft config") @@ -30,12 +31,12 @@ func ExportSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCrea } home := cfg.RootDir - db, err := openDB(home, server.GetAppDBBackend(ctx.Viper)) + db, err := openDB(home, server.GetAppDBBackend(ctx.GetViper())) if err != nil { return err } logger := log.NewLogger(cmd.OutOrStdout()) - app := appCreator(logger, db, nil, ctx.Viper) + app := appCreator(logger, db, nil, ctx.GetViper()) if height == 0 { height = app.CommitMultiStore().LastCommitID().Version diff --git a/client/snapshot/list.go b/client/snapshot/list.go index 501bfd7c5291..0d02192848a2 100644 --- a/client/snapshot/list.go +++ b/client/snapshot/list.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/server" ) @@ -13,8 +14,8 @@ var ListSnapshotsCmd = &cobra.Command{ Use: "list", Short: "List local snapshots", RunE: func(cmd *cobra.Command, args []string) error { - ctx := server.GetServerContextFromCmd(cmd) - snapshotStore, err := server.GetSnapshotStore(ctx.Viper) + ctx := corectx.GetServerContextFromCmd(cmd) + snapshotStore, err := server.GetSnapshotStore(ctx.GetViper()) if err != nil { return err } diff --git a/client/snapshot/load.go b/client/snapshot/load.go index ba37d214061e..4d2db550066b 100644 --- a/client/snapshot/load.go +++ b/client/snapshot/load.go @@ -14,6 +14,7 @@ import ( snapshottypes "cosmossdk.io/store/snapshots/types" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/server" ) @@ -26,8 +27,8 @@ func LoadArchiveCmd() *cobra.Command { Short: "Load a snapshot archive file (.tar.gz) into snapshot store", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - ctx := server.GetServerContextFromCmd(cmd) - snapshotStore, err := server.GetSnapshotStore(ctx.Viper) + ctx := corectx.GetServerContextFromCmd(cmd) + snapshotStore, err := server.GetSnapshotStore(ctx.GetViper()) if err != nil { return err } diff --git a/client/snapshot/restore.go b/client/snapshot/restore.go index 1c6df23ce764..cbd0d8134d14 100644 --- a/client/snapshot/restore.go +++ b/client/snapshot/restore.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" + corectx "cosmossdk.io/core/context" ) // RestoreSnapshotCmd returns a command to restore a snapshot @@ -22,7 +23,7 @@ func RestoreSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCre Long: "Restore app state from local snapshot", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - ctx := server.GetServerContextFromCmd(cmd) + ctx := corectx.GetServerContextFromCmd(cmd) cfg, ok := ctx.GetConfig().(server.CometConfig) if !ok { return fmt.Errorf("Can not convert cometbft config") @@ -38,12 +39,12 @@ func RestoreSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCre } home := cfg.RootDir - db, err := openDB(home, server.GetAppDBBackend(ctx.Viper)) + db, err := openDB(home, server.GetAppDBBackend(ctx.GetViper())) if err != nil { return err } logger := log.NewLogger(cmd.OutOrStdout()) - app := appCreator(logger, db, nil, ctx.Viper) + app := appCreator(logger, db, nil, ctx.GetViper()) sm := app.SnapshotManager() return sm.RestoreLocalSnapshot(height, uint32(format)) diff --git a/core/context/server_context.go b/core/context/server_context.go index dbd71127e3e4..5f36b8d09a41 100644 --- a/core/context/server_context.go +++ b/core/context/server_context.go @@ -1,8 +1,6 @@ package context import ( - "fmt" - "github.com/spf13/cobra" "github.com/spf13/viper" @@ -36,7 +34,6 @@ type CometConfig interface { func GetServerContextFromCmd(cmd *cobra.Command) ServerContext { if v := cmd.Context().Value(ServerContextKey); v != nil { - fmt.Println("serverCtxPtr", v) serverCtxPtr := v.(ServerContext) return serverCtxPtr } diff --git a/server/cmt_cmds.go b/server/cmt_cmds.go index 8397ddb76cc5..8e107e99c530 100644 --- a/server/cmt_cmds.go +++ b/server/cmt_cmds.go @@ -19,6 +19,7 @@ import ( "cosmossdk.io/log" auth "cosmossdk.io/x/auth/client/cli" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" @@ -73,7 +74,7 @@ func ShowNodeIDCmd() *cobra.Command { Use: "show-node-id", Short: "Show this node's ID", RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := GetServerContextFromCmd(cmd) + serverCtx := corectx.GetServerContextFromCmd(cmd) cfg, ok := serverCtx.GetConfig().(CometConfig) if !ok { return fmt.Errorf("Can not convert cometbft config") @@ -96,7 +97,7 @@ func ShowValidatorCmd() *cobra.Command { Use: "show-validator", Short: "Show this node's CometBFT validator info", RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := GetServerContextFromCmd(cmd) + serverCtx := corectx.GetServerContextFromCmd(cmd) cfg, ok := serverCtx.GetConfig().(CometConfig) if !ok { return fmt.Errorf("Can not convert cometbft config") @@ -133,7 +134,7 @@ func ShowAddressCmd() *cobra.Command { Use: "show-address", Short: "Shows this node's CometBFT validator consensus address", RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := GetServerContextFromCmd(cmd) + serverCtx := corectx.GetServerContextFromCmd(cmd) cfg, ok := serverCtx.GetConfig().(CometConfig) if !ok { return fmt.Errorf("Can not convert cometbft config") @@ -371,7 +372,7 @@ func BootstrapStateCmd[T types.Application](appCreator types.AppCreator[T]) *cob Short: "Bootstrap CometBFT state at an arbitrary block height using a light client", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := GetServerContextFromCmd(cmd) + serverCtx := corectx.GetServerContextFromCmd(cmd) logger := log.NewLogger(cmd.OutOrStdout()) cfg, ok := serverCtx.GetConfig().(CometConfig) if !ok { @@ -383,13 +384,13 @@ func BootstrapStateCmd[T types.Application](appCreator types.AppCreator[T]) *cob return err } if height == 0 { - home := serverCtx.Viper.GetString(flags.FlagHome) - db, err := OpenDB(home, GetAppDBBackend(serverCtx.Viper)) + home := serverCtx.GetViper().GetString(flags.FlagHome) + db, err := OpenDB(home, GetAppDBBackend(serverCtx.GetViper())) if err != nil { return err } - app := appCreator(logger, db, nil, serverCtx.Viper) + app := appCreator(logger, db, nil, serverCtx.GetViper()) height = app.CommitMultiStore().LastCommitID().Version } diff --git a/server/rollback.go b/server/rollback.go index e678edc2b1fb..e43c6422de5c 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -6,6 +6,7 @@ import ( cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" "github.com/spf13/cobra" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/server/types" ) @@ -25,18 +26,18 @@ restarting CometBFT the transactions in block n will be re-executed against the application. `, RunE: func(cmd *cobra.Command, args []string) error { - ctx := GetServerContextFromCmd(cmd) + ctx := corectx.GetServerContextFromCmd(cmd) config, ok := ctx.GetConfig().(CometConfig) if !ok { return fmt.Errorf("Can not convert cometbft config") } - db, err := OpenDB(config.RootDir, GetAppDBBackend(ctx.Viper)) + db, err := OpenDB(config.RootDir, GetAppDBBackend(ctx.GetViper())) if err != nil { return err } - app := appCreator(ctx.Logger, db, nil, ctx.Viper) + app := appCreator(ctx.GetLogger(), db, nil, ctx.GetViper()) // rollback CometBFT state height, hash, err := cmtcmd.RollbackState(config.Config, removeBlock) if err != nil { diff --git a/server/start.go b/server/start.go index f6839e7d4a29..0dfac914a0f1 100644 --- a/server/start.go +++ b/server/start.go @@ -39,6 +39,7 @@ import ( "cosmossdk.io/log" pruningtypes "cosmossdk.io/store/pruning/types" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server/api" @@ -177,8 +178,8 @@ bypassed and can be used when legacy queries are needed after an on-chain upgrad is performed. Note, when enabled, gRPC will also be automatically enabled. `, RunE: func(cmd *cobra.Command, _ []string) error { - serverCtx := GetServerContextFromCmd(cmd) - _, err := GetPruningOptionsFromFlags(serverCtx.Viper) + serverCtx := corectx.GetServerContextFromCmd(cmd).(*Context) + _, err := GetPruningOptionsFromFlags(serverCtx.GetViper()) if err != nil { return err } @@ -190,19 +191,19 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. withCMT, _ := cmd.Flags().GetBool(flagWithComet) if !withCMT { - serverCtx.Logger.Info("starting ABCI without CometBFT") + serverCtx.GetLogger().Info("starting ABCI without CometBFT") } err = wrapCPUProfile(serverCtx, func() error { return opts.StartCommandHandler(serverCtx, clientCtx, appCreator, withCMT, opts) }) - serverCtx.Logger.Debug("received quit signal") + serverCtx.GetLogger().Debug("received quit signal") graceDuration, _ := cmd.Flags().GetDuration(FlagShutdownGrace) if graceDuration > 0 { - serverCtx.Logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration) + serverCtx.GetLogger().Info("graceful shutdown start", FlagShutdownGrace, graceDuration) <-time.After(graceDuration) - serverCtx.Logger.Info("graceful shutdown complete") + serverCtx.GetLogger().Info("graceful shutdown complete") } return err @@ -239,8 +240,8 @@ func start[T types.Application](svrCtx *Context, clientCtx client.Context, appCr } func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app T, metrics *telemetry.Metrics, opts StartCmdOptions[T]) error { - addr := svrCtx.Viper.GetString(flagAddress) - transport := svrCtx.Viper.GetString(flagTransport) + addr := svrCtx.GetViper().GetString(flagAddress) + transport := svrCtx.GetViper().GetString(flagTransport) cmtApp := NewCometABCIWrapper(app) svr, err := server.NewServer(addr, transport, cmtApp) @@ -248,7 +249,7 @@ func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.C return fmt.Errorf("error creating listener: %w", err) } - svr.SetLogger(servercmtlog.CometLoggerWrapper{Logger: svrCtx.Logger.With("module", "abci-server")}) + svr.SetLogger(servercmtlog.CometLoggerWrapper{Logger: svrCtx.GetLogger().With("module", "abci-server")}) g, ctx := getCtx(svrCtx, false) @@ -295,14 +296,14 @@ func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.C g.Go(func() error { if err := svr.Start(); err != nil { - svrCtx.Logger.Error("failed to start out-of-process ABCI server", "err", err) + svrCtx.GetLogger().Error("failed to start out-of-process ABCI server", "err", err) return err } // Wait for the calling process to be canceled or close the provided context, // so we can gracefully stop the ABCI server. <-ctx.Done() - svrCtx.Logger.Info("stopping the ABCI server...") + svrCtx.GetLogger().Info("stopping the ABCI server...") return svr.Stop() }) @@ -316,16 +317,16 @@ func startInProcess[T types.Application](svrCtx *Context, svrCfg serverconfig.Co if !ok { return fmt.Errorf("Can not convert cometbft config") } - gRPCOnly := svrCtx.Viper.GetBool(flagGRPCOnly) + gRPCOnly := svrCtx.GetViper().GetBool(flagGRPCOnly) g, ctx := getCtx(svrCtx, true) if gRPCOnly { // TODO: Generalize logic so that gRPC only is really in startStandAlone - svrCtx.Logger.Info("starting node in gRPC only mode; CometBFT is disabled") + svrCtx.GetLogger().Info("starting node in gRPC only mode; CometBFT is disabled") svrCfg.GRPC.Enable = true } else { - svrCtx.Logger.Info("starting node with ABCI CometBFT in-process") + svrCtx.GetLogger().Info("starting node with ABCI CometBFT in-process") tmNode, cleanupFn, err := startCmtNode(ctx, cmtCfg.Config, app, svrCtx) if err != nil { return err @@ -389,7 +390,7 @@ func startCmtNode( getGenDocProvider(cfg), cmtcfg.DefaultDBProvider, node.DefaultMetricsProvider(cfg.Instrumentation), - servercmtlog.CometLoggerWrapper{Logger: svrCtx.Logger}, + servercmtlog.CometLoggerWrapper{Logger: svrCtx.GetLogger()}, ) if err != nil { return tmNode, cleanupFn, err @@ -409,7 +410,7 @@ func startCmtNode( } func getAndValidateConfig(svrCtx *Context) (serverconfig.Config, error) { - config, err := serverconfig.GetConfig(svrCtx.Viper) + config, err := serverconfig.GetConfig(svrCtx.GetViper()) if err != nil { return config, err } @@ -522,7 +523,7 @@ func startGrpcServer( } clientCtx = clientCtx.WithGRPCClient(grpcClient) - svrCtx.Logger.Debug("gRPC client assigned to client context", "target", config.Address) + svrCtx.GetLogger().Debug("gRPC client assigned to client context", "target", config.Address) grpcSrv, err := servergrpc.NewGRPCServer(clientCtx, app, config) if err != nil { @@ -532,7 +533,7 @@ func startGrpcServer( // Start the gRPC server in a goroutine. Note, the provided ctx will ensure // that the server is gracefully shut down. g.Go(func() error { - return servergrpc.StartGRPCServer(ctx, svrCtx.Logger.With("module", "grpc-server"), config, grpcSrv) + return servergrpc.StartGRPCServer(ctx, svrCtx.GetLogger().With("module", "grpc-server"), config, grpcSrv) }) return grpcSrv, clientCtx, nil } @@ -554,7 +555,7 @@ func startAPIServer( clientCtx = clientCtx.WithHomeDir(home) - apiSrv := api.New(clientCtx, svrCtx.Logger.With("module", "api-server"), grpcSrv) + apiSrv := api.New(clientCtx, svrCtx.GetLogger().With("module", "api-server"), grpcSrv) app.RegisterAPIRoutes(apiSrv, svrCfg.API) if svrCfg.Telemetry.Enabled { @@ -577,24 +578,24 @@ func startTelemetry(cfg serverconfig.Config) (*telemetry.Metrics, error) { // // NOTE: We expect the caller to handle graceful shutdown and signal handling. func wrapCPUProfile(svrCtx *Context, callbackFn func() error) error { - if cpuProfile := svrCtx.Viper.GetString(flagCPUProfile); cpuProfile != "" { + if cpuProfile := svrCtx.GetViper().GetString(flagCPUProfile); cpuProfile != "" { f, err := os.Create(cpuProfile) if err != nil { return err } - svrCtx.Logger.Info("starting CPU profiler", "profile", cpuProfile) + svrCtx.GetLogger().Info("starting CPU profiler", "profile", cpuProfile) if err := pprof.StartCPUProfile(f); err != nil { return err } defer func() { - svrCtx.Logger.Info("stopping CPU profiler", "profile", cpuProfile) + svrCtx.GetLogger().Info("stopping CPU profiler", "profile", cpuProfile) pprof.StopCPUProfile() if err := f.Close(); err != nil { - svrCtx.Logger.Info("failed to close cpu-profile file", "profile", cpuProfile, "err", err.Error()) + svrCtx.GetLogger().Info("failed to close cpu-profile file", "profile", cpuProfile, "err", err.Error()) } }() } @@ -625,12 +626,12 @@ func getCtx(svrCtx *Context, block bool) (*errgroup.Group, context.Context) { ctx, cancelFn := context.WithCancel(context.Background()) g, ctx := errgroup.WithContext(ctx) // listen for quit signals so the calling parent process can gracefully exit - ListenForQuitSignals(g, block, cancelFn, svrCtx.Logger) + ListenForQuitSignals(g, block, cancelFn, svrCtx.GetLogger()) return g, ctx } func startApp[T types.Application](svrCtx *Context, appCreator types.AppCreator[T], opts StartCmdOptions[T]) (app T, cleanupFn func(), err error) { - traceWriter, traceCleanupFn, err := SetupTraceWriter(svrCtx.Logger, svrCtx.Viper.GetString(flagTraceStore)) + traceWriter, traceCleanupFn, err := SetupTraceWriter(svrCtx.GetLogger(), svrCtx.GetViper().GetString(flagTraceStore)) if err != nil { return app, traceCleanupFn, err } @@ -641,12 +642,12 @@ func startApp[T types.Application](svrCtx *Context, appCreator types.AppCreator[ } home := cmtCfg.RootDir - db, err := opts.DBOpener(home, GetAppDBBackend(svrCtx.Viper)) + db, err := opts.DBOpener(home, GetAppDBBackend(svrCtx.GetViper())) if err != nil { return app, traceCleanupFn, err } - if isTestnet, ok := svrCtx.Viper.Get(KeyIsTestnet).(bool); ok && isTestnet { + if isTestnet, ok := svrCtx.GetViper().Get(KeyIsTestnet).(bool); ok && isTestnet { var appPtr *T appPtr, err = testnetify[T](svrCtx, appCreator, db, traceWriter) if err != nil { @@ -654,13 +655,13 @@ func startApp[T types.Application](svrCtx *Context, appCreator types.AppCreator[ } app = *appPtr } else { - app = appCreator(svrCtx.Logger, db, traceWriter, svrCtx.Viper) + app = appCreator(svrCtx.GetLogger(), db, traceWriter, svrCtx.GetViper()) } cleanupFn = func() { traceCleanupFn() if localErr := app.Close(); localErr != nil { - svrCtx.Logger.Error(localErr.Error()) + svrCtx.GetLogger().Error(localErr.Error()) } } return app, cleanupFn, nil @@ -703,8 +704,8 @@ you want to test the upgrade handler itself. Example: "in-place-testnet localosmosis osmo12smx2wdlyttvyzvzg54y2vnqwq2qjateuf7thj", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := GetServerContextFromCmd(cmd) - _, err := GetPruningOptionsFromFlags(serverCtx.Viper) + serverCtx := corectx.GetServerContextFromCmd(cmd).(*Context) + _, err := GetPruningOptionsFromFlags(serverCtx.GetViper()) if err != nil { return err } @@ -716,7 +717,7 @@ you want to test the upgrade handler itself. withCMT, _ := cmd.Flags().GetBool(flagWithComet) if !withCMT { - serverCtx.Logger.Info("starting ABCI without CometBFT") + serverCtx.GetLogger().Info("starting ABCI without CometBFT") } newChainID := args[0] @@ -738,20 +739,20 @@ you want to test the upgrade handler itself. // Set testnet keys to be used by the application. // This is done to prevent changes to existing start API. - serverCtx.Viper.Set(KeyIsTestnet, true) - serverCtx.Viper.Set(KeyNewChainID, newChainID) - serverCtx.Viper.Set(KeyNewOpAddr, newOperatorAddress) + serverCtx.GetViper().Set(KeyIsTestnet, true) + serverCtx.GetViper().Set(KeyNewChainID, newChainID) + serverCtx.GetViper().Set(KeyNewOpAddr, newOperatorAddress) err = wrapCPUProfile(serverCtx, func() error { return opts.StartCommandHandler(serverCtx, clientCtx, testnetAppCreator, withCMT, opts) }) - serverCtx.Logger.Debug("received quit signal") + serverCtx.GetLogger().Debug("received quit signal") graceDuration, _ := cmd.Flags().GetDuration(FlagShutdownGrace) if graceDuration > 0 { - serverCtx.Logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration) + serverCtx.GetLogger().Info("graceful shutdown start", FlagShutdownGrace, graceDuration) <-time.After(graceDuration) - serverCtx.Logger.Info("graceful shutdown complete") + serverCtx.GetLogger().Info("graceful shutdown complete") } return err @@ -772,7 +773,7 @@ func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCr return nil, fmt.Errorf("Can not convert cometbft config") } - newChainID, ok := ctx.Viper.Get(KeyNewChainID).(string) + newChainID, ok := ctx.GetViper().Get(KeyNewChainID).(string) if !ok { return nil, fmt.Errorf("expected string for key %s", KeyNewChainID) } @@ -825,9 +826,9 @@ func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCr return nil, err } - ctx.Viper.Set(KeyNewValAddr, validatorAddress) - ctx.Viper.Set(KeyUserPubKey, userPubKey) - testnetApp := testnetAppCreator(ctx.Logger, db, traceWriter, ctx.Viper) + ctx.GetViper().Set(KeyNewValAddr, validatorAddress) + ctx.GetViper().Set(KeyUserPubKey, userPubKey) + testnetApp := testnetAppCreator(ctx.GetLogger(), db, traceWriter, ctx.GetViper()) // We need to create a temporary proxyApp to get the initial state of the application. // Depending on how the node was stopped, the application height can differ from the blockStore height. diff --git a/server/util.go b/server/util.go index 2b37295ed472..05523fd8bbbc 100644 --- a/server/util.go +++ b/server/util.go @@ -45,7 +45,6 @@ import ( const ServerContextKey = corectx.ServerContextKey var _ corectx.ServerContext = &Context{} -var _ corectx.BaseConfig = cmtcfg.BaseConfig{} var _ corectx.CometConfig = &CometConfig{} type CometConfig struct { @@ -69,20 +68,10 @@ func (ctx *Context) GetLogger() log.Logger { func (ctx *Context) GetViper() *viper.Viper { return ctx.Viper } -// cfg.BaseConfig.RootDir = root -// cfg.RPC.RootDir = root -// cfg.P2P.RootDir = root -// cfg.Mempool.RootDir = root -// cfg.Consensus.RootDir = root -// Apply change to viper when config root is changed +// Set rootdir to viper func (ctx *Context) SetRoot(rootDir string) { - v := ctx.GetViper() - v.Set("base_config.root_dir", rootDir) - v.Set("rpc.root_dir", rootDir) - v.Set("p2p.root_dir", rootDir) - v.Set("mempool.root_dir", rootDir) - v.Set("consensus.root_dir", rootDir) + ctx.GetViper().Set(flags.FlagHome, rootDir) } func (config CometConfig) SetRoot(root string) corectx.CometConfig { @@ -93,10 +82,11 @@ func (config CometConfig) SetRoot(root string) corectx.CometConfig { func GetCometConfigFromViper(v *viper.Viper) corectx.CometConfig { conf := cmtcfg.DefaultConfig() err := v.Unmarshal(conf) + rootDir := v.GetString(flags.FlagHome) if err != nil { - return CometConfig{cmtcfg.DefaultConfig()} + return CometConfig{cmtcfg.DefaultConfig().SetRoot(rootDir)} } - return CometConfig{conf} + return CometConfig{conf.SetRoot(rootDir)} } func NewDefaultContext() *Context { @@ -246,16 +236,16 @@ func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) { return log.NewLogger(out, opts...), nil } -// GetServerContextFromCmd returns a Context from a command or an empty Context -// if it has not been set. -func GetServerContextFromCmd(cmd *cobra.Command) *Context { - if v := cmd.Context().Value(ServerContextKey); v != nil { - serverCtxPtr := v.(*Context) - return serverCtxPtr - } +// // GetServerContextFromCmd returns a Context from a command or an empty Context +// // if it has not been set. +// func GetServerContextFromCmd(cmd *cobra.Command) *Context { +// if v := cmd.Context().Value(ServerContextKey); v != nil { +// serverCtxPtr := v.(*Context) +// return serverCtxPtr +// } - return NewDefaultContext() -} +// return NewDefaultContext() +// } // SetCmdServerContext sets a command's Context value to the provided argument. // If the context has not been set, set the given context as the default. diff --git a/server/util_test.go b/server/util_test.go index 650b13e44878..545e69640fec 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -26,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/module/testutil" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + corectx "cosmossdk.io/core/context" ) var errCanceledInPreRun = errors.New("canceled in prerun") @@ -65,7 +66,7 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = server.GetServerContextFromCmd(cmd) + serverCtx = corectx.GetServerContextFromCmd(cmd).(*server.Context) // Test that config.toml is created configTomlPath := path.Join(tempDir, "config", "config.toml") @@ -145,7 +146,7 @@ func TestInterceptConfigsPreRunHandlerReadsConfigToml(t *testing.T) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = server.GetServerContextFromCmd(cmd) + serverCtx = corectx.GetServerContextFromCmd(cmd).(*server.Context) config, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { @@ -190,7 +191,7 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = server.GetServerContextFromCmd(cmd) + serverCtx = corectx.GetServerContextFromCmd(cmd).(*server.Context) if testHaltTime != serverCtx.Viper.GetInt("halt-time") { t.Error("Halt time was not set from app.toml") @@ -220,7 +221,7 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = server.GetServerContextFromCmd(cmd) + serverCtx = corectx.GetServerContextFromCmd(cmd).(*server.Context) config, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { @@ -263,7 +264,7 @@ func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = server.GetServerContextFromCmd(cmd) + serverCtx = corectx.GetServerContextFromCmd(cmd).(*server.Context) config, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { @@ -377,7 +378,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceFlag(t *testing.T) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = server.GetServerContextFromCmd(testCommon.cmd) + serverCtx = corectx.GetServerContextFromCmd(testCommon.cmd).(*server.Context) config, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { @@ -400,7 +401,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceEnvVar(t *testing.T) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = server.GetServerContextFromCmd(testCommon.cmd) + serverCtx = corectx.GetServerContextFromCmd(testCommon.cmd).(*server.Context) config, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { @@ -423,7 +424,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigFile(t *testing.T) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = server.GetServerContextFromCmd(testCommon.cmd) + serverCtx = corectx.GetServerContextFromCmd(testCommon.cmd).(*server.Context) config, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { @@ -446,7 +447,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigDefault(t *testing.T) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = server.GetServerContextFromCmd(testCommon.cmd) + serverCtx = corectx.GetServerContextFromCmd(testCommon.cmd).(*server.Context) config, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 8222e05ef9f5..9fd66923a76d 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -21,6 +21,7 @@ import ( banktypes "cosmossdk.io/x/bank/types" stakingtypes "cosmossdk.io/x/staking/types" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -140,7 +141,7 @@ Example: return err } - serverCtx := server.GetServerContextFromCmd(cmd) + serverCtx := corectx.GetServerContextFromCmd(cmd) config := serverCtx.GetConfig().(server.CometConfig) args := initArgs{} diff --git a/x/genutil/client/cli/collect.go b/x/genutil/client/cli/collect.go index e48dbaaf8536..45ce14bf1345 100644 --- a/x/genutil/client/cli/collect.go +++ b/x/genutil/client/cli/collect.go @@ -9,6 +9,7 @@ import ( "cosmossdk.io/errors" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/x/genutil" @@ -23,7 +24,7 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, validator ty Use: "collect-gentxs", Short: "Collect genesis txs and output a genesis.json file", RunE: func(cmd *cobra.Command, _ []string) error { - serverCtx := server.GetServerContextFromCmd(cmd) + serverCtx := corectx.GetServerContextFromCmd(cmd) config, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { return fmt.Errorf("Can not convert cometbft config") diff --git a/x/genutil/client/cli/export.go b/x/genutil/client/cli/export.go index bd9c18c45289..5dfc7ef0ebc7 100644 --- a/x/genutil/client/cli/export.go +++ b/x/genutil/client/cli/export.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -31,7 +32,7 @@ func ExportCmd(appExporter servertypes.AppExporter) *cobra.Command { Short: "Export state to JSON", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) error { - serverCtx := server.GetServerContextFromCmd(cmd) + serverCtx := corectx.GetServerContextFromCmd(cmd) config, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { return fmt.Errorf("Can not convert cometbft config") @@ -41,7 +42,7 @@ func ExportCmd(appExporter servertypes.AppExporter) *cobra.Command { return err } - db, err := server.OpenDB(config.RootDir, server.GetAppDBBackend(serverCtx.Viper)) + db, err := server.OpenDB(config.RootDir, server.GetAppDBBackend(serverCtx.GetViper())) if err != nil { return err } @@ -69,7 +70,7 @@ func ExportCmd(appExporter servertypes.AppExporter) *cobra.Command { } traceWriterFile, _ := cmd.Flags().GetString(flagTraceStore) - traceWriter, cleanup, err := server.SetupTraceWriter(serverCtx.Logger, traceWriterFile) //resleak:notresource + traceWriter, cleanup, err := server.SetupTraceWriter(serverCtx.GetLogger(), traceWriterFile) //resleak:notresource if err != nil { return err } @@ -81,7 +82,7 @@ func ExportCmd(appExporter servertypes.AppExporter) *cobra.Command { modulesToExport, _ := cmd.Flags().GetStringSlice(flagModulesToExport) outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument) - exported, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper, modulesToExport) + exported, err := appExporter(serverCtx.GetLogger(), db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.GetViper(), modulesToExport) if err != nil { return fmt.Errorf("error exporting state: %w", err) } diff --git a/x/genutil/client/cli/genaccount.go b/x/genutil/client/cli/genaccount.go index 71fc4ea33b36..b800ac44dc57 100644 --- a/x/genutil/client/cli/genaccount.go +++ b/x/genutil/client/cli/genaccount.go @@ -8,6 +8,7 @@ import ( "cosmossdk.io/core/address" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -38,7 +39,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - serverCtx := server.GetServerContextFromCmd(cmd) + serverCtx := corectx.GetServerContextFromCmd(cmd) config, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { return fmt.Errorf("Can not convert cometbft config") diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index 4997de337293..ff8ff97f4a64 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -16,6 +16,7 @@ import ( authclient "cosmossdk.io/x/auth/client" "cosmossdk.io/x/staking/client/cli" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -55,7 +56,7 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o `, defaultsDesc, version.AppName, ), RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := server.GetServerContextFromCmd(cmd) + serverCtx := corectx.GetServerContextFromCmd(cmd) config, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { return fmt.Errorf("Can not convert cometbft config") diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 397f091fa6cd..9a3fe811c4e8 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil/types" @@ -21,7 +22,7 @@ func ValidateGenesisCmd(mm *module.Manager) *cobra.Command { Args: cobra.RangeArgs(0, 1), Short: "Validates the genesis file at the default location or at the location passed as an arg", RunE: func(cmd *cobra.Command, args []string) (err error) { - serverCtx := server.GetServerContextFromCmd(cmd) + serverCtx := corectx.GetServerContextFromCmd(cmd) cfg, ok := serverCtx.GetConfig().(server.CometConfig) if !ok { return fmt.Errorf("Can not convert cometbft config") From f63a54e111e2653c52aef4354674580a40f9d78e Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 9 May 2024 02:36:30 +0700 Subject: [PATCH 13/29] fix test --- core/context/server_context.go | 1 + simapp/simd/cmd/testnet.go | 3 +++ simapp/simd/cmd/testnet_test.go | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/context/server_context.go b/core/context/server_context.go index 5f36b8d09a41..a60710dadecb 100644 --- a/core/context/server_context.go +++ b/core/context/server_context.go @@ -15,6 +15,7 @@ type ServerContext interface { GetLogger() log.Logger GetViper() *viper.Viper GetConfig() CometConfig + SetRoot(rootDir string) } type BaseConfig interface { diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 9fd66923a76d..7f7575d43df7 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -408,6 +408,9 @@ func initTestnetFiles( return err } + // Update viper root since root dir become rootdir/node/simd + corectx.GetServerContextFromCmd(cmd).SetRoot(nodeConfig.RootDir) + cmd.PrintErrf("Successfully initialized %d node directories\n", args.numValidators) return nil } diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index f9de7173373e..91952d2a07b5 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -13,6 +13,7 @@ import ( "cosmossdk.io/x/auth" banktypes "cosmossdk.io/x/bank/types" "cosmossdk.io/x/staking" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -75,7 +76,7 @@ func Test_TestnetCmd(t *testing.T) { err = cmd.ExecuteContext(ctx) require.NoError(t, err) - genFile := cfg.GenesisFile() + genFile := corectx.GetServerContextFromCmd(cmd).GetConfig().GenesisFile() appState, _, err := genutiltypes.GenesisStateFromGenFile(genFile) require.NoError(t, err) From ef68e88ed020f30fcb35ee328d4e43c7eafe3363 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Sat, 11 May 2024 22:11:42 +0700 Subject: [PATCH 14/29] no more server context --- client/cmd.go | 44 ++++++++ client/snapshot/delete.go | 6 +- client/snapshot/dump.go | 6 +- client/snapshot/export.go | 15 +-- client/snapshot/list.go | 6 +- client/snapshot/load.go | 6 +- client/snapshot/restore.go | 14 +-- core/context/server_context.go | 44 +------- core/go.mod | 18 +--- core/go.sum | 52 +-------- server/cmd/execute.go | 11 +- server/cmt_cmds.go | 37 ++----- server/rollback.go | 17 ++- server/start.go | 132 ++++++++++++----------- server/util.go | 111 ++++--------------- server/util_test.go | 113 +++++++------------ simapp/simd/cmd/testnet.go | 8 +- simapp/simd/cmd/testnet_test.go | 12 +-- simapp/test_helpers.go | 7 +- testutil/network/interface.go | 6 +- testutil/network/network.go | 20 ++-- testutil/network/util.go | 11 +- testutil/network/validator.go | 14 ++- x/genutil/client/cli/collect.go | 13 +-- x/genutil/client/cli/export.go | 16 ++- x/genutil/client/cli/export_test.go | 22 ++-- x/genutil/client/cli/genaccount.go | 8 +- x/genutil/client/cli/genaccount_test.go | 9 +- x/genutil/client/cli/gentx.go | 9 +- x/genutil/client/cli/init.go | 17 ++- x/genutil/client/cli/init_test.go | 57 ++++++---- x/genutil/client/cli/validate_genesis.go | 9 +- x/genutil/client/testutil/helpers.go | 8 +- x/genutil/collect_test.go | 6 +- 34 files changed, 357 insertions(+), 527 deletions(-) diff --git a/client/cmd.go b/client/cmd.go index e817649d24dc..9966eaddb6fe 100644 --- a/client/cmd.go +++ b/client/cmd.go @@ -4,6 +4,7 @@ import ( "context" "crypto/tls" "fmt" + "os" "slices" "strings" @@ -16,9 +17,13 @@ import ( signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + corectx "cosmossdk.io/core/context" + "cosmossdk.io/log" + cmtcfg "github.com/cometbft/cometbft/config" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/spf13/viper" ) // ClientContextKey defines the context key used to retrieve a client.Context from @@ -370,3 +375,42 @@ func SetCmdClientContext(cmd *cobra.Command, clientCtx Context) error { cmd.SetContext(context.WithValue(cmdCtx, ClientContextKey, &clientCtx)) return nil } + +func GetViperFromCmd(cmd *cobra.Command) *viper.Viper { + value := cmd.Context().Value(corectx.ViperContextKey) + v, ok := value.(*viper.Viper) + if !ok { + return viper.New() + } + return v +} + +func GetConfigFromCmd(cmd *cobra.Command) *cmtcfg.Config { + v := cmd.Context().Value(corectx.ViperContextKey) + fmt.Println("viper", v) + viper, ok := v.(*viper.Viper) + if !ok { + fmt.Println("viper rong") + return cmtcfg.DefaultConfig() + } + return GetConfigFromViper(viper) +} + +func GetLoggerFromCmd(cmd *cobra.Command) log.Logger { + v := cmd.Context().Value(corectx.LoggerContextKey) + logger, ok := v.(log.Logger) + if !ok { + return log.NewLogger(os.Stdout) + } + return logger +} + +func GetConfigFromViper(v *viper.Viper) *cmtcfg.Config { + conf := cmtcfg.DefaultConfig() + err := v.Unmarshal(conf) + rootDir := v.GetString(flags.FlagHome) + if err != nil { + return cmtcfg.DefaultConfig().SetRoot(rootDir) + } + return conf.SetRoot(rootDir) +} diff --git a/client/snapshot/delete.go b/client/snapshot/delete.go index 3b5a2d715f1d..c4314cd96b45 100644 --- a/client/snapshot/delete.go +++ b/client/snapshot/delete.go @@ -5,7 +5,7 @@ import ( "github.com/spf13/cobra" - corectx "cosmossdk.io/core/context" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server" ) @@ -15,7 +15,7 @@ func DeleteSnapshotCmd() *cobra.Command { Short: "Delete a local snapshot", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - ctx := corectx.GetServerContextFromCmd(cmd) + viper := client.GetViperFromCmd(cmd) height, err := strconv.ParseUint(args[0], 10, 64) if err != nil { @@ -26,7 +26,7 @@ func DeleteSnapshotCmd() *cobra.Command { return err } - snapshotStore, err := server.GetSnapshotStore(ctx.GetViper()) + snapshotStore, err := server.GetSnapshotStore(viper) if err != nil { return err } diff --git a/client/snapshot/dump.go b/client/snapshot/dump.go index 12bb4f570c9c..1b3ac45f00cd 100644 --- a/client/snapshot/dump.go +++ b/client/snapshot/dump.go @@ -11,7 +11,7 @@ import ( "github.com/spf13/cobra" - corectx "cosmossdk.io/core/context" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server" ) @@ -22,8 +22,8 @@ func DumpArchiveCmd() *cobra.Command { Short: "Dump the snapshot as portable archive format", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - ctx := corectx.GetServerContextFromCmd(cmd) - snapshotStore, err := server.GetSnapshotStore(ctx.GetViper()) + viper := client.GetViperFromCmd(cmd) + snapshotStore, err := server.GetSnapshotStore(viper) if err != nil { return err } diff --git a/client/snapshot/export.go b/client/snapshot/export.go index 20c2757beb98..30f573676d33 100644 --- a/client/snapshot/export.go +++ b/client/snapshot/export.go @@ -1,13 +1,11 @@ package snapshot import ( - "fmt" - "github.com/spf13/cobra" "cosmossdk.io/log" - corectx "cosmossdk.io/core/context" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" ) @@ -19,11 +17,8 @@ func ExportSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCrea Short: "Export app state to snapshot store", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - ctx := corectx.GetServerContextFromCmd(cmd) - cfg, ok := ctx.GetConfig().(server.CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + cfg := client.GetConfigFromCmd(cmd) + viper := client.GetViperFromCmd(cmd) height, err := cmd.Flags().GetInt64("height") if err != nil { @@ -31,12 +26,12 @@ func ExportSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCrea } home := cfg.RootDir - db, err := openDB(home, server.GetAppDBBackend(ctx.GetViper())) + db, err := openDB(home, server.GetAppDBBackend(viper)) if err != nil { return err } logger := log.NewLogger(cmd.OutOrStdout()) - app := appCreator(logger, db, nil, ctx.GetViper()) + app := appCreator(logger, db, nil, viper) if height == 0 { height = app.CommitMultiStore().LastCommitID().Version diff --git a/client/snapshot/list.go b/client/snapshot/list.go index 0d02192848a2..43ff31cfd4ac 100644 --- a/client/snapshot/list.go +++ b/client/snapshot/list.go @@ -5,7 +5,7 @@ import ( "github.com/spf13/cobra" - corectx "cosmossdk.io/core/context" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server" ) @@ -14,8 +14,8 @@ var ListSnapshotsCmd = &cobra.Command{ Use: "list", Short: "List local snapshots", RunE: func(cmd *cobra.Command, args []string) error { - ctx := corectx.GetServerContextFromCmd(cmd) - snapshotStore, err := server.GetSnapshotStore(ctx.GetViper()) + viper := client.GetViperFromCmd(cmd) + snapshotStore, err := server.GetSnapshotStore(viper) if err != nil { return err } diff --git a/client/snapshot/load.go b/client/snapshot/load.go index 4d2db550066b..722310167669 100644 --- a/client/snapshot/load.go +++ b/client/snapshot/load.go @@ -14,7 +14,7 @@ import ( snapshottypes "cosmossdk.io/store/snapshots/types" - corectx "cosmossdk.io/core/context" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server" ) @@ -27,8 +27,8 @@ func LoadArchiveCmd() *cobra.Command { Short: "Load a snapshot archive file (.tar.gz) into snapshot store", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - ctx := corectx.GetServerContextFromCmd(cmd) - snapshotStore, err := server.GetSnapshotStore(ctx.GetViper()) + viper := client.GetViperFromCmd(cmd) + snapshotStore, err := server.GetSnapshotStore(viper) if err != nil { return err } diff --git a/client/snapshot/restore.go b/client/snapshot/restore.go index cbd0d8134d14..b0f86b9de678 100644 --- a/client/snapshot/restore.go +++ b/client/snapshot/restore.go @@ -1,7 +1,6 @@ package snapshot import ( - "fmt" "path/filepath" "strconv" @@ -10,9 +9,9 @@ import ( "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" - corectx "cosmossdk.io/core/context" ) // RestoreSnapshotCmd returns a command to restore a snapshot @@ -23,11 +22,8 @@ func RestoreSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCre Long: "Restore app state from local snapshot", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - ctx := corectx.GetServerContextFromCmd(cmd) - cfg, ok := ctx.GetConfig().(server.CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + cfg := client.GetConfigFromCmd(cmd) + viper := client.GetViperFromCmd(cmd) height, err := strconv.ParseUint(args[0], 10, 64) if err != nil { @@ -39,12 +35,12 @@ func RestoreSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCre } home := cfg.RootDir - db, err := openDB(home, server.GetAppDBBackend(ctx.GetViper())) + db, err := openDB(home, server.GetAppDBBackend(viper)) if err != nil { return err } logger := log.NewLogger(cmd.OutOrStdout()) - app := appCreator(logger, db, nil, ctx.GetViper()) + app := appCreator(logger, db, nil, viper) sm := app.SnapshotManager() return sm.RestoreLocalSnapshot(height, uint32(format)) diff --git a/core/context/server_context.go b/core/context/server_context.go index a60710dadecb..fa213d9c524e 100644 --- a/core/context/server_context.go +++ b/core/context/server_context.go @@ -1,42 +1,6 @@ package context -import ( - "github.com/spf13/cobra" - "github.com/spf13/viper" - - "cosmossdk.io/log" -) - -type ContextKey string - -const ServerContextKey ContextKey = "server.context" - -type ServerContext interface { - GetLogger() log.Logger - GetViper() *viper.Viper - GetConfig() CometConfig - SetRoot(rootDir string) -} - -type BaseConfig interface { - DBDir() string - GenesisFile() string - NodeKeyFile() string - PrivValidatorKeyFile() string - PrivValidatorStateFile() string -} - -type CometConfig interface { - BaseConfig - CheckDeprecated() []string - SetRoot(root string) CometConfig - ValidateBasic() error -} - -func GetServerContextFromCmd(cmd *cobra.Command) ServerContext { - if v := cmd.Context().Value(ServerContextKey); v != nil { - serverCtxPtr := v.(ServerContext) - return serverCtxPtr - } - return nil -} +var ( + LoggerContextKey = "server.logger" + ViperContextKey = "server.viper" +) diff --git a/core/go.mod b/core/go.mod index b331a044cc7b..67bc6d3706dd 100644 --- a/core/go.mod +++ b/core/go.mod @@ -5,8 +5,6 @@ go 1.20 require ( cosmossdk.io/log v1.3.1 github.com/cosmos/gogoproto v1.4.12 - github.com/spf13/cobra v1.8.0 - github.com/spf13/viper v1.18.2 github.com/stretchr/testify v1.9.0 google.golang.org/grpc v1.63.2 google.golang.org/protobuf v1.34.1 @@ -14,33 +12,19 @@ require ( require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/hashicorp/hcl v1.0.0 // indirect - github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/magiconair/properties v1.8.7 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/rs/zerolog v1.32.0 // indirect - github.com/sagikazarmark/locafero v0.4.0 // indirect - github.com/sagikazarmark/slog-shim v0.1.0 // indirect - github.com/sourcegraph/conc v0.3.0 // indirect - github.com/spf13/afero v1.11.0 // indirect - github.com/spf13/cast v1.6.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect - github.com/subosito/gotenv v1.6.0 // indirect - go.uber.org/multierr v1.10.0 // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect - gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/core/go.sum b/core/go.sum index 2e4f0936b42f..498373c46b78 100644 --- a/core/go.sum +++ b/core/go.sum @@ -3,77 +3,38 @@ cosmossdk.io/log v1.3.1/go.mod h1:2/dIomt8mKdk6vl3OWJcPk2be3pGOS8OQaLUM/3/tCM= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cosmos/gogoproto v1.4.12 h1:vB6Lbe/rtnYGjQuFxkPiPYiCybqFT8QvLipDZP8JpFE= github.com/cosmos/gogoproto v1.4.12/go.mod h1:LnZob1bXRdUoqMMtwYlcR3wjiElmlC+FkjaZRv1/eLY= -github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= -github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= -github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= -github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= -github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 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/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= -github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= -github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= -github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= -github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= -github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= -github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= -github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= -github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= -github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= -github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= -github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= -github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= -github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= -github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= -go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= @@ -94,9 +55,6 @@ google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHh gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= -gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= diff --git a/server/cmd/execute.go b/server/cmd/execute.go index cf8e7c009f44..a8b7eb58de9f 100644 --- a/server/cmd/execute.go +++ b/server/cmd/execute.go @@ -2,14 +2,18 @@ package cmd import ( "context" + "os" cmtcli "github.com/cometbft/cometbft/libs/cli" "github.com/rs/zerolog" "github.com/spf13/cobra" + "github.com/spf13/viper" + "cosmossdk.io/log" + + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/server" ) // Execute executes the root command of an application. It handles creating a @@ -37,9 +41,10 @@ func Execute(rootCmd *cobra.Command, envPrefix, defaultHome string) error { // CreateExecuteContext returns a base Context with server and client context // values initialized. func CreateExecuteContext(ctx context.Context) context.Context { - srvCtx := server.NewDefaultContext() + // srvCtx := server.NewDefaultContext() ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{}) - ctx = context.WithValue(ctx, server.ServerContextKey, srvCtx) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) return ctx } diff --git a/server/cmt_cmds.go b/server/cmt_cmds.go index 8e107e99c530..1fdd6ca515b4 100644 --- a/server/cmt_cmds.go +++ b/server/cmt_cmds.go @@ -16,10 +16,8 @@ import ( "github.com/spf13/cobra" "sigs.k8s.io/yaml" - "cosmossdk.io/log" auth "cosmossdk.io/x/auth/client/cli" - corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" @@ -74,11 +72,7 @@ func ShowNodeIDCmd() *cobra.Command { Use: "show-node-id", Short: "Show this node's ID", RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := corectx.GetServerContextFromCmd(cmd) - cfg, ok := serverCtx.GetConfig().(CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + cfg := client.GetConfigFromCmd(cmd) nodeKey, err := p2p.LoadNodeKey(cfg.NodeKeyFile()) if err != nil { @@ -97,11 +91,7 @@ func ShowValidatorCmd() *cobra.Command { Use: "show-validator", Short: "Show this node's CometBFT validator info", RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := corectx.GetServerContextFromCmd(cmd) - cfg, ok := serverCtx.GetConfig().(CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + cfg := client.GetConfigFromCmd(cmd) privValidator := pvm.LoadFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()) pk, err := privValidator.GetPubKey() @@ -134,11 +124,7 @@ func ShowAddressCmd() *cobra.Command { Use: "show-address", Short: "Shows this node's CometBFT validator consensus address", RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := corectx.GetServerContextFromCmd(cmd) - cfg, ok := serverCtx.GetConfig().(CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + cfg := client.GetConfigFromCmd(cmd) privValidator := pvm.LoadFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()) @@ -372,29 +358,26 @@ func BootstrapStateCmd[T types.Application](appCreator types.AppCreator[T]) *cob Short: "Bootstrap CometBFT state at an arbitrary block height using a light client", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := corectx.GetServerContextFromCmd(cmd) - logger := log.NewLogger(cmd.OutOrStdout()) - cfg, ok := serverCtx.GetConfig().(CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + cfg := client.GetConfigFromCmd(cmd) + logger := client.GetLoggerFromCmd(cmd) + viper := client.GetViperFromCmd(cmd) height, err := cmd.Flags().GetInt64("height") if err != nil { return err } if height == 0 { - home := serverCtx.GetViper().GetString(flags.FlagHome) - db, err := OpenDB(home, GetAppDBBackend(serverCtx.GetViper())) + home := viper.GetString(flags.FlagHome) + db, err := OpenDB(home, GetAppDBBackend(viper)) if err != nil { return err } - app := appCreator(logger, db, nil, serverCtx.GetViper()) + app := appCreator(logger, db, nil, viper) height = app.CommitMultiStore().LastCommitID().Version } - return node.BootstrapState(cmd.Context(), cfg.Config, cmtcfg.DefaultDBProvider, getGenDocProvider(cfg.Config), uint64(height), nil) + return node.BootstrapState(cmd.Context(), cfg, cmtcfg.DefaultDBProvider, getGenDocProvider(cfg), uint64(height), nil) }, } diff --git a/server/rollback.go b/server/rollback.go index e43c6422de5c..21c5c8e6ed87 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -6,7 +6,7 @@ import ( cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" "github.com/spf13/cobra" - corectx "cosmossdk.io/core/context" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server/types" ) @@ -26,20 +26,17 @@ restarting CometBFT the transactions in block n will be re-executed against the application. `, RunE: func(cmd *cobra.Command, args []string) error { - ctx := corectx.GetServerContextFromCmd(cmd) + config := client.GetConfigFromCmd(cmd) + logger := client.GetLoggerFromCmd(cmd) + viper := client.GetViperFromCmd(cmd) - config, ok := ctx.GetConfig().(CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } - - db, err := OpenDB(config.RootDir, GetAppDBBackend(ctx.GetViper())) + db, err := OpenDB(config.RootDir, GetAppDBBackend(viper)) if err != nil { return err } - app := appCreator(ctx.GetLogger(), db, nil, ctx.GetViper()) + app := appCreator(logger, db, nil, viper) // rollback CometBFT state - height, hash, err := cmtcmd.RollbackState(config.Config, removeBlock) + height, hash, err := cmtcmd.RollbackState(config, removeBlock) if err != nil { return fmt.Errorf("failed to rollback CometBFT state: %w", err) } diff --git a/server/start.go b/server/start.go index 0dfac914a0f1..2848435d81a2 100644 --- a/server/start.go +++ b/server/start.go @@ -32,6 +32,7 @@ import ( "github.com/hashicorp/go-metrics" "github.com/spf13/cobra" "github.com/spf13/pflag" + "github.com/spf13/viper" "golang.org/x/sync/errgroup" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" @@ -39,7 +40,6 @@ import ( "cosmossdk.io/log" pruningtypes "cosmossdk.io/store/pruning/types" - corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server/api" @@ -114,6 +114,12 @@ const ( KeyTriggerTestnetUpgrade = "trigger-testnet-upgrade" ) +// Keep Context type +type Context struct { + Viper *viper.Viper + Logger log.Logger +} + // StartCmdOptions defines options that can be customized in `StartCmdWithOptions`, type StartCmdOptions[T types.Application] struct { // DBOpener can be used to customize db opening, for example customize db options or support different db backends, @@ -178,8 +184,13 @@ bypassed and can be used when legacy queries are needed after an on-chain upgrad is performed. Note, when enabled, gRPC will also be automatically enabled. `, RunE: func(cmd *cobra.Command, _ []string) error { - serverCtx := corectx.GetServerContextFromCmd(cmd).(*Context) - _, err := GetPruningOptionsFromFlags(serverCtx.GetViper()) + viper := client.GetViperFromCmd(cmd) + logger := client.GetLoggerFromCmd(cmd) + serverCtx := &Context{ + Viper: viper, + Logger: logger, + } + _, err := GetPruningOptionsFromFlags(viper) if err != nil { return err } @@ -191,19 +202,19 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. withCMT, _ := cmd.Flags().GetBool(flagWithComet) if !withCMT { - serverCtx.GetLogger().Info("starting ABCI without CometBFT") + logger.Info("starting ABCI without CometBFT") } err = wrapCPUProfile(serverCtx, func() error { return opts.StartCommandHandler(serverCtx, clientCtx, appCreator, withCMT, opts) }) - serverCtx.GetLogger().Debug("received quit signal") + logger.Debug("received quit signal") graceDuration, _ := cmd.Flags().GetDuration(FlagShutdownGrace) if graceDuration > 0 { - serverCtx.GetLogger().Info("graceful shutdown start", FlagShutdownGrace, graceDuration) + logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration) <-time.After(graceDuration) - serverCtx.GetLogger().Info("graceful shutdown complete") + logger.Info("graceful shutdown complete") } return err @@ -240,8 +251,8 @@ func start[T types.Application](svrCtx *Context, clientCtx client.Context, appCr } func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app T, metrics *telemetry.Metrics, opts StartCmdOptions[T]) error { - addr := svrCtx.GetViper().GetString(flagAddress) - transport := svrCtx.GetViper().GetString(flagTransport) + addr := svrCtx.Viper.GetString(flagAddress) + transport := svrCtx.Viper.GetString(flagTransport) cmtApp := NewCometABCIWrapper(app) svr, err := server.NewServer(addr, transport, cmtApp) @@ -249,14 +260,11 @@ func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.C return fmt.Errorf("error creating listener: %w", err) } - svr.SetLogger(servercmtlog.CometLoggerWrapper{Logger: svrCtx.GetLogger().With("module", "abci-server")}) + svr.SetLogger(servercmtlog.CometLoggerWrapper{Logger: svrCtx.Logger.With("module", "abci-server")}) g, ctx := getCtx(svrCtx, false) - config, ok := svrCtx.GetConfig().(CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + config := client.GetConfigFromViper(svrCtx.Viper) // 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 @@ -296,14 +304,14 @@ func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.C g.Go(func() error { if err := svr.Start(); err != nil { - svrCtx.GetLogger().Error("failed to start out-of-process ABCI server", "err", err) + svrCtx.Logger.Error("failed to start out-of-process ABCI server", "err", err) return err } // Wait for the calling process to be canceled or close the provided context, // so we can gracefully stop the ABCI server. <-ctx.Done() - svrCtx.GetLogger().Info("stopping the ABCI server...") + svrCtx.Logger.Info("stopping the ABCI server...") return svr.Stop() }) @@ -313,21 +321,19 @@ func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.C func startInProcess[T types.Application](svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app T, metrics *telemetry.Metrics, opts StartCmdOptions[T], ) error { - cmtCfg, ok := svrCtx.GetConfig().(CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } - gRPCOnly := svrCtx.GetViper().GetBool(flagGRPCOnly) + cmtCfg := client.GetConfigFromViper(svrCtx.Viper) + + gRPCOnly := svrCtx.Viper.GetBool(flagGRPCOnly) g, ctx := getCtx(svrCtx, true) if gRPCOnly { // TODO: Generalize logic so that gRPC only is really in startStandAlone - svrCtx.GetLogger().Info("starting node in gRPC only mode; CometBFT is disabled") + svrCtx.Logger.Info("starting node in gRPC only mode; CometBFT is disabled") svrCfg.GRPC.Enable = true } else { - svrCtx.GetLogger().Info("starting node with ABCI CometBFT in-process") - tmNode, cleanupFn, err := startCmtNode(ctx, cmtCfg.Config, app, svrCtx) + svrCtx.Logger.Info("starting node with ABCI CometBFT in-process") + tmNode, cleanupFn, err := startCmtNode(ctx, cmtCfg, app, svrCtx) if err != nil { return err } @@ -390,7 +396,7 @@ func startCmtNode( getGenDocProvider(cfg), cmtcfg.DefaultDBProvider, node.DefaultMetricsProvider(cfg.Instrumentation), - servercmtlog.CometLoggerWrapper{Logger: svrCtx.GetLogger()}, + servercmtlog.CometLoggerWrapper{Logger: svrCtx.Logger}, ) if err != nil { return tmNode, cleanupFn, err @@ -410,7 +416,7 @@ func startCmtNode( } func getAndValidateConfig(svrCtx *Context) (serverconfig.Config, error) { - config, err := serverconfig.GetConfig(svrCtx.GetViper()) + config, err := serverconfig.GetConfig(svrCtx.Viper) if err != nil { return config, err } @@ -523,7 +529,7 @@ func startGrpcServer( } clientCtx = clientCtx.WithGRPCClient(grpcClient) - svrCtx.GetLogger().Debug("gRPC client assigned to client context", "target", config.Address) + svrCtx.Logger.Debug("gRPC client assigned to client context", "target", config.Address) grpcSrv, err := servergrpc.NewGRPCServer(clientCtx, app, config) if err != nil { @@ -533,7 +539,7 @@ func startGrpcServer( // Start the gRPC server in a goroutine. Note, the provided ctx will ensure // that the server is gracefully shut down. g.Go(func() error { - return servergrpc.StartGRPCServer(ctx, svrCtx.GetLogger().With("module", "grpc-server"), config, grpcSrv) + return servergrpc.StartGRPCServer(ctx, svrCtx.Logger.With("module", "grpc-server"), config, grpcSrv) }) return grpcSrv, clientCtx, nil } @@ -555,7 +561,7 @@ func startAPIServer( clientCtx = clientCtx.WithHomeDir(home) - apiSrv := api.New(clientCtx, svrCtx.GetLogger().With("module", "api-server"), grpcSrv) + apiSrv := api.New(clientCtx, svrCtx.Logger.With("module", "api-server"), grpcSrv) app.RegisterAPIRoutes(apiSrv, svrCfg.API) if svrCfg.Telemetry.Enabled { @@ -578,24 +584,24 @@ func startTelemetry(cfg serverconfig.Config) (*telemetry.Metrics, error) { // // NOTE: We expect the caller to handle graceful shutdown and signal handling. func wrapCPUProfile(svrCtx *Context, callbackFn func() error) error { - if cpuProfile := svrCtx.GetViper().GetString(flagCPUProfile); cpuProfile != "" { + if cpuProfile := svrCtx.Viper.GetString(flagCPUProfile); cpuProfile != "" { f, err := os.Create(cpuProfile) if err != nil { return err } - svrCtx.GetLogger().Info("starting CPU profiler", "profile", cpuProfile) + svrCtx.Logger.Info("starting CPU profiler", "profile", cpuProfile) if err := pprof.StartCPUProfile(f); err != nil { return err } defer func() { - svrCtx.GetLogger().Info("stopping CPU profiler", "profile", cpuProfile) + svrCtx.Logger.Info("stopping CPU profiler", "profile", cpuProfile) pprof.StopCPUProfile() if err := f.Close(); err != nil { - svrCtx.GetLogger().Info("failed to close cpu-profile file", "profile", cpuProfile, "err", err.Error()) + svrCtx.Logger.Info("failed to close cpu-profile file", "profile", cpuProfile, "err", err.Error()) } }() } @@ -626,28 +632,25 @@ func getCtx(svrCtx *Context, block bool) (*errgroup.Group, context.Context) { ctx, cancelFn := context.WithCancel(context.Background()) g, ctx := errgroup.WithContext(ctx) // listen for quit signals so the calling parent process can gracefully exit - ListenForQuitSignals(g, block, cancelFn, svrCtx.GetLogger()) + ListenForQuitSignals(g, block, cancelFn, svrCtx.Logger) return g, ctx } func startApp[T types.Application](svrCtx *Context, appCreator types.AppCreator[T], opts StartCmdOptions[T]) (app T, cleanupFn func(), err error) { - traceWriter, traceCleanupFn, err := SetupTraceWriter(svrCtx.GetLogger(), svrCtx.GetViper().GetString(flagTraceStore)) + traceWriter, traceCleanupFn, err := SetupTraceWriter(svrCtx.Logger, svrCtx.Viper.GetString(flagTraceStore)) if err != nil { return app, traceCleanupFn, err } - cmtCfg, ok := svrCtx.GetConfig().(CometConfig) - if !ok { - return app, traceCleanupFn, fmt.Errorf("Can not convert cometbft config") - } + cmtCfg := client.GetConfigFromViper(svrCtx.Viper) home := cmtCfg.RootDir - db, err := opts.DBOpener(home, GetAppDBBackend(svrCtx.GetViper())) + db, err := opts.DBOpener(home, GetAppDBBackend(svrCtx.Viper)) if err != nil { return app, traceCleanupFn, err } - if isTestnet, ok := svrCtx.GetViper().Get(KeyIsTestnet).(bool); ok && isTestnet { + if isTestnet, ok := svrCtx.Viper.Get(KeyIsTestnet).(bool); ok && isTestnet { var appPtr *T appPtr, err = testnetify[T](svrCtx, appCreator, db, traceWriter) if err != nil { @@ -655,13 +658,13 @@ func startApp[T types.Application](svrCtx *Context, appCreator types.AppCreator[ } app = *appPtr } else { - app = appCreator(svrCtx.GetLogger(), db, traceWriter, svrCtx.GetViper()) + app = appCreator(svrCtx.Logger, db, traceWriter, svrCtx.Viper) } cleanupFn = func() { traceCleanupFn() if localErr := app.Close(); localErr != nil { - svrCtx.GetLogger().Error(localErr.Error()) + svrCtx.Logger.Error(localErr.Error()) } } return app, cleanupFn, nil @@ -704,8 +707,14 @@ you want to test the upgrade handler itself. Example: "in-place-testnet localosmosis osmo12smx2wdlyttvyzvzg54y2vnqwq2qjateuf7thj", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := corectx.GetServerContextFromCmd(cmd).(*Context) - _, err := GetPruningOptionsFromFlags(serverCtx.GetViper()) + viper := client.GetViperFromCmd(cmd) + logger := client.GetLoggerFromCmd(cmd) + serverCtx := &Context{ + Viper: viper, + Logger: logger, + } + + _, err := GetPruningOptionsFromFlags(serverCtx.Viper) if err != nil { return err } @@ -717,7 +726,7 @@ you want to test the upgrade handler itself. withCMT, _ := cmd.Flags().GetBool(flagWithComet) if !withCMT { - serverCtx.GetLogger().Info("starting ABCI without CometBFT") + serverCtx.Logger.Info("starting ABCI without CometBFT") } newChainID := args[0] @@ -739,20 +748,20 @@ you want to test the upgrade handler itself. // Set testnet keys to be used by the application. // This is done to prevent changes to existing start API. - serverCtx.GetViper().Set(KeyIsTestnet, true) - serverCtx.GetViper().Set(KeyNewChainID, newChainID) - serverCtx.GetViper().Set(KeyNewOpAddr, newOperatorAddress) + serverCtx.Viper.Set(KeyIsTestnet, true) + serverCtx.Viper.Set(KeyNewChainID, newChainID) + serverCtx.Viper.Set(KeyNewOpAddr, newOperatorAddress) err = wrapCPUProfile(serverCtx, func() error { return opts.StartCommandHandler(serverCtx, clientCtx, testnetAppCreator, withCMT, opts) }) - serverCtx.GetLogger().Debug("received quit signal") + serverCtx.Logger.Debug("received quit signal") graceDuration, _ := cmd.Flags().GetDuration(FlagShutdownGrace) if graceDuration > 0 { - serverCtx.GetLogger().Info("graceful shutdown start", FlagShutdownGrace, graceDuration) + serverCtx.Logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration) <-time.After(graceDuration) - serverCtx.GetLogger().Info("graceful shutdown complete") + serverCtx.Logger.Info("graceful shutdown complete") } return err @@ -768,12 +777,9 @@ you want to test the upgrade handler itself. // testnetify modifies both state and blockStore, allowing the provided operator address and local validator key to control the network // that the state in the data folder represents. The chainID of the local genesis file is modified to match the provided chainID. func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCreator[T], db dbm.DB, traceWriter io.WriteCloser) (*T, error) { - config, ok := ctx.GetConfig().(CometConfig) - if !ok { - return nil, fmt.Errorf("Can not convert cometbft config") - } + config := client.GetConfigFromViper(ctx.Viper) - newChainID, ok := ctx.GetViper().Get(KeyNewChainID).(string) + newChainID, ok := ctx.Viper.Get(KeyNewChainID).(string) if !ok { return nil, fmt.Errorf("expected string for key %s", KeyNewChainID) } @@ -793,16 +799,16 @@ func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCr } // Load the comet genesis doc provider. - genDocProvider := node.DefaultGenesisDocProviderFunc(config.Config) + genDocProvider := node.DefaultGenesisDocProviderFunc(config) // Initialize blockStore and stateDB. - blockStoreDB, err := cmtcfg.DefaultDBProvider(&cmtcfg.DBContext{ID: "blockstore", Config: config.Config}) + blockStoreDB, err := cmtcfg.DefaultDBProvider(&cmtcfg.DBContext{ID: "blockstore", Config: config}) if err != nil { return nil, err } blockStore := store.NewBlockStore(blockStoreDB) - stateDB, err := cmtcfg.DefaultDBProvider(&cmtcfg.DBContext{ID: "state", Config: config.Config}) + stateDB, err := cmtcfg.DefaultDBProvider(&cmtcfg.DBContext{ID: "state", Config: config}) if err != nil { return nil, err } @@ -826,9 +832,9 @@ func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCr return nil, err } - ctx.GetViper().Set(KeyNewValAddr, validatorAddress) - ctx.GetViper().Set(KeyUserPubKey, userPubKey) - testnetApp := testnetAppCreator(ctx.GetLogger(), db, traceWriter, ctx.GetViper()) + ctx.Viper.Set(KeyNewValAddr, validatorAddress) + ctx.Viper.Set(KeyUserPubKey, userPubKey) + testnetApp := testnetAppCreator(ctx.Logger, db, traceWriter, ctx.Viper) // We need to create a temporary proxyApp to get the initial state of the application. // Depending on how the node was stopped, the application height can differ from the blockStore height. diff --git a/server/util.go b/server/util.go index 05523fd8bbbc..8838f350be63 100644 --- a/server/util.go +++ b/server/util.go @@ -40,65 +40,7 @@ import ( genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) -// ServerContextKey defines the context key used to retrieve a server.Context from -// a command's Context. -const ServerContextKey = corectx.ServerContextKey -var _ corectx.ServerContext = &Context{} -var _ corectx.CometConfig = &CometConfig{} - -type CometConfig struct { - *cmtcfg.Config -} - -// Context server context -type Context struct { - Viper *viper.Viper - Logger log.Logger -} - -func (ctx *Context) GetConfig() corectx.CometConfig { - return GetCometConfigFromViper(ctx.Viper) -} - -func (ctx *Context) GetLogger() log.Logger { - return ctx.Logger -} - -func (ctx *Context) GetViper() *viper.Viper { - return ctx.Viper -} - -// Set rootdir to viper -func (ctx *Context) SetRoot(rootDir string) { - ctx.GetViper().Set(flags.FlagHome, rootDir) -} - -func (config CometConfig) SetRoot(root string) corectx.CometConfig { - config.Config.SetRoot(root) - return config -} - -func GetCometConfigFromViper(v *viper.Viper) corectx.CometConfig { - conf := cmtcfg.DefaultConfig() - err := v.Unmarshal(conf) - rootDir := v.GetString(flags.FlagHome) - if err != nil { - return CometConfig{cmtcfg.DefaultConfig().SetRoot(rootDir)} - } - return CometConfig{conf.SetRoot(rootDir)} -} - -func NewDefaultContext() *Context { - return NewContext( - viper.New(), - log.NewLogger(os.Stdout), - ) -} - -func NewContext(v *viper.Viper, logger log.Logger) *Context { - return &Context{v, logger} -} func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) { defer func() { @@ -137,20 +79,19 @@ func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) // InterceptConfigsPreRunHandler is identical to InterceptConfigsAndCreateContext // except it also sets the server context on the command and the server logger. func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}, cmtConfig *cmtcfg.Config) error { - serverCtx, err := InterceptConfigsAndCreateContext(cmd, customAppConfigTemplate, customAppConfig, cmtConfig) + viper, err := InterceptConfigsAndCreateContext(cmd, customAppConfigTemplate, customAppConfig, cmtConfig) if err != nil { return err } // overwrite default server logger - logger, err := CreateSDKLogger(serverCtx, cmd.OutOrStdout()) + logger, err := CreateSDKLogger(viper, cmd.OutOrStdout()) if err != nil { return err } - serverCtx.Logger = logger.With(log.ModuleKey, "server") // set server context - return SetCmdServerContext(cmd, serverCtx) + return SetCmdServerContext(cmd, viper, logger) } // InterceptConfigsAndCreateContext performs a pre-run function for the root daemon @@ -163,8 +104,8 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate s // is used to read and parse the application configuration. Command handlers can // fetch the server Context to get the CometBFT configuration or to get access // to Viper. -func InterceptConfigsAndCreateContext(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}, cmtConfig *cmtcfg.Config) (*Context, error) { - serverCtx := NewDefaultContext() +func InterceptConfigsAndCreateContext(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}, cmtConfig *cmtcfg.Config) (*viper.Viper, error) { + v := viper.New() // Get the executable name and configure the viper instance so that environmental // variables are checked based off that name. The underscore character is used @@ -177,44 +118,44 @@ func InterceptConfigsAndCreateContext(cmd *cobra.Command, customAppConfigTemplat basename := path.Base(executableName) // configure the viper instance - if err := serverCtx.Viper.BindPFlags(cmd.Flags()); err != nil { + if err := v.BindPFlags(cmd.Flags()); err != nil { return nil, err } - if err := serverCtx.Viper.BindPFlags(cmd.PersistentFlags()); err != nil { + if err := v.BindPFlags(cmd.PersistentFlags()); err != nil { return nil, err } - serverCtx.Viper.SetEnvPrefix(basename) - serverCtx.Viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) - serverCtx.Viper.AutomaticEnv() + v.SetEnvPrefix(basename) + v.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) + v.AutomaticEnv() // intercept configuration files, using both Viper instances separately - err = interceptConfigs(serverCtx.Viper, customAppConfigTemplate, customAppConfig, cmtConfig) + err = interceptConfigs(v, customAppConfigTemplate, customAppConfig, cmtConfig) if err != nil { return nil, err } - if err = bindFlags(basename, cmd, serverCtx.Viper); err != nil { + if err = bindFlags(basename, cmd, v); err != nil { return nil, err } - return serverCtx, nil + return v, nil } // CreateSDKLogger creates a the default SDK logger. // It reads the log level and format from the server context. -func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) { +func CreateSDKLogger(v *viper.Viper, out io.Writer) (log.Logger, error) { var opts []log.Option - if ctx.Viper.GetString(flags.FlagLogFormat) == flags.OutputFormatJSON { + if v.GetString(flags.FlagLogFormat) == flags.OutputFormatJSON { opts = append(opts, log.OutputJSONOption()) } opts = append(opts, - log.ColorOption(!ctx.Viper.GetBool(flags.FlagLogNoColor)), + log.ColorOption(!v.GetBool(flags.FlagLogNoColor)), // We use CometBFT flag (cmtcli.TraceFlag) for trace logging. - log.TraceOption(ctx.Viper.GetBool(FlagTrace))) + log.TraceOption(v.GetBool(FlagTrace))) // check and set filter level or keys for the logger if any - logLvlStr := ctx.Viper.GetString(flags.FlagLogLevel) + logLvlStr := v.GetString(flags.FlagLogLevel) if logLvlStr == "" { return log.NewLogger(out, opts...), nil } @@ -236,20 +177,9 @@ func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) { return log.NewLogger(out, opts...), nil } -// // GetServerContextFromCmd returns a Context from a command or an empty Context -// // if it has not been set. -// func GetServerContextFromCmd(cmd *cobra.Command) *Context { -// if v := cmd.Context().Value(ServerContextKey); v != nil { -// serverCtxPtr := v.(*Context) -// return serverCtxPtr -// } - -// return NewDefaultContext() -// } - // SetCmdServerContext sets a command's Context value to the provided argument. // If the context has not been set, set the given context as the default. -func SetCmdServerContext(cmd *cobra.Command, serverCtx *Context) error { +func SetCmdServerContext(cmd *cobra.Command, viper *viper.Viper, logger log.Logger) error { var cmdCtx context.Context if cmd.Context() == nil { @@ -258,7 +188,8 @@ func SetCmdServerContext(cmd *cobra.Command, serverCtx *Context) error { cmdCtx = cmd.Context() } - cmd.SetContext(context.WithValue(cmdCtx, ServerContextKey, serverCtx)) + cmd.SetContext(context.WithValue(cmdCtx, corectx.LoggerContextKey, logger)) + cmd.SetContext(context.WithValue(cmdCtx, corectx.ViperContextKey, viper)) return nil } diff --git a/server/util_test.go b/server/util_test.go index 545e69640fec..6436c297f8ed 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -27,6 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module/testutil" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" corectx "cosmossdk.io/core/context" + "cosmossdk.io/log" ) var errCanceledInPreRun = errors.New("canceled in prerun") @@ -61,12 +62,13 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T cmd.PreRunE = preRunETestImpl serverCtx := &server.Context{} - ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = corectx.GetServerContextFromCmd(cmd).(*server.Context) + config := client.GetConfigFromCmd(cmd) // Test that config.toml is created configTomlPath := path.Join(tempDir, "config", "config.toml") @@ -84,7 +86,7 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T } // Test that CometBFT config is initialized - if serverCtx.GetConfig() == nil { + if config == nil { t.Fatal("CometBFT config not created") } @@ -139,19 +141,14 @@ func TestInterceptConfigsPreRunHandlerReadsConfigToml(t *testing.T) { cmd.PreRunE = preRunETestImpl - serverCtx := &server.Context{} - ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = corectx.GetServerContextFromCmd(cmd).(*server.Context) - - config, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - t.Error("can not convert to cometbft config") - } + config := client.GetConfigFromCmd(cmd) if testDbBackend != config.DBBackend { t.Error("backend was not set from config.toml") @@ -184,16 +181,16 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) { cmd.PreRunE = preRunETestImpl - serverCtx := &server.Context{} - ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = corectx.GetServerContextFromCmd(cmd).(*server.Context) + viper := client.GetViperFromCmd(cmd) - if testHaltTime != serverCtx.Viper.GetInt("halt-time") { + if testHaltTime != viper.GetInt("halt-time") { t.Error("Halt time was not set from app.toml") } } @@ -214,19 +211,14 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { cmd.PreRunE = preRunETestImpl - serverCtx := &server.Context{} - ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = corectx.GetServerContextFromCmd(cmd).(*server.Context) - - config, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - t.Error("can not convert to cometbft config") - } + config := client.GetConfigFromCmd(cmd) if testAddr != config.RPC.ListenAddress { t.Error("RPCListenAddress was not set from command flags") @@ -257,19 +249,14 @@ func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) { cmd.PreRunE = preRunETestImpl - serverCtx := &server.Context{} - ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = corectx.GetServerContextFromCmd(cmd).(*server.Context) - - config, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - t.Error("can not convert to cometbft config") - } + config := client.GetConfigFromCmd(cmd) if testAddr != config.RPC.ListenAddress { t.Errorf("RPCListenAddress was not set from env. var. %q", envVarName) @@ -371,19 +358,14 @@ func TestInterceptConfigsPreRunHandlerPrecedenceFlag(t *testing.T) { testCommon := newPrecedenceCommon(t) testCommon.setAll(t, &TestAddrExpected, &TestAddrNotExpected, &TestAddrNotExpected) - serverCtx := &server.Context{} - ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = corectx.GetServerContextFromCmd(testCommon.cmd).(*server.Context) - - config, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - t.Error("can not convert to cometbft config") - } + config := client.GetConfigFromCmd(testCommon.cmd) if TestAddrExpected != config.RPC.ListenAddress { t.Fatalf("RPCListenAddress was not set from flag %q", testCommon.flagName) @@ -394,19 +376,14 @@ func TestInterceptConfigsPreRunHandlerPrecedenceEnvVar(t *testing.T) { testCommon := newPrecedenceCommon(t) testCommon.setAll(t, nil, &TestAddrExpected, &TestAddrNotExpected) - serverCtx := &server.Context{} - ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = corectx.GetServerContextFromCmd(testCommon.cmd).(*server.Context) - - config, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - t.Error("can not convert to cometbft config") - } + config := client.GetConfigFromCmd(testCommon.cmd) if TestAddrExpected != config.RPC.ListenAddress { t.Errorf("RPCListenAddress was not set from env. var. %q", testCommon.envVarName) @@ -417,19 +394,14 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigFile(t *testing.T) { testCommon := newPrecedenceCommon(t) testCommon.setAll(t, nil, nil, &TestAddrExpected) - serverCtx := &server.Context{} - ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = corectx.GetServerContextFromCmd(testCommon.cmd).(*server.Context) - - config, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - t.Error("can not convert to cometbft config") - } + config := client.GetConfigFromCmd(testCommon.cmd) if TestAddrExpected != config.RPC.ListenAddress { t.Errorf("RPCListenAddress was not read from file %q", testCommon.configTomlPath) @@ -440,19 +412,14 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigDefault(t *testing.T) { testCommon := newPrecedenceCommon(t) // Do not set anything - serverCtx := &server.Context{} - ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - serverCtx = corectx.GetServerContextFromCmd(testCommon.cmd).(*server.Context) - - config, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - t.Error("can not convert to cometbft config") - } + config := client.GetConfigFromCmd(testCommon.cmd) if config.RPC.ListenAddress != "tcp://127.0.0.1:26657" { t.Error("RPCListenAddress is not using default") @@ -476,10 +443,11 @@ func TestInterceptConfigsWithBadPermissions(t *testing.T) { cmd.PreRunE = preRunETestImpl - serverCtx := &server.Context{} - ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) - if err := cmd.ExecuteContext(ctx); !os.IsPermission(err) { - t.Fatalf("Failed to catch permissions error, got: [%T] %v", err, err) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewNopLogger()) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) + + if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { + t.Fatalf("function failed with [%T] %v", err, err) } } @@ -491,9 +459,10 @@ func TestEmptyMinGasPrices(t *testing.T) { // Run InitCmd to create necessary config files. clientCtx := client.Context{}.WithHomeDir(tempDir).WithCodec(encCfg.Codec) - serverCtx := server.NewDefaultContext() - serverCtx.SetRoot(tempDir) - ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) + viper := viper.New() + viper.Set(flags.FlagHome, tempDir) + ctx := context.WithValue(context.Background(), corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, log.NewLogger(os.Stdout)) ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) cmd := genutilcli.InitCmd(module.NewManager()) cmd.SetArgs([]string{"appnode-test"}) @@ -511,12 +480,12 @@ func TestEmptyMinGasPrices(t *testing.T) { cmd = server.StartCmd[servertypes.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, tempDir, "") cmd.PreRunE = func(cmd *cobra.Command, _ []string) error { - ctx, err := server.InterceptConfigsAndCreateContext(cmd, "", nil, cmtcfg.DefaultConfig()) + viper, err := server.InterceptConfigsAndCreateContext(cmd, "", nil, cmtcfg.DefaultConfig()) if err != nil { return err } - return server.SetCmdServerContext(cmd, ctx) + return server.SetCmdServerContext(cmd, viper, client.GetLoggerFromCmd(cmd)) } err = cmd.ExecuteContext(ctx) require.Errorf(t, err, sdkerrors.ErrAppConfig.Error()) diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 7f7575d43df7..56fffd41479c 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -21,7 +21,6 @@ import ( banktypes "cosmossdk.io/x/bank/types" stakingtypes "cosmossdk.io/x/staking/types" - corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -141,8 +140,7 @@ Example: return err } - serverCtx := corectx.GetServerContextFromCmd(cmd) - config := serverCtx.GetConfig().(server.CometConfig) + config := client.GetConfigFromCmd(cmd) args := initArgs{} args.outputDir, _ = cmd.Flags().GetString(flagOutputDir) @@ -162,7 +160,7 @@ Example: return err } - return initTestnetFiles(clientCtx, cmd, config.Config, mm, genBalIterator, args) + return initTestnetFiles(clientCtx, cmd, config, mm, genBalIterator, args) }, } @@ -409,7 +407,7 @@ func initTestnetFiles( } // Update viper root since root dir become rootdir/node/simd - corectx.GetServerContextFromCmd(cmd).SetRoot(nodeConfig.RootDir) + client.GetViperFromCmd(cmd).Set(flags.FlagHome, nodeConfig.RootDir) cmd.PrintErrf("Successfully initialized %d node directories\n", args.numValidators) return nil diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index 91952d2a07b5..1d73d719e044 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -8,17 +8,16 @@ import ( "github.com/spf13/viper" "github.com/stretchr/testify/require" + corectx "cosmossdk.io/core/context" "cosmossdk.io/depinject" "cosmossdk.io/log" "cosmossdk.io/x/auth" banktypes "cosmossdk.io/x/bank/types" "cosmossdk.io/x/staking" - corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" - "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/testutil/configurator" "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -52,14 +51,14 @@ func Test_TestnetCmd(t *testing.T) { cdcOpts := codectestutil.CodecOptions{} encodingConfig := moduletestutil.MakeTestEncodingConfig(cdcOpts, auth.AppModule{}, staking.AppModule{}) logger := log.NewNopLogger() + viper := viper.New() cfg, err := genutiltest.CreateDefaultCometConfig(home) require.NoError(t, err) err = genutiltest.ExecInitCmd(moduleManager, home, encodingConfig.Codec) require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), logger) - err = genutiltest.WriteAndTrackConfig(serverCtx.GetViper(), home, cfg) + err = genutiltest.WriteAndTrackConfig(viper, home, cfg) require.NoError(t, err) clientCtx := client.Context{}. WithCodec(encodingConfig.Codec). @@ -69,14 +68,15 @@ func Test_TestnetCmd(t *testing.T) { WithValidatorAddressCodec(cdcOpts.GetValidatorCodec()) ctx := context.Background() - ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) cmd := testnetInitFilesCmd(moduleManager, banktypes.GenesisBalancesIterator{}) cmd.SetArgs([]string{fmt.Sprintf("--%s=test", flags.FlagKeyringBackend), fmt.Sprintf("--output-dir=%s", home)}) err = cmd.ExecuteContext(ctx) require.NoError(t, err) - genFile := corectx.GetServerContextFromCmd(cmd).GetConfig().GenesisFile() + genFile := client.GetConfigFromCmd(cmd).GenesisFile() appState, _, err := genutiltypes.GenesisStateFromGenFile(genFile) require.NoError(t, err) diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 21330c0c6fd2..824054800787 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -20,6 +20,7 @@ import ( minttypes "cosmossdk.io/x/mint/types" bam "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/server" @@ -228,11 +229,11 @@ func NewTestNetworkFixture() network.TestFixture { appCtr := func(val network.ValidatorI) servertypes.Application { return NewSimApp( - val.GetCtx().Logger, dbm.NewMemDB(), nil, true, - simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().GetConfig().(server.CometConfig).RootDir), + val.GetLogger(), dbm.NewMemDB(), nil, true, + simtestutil.NewAppOptionsWithFlagHome(client.GetConfigFromViper(val.GetViper()).RootDir), bam.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), bam.SetMinGasPrices(val.GetAppConfig().MinGasPrices), - bam.SetChainID(val.GetCtx().Viper.GetString(flags.FlagChainID)), + bam.SetChainID(val.GetViper().GetString(flags.FlagChainID)), ) } diff --git a/testutil/network/interface.go b/testutil/network/interface.go index 5503e1571f5f..94c10fcdc770 100644 --- a/testutil/network/interface.go +++ b/testutil/network/interface.go @@ -3,11 +3,12 @@ package network import ( "time" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/client" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/server" srvconfig "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/spf13/viper" ) // NetworkI is an interface for a network of validators. @@ -32,7 +33,8 @@ type NetworkI interface { // ValidatorI expose a validator's context and configuration type ValidatorI interface { - GetCtx() *server.Context + GetViper() *viper.Viper + GetLogger() log.Logger GetAppConfig() *srvconfig.Config GetAddress() sdk.AccAddress GetValAddress() sdk.ValAddress diff --git a/testutil/network/network.go b/testutil/network/network.go index 4de152cc9c6c..3d12af8f0ab3 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -19,6 +19,7 @@ import ( dbm "github.com/cosmos/cosmos-db" "github.com/spf13/cobra" + "github.com/spf13/viper" "cosmossdk.io/core/address" "cosmossdk.io/depinject" @@ -48,7 +49,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/server" srvconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/testutil" @@ -224,7 +224,7 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) { if err := depinject.Inject( depinject.Configs( appConfig, - depinject.Supply(val.GetCtx().Logger), + depinject.Supply(val.GetLogger()), ), &appBuilder); err != nil { panic(err) @@ -341,8 +341,9 @@ func New(l Logger, baseDir string, cfg Config) (NetworkI, error) { appCfg.API.Swagger = false appCfg.Telemetry.Enabled = false - ctx := server.NewDefaultContext() - cmtCfg, _ := ctx.GetConfig().(server.CometConfig) + viper := viper.New() + // Create default cometbft config for each validator + cmtCfg := client.GetConfigFromViper(viper) cmtCfg.Consensus.TimeoutCommit = cfg.TimeoutCommit @@ -397,8 +398,6 @@ func New(l Logger, baseDir string, cfg Config) (NetworkI, error) { logger = log.NewLogger(os.Stdout) // TODO(mr): enable selection of log destination. } - ctx.Logger = logger - nodeDirName := fmt.Sprintf("node%d", i) nodeDir := filepath.Join(network.BaseDir, nodeDirName, "simd") clientDir := filepath.Join(network.BaseDir, nodeDirName, "simcli") @@ -435,13 +434,13 @@ func New(l Logger, baseDir string, cfg Config) (NetworkI, error) { cmtCfg.P2P.AllowDuplicateIP = true // write comet config file and track by viper - gentestutil.WriteAndTrackConfig(ctx.GetViper(), nodeDir, cmtCfg.Config) + gentestutil.WriteAndTrackConfig(viper, nodeDir, cmtCfg) var mnemonic string if i < len(cfg.Mnemonics) { mnemonic = cfg.Mnemonics[i] } - nodeID, pubKey, err := genutil.InitializeNodeValidatorFilesFromMnemonic(cmtCfg.Config, mnemonic) + nodeID, pubKey, err := genutil.InitializeNodeValidatorFilesFromMnemonic(cmtCfg, mnemonic) if err != nil { return nil, err } @@ -566,12 +565,13 @@ func New(l Logger, baseDir string, cfg Config) (NetworkI, error) { WithNodeURI(cmtCfg.RPC.ListenAddress) // Provide ChainID here since we can't modify it in the Comet config. - ctx.Viper.Set(flags.FlagChainID, cfg.ChainID) + viper.Set(flags.FlagChainID, cfg.ChainID) network.Validators[i] = &Validator{ AppConfig: appCfg, clientCtx: clientCtx, - ctx: ctx, + viper: viper, + logger: logger, dir: filepath.Join(network.BaseDir, nodeDirName), nodeID: nodeID, pubKey: pubKey, diff --git a/testutil/network/util.go b/testutil/network/util.go index 9fc7e8844d76..c4cf4bc70dbc 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -21,6 +21,7 @@ import ( authtypes "cosmossdk.io/x/auth/types" banktypes "cosmossdk.io/x/bank/types" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" @@ -31,8 +32,8 @@ import ( ) func startInProcess(cfg Config, val *Validator) error { - logger := val.ctx.Logger - cmtCfg := val.ctx.GetConfig().(server.CometConfig) + logger := val.GetLogger() + cmtCfg := client.GetConfigFromViper(val.GetViper()) cmtCfg.Instrumentation.Prometheus = false if err := val.AppConfig.ValidateBasic(); err != nil { @@ -66,7 +67,7 @@ func startInProcess(cfg Config, val *Validator) error { cmtApp := server.NewCometABCIWrapper(app) tmNode, err := node.NewNode( //resleak:notresource context.TODO(), - cmtCfg.Config, + cmtCfg, pvm.LoadOrGenFilePV(cmtCfg.PrivValidatorKeyFile(), cmtCfg.PrivValidatorStateFile()), nodeKey, proxy.NewLocalClientCreator(cmtApp), @@ -140,7 +141,7 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { } for i := 0; i < cfg.NumValidators; i++ { - cmtCfg := vals[i].ctx.GetConfig().(server.CometConfig) + cmtCfg := client.GetConfigFromViper(vals[i].GetViper()) nodeDir := filepath.Join(outputDir, vals[i].moniker, "simd") gentxsDir := filepath.Join(outputDir, "gentxs") @@ -157,7 +158,7 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { } appState, err := genutil.GenAppStateFromConfig(cfg.Codec, cfg.TxConfig, - cmtCfg.Config, initCfg, appGenesis, banktypes.GenesisBalancesIterator{}, genutiltypes.DefaultMessageValidator, + cmtCfg, initCfg, appGenesis, banktypes.GenesisBalancesIterator{}, genutiltypes.DefaultMessageValidator, cfg.ValidatorAddressCodec, cfg.AddressCodec) if err != nil { return err diff --git a/testutil/network/validator.go b/testutil/network/validator.go index 261ecde385cd..feb9a84c1f65 100644 --- a/testutil/network/validator.go +++ b/testutil/network/validator.go @@ -6,12 +6,13 @@ import ( "github.com/cometbft/cometbft/node" cmtclient "github.com/cometbft/cometbft/rpc/client" + "github.com/spf13/viper" "golang.org/x/sync/errgroup" "google.golang.org/grpc" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/client" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" srvconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -24,7 +25,8 @@ import ( type Validator struct { AppConfig *srvconfig.Config clientCtx client.Context - ctx *server.Context + viper *viper.Viper + logger log.Logger dir string nodeID string pubKey cryptotypes.PubKey @@ -47,8 +49,12 @@ type Validator struct { var _ ValidatorI = &Validator{} -func (v *Validator) GetCtx() *server.Context { - return v.ctx +func (v *Validator) GetViper() *viper.Viper { + return v.viper +} + +func (v *Validator) GetLogger() log.Logger { + return v.logger } func (v *Validator) GetClientCtx() client.Context { diff --git a/x/genutil/client/cli/collect.go b/x/genutil/client/cli/collect.go index 45ce14bf1345..3b0354c1073b 100644 --- a/x/genutil/client/cli/collect.go +++ b/x/genutil/client/cli/collect.go @@ -2,16 +2,13 @@ package cli import ( "encoding/json" - "fmt" "path/filepath" "github.com/spf13/cobra" "cosmossdk.io/errors" - corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -24,16 +21,12 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, validator ty Use: "collect-gentxs", Short: "Collect genesis txs and output a genesis.json file", RunE: func(cmd *cobra.Command, _ []string) error { - serverCtx := corectx.GetServerContextFromCmd(cmd) - config, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + config := client.GetConfigFromCmd(cmd) clientCtx := client.GetClientContextFromCmd(cmd) cdc := clientCtx.Codec - nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(config.Config) + nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(config) if err != nil { return errors.Wrap(err, "failed to initialize node validator files") } @@ -52,7 +45,7 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, validator ty toPrint := newPrintInfo(config.Moniker, appGenesis.ChainID, nodeID, genTxsDir, json.RawMessage("")) initCfg := types.NewInitConfig(appGenesis.ChainID, genTxsDir, nodeID, valPubKey) - appMessage, err := genutil.GenAppStateFromConfig(cdc, clientCtx.TxConfig, config.Config, initCfg, appGenesis, genBalIterator, validator, clientCtx.ValidatorAddressCodec, clientCtx.AddressCodec) + appMessage, err := genutil.GenAppStateFromConfig(cdc, clientCtx.TxConfig, config, initCfg, appGenesis, genBalIterator, validator, clientCtx.ValidatorAddressCodec, clientCtx.AddressCodec) if err != nil { return errors.Wrap(err, "failed to get genesis app state from config") } diff --git a/x/genutil/client/cli/export.go b/x/genutil/client/cli/export.go index 5dfc7ef0ebc7..986b9c1cdb2d 100644 --- a/x/genutil/client/cli/export.go +++ b/x/genutil/client/cli/export.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" - corectx "cosmossdk.io/core/context" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -32,17 +32,15 @@ func ExportCmd(appExporter servertypes.AppExporter) *cobra.Command { Short: "Export state to JSON", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) error { - serverCtx := corectx.GetServerContextFromCmd(cmd) - config, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + config := client.GetConfigFromCmd(cmd) + viper := client.GetViperFromCmd(cmd) + logger := client.GetLoggerFromCmd(cmd) if _, err := os.Stat(config.GenesisFile()); os.IsNotExist(err) { return err } - db, err := server.OpenDB(config.RootDir, server.GetAppDBBackend(serverCtx.GetViper())) + db, err := server.OpenDB(config.RootDir, server.GetAppDBBackend(viper)) if err != nil { return err } @@ -70,7 +68,7 @@ func ExportCmd(appExporter servertypes.AppExporter) *cobra.Command { } traceWriterFile, _ := cmd.Flags().GetString(flagTraceStore) - traceWriter, cleanup, err := server.SetupTraceWriter(serverCtx.GetLogger(), traceWriterFile) //resleak:notresource + traceWriter, cleanup, err := server.SetupTraceWriter(logger, traceWriterFile) //resleak:notresource if err != nil { return err } @@ -82,7 +80,7 @@ func ExportCmd(appExporter servertypes.AppExporter) *cobra.Command { modulesToExport, _ := cmd.Flags().GetStringSlice(flagModulesToExport) outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument) - exported, err := appExporter(serverCtx.GetLogger(), db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.GetViper(), modulesToExport) + exported, err := appExporter(logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, viper, modulesToExport) if err != nil { return fmt.Errorf("error exporting state: %w", err) } diff --git a/x/genutil/client/cli/export_test.go b/x/genutil/client/cli/export_test.go index c79d0d83173f..4eb670b8d4b8 100644 --- a/x/genutil/client/cli/export_test.go +++ b/x/genutil/client/cli/export_test.go @@ -19,8 +19,8 @@ import ( "cosmossdk.io/log" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/testutil/cmdtest" "github.com/cosmos/cosmos-sdk/types/module" @@ -36,8 +36,9 @@ type ExportSystem struct { Ctx context.Context - Sctx *server.Context - Cctx client.Context + Viper *viper.Viper + Logger log.Logger + Cctx client.Context HomeDir string } @@ -64,21 +65,22 @@ func NewExportSystem(t *testing.T, exporter types.AppExporter) *ExportSystem { tw := zerolog.NewTestWriter(t) tw.Frame = 5 // Seems to be the magic number to get source location to match logger calls. - sCtx := server.NewContext( - viper.New(), - log.NewCustomLogger(zerolog.New(tw)), - ) - writeAndTrackDefaultConfig(sCtx.GetViper(), homeDir) + viper := viper.New() + logger := log.NewCustomLogger(zerolog.New(tw)) + writeAndTrackDefaultConfig(viper, homeDir) cCtx := (client.Context{}).WithHomeDir(homeDir) - ctx := context.WithValue(context.Background(), server.ServerContextKey, sCtx) + ctx := context.WithValue(context.Background(), corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx = context.WithValue(ctx, client.ClientContextKey, &cCtx) return &ExportSystem{ sys: sys, Ctx: ctx, - Sctx: sCtx, + Viper: viper, + Logger: logger, Cctx: cCtx, HomeDir: homeDir, } diff --git a/x/genutil/client/cli/genaccount.go b/x/genutil/client/cli/genaccount.go index b800ac44dc57..8debe3f97a6d 100644 --- a/x/genutil/client/cli/genaccount.go +++ b/x/genutil/client/cli/genaccount.go @@ -8,11 +8,9 @@ import ( "cosmossdk.io/core/address" - corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/genutil" ) @@ -39,11 +37,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - serverCtx := corectx.GetServerContextFromCmd(cmd) - config, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + config := client.GetConfigFromCmd(cmd) var kr keyring.Keyring addr, err := addressCodec.StringToBytes(args[0]) diff --git a/x/genutil/client/cli/genaccount_test.go b/x/genutil/client/cli/genaccount_test.go index 3e3402f9c0cf..3a9fe05848c1 100644 --- a/x/genutil/client/cli/genaccount_test.go +++ b/x/genutil/client/cli/genaccount_test.go @@ -10,12 +10,12 @@ import ( "cosmossdk.io/log" "cosmossdk.io/x/auth" + corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -71,13 +71,13 @@ func TestAddGenesisAccountCmd(t *testing.T) { t.Run(tc.name, func(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() + viper := viper.New() appCodec := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}).Codec err = genutiltest.ExecInitCmd(testMbm, home, appCodec) require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), logger) - writeAndTrackDefaultConfig(serverCtx.Viper, home) + writeAndTrackDefaultConfig(viper, home) clientCtx := client.Context{}.WithCodec(appCodec).WithHomeDir(home).WithAddressCodec(ac) if tc.withKeyring { @@ -91,7 +91,8 @@ func TestAddGenesisAccountCmd(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) cmd := genutilcli.AddGenesisAccountCmd(addresscodec.NewBech32Codec("cosmos")) cmd.SetArgs([]string{ diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index ff8ff97f4a64..9c6d0c5034c7 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -16,7 +16,6 @@ import ( authclient "cosmossdk.io/x/auth/client" "cosmossdk.io/x/staking/client/cli" - corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -56,18 +55,14 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o `, defaultsDesc, version.AppName, ), RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := corectx.GetServerContextFromCmd(cmd) - config, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + config := client.GetConfigFromCmd(cmd) clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } cdc := clientCtx.Codec - nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(config.Config) + nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(config) if err != nil { return errors.Wrap(err, "failed to initialize node validator files") } diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index 7f8bb6abf246..e87482830cb4 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -15,17 +15,16 @@ import ( errorsmod "cosmossdk.io/errors" "cosmossdk.io/math/unsafe" - corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/input" - "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil/types" + corectx "cosmossdk.io/core/context" ) const ( @@ -82,11 +81,11 @@ func InitCmd(mm *module.Manager) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - serverCtx := corectx.GetServerContextFromCmd(cmd) - config, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + fmt.Println("Init viper", cmd.Context().Value(corectx.ViperContextKey)) + + config := client.GetConfigFromCmd(cmd) + + fmt.Println("Init Root", config.RootDir) chainID, _ := cmd.Flags().GetString(flags.FlagChainID) switch { @@ -119,7 +118,7 @@ func InitCmd(mm *module.Manager) *cobra.Command { initHeight = 1 } - nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(config.Config, mnemonic) + nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(config, mnemonic) if err != nil { return err } @@ -181,7 +180,7 @@ func InitCmd(mm *module.Manager) *cobra.Command { toPrint := newPrintInfo(config.Moniker, chainID, nodeID, "", appState) - cfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config.Config) + cfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config) return displayInfo(toPrint) }, } diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index 42267453a1b0..846e2f906c8c 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -64,9 +64,9 @@ func TestInitCmd(t *testing.T) { t.Run(tt.name, func(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() + viper := viper.New() - serverCtx := server.NewContext(viper.New(), logger) - writeAndTrackDefaultConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(viper, home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -76,7 +76,8 @@ func TestInitCmd(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) cmd := genutilcli.InitCmd(testMbm) cmd.SetArgs( @@ -96,9 +97,9 @@ func TestInitCmd(t *testing.T) { func TestInitRecover(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() + viper := viper.New() - serverCtx := server.NewContext(viper.New(), logger) - writeAndTrackDefaultConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(viper, home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -108,9 +109,11 @@ func TestInitRecover(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) cmd := genutilcli.InitCmd(testMbm) + cmd.SetContext(ctx) mockIn := testutil.ApplyMockIODiscardOutErr(cmd) cmd.SetArgs([]string{ @@ -126,9 +129,9 @@ func TestInitRecover(t *testing.T) { func TestInitDefaultBondDenom(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() + viper := viper.New() - serverCtx := server.NewContext(viper.New(), logger) - writeAndTrackDefaultConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(viper, home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -138,7 +141,8 @@ func TestInitDefaultBondDenom(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) cmd := genutilcli.InitCmd(testMbm) @@ -152,9 +156,9 @@ func TestInitDefaultBondDenom(t *testing.T) { func TestEmptyState(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() + viper := viper.New() - serverCtx := server.NewContext(viper.New(), logger) - writeAndTrackDefaultConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(viper, home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -164,7 +168,8 @@ func TestEmptyState(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) cmd := genutilcli.InitCmd(testMbm) cmd.SetArgs([]string{"appnode-test"}) @@ -244,9 +249,9 @@ func TestInitNodeValidatorFiles(t *testing.T) { func TestInitConfig(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() + viper := viper.New() - serverCtx := server.NewContext(viper.New(), logger) - writeAndTrackDefaultConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(viper, home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -257,12 +262,16 @@ func TestInitConfig(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) cmd := genutilcli.InitCmd(testMbm) cmd.SetArgs([]string{"testnode"}) - require.NoError(t, cmd.ExecuteContext(ctx)) + err := cmd.ExecuteContext(ctx) + require.NoError(t, err) + + // require.NoError(t, cmd.ExecuteContext(ctx)) old := os.Stdout r, w, _ := os.Pipe() @@ -289,11 +298,11 @@ func TestInitConfig(t *testing.T) { func TestInitWithHeight(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() + viper := viper.New() cfg, err := genutiltest.CreateDefaultCometConfig(home) require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), logger) - writeAndTrackDefaultConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(viper, home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -304,11 +313,14 @@ func TestInitWithHeight(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) testInitialHeight := int64(333) cmd := genutilcli.InitCmd(testMbm) + + fmt.Println("RootDir", viper.Get(flags.FlagHome)) cmd.SetArgs([]string{"init-height-test", fmt.Sprintf("--%s=%d", flags.FlagInitHeight, testInitialHeight)}) require.NoError(t, cmd.ExecuteContext(ctx)) @@ -322,11 +334,11 @@ func TestInitWithHeight(t *testing.T) { func TestInitWithNegativeHeight(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() + viper := viper.New() cfg, err := genutiltest.CreateDefaultCometConfig(home) require.NoError(t, err) - serverCtx := server.NewContext(viper.New(), logger) - writeAndTrackDefaultConfig(serverCtx.GetViper(), home) + writeAndTrackDefaultConfig(viper, home) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -337,7 +349,8 @@ func TestInitWithNegativeHeight(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) testInitialHeight := int64(-333) diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 9a3fe811c4e8..735fc51ccd89 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -6,8 +6,7 @@ import ( "github.com/spf13/cobra" - corectx "cosmossdk.io/core/context" - "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -22,11 +21,7 @@ func ValidateGenesisCmd(mm *module.Manager) *cobra.Command { Args: cobra.RangeArgs(0, 1), Short: "Validates the genesis file at the default location or at the location passed as an arg", RunE: func(cmd *cobra.Command, args []string) (err error) { - serverCtx := corectx.GetServerContextFromCmd(cmd) - cfg, ok := serverCtx.GetConfig().(server.CometConfig) - if !ok { - return fmt.Errorf("Can not convert cometbft config") - } + cfg := client.GetConfigFromCmd(cmd) // Load default if passed no args, otherwise load passed file var genesis string diff --git a/x/genutil/client/testutil/helpers.go b/x/genutil/client/testutil/helpers.go index 23950e3743cb..8274f5c4730a 100644 --- a/x/genutil/client/testutil/helpers.go +++ b/x/genutil/client/testutil/helpers.go @@ -14,7 +14,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/types/module" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" @@ -22,10 +21,10 @@ import ( func ExecInitCmd(mm *module.Manager, home string, cdc codec.Codec) error { logger := log.NewNopLogger() + viper := viper.New() cmd := genutilcli.InitCmd(mm) - serverCtx := server.NewContext(viper.New(), logger) cfg, _ := CreateDefaultCometConfig(home) - WriteAndTrackConfig(serverCtx.GetViper(), home, cfg) + WriteAndTrackConfig(viper, home, cfg) clientCtx := client.Context{}.WithCodec(cdc).WithHomeDir(home) _, out := testutil.ApplyMockIO(cmd) @@ -33,7 +32,8 @@ func ExecInitCmd(mm *module.Manager, home string, cdc codec.Codec) error { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) cmd.SetArgs([]string{"appnode-test"}) diff --git a/x/genutil/collect_test.go b/x/genutil/collect_test.go index fd8295728ee5..fea26e1ecb96 100644 --- a/x/genutil/collect_test.go +++ b/x/genutil/collect_test.go @@ -13,7 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil/types" @@ -54,8 +53,9 @@ func TestCollectTxsHandlesDirectories(t *testing.T) { }) // 2. Ensure that we don't encounter any error traversing the directory. - srvCtx := server.NewDefaultContext() - _ = srvCtx + // What is this for??? + // srvCtx := server.NewDefaultContext() + // _ = srvCtx cdc := codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) genesis := &types.AppGenesis{AppState: []byte("{}")} balItr := new(doNothingIterator) From cc3a5dfd2cf034cc16b4607d0b01e0ad5c138adb Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Mon, 20 May 2024 16:10:00 +0700 Subject: [PATCH 15/29] fix network tests --- tests/e2e/genutil/export_test.go | 23 +++++++++++++---------- testutil/network/network.go | 9 +++++---- testutil/network/util.go | 8 ++++++-- x/genutil/client/testutil/helpers.go | 8 ++++++++ 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/tests/e2e/genutil/export_test.go b/tests/e2e/genutil/export_test.go index 78b71d6c58a4..1e1d848be645 100644 --- a/tests/e2e/genutil/export_test.go +++ b/tests/e2e/genutil/export_test.go @@ -16,22 +16,23 @@ import ( abci "github.com/cometbft/cometbft/abci/types" dbm "github.com/cosmos/cosmos-db" "github.com/spf13/cobra" + "github.com/spf13/viper" + "github.com/stretchr/testify/require" "gotest.tools/v3/assert" + corectx "cosmossdk.io/core/context" "cosmossdk.io/log" "cosmossdk.io/simapp" - corectx "cosmossdk.io/core/context" + cmtcfg "github.com/cometbft/cometbft/config" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/x/genutil" - gentestutil "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + gentestutil "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - cmtcfg "github.com/cometbft/cometbft/config" ) func TestExportCmd_ConsensusParams(t *testing.T) { @@ -58,8 +59,10 @@ func TestExportCmd_ConsensusParams(t *testing.T) { func TestExportCmd_HomeDir(t *testing.T) { _, ctx, _, cmd := setupApp(t, t.TempDir()) - serverCtxPtr := ctx.Value(corectx.ServerContextKey) - serverCtxPtr.(corectx.ServerContext).GetConfig().SetRoot("foobar") + v := ctx.Value(corectx.ViperContextKey) + viper, ok := v.(*viper.Viper) + require.True(t, ok) + viper.Set(flags.FlagHome, "foobar") err := cmd.ExecuteContext(ctx) assert.ErrorContains(t, err, "stat foobar/config/genesis.json: no such file or directory") @@ -171,8 +174,8 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, ge stateBytes, err := json.MarshalIndent(genesisState, "", " ") assert.NilError(t, err) - serverCtx := server.NewDefaultContext() - gentestutil.WriteAndTrackConfig(serverCtx.GetViper(), tempDir, cmtcfg.DefaultConfig()) + viper := viper.New() + gentestutil.WriteAndTrackConfig(viper, tempDir, cmtcfg.DefaultConfig()) clientCtx := client.Context{}.WithCodec(app.AppCodec()) appGenesis := genutiltypes.AppGenesis{ @@ -184,7 +187,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, ge } // save genesis file - err = genutil.ExportGenesisFile(&appGenesis, serverCtx.GetConfig().GenesisFile()) + err = genutil.ExportGenesisFile(&appGenesis, client.GetConfigFromViper(viper).GenesisFile()) assert.NilError(t, err) _, err = app.InitChain(&abci.InitChainRequest{ @@ -216,7 +219,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, ge ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) return app, ctx, appGenesis, cmd } diff --git a/testutil/network/network.go b/testutil/network/network.go index 45ab81c9faab..97baf0ca6ca2 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -38,6 +38,7 @@ import ( _ "cosmossdk.io/x/staking" // import staking as a blank stakingtypes "cosmossdk.io/x/staking/types" + cmtcfg "github.com/cometbft/cometbft/config" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -58,7 +59,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/genutil" - gentestutil "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" ) // package-wide network lock to only allow one test network at a time @@ -328,6 +328,7 @@ func New(l Logger, baseDir string, cfg Config) (NetworkI, error) { monikers := make([]string, cfg.NumValidators) nodeIDs := make([]string, cfg.NumValidators) valPubKeys := make([]cryptotypes.PubKey, cfg.NumValidators) + cmtConfigs := make([]*cmtcfg.Config, cfg.NumValidators) var ( genAccounts []authtypes.GenesisAccount @@ -438,8 +439,8 @@ func New(l Logger, baseDir string, cfg Config) (NetworkI, error) { cmtCfg.P2P.AddrBookStrict = false cmtCfg.P2P.AllowDuplicateIP = true - // write comet config file and track by viper - gentestutil.WriteAndTrackConfig(viper, nodeDir, cmtCfg) + cmtConfigs[i] = cmtCfg + var mnemonic string if i < len(cfg.Mnemonics) { mnemonic = cfg.Mnemonics[i] @@ -593,7 +594,7 @@ func New(l Logger, baseDir string, cfg Config) (NetworkI, error) { if err != nil { return nil, err } - err = collectGenFiles(cfg, network.Validators, network.BaseDir) + err = collectGenFiles(cfg, network.Validators, cmtConfigs, network.BaseDir) if err != nil { return nil, err } diff --git a/testutil/network/util.go b/testutil/network/util.go index c4cf4bc70dbc..0be62343d361 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -28,6 +28,7 @@ import ( servercmtlog "github.com/cosmos/cosmos-sdk/server/log" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -134,14 +135,14 @@ func startInProcess(cfg Config, val *Validator) error { return nil } -func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { +func collectGenFiles(cfg Config, vals []*Validator, cmtConfigs []*cmtcfg.Config, outputDir string) error { genTime := cfg.GenesisTime if genTime.IsZero() { genTime = cmttime.Now() } for i := 0; i < cfg.NumValidators; i++ { - cmtCfg := client.GetConfigFromViper(vals[i].GetViper()) + cmtCfg := cmtConfigs[i] nodeDir := filepath.Join(outputDir, vals[i].moniker, "simd") gentxsDir := filepath.Join(outputDir, "gentxs") @@ -168,6 +169,9 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { if err := genutil.ExportGenesisFileWithTime(genFile, cfg.ChainID, nil, appState, genTime); err != nil { return err } + + v := vals[i].GetViper() + genutiltest.TrackConfig(v, nodeDir) } return nil diff --git a/x/genutil/client/testutil/helpers.go b/x/genutil/client/testutil/helpers.go index e8f8b9cc819b..c2a4f24e356b 100644 --- a/x/genutil/client/testutil/helpers.go +++ b/x/genutil/client/testutil/helpers.go @@ -63,3 +63,11 @@ func WriteAndTrackConfig(v *viper.Viper, home string, cfg *cmtcfg.Config) error v.AddConfigPath(filepath.Join(home, "config")) return v.ReadInConfig() } + +func TrackConfig(v *viper.Viper, home string) error { + v.Set(flags.FlagHome, home) + v.SetConfigType("toml") + v.SetConfigName("config") + v.AddConfigPath(filepath.Join(home, "config")) + return v.ReadInConfig() +} From a360be7695d6e18fd7f246e76e55b0014e9e1d5b Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Mon, 20 May 2024 16:31:09 +0700 Subject: [PATCH 16/29] lint + some cleanup --- client/cmd.go | 8 +++----- core/context/server_context.go | 4 ++-- server/cmd/execute.go | 2 +- server/util.go | 4 +--- server/util_test.go | 15 +++++++++------ testutil/network/interface.go | 4 +++- testutil/network/network.go | 2 +- testutil/network/validator.go | 1 + x/genutil/client/cli/export_test.go | 2 +- x/genutil/client/cli/genaccount_test.go | 2 +- x/genutil/client/cli/init.go | 3 --- 11 files changed, 23 insertions(+), 24 deletions(-) diff --git a/client/cmd.go b/client/cmd.go index d023f0a9cd19..aa2d4e878e77 100644 --- a/client/cmd.go +++ b/client/cmd.go @@ -9,21 +9,21 @@ import ( "slices" "strings" + cmtcfg "github.com/cometbft/cometbft/config" "github.com/spf13/cobra" "github.com/spf13/pflag" + "github.com/spf13/viper" "google.golang.org/grpc" "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - corectx "cosmossdk.io/core/context" "cosmossdk.io/log" - cmtcfg "github.com/cometbft/cometbft/config" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/spf13/viper" ) // ClientContextKey defines the context key used to retrieve a client.Context from @@ -390,10 +390,8 @@ func GetViperFromCmd(cmd *cobra.Command) *viper.Viper { func GetConfigFromCmd(cmd *cobra.Command) *cmtcfg.Config { v := cmd.Context().Value(corectx.ViperContextKey) - fmt.Println("viper", v) viper, ok := v.(*viper.Viper) if !ok { - fmt.Println("viper rong") return cmtcfg.DefaultConfig() } return GetConfigFromViper(viper) diff --git a/core/context/server_context.go b/core/context/server_context.go index fa213d9c524e..806ed4742b26 100644 --- a/core/context/server_context.go +++ b/core/context/server_context.go @@ -2,5 +2,5 @@ package context var ( LoggerContextKey = "server.logger" - ViperContextKey = "server.viper" -) + ViperContextKey = "server.viper" +) diff --git a/server/cmd/execute.go b/server/cmd/execute.go index a8b7eb58de9f..1d52b003f953 100644 --- a/server/cmd/execute.go +++ b/server/cmd/execute.go @@ -9,9 +9,9 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + corectx "cosmossdk.io/core/context" "cosmossdk.io/log" - corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" ) diff --git a/server/util.go b/server/util.go index 8838f350be63..f61cfa7f6281 100644 --- a/server/util.go +++ b/server/util.go @@ -24,12 +24,12 @@ import ( "github.com/spf13/viper" "golang.org/x/sync/errgroup" + corectx "cosmossdk.io/core/context" "cosmossdk.io/log" "cosmossdk.io/store" "cosmossdk.io/store/snapshots" snapshottypes "cosmossdk.io/store/snapshots/types" storetypes "cosmossdk.io/store/types" - corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" @@ -40,8 +40,6 @@ import ( genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) - - func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) { defer func() { if r := recover(); r != nil { diff --git a/server/util_test.go b/server/util_test.go index 6436c297f8ed..b58f61a9fc65 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -16,6 +16,9 @@ import ( "github.com/spf13/viper" "github.com/stretchr/testify/require" + corectx "cosmossdk.io/core/context" + "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" @@ -26,8 +29,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/module/testutil" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" - corectx "cosmossdk.io/core/context" - "cosmossdk.io/log" ) var errCanceledInPreRun = errors.New("canceled in prerun") @@ -61,7 +62,6 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T cmd.PreRunE = preRunETestImpl - serverCtx := &server.Context{} ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { @@ -106,7 +106,10 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T } // Test that the config for use in server/start.go is created - if serverCtx.Viper == nil { + v := ctx.Value(corectx.ViperContextKey) + viper, _ := v.(*viper.Viper) + + if viper == nil { t.Error("app config Viper instance not created") } } @@ -446,8 +449,8 @@ func TestInterceptConfigsWithBadPermissions(t *testing.T) { ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewNopLogger()) ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) - if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { - t.Fatalf("function failed with [%T] %v", err, err) + if err := cmd.ExecuteContext(ctx); !os.IsPermission(err) { + t.Fatalf("Failed to catch permissions error, got: [%T] %v", err, err) } } diff --git a/testutil/network/interface.go b/testutil/network/interface.go index 94c10fcdc770..37356ea525c8 100644 --- a/testutil/network/interface.go +++ b/testutil/network/interface.go @@ -3,12 +3,14 @@ package network import ( "time" + "github.com/spf13/viper" + "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/client" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" srvconfig "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/spf13/viper" ) // NetworkI is an interface for a network of validators. diff --git a/testutil/network/network.go b/testutil/network/network.go index 97baf0ca6ca2..3717f7e65b9d 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -17,6 +17,7 @@ import ( "testing" "time" + cmtcfg "github.com/cometbft/cometbft/config" dbm "github.com/cosmos/cosmos-db" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -38,7 +39,6 @@ import ( _ "cosmossdk.io/x/staking" // import staking as a blank stakingtypes "cosmossdk.io/x/staking/types" - cmtcfg "github.com/cometbft/cometbft/config" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" diff --git a/testutil/network/validator.go b/testutil/network/validator.go index feb9a84c1f65..d3ba6b40fad5 100644 --- a/testutil/network/validator.go +++ b/testutil/network/validator.go @@ -11,6 +11,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/client" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/server/api" diff --git a/x/genutil/client/cli/export_test.go b/x/genutil/client/cli/export_test.go index 4eb670b8d4b8..244aa727ef5b 100644 --- a/x/genutil/client/cli/export_test.go +++ b/x/genutil/client/cli/export_test.go @@ -17,9 +17,9 @@ import ( "github.com/spf13/viper" "github.com/stretchr/testify/require" + corectx "cosmossdk.io/core/context" "cosmossdk.io/log" - corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/testutil/cmdtest" diff --git a/x/genutil/client/cli/genaccount_test.go b/x/genutil/client/cli/genaccount_test.go index 3a9fe05848c1..2e2b5964ed4f 100644 --- a/x/genutil/client/cli/genaccount_test.go +++ b/x/genutil/client/cli/genaccount_test.go @@ -7,10 +7,10 @@ import ( "github.com/spf13/viper" "github.com/stretchr/testify/require" + corectx "cosmossdk.io/core/context" "cosmossdk.io/log" "cosmossdk.io/x/auth" - corectx "cosmossdk.io/core/context" "github.com/cosmos/cosmos-sdk/client" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index e87482830cb4..d50f21272e30 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -24,7 +24,6 @@ import ( "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil/types" - corectx "cosmossdk.io/core/context" ) const ( @@ -81,11 +80,9 @@ func InitCmd(mm *module.Manager) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - fmt.Println("Init viper", cmd.Context().Value(corectx.ViperContextKey)) config := client.GetConfigFromCmd(cmd) - fmt.Println("Init Root", config.RootDir) chainID, _ := cmd.Flags().GetString(flags.FlagChainID) switch { From c27b303a258e2a0260adf707478a50cdbf8cd037 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Mon, 20 May 2024 16:39:34 +0700 Subject: [PATCH 17/29] err check --- tests/e2e/genutil/export_test.go | 5 ++-- testutil/network/util.go | 5 +++- x/genutil/client/cli/genaccount_test.go | 3 ++- x/genutil/client/cli/init.go | 3 --- x/genutil/client/cli/init_test.go | 34 +++++++++++++++---------- x/genutil/client/testutil/helpers.go | 9 ++++--- 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/tests/e2e/genutil/export_test.go b/tests/e2e/genutil/export_test.go index 1e1d848be645..8f91908095a2 100644 --- a/tests/e2e/genutil/export_test.go +++ b/tests/e2e/genutil/export_test.go @@ -14,6 +14,7 @@ import ( "testing" abci "github.com/cometbft/cometbft/abci/types" + cmtcfg "github.com/cometbft/cometbft/config" dbm "github.com/cosmos/cosmos-db" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -24,7 +25,6 @@ import ( "cosmossdk.io/log" "cosmossdk.io/simapp" - cmtcfg "github.com/cometbft/cometbft/config" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/types" @@ -175,7 +175,8 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, ge assert.NilError(t, err) viper := viper.New() - gentestutil.WriteAndTrackConfig(viper, tempDir, cmtcfg.DefaultConfig()) + err = gentestutil.WriteAndTrackConfig(viper, tempDir, cmtcfg.DefaultConfig()) + assert.NilError(t, err) clientCtx := client.Context{}.WithCodec(app.AppCodec()) appGenesis := genutiltypes.AppGenesis{ diff --git a/testutil/network/util.go b/testutil/network/util.go index 0be62343d361..14a6196189d6 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -171,7 +171,10 @@ func collectGenFiles(cfg Config, vals []*Validator, cmtConfigs []*cmtcfg.Config, } v := vals[i].GetViper() - genutiltest.TrackConfig(v, nodeDir) + err = genutiltest.TrackConfig(v, nodeDir) + if err != nil { + return err + } } return nil diff --git a/x/genutil/client/cli/genaccount_test.go b/x/genutil/client/cli/genaccount_test.go index 2e2b5964ed4f..d2c6c08b6748 100644 --- a/x/genutil/client/cli/genaccount_test.go +++ b/x/genutil/client/cli/genaccount_test.go @@ -77,7 +77,8 @@ func TestAddGenesisAccountCmd(t *testing.T) { err = genutiltest.ExecInitCmd(testMbm, home, appCodec) require.NoError(t, err) - writeAndTrackDefaultConfig(viper, home) + err := writeAndTrackDefaultConfig(viper, home) + require.NoError(t, err) clientCtx := client.Context{}.WithCodec(appCodec).WithHomeDir(home).WithAddressCodec(ac) if tc.withKeyring { diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index d50f21272e30..920dfcec260f 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -80,10 +80,7 @@ func InitCmd(mm *module.Manager) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - config := client.GetConfigFromCmd(cmd) - - chainID, _ := cmd.Flags().GetString(flags.FlagChainID) switch { case chainID != "": diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index 846e2f906c8c..c4be32548854 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -66,7 +66,8 @@ func TestInitCmd(t *testing.T) { logger := log.NewNopLogger() viper := viper.New() - writeAndTrackDefaultConfig(viper, home) + err := writeAndTrackDefaultConfig(viper, home) + require.NoError(t, err) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -99,7 +100,8 @@ func TestInitRecover(t *testing.T) { logger := log.NewNopLogger() viper := viper.New() - writeAndTrackDefaultConfig(viper, home) + err := writeAndTrackDefaultConfig(viper, home) + require.NoError(t, err) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -131,7 +133,8 @@ func TestInitDefaultBondDenom(t *testing.T) { logger := log.NewNopLogger() viper := viper.New() - writeAndTrackDefaultConfig(viper, home) + err := writeAndTrackDefaultConfig(viper, home) + require.NoError(t, err) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -158,7 +161,8 @@ func TestEmptyState(t *testing.T) { logger := log.NewNopLogger() viper := viper.New() - writeAndTrackDefaultConfig(viper, home) + err := writeAndTrackDefaultConfig(viper, home) + require.NoError(t, err) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -251,7 +255,8 @@ func TestInitConfig(t *testing.T) { logger := log.NewNopLogger() viper := viper.New() - writeAndTrackDefaultConfig(viper, home) + err := writeAndTrackDefaultConfig(viper, home) + require.NoError(t, err) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -268,11 +273,9 @@ func TestInitConfig(t *testing.T) { cmd := genutilcli.InitCmd(testMbm) cmd.SetArgs([]string{"testnode"}) - err := cmd.ExecuteContext(ctx) + err = cmd.ExecuteContext(ctx) require.NoError(t, err) - // require.NoError(t, cmd.ExecuteContext(ctx)) - old := os.Stdout r, w, _ := os.Pipe() os.Stdout = w @@ -302,7 +305,8 @@ func TestInitWithHeight(t *testing.T) { cfg, err := genutiltest.CreateDefaultCometConfig(home) require.NoError(t, err) - writeAndTrackDefaultConfig(viper, home) + err = writeAndTrackDefaultConfig(viper, home) + require.NoError(t, err) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -338,7 +342,8 @@ func TestInitWithNegativeHeight(t *testing.T) { cfg, err := genutiltest.CreateDefaultCometConfig(home) require.NoError(t, err) - writeAndTrackDefaultConfig(viper, home) + err = writeAndTrackDefaultConfig(viper, home) + require.NoError(t, err) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) clientCtx := client.Context{}. @@ -378,7 +383,10 @@ func makeCodec() codec.Codec { return codec.NewProtoCodec(interfaceRegistry) } -func writeAndTrackDefaultConfig(v *viper.Viper, home string) { - cfg, _ := genutiltest.CreateDefaultCometConfig(home) - genutiltest.WriteAndTrackConfig(v, home, cfg) +func writeAndTrackDefaultConfig(v *viper.Viper, home string) error { + cfg, err := genutiltest.CreateDefaultCometConfig(home) + if err != nil { + return err + } + return genutiltest.WriteAndTrackConfig(v, home, cfg) } diff --git a/x/genutil/client/testutil/helpers.go b/x/genutil/client/testutil/helpers.go index c2a4f24e356b..798dad19f9cb 100644 --- a/x/genutil/client/testutil/helpers.go +++ b/x/genutil/client/testutil/helpers.go @@ -24,7 +24,10 @@ func ExecInitCmd(mm *module.Manager, home string, cdc codec.Codec) error { viper := viper.New() cmd := genutilcli.InitCmd(mm) cfg, _ := CreateDefaultCometConfig(home) - WriteAndTrackConfig(viper, home, cfg) + err := WriteAndTrackConfig(viper, home, cfg) + if err != nil { + return err + } clientCtx := client.Context{}.WithCodec(cdc).WithHomeDir(home) _, out := testutil.ApplyMockIO(cmd) @@ -37,9 +40,7 @@ func ExecInitCmd(mm *module.Manager, home string, cdc codec.Codec) error { cmd.SetArgs([]string{"appnode-test"}) - err := cmd.ExecuteContext(ctx) - - return err + return cmd.ExecuteContext(ctx) } func CreateDefaultCometConfig(rootDir string) (*cmtcfg.Config, error) { From 0bcea5e6fa5e2f5b76eda9d6928f629540ddddfe Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Mon, 20 May 2024 17:26:11 +0700 Subject: [PATCH 18/29] lint --- core/context/server_context.go | 8 +++++--- x/genutil/client/cli/export_test.go | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/context/server_context.go b/core/context/server_context.go index 806ed4742b26..63e82d0f03fb 100644 --- a/core/context/server_context.go +++ b/core/context/server_context.go @@ -1,6 +1,8 @@ package context -var ( - LoggerContextKey = "server.logger" - ViperContextKey = "server.viper" +type ServerContextKey string + +const ( + LoggerContextKey ServerContextKey = "server.logger" + ViperContextKey ServerContextKey = "server.viper" ) diff --git a/x/genutil/client/cli/export_test.go b/x/genutil/client/cli/export_test.go index 244aa727ef5b..007e167a82fe 100644 --- a/x/genutil/client/cli/export_test.go +++ b/x/genutil/client/cli/export_test.go @@ -67,7 +67,10 @@ func NewExportSystem(t *testing.T, exporter types.AppExporter) *ExportSystem { viper := viper.New() logger := log.NewCustomLogger(zerolog.New(tw)) - writeAndTrackDefaultConfig(viper, homeDir) + err := writeAndTrackDefaultConfig(viper, homeDir) + if err != nil { + t.Fatal(err) + } cCtx := (client.Context{}).WithHomeDir(homeDir) From 6ab5b568c527f7fd882efe0d641cdd7b78ed4c95 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Mon, 20 May 2024 17:35:03 +0700 Subject: [PATCH 19/29] rerun CI From b31896d9dbfbfcf67e18a077ddeb04c7c66acb64 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 22 May 2024 15:24:30 +0700 Subject: [PATCH 20/29] refactor: keep LegacyServerContext --- server/start.go | 133 +++++++++++++++++++++++------------------------- server/util.go | 31 +++++++++++ 2 files changed, 96 insertions(+), 68 deletions(-) diff --git a/server/start.go b/server/start.go index d2a6049d0556..eceababa18e1 100644 --- a/server/start.go +++ b/server/start.go @@ -127,13 +127,13 @@ type StartCmdOptions[T types.Application] struct { DBOpener func(rootDir string, backendType dbm.BackendType) (dbm.DB, error) // PostSetup can be used to setup extra services under the same cancellable context, // it's not called in stand-alone mode, only for in-process mode. - PostSetup func(app T, svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error + PostSetup func(app T, viper *viper.Viper, logger log.Logger, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error // PostSetupStandalone can be used to setup extra services under the same cancellable context, - PostSetupStandalone func(app T, svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error + PostSetupStandalone func(app T, viper *viper.Viper, logger log.Logger, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error // AddFlags add custom flags to start cmd AddFlags func(cmd *cobra.Command) // StartCommandHanlder can be used to customize the start command handler - StartCommandHandler func(svrCtx *Context, clientCtx client.Context, appCreator types.AppCreator[T], inProcessConsensus bool, opts StartCmdOptions[T]) error + StartCommandHandler func(viper *viper.Viper, logger log.Logger, clientCtx client.Context, appCreator types.AppCreator[T], inProcessConsensus bool, opts StartCmdOptions[T]) error } // StartCmd runs the service passed in, either stand-alone or in-process with @@ -186,10 +186,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. RunE: func(cmd *cobra.Command, _ []string) error { viper := client.GetViperFromCmd(cmd) logger := client.GetLoggerFromCmd(cmd) - serverCtx := &Context{ - Viper: viper, - Logger: logger, - } + _, err := GetPruningOptionsFromFlags(viper) if err != nil { return err @@ -205,8 +202,8 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. logger.Info("starting ABCI without CometBFT") } - err = wrapCPUProfile(serverCtx, func() error { - return opts.StartCommandHandler(serverCtx, clientCtx, appCreator, withCMT, opts) + err = wrapCPUProfile(viper, logger, func() error { + return opts.StartCommandHandler(viper, logger, clientCtx, appCreator, withCMT, opts) }) logger.Debug("received quit signal") @@ -225,13 +222,13 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. return cmd } -func start[T types.Application](svrCtx *Context, clientCtx client.Context, appCreator types.AppCreator[T], withCmt bool, opts StartCmdOptions[T]) error { - svrCfg, err := getAndValidateConfig(svrCtx) +func start[T types.Application](viper *viper.Viper, logger log.Logger, clientCtx client.Context, appCreator types.AppCreator[T], withCmt bool, opts StartCmdOptions[T]) error { + svrCfg, err := getAndValidateConfig(viper) if err != nil { return err } - app, appCleanupFn, err := startApp[T](svrCtx, appCreator, opts) + app, appCleanupFn, err := startApp[T](viper, logger, appCreator, opts) if err != nil { return err } @@ -245,14 +242,14 @@ func start[T types.Application](svrCtx *Context, clientCtx client.Context, appCr emitServerInfoMetrics() if !withCmt { - return startStandAlone[T](svrCtx, svrCfg, clientCtx, app, metrics, opts) + return startStandAlone[T](viper, logger, svrCfg, clientCtx, app, metrics, opts) } - return startInProcess[T](svrCtx, svrCfg, clientCtx, app, metrics, opts) + return startInProcess[T](viper, logger, svrCfg, clientCtx, app, metrics, opts) } -func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app T, metrics *telemetry.Metrics, opts StartCmdOptions[T]) error { - addr := svrCtx.Viper.GetString(flagAddress) - transport := svrCtx.Viper.GetString(flagTransport) +func startStandAlone[T types.Application](viper *viper.Viper, logger log.Logger, svrCfg serverconfig.Config, clientCtx client.Context, app T, metrics *telemetry.Metrics, opts StartCmdOptions[T]) error { + addr := viper.GetString(flagAddress) + transport := viper.GetString(flagTransport) cmtApp := NewCometABCIWrapper(app) svr, err := server.NewServer(addr, transport, cmtApp) @@ -260,11 +257,11 @@ func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.C return fmt.Errorf("error creating listener: %w", err) } - svr.SetLogger(servercmtlog.CometLoggerWrapper{Logger: svrCtx.Logger.With("module", "abci-server")}) + svr.SetLogger(servercmtlog.CometLoggerWrapper{Logger: logger.With("module", "abci-server")}) - g, ctx := getCtx(svrCtx, false) + g, ctx := getCtx(logger, false) - config := client.GetConfigFromViper(svrCtx.Viper) + config := client.GetConfigFromViper(viper) // 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 @@ -286,54 +283,54 @@ func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.C app.RegisterNodeService(clientCtx, svrCfg) } - grpcSrv, clientCtx, err := startGrpcServer(ctx, g, svrCfg.GRPC, clientCtx, svrCtx, app) + grpcSrv, clientCtx, err := startGrpcServer(ctx, g, svrCfg.GRPC, clientCtx, viper, logger, app) if err != nil { return err } - err = startAPIServer(ctx, g, svrCfg, clientCtx, svrCtx, app, config.RootDir, grpcSrv, metrics) + err = startAPIServer(ctx, g, svrCfg, clientCtx, viper, logger, app, config.RootDir, grpcSrv, metrics) if err != nil { return err } if opts.PostSetupStandalone != nil { - if err := opts.PostSetupStandalone(app, svrCtx, clientCtx, ctx, g); err != nil { + if err := opts.PostSetupStandalone(app, viper, logger, clientCtx, ctx, g); err != nil { return err } } g.Go(func() error { if err := svr.Start(); err != nil { - svrCtx.Logger.Error("failed to start out-of-process ABCI server", "err", err) + logger.Error("failed to start out-of-process ABCI server", "err", err) return err } // Wait for the calling process to be canceled or close the provided context, // so we can gracefully stop the ABCI server. <-ctx.Done() - svrCtx.Logger.Info("stopping the ABCI server...") + logger.Info("stopping the ABCI server...") return svr.Stop() }) return g.Wait() } -func startInProcess[T types.Application](svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app T, +func startInProcess[T types.Application](viper *viper.Viper, logger log.Logger, svrCfg serverconfig.Config, clientCtx client.Context, app T, metrics *telemetry.Metrics, opts StartCmdOptions[T], ) error { - cmtCfg := client.GetConfigFromViper(svrCtx.Viper) + cmtCfg := client.GetConfigFromViper(viper) - gRPCOnly := svrCtx.Viper.GetBool(flagGRPCOnly) + gRPCOnly := viper.GetBool(flagGRPCOnly) - g, ctx := getCtx(svrCtx, true) + g, ctx := getCtx(logger, true) if gRPCOnly { // TODO: Generalize logic so that gRPC only is really in startStandAlone - svrCtx.Logger.Info("starting node in gRPC only mode; CometBFT is disabled") + logger.Info("starting node in gRPC only mode; CometBFT is disabled") svrCfg.GRPC.Enable = true } else { - svrCtx.Logger.Info("starting node with ABCI CometBFT in-process") - tmNode, cleanupFn, err := startCmtNode(ctx, cmtCfg, app, svrCtx) + logger.Info("starting node with ABCI CometBFT in-process") + tmNode, cleanupFn, err := startCmtNode(ctx, cmtCfg, app, viper, logger) if err != nil { return err } @@ -353,18 +350,18 @@ func startInProcess[T types.Application](svrCtx *Context, svrCfg serverconfig.Co } } - grpcSrv, clientCtx, err := startGrpcServer(ctx, g, svrCfg.GRPC, clientCtx, svrCtx, app) + grpcSrv, clientCtx, err := startGrpcServer(ctx, g, svrCfg.GRPC, clientCtx, viper, logger, app) if err != nil { return err } - err = startAPIServer(ctx, g, svrCfg, clientCtx, svrCtx, app, cmtCfg.RootDir, grpcSrv, metrics) + err = startAPIServer(ctx, g, svrCfg, clientCtx, viper, logger, app, cmtCfg.RootDir, grpcSrv, metrics) if err != nil { return err } if opts.PostSetup != nil { - if err := opts.PostSetup(app, svrCtx, clientCtx, ctx, g); err != nil { + if err := opts.PostSetup(app, viper, logger, clientCtx, ctx, g); err != nil { return err } } @@ -379,7 +376,7 @@ func startCmtNode( ctx context.Context, cfg *cmtcfg.Config, app types.Application, - svrCtx *Context, + viper *viper.Viper, logger log.Logger, ) (tmNode *node.Node, cleanupFn func(), err error) { nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile()) if err != nil { @@ -396,7 +393,7 @@ func startCmtNode( getGenDocProvider(cfg), cmtcfg.DefaultDBProvider, node.DefaultMetricsProvider(cfg.Instrumentation), - servercmtlog.CometLoggerWrapper{Logger: svrCtx.Logger}, + servercmtlog.CometLoggerWrapper{Logger: logger}, ) if err != nil { return tmNode, cleanupFn, err @@ -415,8 +412,8 @@ func startCmtNode( return tmNode, cleanupFn, nil } -func getAndValidateConfig(svrCtx *Context) (serverconfig.Config, error) { - config, err := serverconfig.GetConfig(svrCtx.Viper) +func getAndValidateConfig(viper *viper.Viper) (serverconfig.Config, error) { + config, err := serverconfig.GetConfig(viper) if err != nil { return config, err } @@ -492,7 +489,7 @@ func startGrpcServer( g *errgroup.Group, config serverconfig.GRPCConfig, clientCtx client.Context, - svrCtx *Context, + viper *viper.Viper, logger log.Logger, app types.Application, ) (*grpc.Server, client.Context, error) { if !config.Enable { @@ -529,7 +526,7 @@ func startGrpcServer( } clientCtx = clientCtx.WithGRPCClient(grpcClient) - svrCtx.Logger.Debug("gRPC client assigned to client context", "target", config.Address) + logger.Debug("gRPC client assigned to client context", "target", config.Address) grpcSrv, err := servergrpc.NewGRPCServer(clientCtx, app, config) if err != nil { @@ -539,7 +536,7 @@ func startGrpcServer( // Start the gRPC server in a goroutine. Note, the provided ctx will ensure // that the server is gracefully shut down. g.Go(func() error { - return servergrpc.StartGRPCServer(ctx, svrCtx.Logger.With("module", "grpc-server"), config, grpcSrv) + return servergrpc.StartGRPCServer(ctx, logger.With("module", "grpc-server"), config, grpcSrv) }) return grpcSrv, clientCtx, nil } @@ -549,7 +546,7 @@ func startAPIServer( g *errgroup.Group, svrCfg serverconfig.Config, clientCtx client.Context, - svrCtx *Context, + viper *viper.Viper, logger log.Logger, app types.Application, home string, grpcSrv *grpc.Server, @@ -561,7 +558,7 @@ func startAPIServer( clientCtx = clientCtx.WithHomeDir(home) - apiSrv := api.New(clientCtx, svrCtx.Logger.With("module", "api-server"), grpcSrv) + apiSrv := api.New(clientCtx, logger.With("module", "api-server"), grpcSrv) app.RegisterAPIRoutes(apiSrv, svrCfg.API) if svrCfg.Telemetry.Enabled { @@ -583,25 +580,25 @@ func startTelemetry(cfg serverconfig.Config) (*telemetry.Metrics, error) { // return. // // NOTE: We expect the caller to handle graceful shutdown and signal handling. -func wrapCPUProfile(svrCtx *Context, callbackFn func() error) error { - if cpuProfile := svrCtx.Viper.GetString(flagCPUProfile); cpuProfile != "" { +func wrapCPUProfile(viper *viper.Viper, logger log.Logger, callbackFn func() error) error { + if cpuProfile := viper.GetString(flagCPUProfile); cpuProfile != "" { f, err := os.Create(cpuProfile) if err != nil { return err } - svrCtx.Logger.Info("starting CPU profiler", "profile", cpuProfile) + logger.Info("starting CPU profiler", "profile", cpuProfile) if err := pprof.StartCPUProfile(f); err != nil { return err } defer func() { - svrCtx.Logger.Info("stopping CPU profiler", "profile", cpuProfile) + logger.Info("stopping CPU profiler", "profile", cpuProfile) pprof.StopCPUProfile() if err := f.Close(); err != nil { - svrCtx.Logger.Info("failed to close cpu-profile file", "profile", cpuProfile, "err", err.Error()) + logger.Info("failed to close cpu-profile file", "profile", cpuProfile, "err", err.Error()) } }() } @@ -628,43 +625,43 @@ func emitServerInfoMetrics() { telemetry.SetGaugeWithLabels([]string{"server", "info"}, 1, ls) } -func getCtx(svrCtx *Context, block bool) (*errgroup.Group, context.Context) { +func getCtx(logger log.Logger, block bool) (*errgroup.Group, context.Context) { ctx, cancelFn := context.WithCancel(context.Background()) g, ctx := errgroup.WithContext(ctx) // listen for quit signals so the calling parent process can gracefully exit - ListenForQuitSignals(g, block, cancelFn, svrCtx.Logger) + ListenForQuitSignals(g, block, cancelFn, logger) return g, ctx } -func startApp[T types.Application](svrCtx *Context, appCreator types.AppCreator[T], opts StartCmdOptions[T]) (app T, cleanupFn func(), err error) { - traceWriter, traceCleanupFn, err := SetupTraceWriter(svrCtx.Logger, svrCtx.Viper.GetString(flagTraceStore)) +func startApp[T types.Application](viper *viper.Viper, logger log.Logger, appCreator types.AppCreator[T], opts StartCmdOptions[T]) (app T, cleanupFn func(), err error) { + traceWriter, traceCleanupFn, err := SetupTraceWriter(logger, viper.GetString(flagTraceStore)) if err != nil { return app, traceCleanupFn, err } - cmtCfg := client.GetConfigFromViper(svrCtx.Viper) + cmtCfg := client.GetConfigFromViper(viper) home := cmtCfg.RootDir - db, err := opts.DBOpener(home, GetAppDBBackend(svrCtx.Viper)) + db, err := opts.DBOpener(home, GetAppDBBackend(viper)) if err != nil { return app, traceCleanupFn, err } - if isTestnet, ok := svrCtx.Viper.Get(KeyIsTestnet).(bool); ok && isTestnet { + if isTestnet, ok := viper.Get(KeyIsTestnet).(bool); ok && isTestnet { var appPtr *T - appPtr, err = testnetify[T](svrCtx, appCreator, db, traceWriter) + appPtr, err = testnetify[T](viper, logger, appCreator, db, traceWriter) if err != nil { return app, traceCleanupFn, err } app = *appPtr } else { - app = appCreator(svrCtx.Logger, db, traceWriter, svrCtx.Viper) + app = appCreator(logger, db, traceWriter, viper) } cleanupFn = func() { traceCleanupFn() if localErr := app.Close(); localErr != nil { - svrCtx.Logger.Error(localErr.Error()) + logger.Error(localErr.Error()) } } return app, cleanupFn, nil @@ -752,8 +749,8 @@ you want to test the upgrade handler itself. serverCtx.Viper.Set(KeyNewChainID, newChainID) serverCtx.Viper.Set(KeyNewOpAddr, newOperatorAddress) - err = wrapCPUProfile(serverCtx, func() error { - return opts.StartCommandHandler(serverCtx, clientCtx, testnetAppCreator, withCMT, opts) + err = wrapCPUProfile(viper, logger, func() error { + return opts.StartCommandHandler(viper, logger, clientCtx, testnetAppCreator, withCMT, opts) }) serverCtx.Logger.Debug("received quit signal") @@ -776,10 +773,10 @@ you want to test the upgrade handler itself. // testnetify modifies both state and blockStore, allowing the provided operator address and local validator key to control the network // that the state in the data folder represents. The chainID of the local genesis file is modified to match the provided chainID. -func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCreator[T], db dbm.DB, traceWriter io.WriteCloser) (*T, error) { - config := client.GetConfigFromViper(ctx.Viper) +func testnetify[T types.Application](viper *viper.Viper, logger log.Logger, testnetAppCreator types.AppCreator[T], db dbm.DB, traceWriter io.WriteCloser) (*T, error) { + config := client.GetConfigFromViper(viper) - newChainID, ok := ctx.Viper.Get(KeyNewChainID).(string) + newChainID, ok := viper.Get(KeyNewChainID).(string) if !ok { return nil, fmt.Errorf("expected string for key %s", KeyNewChainID) } @@ -832,15 +829,15 @@ func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCr return nil, err } - ctx.Viper.Set(KeyNewValAddr, validatorAddress) - ctx.Viper.Set(KeyUserPubKey, userPubKey) - testnetApp := testnetAppCreator(ctx.Logger, db, traceWriter, ctx.Viper) + viper.Set(KeyNewValAddr, validatorAddress) + viper.Set(KeyUserPubKey, userPubKey) + testnetApp := testnetAppCreator(logger, db, traceWriter, viper) // We need to create a temporary proxyApp to get the initial state of the application. // Depending on how the node was stopped, the application height can differ from the blockStore height. // This height difference changes how we go about modifying the state. cmtApp := NewCometABCIWrapper(testnetApp) - _, context := getCtx(ctx, true) + _, context := getCtx(logger, true) clientCreator := proxy.NewLocalClientCreator(cmtApp) metrics := node.DefaultMetricsProvider(cmtcfg.DefaultConfig().Instrumentation) _, _, _, _, _, proxyMetrics, _, _ := metrics(genDoc.ChainID) // nolint: dogsled // function from comet diff --git a/server/util.go b/server/util.go index f61cfa7f6281..4f8cae25e2cd 100644 --- a/server/util.go +++ b/server/util.go @@ -32,6 +32,7 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/config" "github.com/cosmos/cosmos-sdk/server/types" @@ -40,6 +41,13 @@ import ( genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) +// Keep Context type as LegacyContext +type LegacyContext struct { + Viper *viper.Viper + Logger log.Logger + Config *cmtcfg.Config +} + func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) { defer func() { if r := recover(); r != nil { @@ -175,6 +183,29 @@ func CreateSDKLogger(v *viper.Viper, out io.Writer) (log.Logger, error) { return log.NewLogger(out, opts...), nil } +// GetServerContextFromCmd returns a Context from a command or an empty Context +// if it has not been set. +func GetServerContextFromCmd(cmd *cobra.Command) *LegacyContext { + serverCtx := &LegacyContext{} + if v := cmd.Context().Value(corectx.ViperContextKey); v != nil { + viper := v.(*viper.Viper) + serverCtx.Viper = viper + serverCtx.Config = client.GetConfigFromViper(viper) + } else { + serverCtx.Viper = viper.New() + serverCtx.Config = cmtcfg.DefaultConfig() + } + + if v := cmd.Context().Value(corectx.LoggerContextKey); v != nil { + logger := v.(log.Logger) + serverCtx.Logger = logger + } else { + serverCtx.Logger = log.NewLogger(os.Stdout) + } + + return serverCtx +} + // SetCmdServerContext sets a command's Context value to the provided argument. // If the context has not been set, set the given context as the default. func SetCmdServerContext(cmd *cobra.Command, viper *viper.Viper, logger log.Logger) error { From 7c4e602b069525aa3933804c3c2f8241b684ee01 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 22 May 2024 15:33:17 +0700 Subject: [PATCH 21/29] address comment --- client/cmd.go | 3 +-- core/context/server_context.go | 8 +++----- server/util.go | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/client/cmd.go b/client/cmd.go index aa2d4e878e77..c5b40774d9e4 100644 --- a/client/cmd.go +++ b/client/cmd.go @@ -5,7 +5,6 @@ import ( "crypto/tls" "errors" "fmt" - "os" "slices" "strings" @@ -401,7 +400,7 @@ func GetLoggerFromCmd(cmd *cobra.Command) log.Logger { v := cmd.Context().Value(corectx.LoggerContextKey) logger, ok := v.(log.Logger) if !ok { - return log.NewLogger(os.Stdout) + return log.NewLogger(cmd.OutOrStdout()) } return logger } diff --git a/core/context/server_context.go b/core/context/server_context.go index 63e82d0f03fb..eade2999b5ab 100644 --- a/core/context/server_context.go +++ b/core/context/server_context.go @@ -1,8 +1,6 @@ package context -type ServerContextKey string - -const ( - LoggerContextKey ServerContextKey = "server.logger" - ViperContextKey ServerContextKey = "server.viper" +var ( + LoggerContextKey struct{} + ViperContextKey struct{} ) diff --git a/server/util.go b/server/util.go index 4f8cae25e2cd..13685691fd59 100644 --- a/server/util.go +++ b/server/util.go @@ -200,7 +200,7 @@ func GetServerContextFromCmd(cmd *cobra.Command) *LegacyContext { logger := v.(log.Logger) serverCtx.Logger = logger } else { - serverCtx.Logger = log.NewLogger(os.Stdout) + serverCtx.Logger = log.NewLogger(cmd.OutOrStdout()) } return serverCtx From baae5d4ac04c6c432c4c1c485439e523581bfd1d Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 22 May 2024 16:01:19 +0700 Subject: [PATCH 22/29] key as type --- client/cmd.go | 6 ++-- core/context/server_context.go | 4 +-- server/cmd/execute.go | 4 +-- server/util.go | 10 +++--- server/util_test.go | 46 ++++++++++++------------- simapp/simd/cmd/testnet_test.go | 4 +-- tests/e2e/genutil/export_test.go | 4 +-- x/genutil/client/cli/export_test.go | 4 +-- x/genutil/client/cli/genaccount_test.go | 4 +-- x/genutil/client/cli/init_test.go | 28 +++++++-------- x/genutil/client/testutil/helpers.go | 4 +-- 11 files changed, 59 insertions(+), 59 deletions(-) diff --git a/client/cmd.go b/client/cmd.go index c5b40774d9e4..1ea5d9d6bfc3 100644 --- a/client/cmd.go +++ b/client/cmd.go @@ -379,7 +379,7 @@ func SetCmdClientContext(cmd *cobra.Command, clientCtx Context) error { } func GetViperFromCmd(cmd *cobra.Command) *viper.Viper { - value := cmd.Context().Value(corectx.ViperContextKey) + value := cmd.Context().Value(corectx.ViperContextKey{}) v, ok := value.(*viper.Viper) if !ok { return viper.New() @@ -388,7 +388,7 @@ func GetViperFromCmd(cmd *cobra.Command) *viper.Viper { } func GetConfigFromCmd(cmd *cobra.Command) *cmtcfg.Config { - v := cmd.Context().Value(corectx.ViperContextKey) + v := cmd.Context().Value(corectx.ViperContextKey{}) viper, ok := v.(*viper.Viper) if !ok { return cmtcfg.DefaultConfig() @@ -397,7 +397,7 @@ func GetConfigFromCmd(cmd *cobra.Command) *cmtcfg.Config { } func GetLoggerFromCmd(cmd *cobra.Command) log.Logger { - v := cmd.Context().Value(corectx.LoggerContextKey) + v := cmd.Context().Value(corectx.LoggerContextKey{}) logger, ok := v.(log.Logger) if !ok { return log.NewLogger(cmd.OutOrStdout()) diff --git a/core/context/server_context.go b/core/context/server_context.go index eade2999b5ab..c8b532a5db2e 100644 --- a/core/context/server_context.go +++ b/core/context/server_context.go @@ -1,6 +1,6 @@ package context -var ( +type ( LoggerContextKey struct{} - ViperContextKey struct{} + ViperContextKey struct{} ) diff --git a/server/cmd/execute.go b/server/cmd/execute.go index 1d52b003f953..321512bd551c 100644 --- a/server/cmd/execute.go +++ b/server/cmd/execute.go @@ -43,8 +43,8 @@ func Execute(rootCmd *cobra.Command, envPrefix, defaultHome string) error { func CreateExecuteContext(ctx context.Context) context.Context { // srvCtx := server.NewDefaultContext() ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{}) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) return ctx } diff --git a/server/util.go b/server/util.go index 13685691fd59..5c8f9b455104 100644 --- a/server/util.go +++ b/server/util.go @@ -187,7 +187,7 @@ func CreateSDKLogger(v *viper.Viper, out io.Writer) (log.Logger, error) { // if it has not been set. func GetServerContextFromCmd(cmd *cobra.Command) *LegacyContext { serverCtx := &LegacyContext{} - if v := cmd.Context().Value(corectx.ViperContextKey); v != nil { + if v := cmd.Context().Value(corectx.ViperContextKey{}); v != nil { viper := v.(*viper.Viper) serverCtx.Viper = viper serverCtx.Config = client.GetConfigFromViper(viper) @@ -196,13 +196,13 @@ func GetServerContextFromCmd(cmd *cobra.Command) *LegacyContext { serverCtx.Config = cmtcfg.DefaultConfig() } - if v := cmd.Context().Value(corectx.LoggerContextKey); v != nil { + if v := cmd.Context().Value(corectx.LoggerContextKey{}); v != nil { logger := v.(log.Logger) serverCtx.Logger = logger } else { serverCtx.Logger = log.NewLogger(cmd.OutOrStdout()) } - + return serverCtx } @@ -217,8 +217,8 @@ func SetCmdServerContext(cmd *cobra.Command, viper *viper.Viper, logger log.Logg cmdCtx = cmd.Context() } - cmd.SetContext(context.WithValue(cmdCtx, corectx.LoggerContextKey, logger)) - cmd.SetContext(context.WithValue(cmdCtx, corectx.ViperContextKey, viper)) + cmd.SetContext(context.WithValue(cmdCtx, corectx.LoggerContextKey{}, logger)) + cmd.SetContext(context.WithValue(cmdCtx, corectx.ViperContextKey{}, viper)) return nil } diff --git a/server/util_test.go b/server/util_test.go index b58f61a9fc65..040bb6415a9b 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -62,8 +62,8 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T cmd.PreRunE = preRunETestImpl - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } @@ -106,7 +106,7 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T } // Test that the config for use in server/start.go is created - v := ctx.Value(corectx.ViperContextKey) + v := ctx.Value(corectx.ViperContextKey{}) viper, _ := v.(*viper.Viper) if viper == nil { @@ -144,8 +144,8 @@ func TestInterceptConfigsPreRunHandlerReadsConfigToml(t *testing.T) { cmd.PreRunE = preRunETestImpl - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) @@ -184,8 +184,8 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) { cmd.PreRunE = preRunETestImpl - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) @@ -214,8 +214,8 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { cmd.PreRunE = preRunETestImpl - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) @@ -252,8 +252,8 @@ func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) { cmd.PreRunE = preRunETestImpl - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) @@ -361,8 +361,8 @@ func TestInterceptConfigsPreRunHandlerPrecedenceFlag(t *testing.T) { testCommon := newPrecedenceCommon(t) testCommon.setAll(t, &TestAddrExpected, &TestAddrNotExpected, &TestAddrNotExpected) - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) @@ -379,8 +379,8 @@ func TestInterceptConfigsPreRunHandlerPrecedenceEnvVar(t *testing.T) { testCommon := newPrecedenceCommon(t) testCommon.setAll(t, nil, &TestAddrExpected, &TestAddrNotExpected) - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) @@ -397,8 +397,8 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigFile(t *testing.T) { testCommon := newPrecedenceCommon(t) testCommon.setAll(t, nil, nil, &TestAddrExpected) - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) @@ -415,8 +415,8 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigDefault(t *testing.T) { testCommon := newPrecedenceCommon(t) // Do not set anything - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) @@ -446,8 +446,8 @@ func TestInterceptConfigsWithBadPermissions(t *testing.T) { cmd.PreRunE = preRunETestImpl - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey, log.NewNopLogger()) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper.New()) + ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewNopLogger()) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) if err := cmd.ExecuteContext(ctx); !os.IsPermission(err) { t.Fatalf("Failed to catch permissions error, got: [%T] %v", err, err) @@ -464,8 +464,8 @@ func TestEmptyMinGasPrices(t *testing.T) { clientCtx := client.Context{}.WithHomeDir(tempDir).WithCodec(encCfg.Codec) viper := viper.New() viper.Set(flags.FlagHome, tempDir) - ctx := context.WithValue(context.Background(), corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, log.NewLogger(os.Stdout)) + ctx := context.WithValue(context.Background(), corectx.ViperContextKey{}, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) cmd := genutilcli.InitCmd(module.NewManager()) cmd.SetArgs([]string{"appnode-test"}) diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index 1d73d719e044..524d7d01c523 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -68,8 +68,8 @@ func Test_TestnetCmd(t *testing.T) { WithValidatorAddressCodec(cdcOpts.GetValidatorCodec()) ctx := context.Background() - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, logger) ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) cmd := testnetInitFilesCmd(moduleManager, banktypes.GenesisBalancesIterator{}) cmd.SetArgs([]string{fmt.Sprintf("--%s=test", flags.FlagKeyringBackend), fmt.Sprintf("--output-dir=%s", home)}) diff --git a/tests/e2e/genutil/export_test.go b/tests/e2e/genutil/export_test.go index 8f91908095a2..611df3671ccf 100644 --- a/tests/e2e/genutil/export_test.go +++ b/tests/e2e/genutil/export_test.go @@ -59,7 +59,7 @@ func TestExportCmd_ConsensusParams(t *testing.T) { func TestExportCmd_HomeDir(t *testing.T) { _, ctx, _, cmd := setupApp(t, t.TempDir()) - v := ctx.Value(corectx.ViperContextKey) + v := ctx.Value(corectx.ViperContextKey{}) viper, ok := v.(*viper.Viper) require.True(t, ok) viper.Set(flags.FlagHome, "foobar") @@ -220,7 +220,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, ge ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper) return app, ctx, appGenesis, cmd } diff --git a/x/genutil/client/cli/export_test.go b/x/genutil/client/cli/export_test.go index 007e167a82fe..0311619cfe79 100644 --- a/x/genutil/client/cli/export_test.go +++ b/x/genutil/client/cli/export_test.go @@ -74,8 +74,8 @@ func NewExportSystem(t *testing.T, exporter types.AppExporter) *ExportSystem { cCtx := (client.Context{}).WithHomeDir(homeDir) - ctx := context.WithValue(context.Background(), corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx := context.WithValue(context.Background(), corectx.ViperContextKey{}, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, logger) ctx = context.WithValue(ctx, client.ClientContextKey, &cCtx) diff --git a/x/genutil/client/cli/genaccount_test.go b/x/genutil/client/cli/genaccount_test.go index d2c6c08b6748..6351a76ea3b2 100644 --- a/x/genutil/client/cli/genaccount_test.go +++ b/x/genutil/client/cli/genaccount_test.go @@ -92,8 +92,8 @@ func TestAddGenesisAccountCmd(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, logger) cmd := genutilcli.AddGenesisAccountCmd(addresscodec.NewBech32Codec("cosmos")) cmd.SetArgs([]string{ diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index c4be32548854..b3a8b648764e 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -77,8 +77,8 @@ func TestInitCmd(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, logger) cmd := genutilcli.InitCmd(testMbm) cmd.SetArgs( @@ -111,8 +111,8 @@ func TestInitRecover(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, logger) cmd := genutilcli.InitCmd(testMbm) cmd.SetContext(ctx) @@ -144,8 +144,8 @@ func TestInitDefaultBondDenom(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, logger) cmd := genutilcli.InitCmd(testMbm) @@ -172,8 +172,8 @@ func TestEmptyState(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, logger) cmd := genutilcli.InitCmd(testMbm) cmd.SetArgs([]string{"appnode-test"}) @@ -267,8 +267,8 @@ func TestInitConfig(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, logger) cmd := genutilcli.InitCmd(testMbm) cmd.SetArgs([]string{"testnode"}) @@ -317,8 +317,8 @@ func TestInitWithHeight(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, logger) testInitialHeight := int64(333) @@ -354,8 +354,8 @@ func TestInitWithNegativeHeight(t *testing.T) { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, logger) testInitialHeight := int64(-333) diff --git a/x/genutil/client/testutil/helpers.go b/x/genutil/client/testutil/helpers.go index 798dad19f9cb..77560ad16d1f 100644 --- a/x/genutil/client/testutil/helpers.go +++ b/x/genutil/client/testutil/helpers.go @@ -35,8 +35,8 @@ func ExecInitCmd(mm *module.Manager, home string, cdc codec.Codec) error { ctx := context.Background() ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper) + ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, logger) cmd.SetArgs([]string{"appnode-test"}) From 5de4f6cc85f67a3b418ddc4f85366b1a0f5c5d63 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 23 May 2024 12:54:39 +0700 Subject: [PATCH 23/29] add deprecated cmt --- server/start.go | 26 ++++++++------------------ server/util.go | 8 ++++---- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/server/start.go b/server/start.go index eceababa18e1..db7ab63b7730 100644 --- a/server/start.go +++ b/server/start.go @@ -114,12 +114,6 @@ const ( KeyTriggerTestnetUpgrade = "trigger-testnet-upgrade" ) -// Keep Context type -type Context struct { - Viper *viper.Viper - Logger log.Logger -} - // StartCmdOptions defines options that can be customized in `StartCmdWithOptions`, type StartCmdOptions[T types.Application] struct { // DBOpener can be used to customize db opening, for example customize db options or support different db backends, @@ -706,12 +700,8 @@ you want to test the upgrade handler itself. RunE: func(cmd *cobra.Command, args []string) error { viper := client.GetViperFromCmd(cmd) logger := client.GetLoggerFromCmd(cmd) - serverCtx := &Context{ - Viper: viper, - Logger: logger, - } - _, err := GetPruningOptionsFromFlags(serverCtx.Viper) + _, err := GetPruningOptionsFromFlags(viper) if err != nil { return err } @@ -723,7 +713,7 @@ you want to test the upgrade handler itself. withCMT, _ := cmd.Flags().GetBool(flagWithComet) if !withCMT { - serverCtx.Logger.Info("starting ABCI without CometBFT") + logger.Info("starting ABCI without CometBFT") } newChainID := args[0] @@ -745,20 +735,20 @@ you want to test the upgrade handler itself. // Set testnet keys to be used by the application. // This is done to prevent changes to existing start API. - serverCtx.Viper.Set(KeyIsTestnet, true) - serverCtx.Viper.Set(KeyNewChainID, newChainID) - serverCtx.Viper.Set(KeyNewOpAddr, newOperatorAddress) + viper.Set(KeyIsTestnet, true) + viper.Set(KeyNewChainID, newChainID) + viper.Set(KeyNewOpAddr, newOperatorAddress) err = wrapCPUProfile(viper, logger, func() error { return opts.StartCommandHandler(viper, logger, clientCtx, testnetAppCreator, withCMT, opts) }) - serverCtx.Logger.Debug("received quit signal") + logger.Debug("received quit signal") graceDuration, _ := cmd.Flags().GetDuration(FlagShutdownGrace) if graceDuration > 0 { - serverCtx.Logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration) + logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration) <-time.After(graceDuration) - serverCtx.Logger.Info("graceful shutdown complete") + logger.Info("graceful shutdown complete") } return err diff --git a/server/util.go b/server/util.go index 5c8f9b455104..493d0a5daaa8 100644 --- a/server/util.go +++ b/server/util.go @@ -41,8 +41,8 @@ import ( genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) -// Keep Context type as LegacyContext -type LegacyContext struct { +// Deprecated: Do not use, we use viper to track all config +type Context struct { Viper *viper.Viper Logger log.Logger Config *cmtcfg.Config @@ -185,8 +185,8 @@ func CreateSDKLogger(v *viper.Viper, out io.Writer) (log.Logger, error) { // GetServerContextFromCmd returns a Context from a command or an empty Context // if it has not been set. -func GetServerContextFromCmd(cmd *cobra.Command) *LegacyContext { - serverCtx := &LegacyContext{} +func GetServerContextFromCmd(cmd *cobra.Command) *Context { + serverCtx := &Context{} if v := cmd.Context().Value(corectx.ViperContextKey{}); v != nil { viper := v.(*viper.Viper) serverCtx.Viper = viper From 9fbb8e8fb80ba27f39120da08c732cff57344f2e Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 23 May 2024 15:29:52 +0700 Subject: [PATCH 24/29] revert: server v0 use Context --- server/cmd/execute.go | 11 +-- server/cmt_cmds.go | 22 +++--- server/rollback.go | 11 +-- server/start.go | 172 ++++++++++++++++++++---------------------- server/util.go | 124 +++++++++++++++++------------- server/util_test.go | 96 +++++++++++------------ 6 files changed, 215 insertions(+), 221 deletions(-) diff --git a/server/cmd/execute.go b/server/cmd/execute.go index 321512bd551c..cf8e7c009f44 100644 --- a/server/cmd/execute.go +++ b/server/cmd/execute.go @@ -2,18 +2,14 @@ package cmd import ( "context" - "os" cmtcli "github.com/cometbft/cometbft/libs/cli" "github.com/rs/zerolog" "github.com/spf13/cobra" - "github.com/spf13/viper" - - corectx "cosmossdk.io/core/context" - "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/server" ) // Execute executes the root command of an application. It handles creating a @@ -41,10 +37,9 @@ func Execute(rootCmd *cobra.Command, envPrefix, defaultHome string) error { // CreateExecuteContext returns a base Context with server and client context // values initialized. func CreateExecuteContext(ctx context.Context) context.Context { - // srvCtx := server.NewDefaultContext() + srvCtx := server.NewDefaultContext() ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{}) - ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) + ctx = context.WithValue(ctx, server.ServerContextKey, srvCtx) return ctx } diff --git a/server/cmt_cmds.go b/server/cmt_cmds.go index 1fdd6ca515b4..e4fdf1ed814c 100644 --- a/server/cmt_cmds.go +++ b/server/cmt_cmds.go @@ -16,6 +16,7 @@ import ( "github.com/spf13/cobra" "sigs.k8s.io/yaml" + "cosmossdk.io/log" auth "cosmossdk.io/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/client" @@ -72,7 +73,8 @@ func ShowNodeIDCmd() *cobra.Command { Use: "show-node-id", Short: "Show this node's ID", RunE: func(cmd *cobra.Command, args []string) error { - cfg := client.GetConfigFromCmd(cmd) + serverCtx := GetServerContextFromCmd(cmd) + cfg := serverCtx.Config nodeKey, err := p2p.LoadNodeKey(cfg.NodeKeyFile()) if err != nil { @@ -91,7 +93,8 @@ func ShowValidatorCmd() *cobra.Command { Use: "show-validator", Short: "Show this node's CometBFT validator info", RunE: func(cmd *cobra.Command, args []string) error { - cfg := client.GetConfigFromCmd(cmd) + serverCtx := GetServerContextFromCmd(cmd) + cfg := serverCtx.Config privValidator := pvm.LoadFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()) pk, err := privValidator.GetPubKey() @@ -124,7 +127,8 @@ func ShowAddressCmd() *cobra.Command { Use: "show-address", Short: "Shows this node's CometBFT validator consensus address", RunE: func(cmd *cobra.Command, args []string) error { - cfg := client.GetConfigFromCmd(cmd) + serverCtx := GetServerContextFromCmd(cmd) + cfg := serverCtx.Config privValidator := pvm.LoadFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()) @@ -358,22 +362,22 @@ func BootstrapStateCmd[T types.Application](appCreator types.AppCreator[T]) *cob Short: "Bootstrap CometBFT state at an arbitrary block height using a light client", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - cfg := client.GetConfigFromCmd(cmd) - logger := client.GetLoggerFromCmd(cmd) - viper := client.GetViperFromCmd(cmd) + serverCtx := GetServerContextFromCmd(cmd) + logger := log.NewLogger(cmd.OutOrStdout()) + cfg := serverCtx.Config height, err := cmd.Flags().GetInt64("height") if err != nil { return err } if height == 0 { - home := viper.GetString(flags.FlagHome) - db, err := OpenDB(home, GetAppDBBackend(viper)) + home := serverCtx.Viper.GetString(flags.FlagHome) + db, err := OpenDB(home, GetAppDBBackend(serverCtx.Viper)) if err != nil { return err } - app := appCreator(logger, db, nil, viper) + app := appCreator(logger, db, nil, serverCtx.Viper) height = app.CommitMultiStore().LastCommitID().Version } diff --git a/server/rollback.go b/server/rollback.go index 21c5c8e6ed87..7dd58bcedf64 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -6,7 +6,6 @@ import ( cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" "github.com/spf13/cobra" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server/types" ) @@ -26,17 +25,15 @@ restarting CometBFT the transactions in block n will be re-executed against the application. `, RunE: func(cmd *cobra.Command, args []string) error { - config := client.GetConfigFromCmd(cmd) - logger := client.GetLoggerFromCmd(cmd) - viper := client.GetViperFromCmd(cmd) + ctx := GetServerContextFromCmd(cmd) - db, err := OpenDB(config.RootDir, GetAppDBBackend(viper)) + db, err := OpenDB(ctx.Config.RootDir, GetAppDBBackend(ctx.Viper)) if err != nil { return err } - app := appCreator(logger, db, nil, viper) + app := appCreator(ctx.Logger, db, nil, ctx.Viper) // rollback CometBFT state - height, hash, err := cmtcmd.RollbackState(config, removeBlock) + height, hash, err := cmtcmd.RollbackState(ctx.Config, removeBlock) if err != nil { return fmt.Errorf("failed to rollback CometBFT state: %w", err) } diff --git a/server/start.go b/server/start.go index db7ab63b7730..ea0e43d31319 100644 --- a/server/start.go +++ b/server/start.go @@ -32,7 +32,6 @@ import ( "github.com/hashicorp/go-metrics" "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/spf13/viper" "golang.org/x/sync/errgroup" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" @@ -121,13 +120,13 @@ type StartCmdOptions[T types.Application] struct { DBOpener func(rootDir string, backendType dbm.BackendType) (dbm.DB, error) // PostSetup can be used to setup extra services under the same cancellable context, // it's not called in stand-alone mode, only for in-process mode. - PostSetup func(app T, viper *viper.Viper, logger log.Logger, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error + PostSetup func(app T, svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error // PostSetupStandalone can be used to setup extra services under the same cancellable context, - PostSetupStandalone func(app T, viper *viper.Viper, logger log.Logger, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error + PostSetupStandalone func(app T, svrCtx *Context, clientCtx client.Context, ctx context.Context, g *errgroup.Group) error // AddFlags add custom flags to start cmd AddFlags func(cmd *cobra.Command) // StartCommandHanlder can be used to customize the start command handler - StartCommandHandler func(viper *viper.Viper, logger log.Logger, clientCtx client.Context, appCreator types.AppCreator[T], inProcessConsensus bool, opts StartCmdOptions[T]) error + StartCommandHandler func(svrCtx *Context, clientCtx client.Context, appCreator types.AppCreator[T], inProcessConsensus bool, opts StartCmdOptions[T]) error } // StartCmd runs the service passed in, either stand-alone or in-process with @@ -178,10 +177,8 @@ bypassed and can be used when legacy queries are needed after an on-chain upgrad is performed. Note, when enabled, gRPC will also be automatically enabled. `, RunE: func(cmd *cobra.Command, _ []string) error { - viper := client.GetViperFromCmd(cmd) - logger := client.GetLoggerFromCmd(cmd) - - _, err := GetPruningOptionsFromFlags(viper) + serverCtx := GetServerContextFromCmd(cmd) + _, err := GetPruningOptionsFromFlags(serverCtx.Viper) if err != nil { return err } @@ -193,19 +190,19 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. withCMT, _ := cmd.Flags().GetBool(flagWithComet) if !withCMT { - logger.Info("starting ABCI without CometBFT") + serverCtx.Logger.Info("starting ABCI without CometBFT") } - err = wrapCPUProfile(viper, logger, func() error { - return opts.StartCommandHandler(viper, logger, clientCtx, appCreator, withCMT, opts) + err = wrapCPUProfile(serverCtx, func() error { + return opts.StartCommandHandler(serverCtx, clientCtx, appCreator, withCMT, opts) }) - logger.Debug("received quit signal") + serverCtx.Logger.Debug("received quit signal") graceDuration, _ := cmd.Flags().GetDuration(FlagShutdownGrace) if graceDuration > 0 { - logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration) + serverCtx.Logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration) <-time.After(graceDuration) - logger.Info("graceful shutdown complete") + serverCtx.Logger.Info("graceful shutdown complete") } return err @@ -216,13 +213,13 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. return cmd } -func start[T types.Application](viper *viper.Viper, logger log.Logger, clientCtx client.Context, appCreator types.AppCreator[T], withCmt bool, opts StartCmdOptions[T]) error { - svrCfg, err := getAndValidateConfig(viper) +func start[T types.Application](svrCtx *Context, clientCtx client.Context, appCreator types.AppCreator[T], withCmt bool, opts StartCmdOptions[T]) error { + svrCfg, err := getAndValidateConfig(svrCtx) if err != nil { return err } - app, appCleanupFn, err := startApp[T](viper, logger, appCreator, opts) + app, appCleanupFn, err := startApp[T](svrCtx, appCreator, opts) if err != nil { return err } @@ -236,14 +233,14 @@ func start[T types.Application](viper *viper.Viper, logger log.Logger, clientCtx emitServerInfoMetrics() if !withCmt { - return startStandAlone[T](viper, logger, svrCfg, clientCtx, app, metrics, opts) + return startStandAlone[T](svrCtx, svrCfg, clientCtx, app, metrics, opts) } - return startInProcess[T](viper, logger, svrCfg, clientCtx, app, metrics, opts) + return startInProcess[T](svrCtx, svrCfg, clientCtx, app, metrics, opts) } -func startStandAlone[T types.Application](viper *viper.Viper, logger log.Logger, svrCfg serverconfig.Config, clientCtx client.Context, app T, metrics *telemetry.Metrics, opts StartCmdOptions[T]) error { - addr := viper.GetString(flagAddress) - transport := viper.GetString(flagTransport) +func startStandAlone[T types.Application](svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app T, metrics *telemetry.Metrics, opts StartCmdOptions[T]) error { + addr := svrCtx.Viper.GetString(flagAddress) + transport := svrCtx.Viper.GetString(flagTransport) cmtApp := NewCometABCIWrapper(app) svr, err := server.NewServer(addr, transport, cmtApp) @@ -251,11 +248,9 @@ func startStandAlone[T types.Application](viper *viper.Viper, logger log.Logger, return fmt.Errorf("error creating listener: %w", err) } - svr.SetLogger(servercmtlog.CometLoggerWrapper{Logger: logger.With("module", "abci-server")}) - - g, ctx := getCtx(logger, false) + svr.SetLogger(servercmtlog.CometLoggerWrapper{Logger: svrCtx.Logger.With("module", "abci-server")}) - config := client.GetConfigFromViper(viper) + g, ctx := getCtx(svrCtx, false) // 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 @@ -263,7 +258,7 @@ func startStandAlone[T types.Application](viper *viper.Viper, logger log.Logger, if svrCfg.API.Enable || svrCfg.GRPC.Enable { // create tendermint client // assumes the rpc listen address is where tendermint has its rpc server - rpcclient, err := rpchttp.New(config.RPC.ListenAddress) + rpcclient, err := rpchttp.New(svrCtx.Config.RPC.ListenAddress) if err != nil { return err } @@ -277,54 +272,53 @@ func startStandAlone[T types.Application](viper *viper.Viper, logger log.Logger, app.RegisterNodeService(clientCtx, svrCfg) } - grpcSrv, clientCtx, err := startGrpcServer(ctx, g, svrCfg.GRPC, clientCtx, viper, logger, app) + grpcSrv, clientCtx, err := startGrpcServer(ctx, g, svrCfg.GRPC, clientCtx, svrCtx, app) if err != nil { return err } - err = startAPIServer(ctx, g, svrCfg, clientCtx, viper, logger, app, config.RootDir, grpcSrv, metrics) + err = startAPIServer(ctx, g, svrCfg, clientCtx, svrCtx, app, svrCtx.Config.RootDir, grpcSrv, metrics) if err != nil { return err } if opts.PostSetupStandalone != nil { - if err := opts.PostSetupStandalone(app, viper, logger, clientCtx, ctx, g); err != nil { + if err := opts.PostSetupStandalone(app, svrCtx, clientCtx, ctx, g); err != nil { return err } } g.Go(func() error { if err := svr.Start(); err != nil { - logger.Error("failed to start out-of-process ABCI server", "err", err) + svrCtx.Logger.Error("failed to start out-of-process ABCI server", "err", err) return err } // Wait for the calling process to be canceled or close the provided context, // so we can gracefully stop the ABCI server. <-ctx.Done() - logger.Info("stopping the ABCI server...") + svrCtx.Logger.Info("stopping the ABCI server...") return svr.Stop() }) return g.Wait() } -func startInProcess[T types.Application](viper *viper.Viper, logger log.Logger, svrCfg serverconfig.Config, clientCtx client.Context, app T, +func startInProcess[T types.Application](svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app T, metrics *telemetry.Metrics, opts StartCmdOptions[T], ) error { - cmtCfg := client.GetConfigFromViper(viper) - - gRPCOnly := viper.GetBool(flagGRPCOnly) + cmtCfg := svrCtx.Config + gRPCOnly := svrCtx.Viper.GetBool(flagGRPCOnly) - g, ctx := getCtx(logger, true) + g, ctx := getCtx(svrCtx, true) if gRPCOnly { // TODO: Generalize logic so that gRPC only is really in startStandAlone - logger.Info("starting node in gRPC only mode; CometBFT is disabled") + svrCtx.Logger.Info("starting node in gRPC only mode; CometBFT is disabled") svrCfg.GRPC.Enable = true } else { - logger.Info("starting node with ABCI CometBFT in-process") - tmNode, cleanupFn, err := startCmtNode(ctx, cmtCfg, app, viper, logger) + svrCtx.Logger.Info("starting node with ABCI CometBFT in-process") + tmNode, cleanupFn, err := startCmtNode(ctx, cmtCfg, app, svrCtx) if err != nil { return err } @@ -344,18 +338,18 @@ func startInProcess[T types.Application](viper *viper.Viper, logger log.Logger, } } - grpcSrv, clientCtx, err := startGrpcServer(ctx, g, svrCfg.GRPC, clientCtx, viper, logger, app) + grpcSrv, clientCtx, err := startGrpcServer(ctx, g, svrCfg.GRPC, clientCtx, svrCtx, app) if err != nil { return err } - err = startAPIServer(ctx, g, svrCfg, clientCtx, viper, logger, app, cmtCfg.RootDir, grpcSrv, metrics) + err = startAPIServer(ctx, g, svrCfg, clientCtx, svrCtx, app, cmtCfg.RootDir, grpcSrv, metrics) if err != nil { return err } if opts.PostSetup != nil { - if err := opts.PostSetup(app, viper, logger, clientCtx, ctx, g); err != nil { + if err := opts.PostSetup(app, svrCtx, clientCtx, ctx, g); err != nil { return err } } @@ -370,7 +364,7 @@ func startCmtNode( ctx context.Context, cfg *cmtcfg.Config, app types.Application, - viper *viper.Viper, logger log.Logger, + svrCtx *Context, ) (tmNode *node.Node, cleanupFn func(), err error) { nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile()) if err != nil { @@ -387,7 +381,7 @@ func startCmtNode( getGenDocProvider(cfg), cmtcfg.DefaultDBProvider, node.DefaultMetricsProvider(cfg.Instrumentation), - servercmtlog.CometLoggerWrapper{Logger: logger}, + servercmtlog.CometLoggerWrapper{Logger: svrCtx.Logger}, ) if err != nil { return tmNode, cleanupFn, err @@ -406,8 +400,8 @@ func startCmtNode( return tmNode, cleanupFn, nil } -func getAndValidateConfig(viper *viper.Viper) (serverconfig.Config, error) { - config, err := serverconfig.GetConfig(viper) +func getAndValidateConfig(svrCtx *Context) (serverconfig.Config, error) { + config, err := serverconfig.GetConfig(svrCtx.Viper) if err != nil { return config, err } @@ -483,7 +477,7 @@ func startGrpcServer( g *errgroup.Group, config serverconfig.GRPCConfig, clientCtx client.Context, - viper *viper.Viper, logger log.Logger, + svrCtx *Context, app types.Application, ) (*grpc.Server, client.Context, error) { if !config.Enable { @@ -520,7 +514,7 @@ func startGrpcServer( } clientCtx = clientCtx.WithGRPCClient(grpcClient) - logger.Debug("gRPC client assigned to client context", "target", config.Address) + svrCtx.Logger.Debug("gRPC client assigned to client context", "target", config.Address) grpcSrv, err := servergrpc.NewGRPCServer(clientCtx, app, config) if err != nil { @@ -530,7 +524,7 @@ func startGrpcServer( // Start the gRPC server in a goroutine. Note, the provided ctx will ensure // that the server is gracefully shut down. g.Go(func() error { - return servergrpc.StartGRPCServer(ctx, logger.With("module", "grpc-server"), config, grpcSrv) + return servergrpc.StartGRPCServer(ctx, svrCtx.Logger.With("module", "grpc-server"), config, grpcSrv) }) return grpcSrv, clientCtx, nil } @@ -540,7 +534,7 @@ func startAPIServer( g *errgroup.Group, svrCfg serverconfig.Config, clientCtx client.Context, - viper *viper.Viper, logger log.Logger, + svrCtx *Context, app types.Application, home string, grpcSrv *grpc.Server, @@ -552,7 +546,7 @@ func startAPIServer( clientCtx = clientCtx.WithHomeDir(home) - apiSrv := api.New(clientCtx, logger.With("module", "api-server"), grpcSrv) + apiSrv := api.New(clientCtx, svrCtx.Logger.With("module", "api-server"), grpcSrv) app.RegisterAPIRoutes(apiSrv, svrCfg.API) if svrCfg.Telemetry.Enabled { @@ -574,25 +568,25 @@ func startTelemetry(cfg serverconfig.Config) (*telemetry.Metrics, error) { // return. // // NOTE: We expect the caller to handle graceful shutdown and signal handling. -func wrapCPUProfile(viper *viper.Viper, logger log.Logger, callbackFn func() error) error { - if cpuProfile := viper.GetString(flagCPUProfile); cpuProfile != "" { +func wrapCPUProfile(svrCtx *Context, callbackFn func() error) error { + if cpuProfile := svrCtx.Viper.GetString(flagCPUProfile); cpuProfile != "" { f, err := os.Create(cpuProfile) if err != nil { return err } - logger.Info("starting CPU profiler", "profile", cpuProfile) + svrCtx.Logger.Info("starting CPU profiler", "profile", cpuProfile) if err := pprof.StartCPUProfile(f); err != nil { return err } defer func() { - logger.Info("stopping CPU profiler", "profile", cpuProfile) + svrCtx.Logger.Info("stopping CPU profiler", "profile", cpuProfile) pprof.StopCPUProfile() if err := f.Close(); err != nil { - logger.Info("failed to close cpu-profile file", "profile", cpuProfile, "err", err.Error()) + svrCtx.Logger.Info("failed to close cpu-profile file", "profile", cpuProfile, "err", err.Error()) } }() } @@ -619,43 +613,41 @@ func emitServerInfoMetrics() { telemetry.SetGaugeWithLabels([]string{"server", "info"}, 1, ls) } -func getCtx(logger log.Logger, block bool) (*errgroup.Group, context.Context) { +func getCtx(svrCtx *Context, block bool) (*errgroup.Group, context.Context) { ctx, cancelFn := context.WithCancel(context.Background()) g, ctx := errgroup.WithContext(ctx) // listen for quit signals so the calling parent process can gracefully exit - ListenForQuitSignals(g, block, cancelFn, logger) + ListenForQuitSignals(g, block, cancelFn, svrCtx.Logger) return g, ctx } -func startApp[T types.Application](viper *viper.Viper, logger log.Logger, appCreator types.AppCreator[T], opts StartCmdOptions[T]) (app T, cleanupFn func(), err error) { - traceWriter, traceCleanupFn, err := SetupTraceWriter(logger, viper.GetString(flagTraceStore)) +func startApp[T types.Application](svrCtx *Context, appCreator types.AppCreator[T], opts StartCmdOptions[T]) (app T, cleanupFn func(), err error) { + traceWriter, traceCleanupFn, err := SetupTraceWriter(svrCtx.Logger, svrCtx.Viper.GetString(flagTraceStore)) if err != nil { return app, traceCleanupFn, err } - cmtCfg := client.GetConfigFromViper(viper) - - home := cmtCfg.RootDir - db, err := opts.DBOpener(home, GetAppDBBackend(viper)) + home := svrCtx.Config.RootDir + db, err := opts.DBOpener(home, GetAppDBBackend(svrCtx.Viper)) if err != nil { return app, traceCleanupFn, err } - if isTestnet, ok := viper.Get(KeyIsTestnet).(bool); ok && isTestnet { + if isTestnet, ok := svrCtx.Viper.Get(KeyIsTestnet).(bool); ok && isTestnet { var appPtr *T - appPtr, err = testnetify[T](viper, logger, appCreator, db, traceWriter) + appPtr, err = testnetify[T](svrCtx, appCreator, db, traceWriter) if err != nil { return app, traceCleanupFn, err } app = *appPtr } else { - app = appCreator(logger, db, traceWriter, viper) + app = appCreator(svrCtx.Logger, db, traceWriter, svrCtx.Viper) } cleanupFn = func() { traceCleanupFn() if localErr := app.Close(); localErr != nil { - logger.Error(localErr.Error()) + svrCtx.Logger.Error(localErr.Error()) } } return app, cleanupFn, nil @@ -698,10 +690,8 @@ you want to test the upgrade handler itself. Example: "in-place-testnet localosmosis osmo12smx2wdlyttvyzvzg54y2vnqwq2qjateuf7thj", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - viper := client.GetViperFromCmd(cmd) - logger := client.GetLoggerFromCmd(cmd) - - _, err := GetPruningOptionsFromFlags(viper) + serverCtx := GetServerContextFromCmd(cmd) + _, err := GetPruningOptionsFromFlags(serverCtx.Viper) if err != nil { return err } @@ -713,7 +703,7 @@ you want to test the upgrade handler itself. withCMT, _ := cmd.Flags().GetBool(flagWithComet) if !withCMT { - logger.Info("starting ABCI without CometBFT") + serverCtx.Logger.Info("starting ABCI without CometBFT") } newChainID := args[0] @@ -735,20 +725,20 @@ you want to test the upgrade handler itself. // Set testnet keys to be used by the application. // This is done to prevent changes to existing start API. - viper.Set(KeyIsTestnet, true) - viper.Set(KeyNewChainID, newChainID) - viper.Set(KeyNewOpAddr, newOperatorAddress) + serverCtx.Viper.Set(KeyIsTestnet, true) + serverCtx.Viper.Set(KeyNewChainID, newChainID) + serverCtx.Viper.Set(KeyNewOpAddr, newOperatorAddress) - err = wrapCPUProfile(viper, logger, func() error { - return opts.StartCommandHandler(viper, logger, clientCtx, testnetAppCreator, withCMT, opts) + err = wrapCPUProfile(serverCtx, func() error { + return opts.StartCommandHandler(serverCtx, clientCtx, testnetAppCreator, withCMT, opts) }) - logger.Debug("received quit signal") + serverCtx.Logger.Debug("received quit signal") graceDuration, _ := cmd.Flags().GetDuration(FlagShutdownGrace) if graceDuration > 0 { - logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration) + serverCtx.Logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration) <-time.After(graceDuration) - logger.Info("graceful shutdown complete") + serverCtx.Logger.Info("graceful shutdown complete") } return err @@ -763,10 +753,10 @@ you want to test the upgrade handler itself. // testnetify modifies both state and blockStore, allowing the provided operator address and local validator key to control the network // that the state in the data folder represents. The chainID of the local genesis file is modified to match the provided chainID. -func testnetify[T types.Application](viper *viper.Viper, logger log.Logger, testnetAppCreator types.AppCreator[T], db dbm.DB, traceWriter io.WriteCloser) (*T, error) { - config := client.GetConfigFromViper(viper) +func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCreator[T], db dbm.DB, traceWriter io.WriteCloser) (*T, error) { + config := ctx.Config - newChainID, ok := viper.Get(KeyNewChainID).(string) + newChainID, ok := ctx.Viper.Get(KeyNewChainID).(string) if !ok { return nil, fmt.Errorf("expected string for key %s", KeyNewChainID) } @@ -819,25 +809,25 @@ func testnetify[T types.Application](viper *viper.Viper, logger log.Logger, test return nil, err } - viper.Set(KeyNewValAddr, validatorAddress) - viper.Set(KeyUserPubKey, userPubKey) - testnetApp := testnetAppCreator(logger, db, traceWriter, viper) + ctx.Viper.Set(KeyNewValAddr, validatorAddress) + ctx.Viper.Set(KeyUserPubKey, userPubKey) + testnetApp := testnetAppCreator(ctx.Logger, db, traceWriter, ctx.Viper) // We need to create a temporary proxyApp to get the initial state of the application. // Depending on how the node was stopped, the application height can differ from the blockStore height. // This height difference changes how we go about modifying the state. cmtApp := NewCometABCIWrapper(testnetApp) - _, context := getCtx(logger, true) + _, context := getCtx(ctx, true) clientCreator := proxy.NewLocalClientCreator(cmtApp) metrics := node.DefaultMetricsProvider(cmtcfg.DefaultConfig().Instrumentation) _, _, _, _, _, proxyMetrics, _, _ := metrics(genDoc.ChainID) // nolint: dogsled // function from comet proxyApp := proxy.NewAppConns(clientCreator, proxyMetrics) if err := proxyApp.Start(); err != nil { - return nil, fmt.Errorf("error starting proxy app connections: %w", err) + return nil, fmt.Errorf("error starting proxy app connections: %v", err) } res, err := proxyApp.Query().Info(context, proxy.InfoRequest) if err != nil { - return nil, fmt.Errorf("error calling Info: %w", err) + return nil, fmt.Errorf("error calling Info: %v", err) } err = proxyApp.Stop() if err != nil { diff --git a/server/util.go b/server/util.go index 493d0a5daaa8..2722bc458390 100644 --- a/server/util.go +++ b/server/util.go @@ -24,28 +24,45 @@ import ( "github.com/spf13/viper" "golang.org/x/sync/errgroup" - corectx "cosmossdk.io/core/context" "cosmossdk.io/log" + corectx "cosmossdk.io/core/context" "cosmossdk.io/store" "cosmossdk.io/store/snapshots" snapshottypes "cosmossdk.io/store/snapshots/types" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/config" "github.com/cosmos/cosmos-sdk/server/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/mempool" "github.com/cosmos/cosmos-sdk/version" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) -// Deprecated: Do not use, we use viper to track all config +// ServerContextKey defines the context key used to retrieve a server.Context from +// a command's Context. +const ServerContextKey = sdk.ContextKey("server.context") + +// Context server context +// Deprecated: Do not use since we use viper to track all config type Context struct { Viper *viper.Viper - Logger log.Logger Config *cmtcfg.Config + Logger log.Logger +} + +func NewDefaultContext() *Context { + return NewContext( + viper.New(), + cmtcfg.DefaultConfig(), + log.NewLogger(os.Stdout), + ) +} + +func NewContext(v *viper.Viper, config *cmtcfg.Config, logger log.Logger) *Context { + return &Context{v, config, logger} } func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) { @@ -85,19 +102,20 @@ func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) // InterceptConfigsPreRunHandler is identical to InterceptConfigsAndCreateContext // except it also sets the server context on the command and the server logger. func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}, cmtConfig *cmtcfg.Config) error { - viper, err := InterceptConfigsAndCreateContext(cmd, customAppConfigTemplate, customAppConfig, cmtConfig) + serverCtx, err := InterceptConfigsAndCreateContext(cmd, customAppConfigTemplate, customAppConfig, cmtConfig) if err != nil { return err } // overwrite default server logger - logger, err := CreateSDKLogger(viper, cmd.OutOrStdout()) + logger, err := CreateSDKLogger(serverCtx, cmd.OutOrStdout()) if err != nil { return err } + serverCtx.Logger = logger.With(log.ModuleKey, "server") // set server context - return SetCmdServerContext(cmd, viper, logger) + return SetCmdServerContext(cmd, serverCtx) } // InterceptConfigsAndCreateContext performs a pre-run function for the root daemon @@ -110,8 +128,8 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate s // is used to read and parse the application configuration. Command handlers can // fetch the server Context to get the CometBFT configuration or to get access // to Viper. -func InterceptConfigsAndCreateContext(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}, cmtConfig *cmtcfg.Config) (*viper.Viper, error) { - v := viper.New() +func InterceptConfigsAndCreateContext(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}, cmtConfig *cmtcfg.Config) (*Context, error) { + serverCtx := NewDefaultContext() // Get the executable name and configure the viper instance so that environmental // variables are checked based off that name. The underscore character is used @@ -124,44 +142,46 @@ func InterceptConfigsAndCreateContext(cmd *cobra.Command, customAppConfigTemplat basename := path.Base(executableName) // configure the viper instance - if err := v.BindPFlags(cmd.Flags()); err != nil { + if err := serverCtx.Viper.BindPFlags(cmd.Flags()); err != nil { return nil, err } - if err := v.BindPFlags(cmd.PersistentFlags()); err != nil { + if err := serverCtx.Viper.BindPFlags(cmd.PersistentFlags()); err != nil { return nil, err } - v.SetEnvPrefix(basename) - v.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) - v.AutomaticEnv() + serverCtx.Viper.SetEnvPrefix(basename) + serverCtx.Viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) + serverCtx.Viper.AutomaticEnv() // intercept configuration files, using both Viper instances separately - err = interceptConfigs(v, customAppConfigTemplate, customAppConfig, cmtConfig) + config, err := interceptConfigs(serverCtx.Viper, customAppConfigTemplate, customAppConfig, cmtConfig) if err != nil { return nil, err } - if err = bindFlags(basename, cmd, v); err != nil { + // return value is a CometBFT configuration object + serverCtx.Config = config + if err = bindFlags(basename, cmd, serverCtx.Viper); err != nil { return nil, err } - return v, nil + return serverCtx, nil } // CreateSDKLogger creates a the default SDK logger. // It reads the log level and format from the server context. -func CreateSDKLogger(v *viper.Viper, out io.Writer) (log.Logger, error) { +func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) { var opts []log.Option - if v.GetString(flags.FlagLogFormat) == flags.OutputFormatJSON { + if ctx.Viper.GetString(flags.FlagLogFormat) == flags.OutputFormatJSON { opts = append(opts, log.OutputJSONOption()) } opts = append(opts, - log.ColorOption(!v.GetBool(flags.FlagLogNoColor)), + log.ColorOption(!ctx.Viper.GetBool(flags.FlagLogNoColor)), // We use CometBFT flag (cmtcli.TraceFlag) for trace logging. - log.TraceOption(v.GetBool(FlagTrace))) + log.TraceOption(ctx.Viper.GetBool(FlagTrace))) // check and set filter level or keys for the logger if any - logLvlStr := v.GetString(flags.FlagLogLevel) + logLvlStr := ctx.Viper.GetString(flags.FlagLogLevel) if logLvlStr == "" { return log.NewLogger(out, opts...), nil } @@ -186,29 +206,17 @@ func CreateSDKLogger(v *viper.Viper, out io.Writer) (log.Logger, error) { // GetServerContextFromCmd returns a Context from a command or an empty Context // if it has not been set. func GetServerContextFromCmd(cmd *cobra.Command) *Context { - serverCtx := &Context{} - if v := cmd.Context().Value(corectx.ViperContextKey{}); v != nil { - viper := v.(*viper.Viper) - serverCtx.Viper = viper - serverCtx.Config = client.GetConfigFromViper(viper) - } else { - serverCtx.Viper = viper.New() - serverCtx.Config = cmtcfg.DefaultConfig() + if v := cmd.Context().Value(ServerContextKey); v != nil { + serverCtxPtr := v.(*Context) + return serverCtxPtr } - if v := cmd.Context().Value(corectx.LoggerContextKey{}); v != nil { - logger := v.(log.Logger) - serverCtx.Logger = logger - } else { - serverCtx.Logger = log.NewLogger(cmd.OutOrStdout()) - } - - return serverCtx + return NewDefaultContext() } // SetCmdServerContext sets a command's Context value to the provided argument. // If the context has not been set, set the given context as the default. -func SetCmdServerContext(cmd *cobra.Command, viper *viper.Viper, logger log.Logger) error { +func SetCmdServerContext(cmd *cobra.Command, serverCtx *Context) error { var cmdCtx context.Context if cmd.Context() == nil { @@ -217,8 +225,13 @@ func SetCmdServerContext(cmd *cobra.Command, viper *viper.Viper, logger log.Logg cmdCtx = cmd.Context() } - cmd.SetContext(context.WithValue(cmdCtx, corectx.LoggerContextKey{}, logger)) - cmd.SetContext(context.WithValue(cmdCtx, corectx.ViperContextKey{}, viper)) + cmdCtx = context.WithValue(cmdCtx, ServerContextKey, serverCtx) + cmdCtx = context.WithValue(cmdCtx, corectx.ViperContextKey{}, serverCtx.Viper) + cmdCtx = context.WithValue(cmdCtx, corectx.LoggerContextKey{}, serverCtx.Logger) + + cmd.SetContext(cmdCtx) + + fmt.Println("After set", serverCtx.Viper.GetString(flags.FlagHome)) return nil } @@ -228,8 +241,9 @@ func SetCmdServerContext(cmd *cobra.Command, viper *viper.Viper, logger log.Logg // 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{}, cmtConfig *cmtcfg.Config) error { +func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customConfig interface{}, cmtConfig *cmtcfg.Config) (*cmtcfg.Config, error) { rootDir := rootViper.GetString(flags.FlagHome) + fmt.Println("Init root", rootDir) configPath := filepath.Join(rootDir, "config") cmtCfgFile := filepath.Join(configPath, "config.toml") @@ -240,7 +254,7 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo cmtcfg.EnsureRoot(rootDir) if err = conf.ValidateBasic(); err != nil { - return fmt.Errorf("error in config file: %w", err) + return nil, fmt.Errorf("error in config file: %w", err) } defaultCometCfg := cmtcfg.DefaultConfig() @@ -256,7 +270,7 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo cmtcfg.WriteConfigFile(cmtCfgFile, conf) case err != nil: - return err + return nil, err default: rootViper.SetConfigType("toml") @@ -264,7 +278,7 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo rootViper.AddConfigPath(configPath) if err := rootViper.ReadInConfig(); err != nil { - return fmt.Errorf("failed to read in %s: %w", cmtCfgFile, err) + return nil, fmt.Errorf("failed to read in %s: %w", cmtCfgFile, err) } } @@ -272,35 +286,37 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo // This may come from the configuration file above but also any of the other // sources viper uses. if err := rootViper.Unmarshal(conf); err != nil { - return err + return nil, err } + conf.SetRoot(rootDir) + appCfgFilePath := filepath.Join(configPath, "app.toml") if _, err := os.Stat(appCfgFilePath); os.IsNotExist(err) { if (customAppTemplate != "" && customConfig == nil) || (customAppTemplate == "" && customConfig != nil) { - return fmt.Errorf("customAppTemplate and customConfig should be both nil or not nil") + return nil, fmt.Errorf("customAppTemplate and customConfig should be both nil or not nil") } if customAppTemplate != "" { if err := config.SetConfigTemplate(customAppTemplate); err != nil { - return fmt.Errorf("failed to set config template: %w", err) + return nil, fmt.Errorf("failed to set config template: %w", err) } if err = rootViper.Unmarshal(&customConfig); err != nil { - return fmt.Errorf("failed to parse %s: %w", appCfgFilePath, err) + return nil, fmt.Errorf("failed to parse %s: %w", appCfgFilePath, err) } if err := config.WriteConfigFile(appCfgFilePath, customConfig); err != nil { - return fmt.Errorf("failed to write %s: %w", appCfgFilePath, err) + return nil, fmt.Errorf("failed to write %s: %w", appCfgFilePath, err) } } else { appConf, err := config.ParseConfig(rootViper) if err != nil { - return fmt.Errorf("failed to parse %s: %w", appCfgFilePath, err) + return nil, fmt.Errorf("failed to parse %s: %w", appCfgFilePath, err) } if err := config.WriteConfigFile(appCfgFilePath, appConf); err != nil { - return fmt.Errorf("failed to write %s: %w", appCfgFilePath, err) + return nil, fmt.Errorf("failed to write %s: %w", appCfgFilePath, err) } } } @@ -310,10 +326,10 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo rootViper.AddConfigPath(configPath) if err := rootViper.MergeInConfig(); err != nil { - return fmt.Errorf("failed to merge configuration: %w", err) + return nil, fmt.Errorf("failed to merge configuration: %w", err) } - return nil + return conf, nil } // AddCommands add server commands diff --git a/server/util_test.go b/server/util_test.go index 040bb6415a9b..11f5cbb208c9 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -16,9 +16,6 @@ import ( "github.com/spf13/viper" "github.com/stretchr/testify/require" - corectx "cosmossdk.io/core/context" - "cosmossdk.io/log" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" @@ -62,13 +59,13 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T cmd.PreRunE = preRunETestImpl - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) + serverCtx := &server.Context{} + ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - config := client.GetConfigFromCmd(cmd) + serverCtx = server.GetServerContextFromCmd(cmd) // Test that config.toml is created configTomlPath := path.Join(tempDir, "config", "config.toml") @@ -86,7 +83,7 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T } // Test that CometBFT config is initialized - if config == nil { + if serverCtx.Config == nil { t.Fatal("CometBFT config not created") } @@ -106,10 +103,7 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T } // Test that the config for use in server/start.go is created - v := ctx.Value(corectx.ViperContextKey{}) - viper, _ := v.(*viper.Viper) - - if viper == nil { + if serverCtx.Viper == nil { t.Error("app config Viper instance not created") } } @@ -144,16 +138,16 @@ func TestInterceptConfigsPreRunHandlerReadsConfigToml(t *testing.T) { cmd.PreRunE = preRunETestImpl - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) + serverCtx := &server.Context{} + ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - config := client.GetConfigFromCmd(cmd) + serverCtx = server.GetServerContextFromCmd(cmd) - if testDbBackend != config.DBBackend { + if testDbBackend != serverCtx.Config.DBBackend { t.Error("backend was not set from config.toml") } } @@ -184,16 +178,16 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) { cmd.PreRunE = preRunETestImpl - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) + serverCtx := &server.Context{} + ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - viper := client.GetViperFromCmd(cmd) + serverCtx = server.GetServerContextFromCmd(cmd) - if testHaltTime != viper.GetInt("halt-time") { + if testHaltTime != serverCtx.Viper.GetInt("halt-time") { t.Error("Halt time was not set from app.toml") } } @@ -214,16 +208,16 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { cmd.PreRunE = preRunETestImpl - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) + serverCtx := &server.Context{} + ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - config := client.GetConfigFromCmd(cmd) + serverCtx = server.GetServerContextFromCmd(cmd) - if testAddr != config.RPC.ListenAddress { + if testAddr != serverCtx.Config.RPC.ListenAddress { t.Error("RPCListenAddress was not set from command flags") } } @@ -252,16 +246,16 @@ func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) { cmd.PreRunE = preRunETestImpl - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) + serverCtx := &server.Context{} + ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - config := client.GetConfigFromCmd(cmd) + serverCtx = server.GetServerContextFromCmd(cmd) - if testAddr != config.RPC.ListenAddress { + if testAddr != serverCtx.Config.RPC.ListenAddress { t.Errorf("RPCListenAddress was not set from env. var. %q", envVarName) } } @@ -361,16 +355,16 @@ func TestInterceptConfigsPreRunHandlerPrecedenceFlag(t *testing.T) { testCommon := newPrecedenceCommon(t) testCommon.setAll(t, &TestAddrExpected, &TestAddrNotExpected, &TestAddrNotExpected) - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) + serverCtx := &server.Context{} + ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - config := client.GetConfigFromCmd(testCommon.cmd) + serverCtx = server.GetServerContextFromCmd(testCommon.cmd) - if TestAddrExpected != config.RPC.ListenAddress { + if TestAddrExpected != serverCtx.Config.RPC.ListenAddress { t.Fatalf("RPCListenAddress was not set from flag %q", testCommon.flagName) } } @@ -379,16 +373,16 @@ func TestInterceptConfigsPreRunHandlerPrecedenceEnvVar(t *testing.T) { testCommon := newPrecedenceCommon(t) testCommon.setAll(t, nil, &TestAddrExpected, &TestAddrNotExpected) - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) + serverCtx := &server.Context{} + ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - config := client.GetConfigFromCmd(testCommon.cmd) + serverCtx = server.GetServerContextFromCmd(testCommon.cmd) - if TestAddrExpected != config.RPC.ListenAddress { + if TestAddrExpected != serverCtx.Config.RPC.ListenAddress { t.Errorf("RPCListenAddress was not set from env. var. %q", testCommon.envVarName) } } @@ -397,16 +391,16 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigFile(t *testing.T) { testCommon := newPrecedenceCommon(t) testCommon.setAll(t, nil, nil, &TestAddrExpected) - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) + serverCtx := &server.Context{} + ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - config := client.GetConfigFromCmd(testCommon.cmd) + serverCtx = server.GetServerContextFromCmd(testCommon.cmd) - if TestAddrExpected != config.RPC.ListenAddress { + if TestAddrExpected != serverCtx.Config.RPC.ListenAddress { t.Errorf("RPCListenAddress was not read from file %q", testCommon.configTomlPath) } } @@ -415,16 +409,16 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigDefault(t *testing.T) { testCommon := newPrecedenceCommon(t) // Do not set anything - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) - ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) + serverCtx := &server.Context{} + ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCanceledInPreRun) { t.Fatalf("function failed with [%T] %v", err, err) } - config := client.GetConfigFromCmd(testCommon.cmd) + serverCtx = server.GetServerContextFromCmd(testCommon.cmd) - if config.RPC.ListenAddress != "tcp://127.0.0.1:26657" { + if serverCtx.Config.RPC.ListenAddress != "tcp://127.0.0.1:26657" { t.Error("RPCListenAddress is not using default") } } @@ -446,9 +440,8 @@ func TestInterceptConfigsWithBadPermissions(t *testing.T) { cmd.PreRunE = preRunETestImpl - ctx := context.WithValue(context.Background(), corectx.LoggerContextKey{}, log.NewNopLogger()) - ctx = context.WithValue(ctx, corectx.ViperContextKey{}, viper.New()) - + serverCtx := &server.Context{} + ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) if err := cmd.ExecuteContext(ctx); !os.IsPermission(err) { t.Fatalf("Failed to catch permissions error, got: [%T] %v", err, err) } @@ -462,10 +455,9 @@ func TestEmptyMinGasPrices(t *testing.T) { // Run InitCmd to create necessary config files. clientCtx := client.Context{}.WithHomeDir(tempDir).WithCodec(encCfg.Codec) - viper := viper.New() - viper.Set(flags.FlagHome, tempDir) - ctx := context.WithValue(context.Background(), corectx.ViperContextKey{}, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey{}, log.NewLogger(os.Stdout)) + serverCtx := server.NewDefaultContext() + serverCtx.Config.SetRoot(tempDir) + ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx) ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) cmd := genutilcli.InitCmd(module.NewManager()) cmd.SetArgs([]string{"appnode-test"}) @@ -483,12 +475,12 @@ func TestEmptyMinGasPrices(t *testing.T) { cmd = server.StartCmd[servertypes.Application](nil) cmd.PersistentFlags().String(flags.FlagHome, tempDir, "") cmd.PreRunE = func(cmd *cobra.Command, _ []string) error { - viper, err := server.InterceptConfigsAndCreateContext(cmd, "", nil, cmtcfg.DefaultConfig()) + ctx, err := server.InterceptConfigsAndCreateContext(cmd, "", nil, cmtcfg.DefaultConfig()) if err != nil { return err } - return server.SetCmdServerContext(cmd, viper, client.GetLoggerFromCmd(cmd)) + return server.SetCmdServerContext(cmd, ctx) } err = cmd.ExecuteContext(ctx) require.Errorf(t, err, sdkerrors.ErrAppConfig.Error()) From 731751be6de166555f4c5af054f094378cd90509 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 23 May 2024 15:31:15 +0700 Subject: [PATCH 25/29] fix err format --- server/start.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/start.go b/server/start.go index ea0e43d31319..6f4f3eaf5268 100644 --- a/server/start.go +++ b/server/start.go @@ -823,11 +823,11 @@ func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCr _, _, _, _, _, proxyMetrics, _, _ := metrics(genDoc.ChainID) // nolint: dogsled // function from comet proxyApp := proxy.NewAppConns(clientCreator, proxyMetrics) if err := proxyApp.Start(); err != nil { - return nil, fmt.Errorf("error starting proxy app connections: %v", err) + return nil, fmt.Errorf("error starting proxy app connections: %w", err) } res, err := proxyApp.Query().Info(context, proxy.InfoRequest) if err != nil { - return nil, fmt.Errorf("error calling Info: %v", err) + return nil, fmt.Errorf("error calling Info: %w", err) } err = proxyApp.Stop() if err != nil { From d7e786419cf85fce0c3931df748349d65dae492b Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 23 May 2024 15:47:13 +0700 Subject: [PATCH 26/29] lint --- core/context/server_context.go | 2 +- server/util.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/context/server_context.go b/core/context/server_context.go index c8b532a5db2e..98c0821550fa 100644 --- a/core/context/server_context.go +++ b/core/context/server_context.go @@ -2,5 +2,5 @@ package context type ( LoggerContextKey struct{} - ViperContextKey struct{} + ViperContextKey struct{} ) diff --git a/server/util.go b/server/util.go index 2722bc458390..af218b9f769e 100644 --- a/server/util.go +++ b/server/util.go @@ -24,8 +24,8 @@ import ( "github.com/spf13/viper" "golang.org/x/sync/errgroup" - "cosmossdk.io/log" corectx "cosmossdk.io/core/context" + "cosmossdk.io/log" "cosmossdk.io/store" "cosmossdk.io/store/snapshots" snapshottypes "cosmossdk.io/store/snapshots/types" From c90c6ac691bf3416cd5ef95a1b62a524d965c495 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 23 May 2024 15:55:00 +0700 Subject: [PATCH 27/29] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9be19bde7b1a..6875a68e65bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -119,6 +119,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### API Breaking Changes +* (server) [#20422](https://github.com/cosmos/cosmos-sdk/pull/20422) Remove `cmtcfg.Config` from `ServerContext`. To get `cmtcfg.Config` from cmd, use `client.GetConfigFromCmd(cmd)` instead of `server.GetServerContextFromCmd(cmd).Config` * (types)[#20369](https://github.com/cosmos/cosmos-sdk/pull/20369) The signature of `HasAminoCodec` has changed to accept a `core/legacy.Amino` interface instead of `codec.LegacyAmino`. * (x/simulation)[#20056](https://github.com/cosmos/cosmos-sdk/pull/20056) `SimulateFromSeed` now takes an address codec as argument. * (x/crisis) [#20043](https://github.com/cosmos/cosmos-sdk/pull/20043) Changed `NewMsgVerifyInvariant` to accept a string as argument instead of an `AccAddress`. From e3c0a034cefe7189ed1d11918651176f61217f4f Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 23 May 2024 19:31:17 +0700 Subject: [PATCH 28/29] rename --- CHANGELOG.md | 2 +- server/util.go | 3 --- simapp/simd/cmd/testnet_test.go | 2 +- tests/e2e/genutil/export_test.go | 2 +- testutil/network/util.go | 2 +- x/genutil/client/cli/init_test.go | 2 +- x/genutil/client/testutil/helpers.go | 6 +++--- x/genutil/collect_test.go | 3 --- 8 files changed, 8 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6875a68e65bf..dcbae6d38f79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -119,7 +119,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### API Breaking Changes -* (server) [#20422](https://github.com/cosmos/cosmos-sdk/pull/20422) Remove `cmtcfg.Config` from `ServerContext`. To get `cmtcfg.Config` from cmd, use `client.GetConfigFromCmd(cmd)` instead of `server.GetServerContextFromCmd(cmd).Config` +* (server) [#20422](https://github.com/cosmos/cosmos-sdk/pull/20422) Deprecated `ServerContext`. To get `cmtcfg.Config` from cmd, use `client.GetCometConfigFromCmd(cmd)` instead of `server.GetServerContextFromCmd(cmd).Config` * (types)[#20369](https://github.com/cosmos/cosmos-sdk/pull/20369) The signature of `HasAminoCodec` has changed to accept a `core/legacy.Amino` interface instead of `codec.LegacyAmino`. * (x/simulation)[#20056](https://github.com/cosmos/cosmos-sdk/pull/20056) `SimulateFromSeed` now takes an address codec as argument. * (x/crisis) [#20043](https://github.com/cosmos/cosmos-sdk/pull/20043) Changed `NewMsgVerifyInvariant` to accept a string as argument instead of an `AccAddress`. diff --git a/server/util.go b/server/util.go index af218b9f769e..ccb081395099 100644 --- a/server/util.go +++ b/server/util.go @@ -231,8 +231,6 @@ func SetCmdServerContext(cmd *cobra.Command, serverCtx *Context) error { cmd.SetContext(cmdCtx) - fmt.Println("After set", serverCtx.Viper.GetString(flags.FlagHome)) - return nil } @@ -243,7 +241,6 @@ func SetCmdServerContext(cmd *cobra.Command, serverCtx *Context) error { // viperCfg object. func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customConfig interface{}, cmtConfig *cmtcfg.Config) (*cmtcfg.Config, error) { rootDir := rootViper.GetString(flags.FlagHome) - fmt.Println("Init root", rootDir) configPath := filepath.Join(rootDir, "config") cmtCfgFile := filepath.Join(configPath, "config.toml") diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index 524d7d01c523..fee803721e52 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -58,7 +58,7 @@ func Test_TestnetCmd(t *testing.T) { err = genutiltest.ExecInitCmd(moduleManager, home, encodingConfig.Codec) require.NoError(t, err) - err = genutiltest.WriteAndTrackConfig(viper, home, cfg) + err = genutiltest.WriteAndTrackCometConfig(viper, home, cfg) require.NoError(t, err) clientCtx := client.Context{}. WithCodec(encodingConfig.Codec). diff --git a/tests/e2e/genutil/export_test.go b/tests/e2e/genutil/export_test.go index 611df3671ccf..febda09efcff 100644 --- a/tests/e2e/genutil/export_test.go +++ b/tests/e2e/genutil/export_test.go @@ -175,7 +175,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, ge assert.NilError(t, err) viper := viper.New() - err = gentestutil.WriteAndTrackConfig(viper, tempDir, cmtcfg.DefaultConfig()) + err = gentestutil.WriteAndTrackCometConfig(viper, tempDir, cmtcfg.DefaultConfig()) assert.NilError(t, err) clientCtx := client.Context{}.WithCodec(app.AppCodec()) diff --git a/testutil/network/util.go b/testutil/network/util.go index 14a6196189d6..a3662bf6ea67 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -171,7 +171,7 @@ func collectGenFiles(cfg Config, vals []*Validator, cmtConfigs []*cmtcfg.Config, } v := vals[i].GetViper() - err = genutiltest.TrackConfig(v, nodeDir) + err = genutiltest.TrackCometConfig(v, nodeDir) if err != nil { return err } diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index b3a8b648764e..b57bba44cd50 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -388,5 +388,5 @@ func writeAndTrackDefaultConfig(v *viper.Viper, home string) error { if err != nil { return err } - return genutiltest.WriteAndTrackConfig(v, home, cfg) + return genutiltest.WriteAndTrackCometConfig(v, home, cfg) } diff --git a/x/genutil/client/testutil/helpers.go b/x/genutil/client/testutil/helpers.go index 77560ad16d1f..54df530e86ce 100644 --- a/x/genutil/client/testutil/helpers.go +++ b/x/genutil/client/testutil/helpers.go @@ -24,7 +24,7 @@ func ExecInitCmd(mm *module.Manager, home string, cdc codec.Codec) error { viper := viper.New() cmd := genutilcli.InitCmd(mm) cfg, _ := CreateDefaultCometConfig(home) - err := WriteAndTrackConfig(viper, home, cfg) + err := WriteAndTrackCometConfig(viper, home, cfg) if err != nil { return err } @@ -55,7 +55,7 @@ func CreateDefaultCometConfig(rootDir string) (*cmtcfg.Config, error) { return conf, nil } -func WriteAndTrackConfig(v *viper.Viper, home string, cfg *cmtcfg.Config) error { +func WriteAndTrackCometConfig(v *viper.Viper, home string, cfg *cmtcfg.Config) error { cmtcfg.WriteConfigFile(filepath.Join(home, "config", "config.toml"), cfg) v.Set(flags.FlagHome, home) @@ -65,7 +65,7 @@ func WriteAndTrackConfig(v *viper.Viper, home string, cfg *cmtcfg.Config) error return v.ReadInConfig() } -func TrackConfig(v *viper.Viper, home string) error { +func TrackCometConfig(v *viper.Viper, home string) error { v.Set(flags.FlagHome, home) v.SetConfigType("toml") v.SetConfigName("config") diff --git a/x/genutil/collect_test.go b/x/genutil/collect_test.go index fea26e1ecb96..15215076fd4c 100644 --- a/x/genutil/collect_test.go +++ b/x/genutil/collect_test.go @@ -53,9 +53,6 @@ func TestCollectTxsHandlesDirectories(t *testing.T) { }) // 2. Ensure that we don't encounter any error traversing the directory. - // What is this for??? - // srvCtx := server.NewDefaultContext() - // _ = srvCtx cdc := codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) genesis := &types.AppGenesis{AppState: []byte("{}")} balItr := new(doNothingIterator) From 7896c75626b9cbcfbea780903f969b651952e076 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 23 May 2024 22:11:50 +0700 Subject: [PATCH 29/29] unused --- x/genutil/client/cli/export_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x/genutil/client/cli/export_test.go b/x/genutil/client/cli/export_test.go index 0311619cfe79..3c3c870c7fee 100644 --- a/x/genutil/client/cli/export_test.go +++ b/x/genutil/client/cli/export_test.go @@ -38,7 +38,6 @@ type ExportSystem struct { Viper *viper.Viper Logger log.Logger - Cctx client.Context HomeDir string } @@ -84,7 +83,6 @@ func NewExportSystem(t *testing.T, exporter types.AppExporter) *ExportSystem { Ctx: ctx, Viper: viper, Logger: logger, - Cctx: cCtx, HomeDir: homeDir, } }