diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index fab7e3de6060..7b32a338c2c0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -10,62 +10,62 @@ # Components -/baseapp/ @facundomedica @aaronc @testinginprod @kocubinski @cosmos/sdk-core-dev +/baseapp/ @cosmos/sdk-core-dev /client/ @julienrbrt @JulianToledano @cosmos/sdk-core-dev /client/v2/ @julienrbrt @JulianToledano @cosmos/sdk-core-dev -/collections/ @testinginprod @facundomedica @cosmos/sdk-core-dev +/collections/ @cosmos/sdk-core-dev /core/ @cosmos/sdk-core-dev /crypto/ @JulianToledano @raynaudoe @cosmos/sdk-core-dev -/depinject/ @aaronc @kocubinski @julienrbrt @cosmos/sdk-core-dev -/indexer/ @aaronc @cool-develope @cosmos/sdk-core-dev -/log/ @julienrbrt @sontrinh16 @cosmos/sdk-core-dev -/math/ @testinginprod @alpe @cosmos/sdk-core-dev -/orm/ @aaronc @testinginprod @lucaslopezf @cosmos/sdk-core-dev -/runtime/ @julienrbrt @hieuvubk @cosmos/sdk-core-dev -/runtime/v2/ @julienrbrt @hieuvubk @cosmos/sdk-core-dev -/schema/ @aaronc @testinginprod @cosmos/sdk-core-dev +/depinject/ @julienrbrt @cosmos/sdk-core-dev +/indexer/ @cosmos/sdk-core-dev +/log/ @julienrbrt @cosmos/sdk-core-dev +/math/ @alpe @cosmos/sdk-core-dev +/orm/ @lucaslopezf @cosmos/sdk-core-dev +/runtime/ @julienrbrt @cosmos/sdk-core-dev +/runtime/v2/ @julienrbrt @cosmos/sdk-core-dev +/schema/ @cosmos/sdk-core-dev /server/ @cosmos/sdk-core-dev -/server/v2/ @julienrbrt @hieuvubk @kocubinski @cosmos/sdk-core-dev -/server/v2/stf/ @testinginprod @kocubinski @cosmos/sdk-core-dev -/server/v2/appmanager/ @testinginprod @facundomedica @cosmos/sdk-core-dev -/server/v2/cometbft/ @facundomedica @sontrinh16 @cosmos/sdk-core-dev -/simsx @alpe @facundomedica @kocubinski @cosmos/sdk-core-dev -/simapp/ @facundomedica @julienrbrt @cosmos/sdk-core-dev -/simapp/v2/ @kocubinski @julienrbrt @cosmos/sdk-core-dev -/store/ @cool-develope @kocubinski @cosmos/sdk-core-dev -/store/v2/ @cool-develope @kocubinski @cosmos/sdk-core-dev -/types/mempool/ @kocubinski @cosmos/sdk-core-dev +/server/v2/ @julienrbrt @cosmos/sdk-core-dev +/server/v2/stf/ @cosmos/sdk-core-dev +/server/v2/appmanager/ @cosmos/sdk-core-dev +/server/v2/cometbft/ @cosmos/sdk-core-dev +/simsx @alpe @cosmos/sdk-core-dev +/simapp/ @julienrbrt @cosmos/sdk-core-dev +/simapp/v2/ @julienrbrt @cosmos/sdk-core-dev +/store/ @cosmos/sdk-core-dev +/store/v2/ @cosmos/sdk-core-dev +/types/mempool/ @cosmos/sdk-core-dev /tools/hubl @julienrbrt @JulianToledano @cosmos/sdk-core-dev -/tools/cosmovisor @julienrbrt @facundomedica @cosmos/sdk-core-dev -/tools/confix @julienrbrt @akhilkumarpilli @cosmos/sdk-core-dev -/tests/integration/aminojson @kocubinski @cosmos/sdk-core-dev +/tools/cosmovisor @julienrbrt @cosmos/sdk-core-dev +/tools/confix @julienrbrt @cosmos/sdk-core-dev +/tests/integration/aminojson @cosmos/sdk-core-dev # x modules -/x/accounts/ @testinginprod @sontrinh16 @cosmos/sdk-core-dev -/x/auth/ @facundomedica @testinginprod @aaronc @cosmos/sdk-core-dev -/x/auth/tx/config @julienrbrt @akhilkumarpilli @kocubinski @cosmos/sdk-core-dev -/x/authz/ @akhilkumarpilli @raynaudoe @cosmos/sdk-core-dev -/x/bank/ @julienrbrt @sontrinh16 @cosmos/sdk-core-dev -/x/bank/v2 @julienrbrt @hieuvubk @akhilkumarpilli @cosmos/sdk-core-dev -/x/circuit/ @kocubinski @akhilkumarpilli @raynaudoe @cosmos/sdk-core-dev -/x/consensus/ @testinginprod @raynaudoe @cosmos/sdk-core-dev +/x/accounts/ @cosmos/sdk-core-dev +/x/auth/ @cosmos/sdk-core-dev +/x/auth/tx/config @julienrbrt @cosmos/sdk-core-dev +/x/authz/ @raynaudoe @cosmos/sdk-core-dev +/x/bank/ @julienrbrt @cosmos/sdk-core-dev +/x/bank/v2 @julienrbrt @cosmos/sdk-core-dev +/x/circuit/ @raynaudoe @cosmos/sdk-core-dev +/x/consensus/ @raynaudoe @cosmos/sdk-core-dev /x/distribution/ @alpe @JulianToledano @cosmos/sdk-core-dev -/x/epochs/ @alpe @facundomedica @cosmos/sdk-core-dev -/x/evidence/ @alpe @akhilkumarpilli @cosmos/sdk-core-dev -/x/feegrant/ @cool-develope @alpe @cosmos/sdk-core-dev -/x/genutil/ @kocubinski @hieuvubk @julienrbrt @cosmos/sdk-core-dev -/x/gov/ @julienrbrt @sontrinh16 @cosmos/sdk-core-dev -/x/group/ @kocubinski @akhilkumarpilli @cosmos/sdk-core-dev -/x/mint/ @lucaslopezf @facundomedica @cosmos/sdk-core-dev +/x/epochs/ @alpe @cosmos/sdk-core-dev +/x/evidence/ @alpe @cosmos/sdk-core-dev +/x/feegrant/ @alpe @cosmos/sdk-core-dev +/x/genutil/ @julienrbrt @cosmos/sdk-core-dev +/x/gov/ @julienrbrt @cosmos/sdk-core-dev +/x/group/ @cosmos/sdk-core-dev +/x/mint/ @lucaslopezf @cosmos/sdk-core-dev /x/nft/ @alpe @lucaslopezf @cosmos/sdk-core-dev -/x/protocolpool/ @facundomedica @hieuvubk @alpe @cosmos/sdk-core-dev +/x/protocolpool/ @alpe @cosmos/sdk-core-dev /x/simulation/ @cosmos/sdk-core-dev # deprecated so whole team -/x/slashing/ @testinginprod @raynaudoe @lucaslopezf @cosmos/sdk-core-dev -/x/staking/ @facundomedica @testinginprod @JulianToledano @ziscky @cosmos/sdk-core-dev -/x/tx/ @kocubinski @testinginprod @aaronc @cosmos/sdk-core-dev -/x/upgrade/ @facundomedica @cool-develope @akhilkumarpilli @lucaslopezf @cosmos/sdk-core-dev -/x/validate @julienrbrt @akhilkumarpilli @kocubinski @cosmos/sdk-core-dev +/x/slashing/ @raynaudoe @lucaslopezf @cosmos/sdk-core-dev +/x/staking/ @JulianToledano @ziscky @cosmos/sdk-core-dev +/x/tx/ @cosmos/sdk-core-dev +/x/upgrade/ @lucaslopezf @cosmos/sdk-core-dev +/x/validate @julienrbrt @cosmos/sdk-core-dev # go mods @@ -74,11 +74,11 @@ # ci & build -.github/ @auricom @julienrbrt @tac0turtle -scripts/ @auricom @julienrbrt @tac0turtle -contrib/ @auricom @julienrbrt @tac0turtle -*.mk @auricom @julienrbrt @tac0turtle -Makefile @auricom @julienrbrt @tac0turtle +.github/ @julienrbrt @tac0turtle +scripts/ @julienrbrt @tac0turtle +contrib/ @julienrbrt @tac0turtle +*.mk @julienrbrt @tac0turtle +Makefile @julienrbrt @tac0turtle # docs configuration diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e2830964cd4..34813000c836 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,15 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (x/params) [#22995](https://github.com/cosmos/cosmos-sdk/pull/22995) Remove `x/params`. Migrate to the new params system introduced in `v0.47` as demonstrated [here](https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md#xparams). * (testutil) [#22392](https://github.com/cosmos/cosmos-sdk/pull/22392) Remove `testutil/network` package. Use the integration framework or systemtests framework instead. +#### Removal of v1 components + +This subsection lists the API breaking changes that are [part of the removal of v1 components](https://github.com/cosmos/cosmos-sdk/issues/22904). The v1 components were deprecated in `v0.52` and are now removed. + +* (simapp) [#23009](https://github.com/cosmos/cosmos-sdk/pull/23009) Simapp has been removed. Check-out Simapp/v2 instead. +* (server) [#23018](https://github.com/cosmos/cosmos-sdk/pull/23018) [#23238](https://github.com/cosmos/cosmos-sdk/pull/23238) The server package has been removed. Use server/v2 instead +* (x/genutil) [#23238](https://github.com/cosmos/cosmos-sdk/pull/23238) Genutil commands specific to a baseapp chain have been deleted. +* (client) [#22904](https://github.com/cosmos/cosmos-sdk/issues/22904) v1 specific client commands have been removed. + ### Deprecated * (modules) [#22994](https://github.com/cosmos/cosmos-sdk/pull/22994) Deprecate `Invariants` and associated methods. diff --git a/api/cosmos/base/reflection/v1beta1/reflection.pulsar.go b/api/cosmos/base/reflection/v1beta1/reflection.pulsar.go index f886d9174051..e94f03820fe4 100644 --- a/api/cosmos/base/reflection/v1beta1/reflection.pulsar.go +++ b/api/cosmos/base/reflection/v1beta1/reflection.pulsar.go @@ -1833,7 +1833,7 @@ type ListImplementationsRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // interface_name defines the interface to query the implementations for. + // interface_name defines the interface to query the implementations. InterfaceName string `protobuf:"bytes,1,opt,name=interface_name,json=interfaceName,proto3" json:"interface_name,omitempty"` } diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 98adf6e1a94e..455be68cdf48 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -29,7 +29,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp/oe" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -58,8 +57,6 @@ const ( execModeFinalize // Finalize a block proposal ) -var _ servertypes.ABCI = (*BaseApp)(nil) - // BaseApp reflects the ABCI application implementation. type BaseApp struct { // initialized on creation diff --git a/baseapp/streaming.go b/baseapp/streaming.go index 78b19d5337c4..8961894cf520 100644 --- a/baseapp/streaming.go +++ b/baseapp/streaming.go @@ -12,6 +12,7 @@ import ( abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" "github.com/spf13/cast" + "cosmossdk.io/core/server" "cosmossdk.io/log" "cosmossdk.io/schema" "cosmossdk.io/schema/appdata" @@ -21,7 +22,6 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/client/flags" - servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -60,7 +60,7 @@ func (app *BaseApp) EnableIndexer(indexerOpts interface{}, keys map[string]*stor } // RegisterStreamingServices registers streaming services with the BaseApp. -func (app *BaseApp) RegisterStreamingServices(appOpts servertypes.AppOptions, keys map[string]*storetypes.KVStoreKey) error { +func (app *BaseApp) RegisterStreamingServices(appOpts server.DynamicConfig, keys map[string]*storetypes.KVStoreKey) error { // register streaming services streamingCfg := cast.ToStringMap(appOpts.Get(StreamingTomlKey)) for service := range streamingCfg { @@ -83,7 +83,7 @@ func (app *BaseApp) RegisterStreamingServices(appOpts servertypes.AppOptions, ke // registerStreamingPlugin registers streaming plugins with the BaseApp. func (app *BaseApp) registerStreamingPlugin( - appOpts servertypes.AppOptions, + appOpts server.DynamicConfig, keys map[string]*storetypes.KVStoreKey, streamingPlugin interface{}, ) error { @@ -98,7 +98,7 @@ func (app *BaseApp) registerStreamingPlugin( // registerABCIListenerPlugin registers plugins that implement the ABCIListener interface. func (app *BaseApp) registerABCIListenerPlugin( - appOpts servertypes.AppOptions, + appOpts server.DynamicConfig, keys map[string]*storetypes.KVStoreKey, abciListener storetypes.ABCIListener, ) { diff --git a/client/flags/flags.go b/client/flags/flags.go index d44ed316792d..a001f7cda058 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -83,6 +83,7 @@ const ( FlagTip = "tip" FlagAux = "aux" FlagInitHeight = "initial-height" + FlagInvCheckPeriod = "inv-check-period" // FlagOutput is the flag to set the output format. // This differs from FlagOutputDocument that is used to set the output file. FlagOutput = "output" @@ -90,6 +91,7 @@ const ( FlagLogLevel = "log_level" FlagLogFormat = "log_format" FlagLogNoColor = "log_no_color" + FlagTrace = "trace" ) // List of supported output formats diff --git a/client/grpc/node/service.go b/client/grpc/node/service.go deleted file mode 100644 index f9fc13ea35df..000000000000 --- a/client/grpc/node/service.go +++ /dev/null @@ -1,65 +0,0 @@ -package node - -import ( - "context" - - gogogrpc "github.com/cosmos/gogoproto/grpc" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/server/config" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// RegisterNodeService registers the node gRPC service on the provided gRPC router. -func RegisterNodeService(clientCtx client.Context, server gogogrpc.Server, cfg config.Config) { - RegisterServiceServer(server, NewQueryServer(clientCtx, cfg)) -} - -// RegisterGRPCGatewayRoutes mounts the node gRPC service's GRPC-gateway routes -// on the given mux object. -func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) { - _ = RegisterServiceHandlerClient(context.Background(), mux, NewServiceClient(clientConn)) -} - -var _ ServiceServer = queryServer{} - -type queryServer struct { - clientCtx client.Context - cfg config.Config -} - -func NewQueryServer(clientCtx client.Context, cfg config.Config) ServiceServer { - return queryServer{ - clientCtx: clientCtx, - cfg: cfg, - } -} - -func (s queryServer) Config(ctx context.Context, _ *ConfigRequest) (*ConfigResponse, error) { - sdkCtx := sdk.UnwrapSDKContext(ctx) - - return &ConfigResponse{ - MinimumGasPrice: sdkCtx.MinGasPrices().String(), - PruningKeepRecent: s.cfg.PruningKeepRecent, - PruningInterval: s.cfg.PruningInterval, - HaltHeight: s.cfg.HaltHeight, - }, nil -} - -func (s queryServer) Status(ctx context.Context, _ *StatusRequest) (*StatusResponse, error) { - sdkCtx := sdk.UnwrapSDKContext(ctx) - - blockTime := sdkCtx.HeaderInfo().Time - - return &StatusResponse{ - // TODO: Get earliest version from store. - // - // Ref: ... - // EarliestStoreHeight: sdkCtx.MultiStore(), - Height: uint64(sdkCtx.BlockHeight()), - Timestamp: &blockTime, - AppHash: sdkCtx.BlockHeader().AppHash, - ValidatorHash: sdkCtx.BlockHeader().NextValidatorsHash, - }, nil -} diff --git a/client/grpc/node/service_test.go b/client/grpc/node/service_test.go deleted file mode 100644 index fc9ddbb5101e..000000000000 --- a/client/grpc/node/service_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package node - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/server/config" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func TestServiceServer_Config(t *testing.T) { - defaultCfg := config.DefaultConfig() - defaultCfg.PruningKeepRecent = "2000" - defaultCfg.PruningInterval = "10" - defaultCfg.HaltHeight = 100 - svr := NewQueryServer(client.Context{}, *defaultCfg) - ctx := sdk.Context{}.WithMinGasPrices(sdk.NewDecCoins(sdk.NewInt64DecCoin("stake", 15))) - - resp, err := svr.Config(ctx, &ConfigRequest{}) - require.NoError(t, err) - require.NotNil(t, resp) - require.Equal(t, ctx.MinGasPrices().String(), resp.MinimumGasPrice) - require.Equal(t, defaultCfg.PruningKeepRecent, resp.PruningKeepRecent) - require.Equal(t, defaultCfg.PruningInterval, resp.PruningInterval) - require.Equal(t, defaultCfg.HaltHeight, resp.HaltHeight) -} diff --git a/client/grpc/reflection/reflection.pb.go b/client/grpc/reflection/reflection.pb.go index 3fa8e97b089c..2f159025d30f 100644 --- a/client/grpc/reflection/reflection.pb.go +++ b/client/grpc/reflection/reflection.pb.go @@ -300,12 +300,12 @@ type ReflectionServiceServer interface { ListImplementations(context.Context, *ListImplementationsRequest) (*ListImplementationsResponse, error) } -// UnimplementedReflectionServiceServer can be embedded to have forward-compatible implementations. +// UnimplementedReflectionServiceServer can be embedded to have forward compatible implementations. type UnimplementedReflectionServiceServer struct { } func (*UnimplementedReflectionServiceServer) ListAllInterfaces(ctx context.Context, req *ListAllInterfacesRequest) (*ListAllInterfacesResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ListAllInterfaces is not implemented") + return nil, status.Errorf(codes.Unimplemented, "method ListAllInterfaces not implemented") } func (*UnimplementedReflectionServiceServer) ListImplementations(ctx context.Context, req *ListImplementationsRequest) (*ListImplementationsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ListImplementations not implemented") diff --git a/client/v2/internal/testpb/msg.pulsar.go b/client/v2/internal/testpb/msg.pulsar.go index c156d4131627..216a5c15bf46 100644 --- a/client/v2/internal/testpb/msg.pulsar.go +++ b/client/v2/internal/testpb/msg.pulsar.go @@ -3870,7 +3870,7 @@ type MsgRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // u32 is an uint32 + // u32 is a uint32 U32 uint32 `protobuf:"varint,1,opt,name=u32,proto3" json:"u32,omitempty"` U64 uint64 `protobuf:"varint,2,opt,name=u64,proto3" json:"u64,omitempty"` Str string `protobuf:"bytes,3,opt,name=str,proto3" json:"str,omitempty"` diff --git a/docs/architecture/adr-040-storage-and-smt-state-commitments.md b/docs/architecture/adr-040-storage-and-smt-state-commitments.md index 9fc57e8c60c6..3d5f40087229 100644 --- a/docs/architecture/adr-040-storage-and-smt-state-commitments.md +++ b/docs/architecture/adr-040-storage-and-smt-state-commitments.md @@ -258,8 +258,6 @@ We change the storage layout of the state machine, a storage hard fork and netwo ## Alternative designs -Most of the alternative designs were evaluated in [state commitments and storage report](https://paper.dropbox.com/published/State-commitments-and-storage-review--BDvA1MLwRtOx55KRihJ5xxLbBw-KeEB7eOd11pNrZvVtqUgL3h). - Ethereum research published [Verkle Trie](https://dankradfeist.de/ethereum/2021/06/18/verkle-trie-for-eth1.html) - an idea of combining polynomial commitments with merkle tree in order to reduce the tree height. This concept has a very good potential, but we think it's too early to implement it. The current, SMT based design could be easily updated to the Verkle Trie once other research implement all necessary libraries. The main advantage of the design described in this ADR is the separation of state commitments from the data storage and designing a more powerful interface. ## Further Discussions @@ -280,7 +278,6 @@ We were discussing use case where modules can use a support database, which is n * [IAVL What's Next?](https://github.com/cosmos/cosmos-sdk/issues/7100) * [IAVL overview](https://docs.google.com/document/d/16Z_hW2rSAmoyMENO-RlAhQjAG3mSNKsQueMnKpmcBv0/edit#heading=h.yd2th7x3o1iv) of its state v0.15 -* [State commitments and storage report](https://paper.dropbox.com/published/State-commitments-and-storage-review--BDvA1MLwRtOx55KRihJ5xxLbBw-KeEB7eOd11pNrZvVtqUgL3h) * [Celestia (LazyLedger) SMT](https://github.com/lazyledger/smt) * Facebook Diem (Libra) SMT [design](https://developers.diem.com/papers/jellyfish-merkle-tree/2021-01-14.pdf) * [Trillian Revocation Transparency](https://github.com/google/trillian/blob/master/docs/papers/RevocationTransparency.pdf), [Trillian Verifiable Data Structures](https://github.com/google/trillian/blob/master/docs/papers/VerifiableDataStructures.pdf). diff --git a/docs/architecture/adr-062-collections-state-layer.md b/docs/architecture/adr-062-collections-state-layer.md index 8d3a7b61cd2f..fa5df2a7a589 100644 --- a/docs/architecture/adr-062-collections-state-layer.md +++ b/docs/architecture/adr-062-collections-state-layer.md @@ -78,7 +78,7 @@ These default implementations also offer safety around proper lexicographic orde Examples of the collections API can be found here: - introduction: https://github.com/NibiruChain/collections/tree/main/examples -- usage in nibiru: [x/oracle](https://github.com/NibiruChain/nibiru/blob/master/x/oracle/keeper/keeper.go#L32), [x/epoch](https://github.com/NibiruChain/nibiru/blob/4566d9f6d22807abbd78c01454664d64f6e108e0/x/epochs/keeper/epoch.go) +- usage in nibiru: [x/oracle](https://github.com/NibiruChain/nibiru/blob/v2.0.0-rc.14/x/oracle/keeper/keeper.go#L37~L50), [x/epoch](https://github.com/NibiruChain/nibiru/blob/4566d9f6d22807abbd78c01454664d64f6e108e0/x/epochs/keeper/epoch.go) - cosmos-sdk's x/staking migrated: https://github.com/testinginprod/cosmos-sdk/pull/22 diff --git a/docs/build/build.md b/docs/build/build.md index 3ae4eea94db0..487ea5be53d0 100644 --- a/docs/build/build.md +++ b/docs/build/build.md @@ -4,7 +4,7 @@ sidebar_position: 0 # Build -* [Building Apps](./building-apps/00-app-go.md) - The documentation in this section will guide you through the process of developing your dApp using the Cosmos SDK framework. +* [Building Apps](./building-apps/00-runtime.md) - The documentation in this section will guide you through the process of developing your dApp using the Cosmos SDK framework. * [Modules](./modules/README.md) - Information about the various modules available in the Cosmos SDK: Accounts, Auth, Authz, Bank, Circuit, Consensus, Distribution, Epochs, Evidence, Feegrant, Genutil, Governance, Group, Mint, NFT, Protocolpool, Slashing, Staking, Tx, Upgrade, Validate. * [Migrations](./migrations/01-intro.md) - See what has been updated in each release the process of the transition between versions. * [Packages](./packages/README.md) - Explore a curated collection of pre-built modules and functionalities, streamlining the development process. diff --git a/docs/build/building-apps/00-runtime.md b/docs/build/building-apps/00-runtime.md index 5da91a65396e..838905750574 100644 --- a/docs/build/building-apps/00-runtime.md +++ b/docs/build/building-apps/00-runtime.md @@ -134,7 +134,7 @@ An application only needs to call `AppBuilder.Build` to create a fully configure https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.2/runtime/builder.go#L36-L80 ``` -More information on building applications can be found in the [next section](./02-app-building.md). +More information on building applications can be found in the [next section](./02-app-go-di.md). ## Best Practices diff --git a/docs/build/building-apps/upgrades/0.52.md b/docs/build/building-apps/upgrades/0.52.md new file mode 100644 index 000000000000..0b93ba8ab086 --- /dev/null +++ b/docs/build/building-apps/upgrades/0.52.md @@ -0,0 +1,554 @@ +--- +sidebar_position: 1 +--- + +# Cosmos SDK Upgrade Guide: v0.50 → v0.52 + +Below is a high-level guide on how to upgrade your chain from Cosmos SDK **v0.50** to **v0.52**. This tutorial will walk you through each major change, why it matters, and how to update your code base. Please note that every chain is different, and you may not need to apply every step below. + +Note: **v0.52** relies on [Comet v1](https://github.com/cometbft/cometbft/releases/tag/v1.0.0) + +--- + +## Table of Contents + +1. [Prerequisites](#prerequisites) +2. [Important Changes Overview](#important-changes-overview) +3. [Step-by-Step Upgrade Guide](#step-by-step-upgrade-guide) + 1. [Remove `x/params`](#remove-xparams) + 2. [Update `root.go` / Client Wiring](#update-rootgo--client-wiring) + 3. [Update `app.go` / Server Wiring](#update-appgo--server-wiring) + 1. [Module Manager](#module-manager) + 2. [gRPC-Web](#grpc-web) + 4. [Enable (or Skip) gRPC-Web Support](#enable-or-skip-grpc-web-support) + 5. [Remove `GasConsumptionDecorator` and `IncreaseSequenceDecorator`](#remove-gasconsumptiondecorator-and-increasesequencedecorator) + 6. [Unordered Transactions](#unordered-transactions) + 7. [Handle Sign Mode Textual](#handle-sign-mode-textual) + 8. [Update Depinject `app_config.go` / `app.yml` if Applicable](#update-depinject-app_configgo--appyml-if-applicable) + 9. [Protobuf Changes](#protobuf-changes) + 10. [Refactor Module Imports to `cosmossdk.io/x/...`](#refactor-module-imports-to-cosmossdkiox) + 11. [Adopt Core API Interfaces](#adopt-core-api-interfaces) + 12. [Simulation Changes](#simulation-changes) + 13. [Depinject: Update Usage of `Invoke`, `Provide`, `Register` → `appconfig`](#depinject-update-usage-of-invoke-provide-register--appconfig) + 14. [Genesis Interfaces Updated](#genesis-interfaces-updated) + 15. [Migration to Collections](#migration-to-collections) + 16. [Vesting Accounts Removal in `x/auth`](#vesting-accounts-removal-in-xauth) + 17. [Introducing `x/accounts` AccountNumber](#introducing-xaccounts-accountnumber) + 18. [TX Decoder Setup for `x/accounts`](#tx-decoder-setup-for-xaccounts) + 19. [Remove `x/crisis`](#remove-xcrisis) + 20. [Add `x/protocolpool` if Using `x/distribution`](#add-xprotocolpool-if-using-xdistribution) + 21. [Proposal Handler Changes in `x/gov`](#proposal-handler-changes-in-xgov) + 22. [Mint Function Updates in `x/mint`](#mint-function-updates-in-xmint) + 23. [Add `x/validate`](#add-xvalidate) + 24. [Remove AppmoduleBasic](#remove-appmodulebasic) +4. [Preparing the Upgrade Handler (On-Chain)](#preparing-the-upgrade-handler-on-chain) +5. [Testing & Verifying the Upgrade](#testing--verifying-the-upgrade) +6. [Conclusion](#conclusion) + +--- + +## Prerequisites + +* You have already upgraded your chain to **Cosmos SDK v0.50** (as recommended in the official docs, all migrations up to v0.50 should be complete). +* Your chain code is managed in a repository (e.g., Git) and you are comfortable creating feature branches and pushing upgrades. +* You have pinned down a plan or block height at which you want to upgrade (via `x/upgrade` or manual chain restart). +* You have adequate test coverage and a test network (testnet/local environment) to validate the upgrade before rolling out to production. + +--- + +## Important Changes Overview + +1. **`x/params` module removed** – Must migrate any usage of `x/params` to new module-managed parameters. +2. **Simplified module manager** – The “basic module manager” is removed; use `module.Manager` directly. +3. **Server refactor** – The `server/v2` updates remove embedded gRPC-Web and unify startup commands. +4. **Unordered Transactions** – New feature that allows the chain to process transactions without a strict sequence. +5. **gRPC-Web** – `grpc-web` is no longer embedded; set up a reverse proxy like Envoy if you need it. +6. **`x/crisis` removal** – The crisis module is completely removed. +7. **`x/validate`** – A new module for default ante/post handlers if you want to rely on runtime. +8. **`x/accounts`** – Replaces vesting accounts and handles account numbering. +9. **Protobuf changes** – Updated location for `Any`, removal of `cosmossdk.io/api/tendermint`. +10. **All modules except `auth` split off** – Modules now import from `cosmossdk.io/x/...`. +11. **Genesis & ADR-070** – Constructors now take `context.Context` and do not pass around a codec. +12. **Migration to Collections** – Some modules adopt `collections.ErrNotFound`; check for usage changes. +13. **Other refactors** – AnteHandlers, textual sign modes, plus smaller naming changes in the simulation framework. + +--- + +## Step-by-Step Upgrade Guide + +Below, you can follow along as though you maintain an application called `MyApp`. Adapt these steps for your own chain. + +### Remove `x/params` + +The Cosmos SDK removed `x/params`. In 0.52, parameters must live in their respective modules (module-managed params). + + + +* Remove all references to `x/params` from your code: +* Delete any keepers, references, or param-store usage referencing `paramsKeeper`. +* For each module using `x/params`, replace it with the new approach of storing parameters via that module’s param structure or via `cosmossdk.io/core/appmodule`. +* If you have custom modules using `params`, see the [migration reference](https://github.com/cosmos/cosmos-sdk/blob/828fcf2f05db0c4759ed370852b6dacc589ea472/x/mint/migrations/v2/migrate.go) for how to adapt to module-managed parameters. + +### Update `root.go` / Client Wiring + +The `client` package no longer relies on a global bech32 config and uses address codecs and address prefixes via `client.Context`. This is inline with moving away from the concept of globals in the software. + +In `cmd/myappd/root.go` (or `root_di.go` if using depinject), ensure you set the address and validator prefixes: + +```diff +clientCtx = clientCtx. ++ WithAddressCodec(addressCodec). ++ WithValidatorAddressCodec(validatorAddressCodec). ++ WithConsensusAddressCodec(consensusAddressCodec). ++ WithAddressPrefix("cosmos"). ++ WithValidatorPrefix("cosmosvaloper") +``` + +Additionally, the start command changed slightly: + +```diff +- server.AddCommands(rootCmd, newApp, func(startCmd *cobra.Command) {}) ++ server.AddCommands(rootCmd, newApp, server.StartCmdOptions[servertypes.Application]{}) +``` + +### Update app.go / Server Wiring + +#### Module Manager + +**What changed** + • The “basic module manager” is removed. You should directly use module.Manager. + +**Action** + • Remove references to the BasicModuleManager or “basic module manager” in your app.go. + • Instead, invoke RegisterLegacyAminoCodec and RegisterInterfaces on app.ModuleManager. + +```diff +-app.BasicModuleManager = module.NewBasicManagerFromManager(...) +-app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino) +-app.BasicModuleManager.RegisterInterfaces(interfaceRegistry) ++app.ModuleManager.RegisterLegacyAminoCodec(legacyAmino) ++app.ModuleManager.RegisterInterfaces(interfaceRegistry) +``` + +#### gRPC-Web + +The embedding of gRPC-Web was removed. if you would like to continue using gRPC-Web you will need to use [Envoy](https://www.envoyproxy.io/) + + +### Enable (or Skip) gRPC-Web Support + +If you need gRPC-Web, follow the sample envoy.yaml config in the changelog snippet. Otherwise, you can skip this step. + +### Remove GasConsumptionDecorator and IncreaseSequenceDecorator + +The GasDecorator and Sequence decorator were merged into the SigVerificationDecorator. This change reduces the gas consumed by transactions. + +### Unordered Transactions + +v0.52 introduces unordered transactions, this feature allows transcations to not need sequence numbers and has its own replay protection system. + +* Important: This is optional. + +Depinject / servertypes.AppOptions: Supply the appOpts to enable it automatically: + +```go +depinject.Supply( + appOpts, + logger, +) +``` + + +Legacy wiring: If you do want unordered transactions but are not using depinject, see the “Step-by-step wiring” block from the changelog: + 1. Create and start unorderedtx.NewManager in your App constructor. + 2. Add ante.NewUnorderedTxDecorator(...) near the start of your AnteHandler chain. + 3. Register a Snapshotter if using snapshots. + 4. Call app.UnorderedTxManager.OnNewBlock() in your PreBlocker(). + 5. Close the manager in app.Close(). + +### Handle Sign Mode Textual + +With the split of x/auth/tx/config in two (`x/auth/tx/config` as depinject module for txconfig and tx options) and `x/validate`, sign mode textual is no more automatically configured when using runtime (it was previously the case). For the same instructions than for legacy app wiring to enable sign mode textual (see in v0.50 UPGRADING documentation). + +### Update Depinject app_config.go / app.yml if Applicable + +With the introduction of environment in modules, depinject automatically creates the environment for all modules. Learn more about environment here . Given the fields of environment, this means runtime creates a kv store service for all modules by default. It can happen that some modules do not have a store necessary (such as x/auth/tx for instance). In this case, the store creation should be skipped in app_config.go: + +* In your app_config.go (or app.yml), if you have modules like x/auth/tx that do not need a KV store, skip them: + +```diff +InitGenesis: []string{ + "..." +}, ++ // SkipStoreKeys is an optional list of store keys to skip when constructing the ++ // module's keeper. This is useful when a module does not have a store key. ++ SkipStoreKeys: []string{ ++ "tx", ++ }, +``` + + + +### Protobuf Changes + +The cosmossdk.io/api/tendermint package has been removed as CometBFT now publishes its protos to buf.build/tendermint and buf.build/cometbft + + +The codectypes.Any has moved to github.com/cosmos/gogoproto/types/any. Module developers need to update the buf.gen.gogo.yaml configuration files by adjusting the corresponding opt option to Mgoogle/protobuf/any.proto=github.com/cosmos/gogoproto/types/any for directly mapping theAny type to its new location: + +```diff +version: v1 +plugins: + - name: gocosmos + out: .. +- opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,Mcosmos/orm/v1/orm.proto=cosmossdk.io/orm ++ opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/gogoproto/types/any,Mcosmos/orm/v1/orm.proto=cosmossdk.io/orm + - name: grpc-gateway + out: .. + opt: logtostderr=true,allow_colon_final_segments=true + +``` + +* Replace any usage of AnyUnpacker and UnpackInterfacesMessage from cosmos/cosmos-sdk/codec/types with the equivalents in github.com/cosmos/gogoproto/types/any. + +### Refactor Module Imports to cosmossdk.io/x/ + +All modules except auth have been split into their own go.mod and are imported via cosmossdk.io/x/. + + +* Replace import paths from github.com/cosmos/cosmos-sdk/x/{moduleName} to cosmossdk.io/x/{moduleName}. +* Example: + +```diff +- import govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ++ import govtypes "cosmossdk.io/x/gov/types" +``` + +### Adopt Core API Interfaces + +Core API has been introduced for modules since v0.47. With the deprecation of `sdk.Context`, we strongly recommend to use the cosmossdk.io/core/appmodule interfaces for the modules. This will allow the modules to work out of the box with server/v2 and baseapp, as well as limit their dependencies on the SDK. + +Additionally, the `appmodule.Environment` struct is introduced to fetch different services from the application. This should be used as an alternative to using `sdk.UnwrapContext(ctx)` to fetch the services. It needs to be passed into a module at instantiation (or depinject will inject the correct environment). + +Example: + +```go +app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[circuittypes.StoreKey]), logger.With(log.ModuleKey, "x/circuit")), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) +``` + + +#### Interface Registry + +* Replace codec.InterfaceRegistry usage in the HasRegisterInterfaces function with cosmossdk.io/core/registry.InterfaceRegistrar. Same for Amino with cosmossdk.io/core/registry.AminoRegistrar. +* Example: + +```diff +-func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { ++func (AppModule) RegisterInterfaces(registry registry.InterfaceRegistrar) { +``` + +#### Amino Codec Registry + +* Replace codec.LegacyAmino usage in the HasAminoCodec function with cosmossdk.io/core/registry.AminoRegistrar. +* Example: + +```diff +-func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { ++func (AppModule) RegisterLegacyAminoCodec(registrar registry.AminoRegistrar) { +``` + +### Simulation Changes + +* MsgSimulatorFn now returns an error and no longer has sdk.Context; it instead passes in an address.Codec. + * Example: + +```diff +-type MsgSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account) sdk.Msg ++type MsgSimulatorFn func(r *rand.Rand, accs []Account, cdc address.Codec) (sdk.Msg, error) +``` + +The interface HasProposalMsgs has been renamed to HasLegacyProposalMsgs, as we've introduced a new simulation framework, simpler and easier to use, named [simsx](https://github.com/cosmos/cosmos-sdk/tree/main/simsx). + +### Depinject: Update Usage of Invoke, Provide, Register → appconfig + +Previously cosmossdk.io/core/appconfig held functions Invoke, Provide and Register were moved to cosmossdk.io/depinject/appconfig. All modules using dependency injection must update their imports. + +```diff +import { +- "cosmossdk.io/core/appconfig" ++ "cosmossdk.io/depinject/appconfig" +} +``` + +### Genesis Interfaces Updated + +The genesis interfaces in `x/{module_name}/module.go` were modified to avoid Cosmos SDK dependencies. + + +Update your modules’ InitGenesis / ExportGenesis to: + +```diff +- func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { ++ func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error { + // ... +} +- func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { ++ func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) { + // ... +} +``` + +### Migration to Collections + +Modules within the Cosmos SDK were migrated to use [collections](https://github.com/cosmos/cosmos-sdk/tree/main/collections). It is not required to migrate your own modules, but it is recommended to use collections for future modules. + +Note: When migrating to collections, the previous logic for not found was returning nil with no error. When migrating collections will return `collections.ErrNotFound`. + +Checking for the errors should follow: + +```go +if err != nil { + if err == collections.ErrNotFound { + // handle not found + } + // handle other errors +} +``` + + +* If your module or code interacts with updated modules, watch for errors like `collections.ErrNotFound`. + +### Vesting Accounts Removal in x/auth + +The vesting account message and CLI are removed. Existing vesting accounts remain, but you cannot create new ones. + +In order to create new vesting accounts you need to add the accounts module to your chain. We provide vesting acccounts by default which have simlar logic to the previous vesting accounts. If you would like custom vesting accounts, they can be implemented in `x/accounts`. + +### Introducing x/accounts AccountNumber + +`x/accounts` uses its own account numbering (global) instead of `x/auth`. The auth module will now use the `x/accounts` account numbering. + +* In your upgrade handler, if you have existing accounts, you must migrate them: + +```go +import authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + +func MyUpgradeLogic(ctx sdk.Context) error { + err := authkeeper.MigrateAccountNumberUnsafe(ctx, &app.AuthKeeper) + if err != nil { + return err + } + return nil +} +``` + +### TX Decoder Setup for x/accounts + +In order to support x/accounts, you need to initialize a TxDecoder. + +In app.go: + +```go +import ( + txdecode "cosmossdk.io/x/tx/decode" +) + +func NewApp(...) *App { + // ... + txDecoder, err := txdecode.NewDecoder(txdecode.Options{ + SigningContext: signingCtx, + ProtoCodec: appCodec, + }) + if err != nil { + panic(err) + } + // ... +} +``` + +### Remove x/crisis + +The x/crisis module was removed entirely and should removed from your application. + +* Remove code references to x/crisis from your application. + +```go + storeUpgrades := store.StoreUpgrades{ + Deleted: []string{"crisis"}, // The SDK discontinued the crisis module in v0.52.0 + } +``` + +### Add x/protocolpool if Using x/distribution + +The community pool was moved from distribution to a new module called protocolpool. This new module allows teams and the community to create funding opportunities fot the development team and the community. + +* Add protocolpool keeper + store key in your app.go. +* In your upgrade handler, ensure you add a store for protocolpooltypes.ModuleName. For example: + +```go +storeUpgrades := storetypes.StoreUpgrades{ + Added: []string{ + protocolpooltypes.ModuleName, + }, +} +``` + +### Proposal Handler Changes in x/gov + +The proposal handler was updated away from `sdk.Context` to `context.Context`. This change is a prerequisite for upgrading to v2. Stay tuned for a separate document explaining how to migrate to v2. + +```diff +- func ProposalHandler(_ sdk.Context, c Content) error { ++ func ProposalHandler(_ context.Context, c Content) error { +``` + + +### Mint Function Updates in x/mint + +The custom mint function allows teams to customize the minting logic for their chain. + +* If you want a custom inflation function or rely on `x/mint`, set the keeper’s mint function explicitly if you do not use the default: + +```go +mintKeeper.SetMintFn(keeper.DefaultMintFn( + types.DefaultInflationCalculationFn, + stakingKeeper, + mintKeeper, +)) +``` + +### Add x/validate + +`x/validate` is a module for antehandlers. If you are using runtime/depinject or v2 this module is required. Skip this step or define your own custom ante/post handlers, see `x/validate` documentation for more details. + +### Remove AppmoduleBasic + +In 0.52, there is a single entry point for a module. The `appmodule` is the single entry point. In order to make the necessary changes the appmodulebasic struct in the module.go should be merged with appmodule. + +```diff +// AppModuleBasic defines the basic application module used by the bank module. +- type AppModuleBasic struct { +- cdc codec.Codec +- ac address.Codec +- } + +// AppModule implements an application module for the bank module. +type AppModule struct { +- AppModuleBasic ++ cdc codec.Codec + + keeper keeper.Keeper + accountKeeper types.AccountKeeper + + // legacySubspace is used solely for migration of x/params managed parameters + legacySubspace exported.Subspace +} + +// Name returns the bank module's name. +- func (AppModuleBasic) Name() string { return types.ModuleName } ++ func (AppModule) Name() string { return types.ModuleName } + +// RegisterLegacyAminoCodec registers the bank module's types on the LegacyAmino codec. +- func (AppModuleBasic) RegisterLegacyAminoCodec(registrar registry.AminoRegistrar) { ++ func (AppModule) RegisterLegacyAminoCodec(registrar registry.AminoRegistrar) { + types.RegisterLegacyAminoCodec(cdc) +} + +// DefaultGenesis returns default genesis state as raw bytes for the bank +// module. +- func (AppModuleBasic) DefaultGenesis() json.RawMessage { ++ func (am AppModule) DefaultGenesis() json.RawMessage { + return am.cdc.MustMarshalJSON(types.DefaultGenesisState()) +} + +// ValidateGenesis performs genesis state validation for the bank module. +- func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { ++ func (am AppModule) ValidateGenesis(bz json.RawMessage) error { + var data types.GenesisState +- if err := cdc.UnmarshalJSON(bz, &data); err != nil { ++ if err := am.cdc.UnmarshalJSON(bz, &data); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return data.Validate() +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the bank module. +- func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { ++ func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// GetTxCmd returns the root tx command for the bank module. +- func (ab AppModuleBasic) GetTxCmd() *cobra.Command { ++ func (ab AppModule) GetTxCmd() *cobra.Command { + return cli.NewTxCmd(ab.ac) +} + +// RegisterInterfaces registers interfaces and implementations of the bank module. +- func (AppModuleBasic) RegisterInterfaces(registry.InterfaceRegistrar) { ++ func (AppModule) RegisterInterfaces(registry.InterfaceRegistrar) { + types.RegisterInterfaces(registry) + + // Register legacy interfaces for migration scripts. + v1bank.RegisterInterfaces(registry) +} +``` + +## Preparing the Upgrade Handler (On-Chain) + +If your chain uses `x/upgrade` to do in-place upgrades: + 1. Create a new upgrade name (e.g. v0.52). + 2. Register the upgrade handler in app.go: + ```go + func (app *MyApp) RegisterUpgradeHandlers() { + app.UpgradeKeeper.SetUpgradeHandler( + "v0.52", + func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + // Run any store migrations needed (e.g. add "protocolpool" store) + storeUpgrades := storetypes.StoreUpgrades{ + Added: []string{protocolpooltypes.ModuleName}, + } + // ... + // Then run the module migrations + return app.ModuleManager.RunMigrations(ctx, app.Configurator(), vm) + }, + ) + } + ``` + 3. Set the upgrade in your governance proposal or simply do a manual upgrade (depending on your chain’s process). + 4. On reaching the plan’s height, your node will run the above logic, adding store keys, migrating accounts, etc. + +If your chain is small or you do not rely on x/upgrade, you can do a chain halt and manual restart with the new binary after updating your genesis (if needed). + +## Testing & Verifying the Upgrade + +1. Local test + + * Spin up a local one-node testnet. + * Import or create some sample data. + * Execute the upgrade at a known block height. + * Validate that the chain restarts and that the new features (like x/accounts or x/protocolpool) function correctly. + +2. Integration test + + * If you have a continuous integration (CI) environment, update your go.mod and run all tests. + +3. Public testnet + + * Run a short-lived testnet with the new binary, replicate production environment if possible. + +## Conclusion + +Upgrading from Cosmos SDK v0.50 to v0.52 involves a number of structural and conceptual changes. The major points are: + • Removing x/params for new parameter management, + • Refactoring module imports to cosmossdk.io/x/..., + • Adopting the new environment approach in modules and code, + • Handling new or removed modules like x/crisis (removed), x/protocolpool (added), and x/accounts, + • Adjusting any custom logic around vesting, ante handlers, simulation, and Protobuf interfaces. + +Once completed, your chain will align with the latest design of the Cosmos SDK and be ready to take advantage of new features like unordered transactions, improved parameter management, and a more flexible environment-based architecture. + +Good luck with your upgrade! If you run into any issues, check the official Cosmos SDK release notes or ask for help in the Cosmos SDK community channels. diff --git a/docs/build/building-apps/upgrades/_category_.json b/docs/build/building-apps/upgrades/_category_.json new file mode 100644 index 000000000000..949dd3319af9 --- /dev/null +++ b/docs/build/building-apps/upgrades/_category_.json @@ -0,0 +1,5 @@ +{ + "label": "Upgrade Tutorials", + "position": 0, + "link": null +} diff --git a/docs/build/building-modules/06-keeper.md b/docs/build/building-modules/06-keeper.md index 23a221fb19c0..7ab845f97055 100644 --- a/docs/build/building-modules/06-keeper.md +++ b/docs/build/building-modules/06-keeper.md @@ -46,7 +46,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/staking/keeper/keeper Let us go through the different parameters: -* Environment is a struct that holds the necessary references to services available to the modules. This includes the [store services](../../advanced/04-store.md#store-services), the [event manager](../../learn/advanced/06-events.md) and more. +* Environment is a struct that holds the necessary references to services available to the modules. This includes the [kvstore services](../../learn/advanced/02-core.md#kvstore-service), the [event manager](../../learn/advanced/02-core.md#event-service) and more. * An expected `keeper` is a `keeper` external to a module that is required by the internal `keeper` of said module. External `keeper`s are listed in the internal `keeper`'s type definition as interfaces. These interfaces are themselves defined in an `expected_keepers.go` file in the root of the module's folder. In this context, interfaces are used to reduce the number of dependencies, as well as to facilitate the maintenance of the module itself. * `cdc` is the [codec](../../learn/advanced/05-encoding.md) used to marshal and unmarshal structs to/from `[]byte`. The `cdc` can be any of `codec.BinaryCodec`, `codec.JSONCodec` or `codec.Codec` based on your requirements. It can be either a proto or amino codec as long as they implement these interfaces. * The authority listed is a module account or user account that has the right to change module level parameters. Previously this was handled by the param module, which has been deprecated. diff --git a/docs/build/building-modules/16-testing.md b/docs/build/building-modules/16-testing.md index 6b9441bbee06..828a1f72b23f 100644 --- a/docs/build/building-modules/16-testing.md +++ b/docs/build/building-modules/16-testing.md @@ -61,7 +61,7 @@ The goal of these integration tests is to test how a component interacts with ot Integration tests interact with the tested module via the defined `Msg` and `Query` services. The result of the test can be verified by checking the state of the application, by checking the emitted events or the response. It is advised to combine two of these methods to verify the result of the test. -The SDK provides small helpers for quickly setting up an integration tests. These helpers can be found at . +The SDK provides small helpers for quickly setting up an integration tests. These helpers can be found at . ### Example diff --git a/docs/learn/advanced/00-baseapp.md b/docs/learn/advanced/00-baseapp.md index 8fea13d4fd39..0017d3accd1f 100644 --- a/docs/learn/advanced/00-baseapp.md +++ b/docs/learn/advanced/00-baseapp.md @@ -309,7 +309,7 @@ Unconfirmed transactions are relayed to peers only if they pass `CheckTx`. `CheckTx()` can perform both _stateful_ and _stateless_ checks, but developers should strive to make the checks **lightweight** because gas fees are not charged for the resources (CPU, data load...) used during the `CheckTx`. -The [`Context`](../advanced/02-context.md), which includes a `GasMeter` that tracks how much gas is used during the execution of `Tx`, is initialized at the beginning of `CheckTx`. The user-provided amount of gas for `Tx` is referred to as `GasWanted`. If `GasConsumed`, the amount of gas used during execution, exceeds `GasWanted`, the execution is halted and the changes made to the cached copy of the state are not committed. Otherwise, `CheckTx` sets `GasUsed` equal to `GasConsumed` and returns it in the result. After calculating the gas and fee values, validator-nodes ensure that the user-specified `gas-prices` exceed their locally defined `min-gas-prices`. +The [`Core pkg`](../advanced/02-core.md), which includes a `GasService` that tracks how much gas is used during the execution of `Tx`, is initialized at the beginning of `CheckTx`. The user-provided amount of gas for `Tx` is referred to as `GasWanted`. If `GasConsumed`, the amount of gas used during execution, exceeds `GasWanted`, the execution is halted and the changes made to the cached copy of the state are not committed. Otherwise, `CheckTx` sets `GasUsed` equal to `GasConsumed` and returns it in the result. After calculating the gas and fee values, validator-nodes ensure that the user-specified `gas-prices` exceed their locally defined `min-gas-prices`. In the Cosmos SDK, after [decoding transactions](./05-encoding.md), `CheckTx()` is implemented to do the following checks: diff --git a/docs/learn/advanced/04-store.md b/docs/learn/advanced/04-store.md index d1b20d20ef66..40a2eaada985 100644 --- a/docs/learn/advanced/04-store.md +++ b/docs/learn/advanced/04-store.md @@ -189,12 +189,6 @@ When methods of the parent `KVStore` are called, `GasKv.Store` automatically con https://github.com/cosmos/cosmos-sdk/blob/store/v1.1.1/store/types/gas.go#L220-L229 ``` -By default, all `KVStores` are wrapped in `GasKv.Stores` when retrieved. This is done in the `KVStore()` method of the [`context`](./02-context.md): - -```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.2/types/context.go#L339-L342 -``` - `KVStores` can be accessed in their corresponding modules by using the [`kvStoreService` and `memStoreService`](./02-core.md#kvstore-service). ### `TraceKv` Store diff --git a/docs/user/run-node/06-run-production.md b/docs/user/run-node/06-run-production.md index 9f3f31677bf2..e650f7103c5e 100644 --- a/docs/user/run-node/06-run-production.md +++ b/docs/user/run-node/06-run-production.md @@ -48,7 +48,7 @@ In the past, validators [have had issues](https://github.com/cosmos/cosmos-sdk/i ### Firewall -Nodes should not have all ports open to the public, this is a simple way to get DDOS'd. Secondly it is recommended by [CometBFT](github.com/cometbft/cometbft) to never expose ports that are not required to operate a node. +Nodes should not have all ports open to the public, this is a simple way to get DDOS'd. Secondly it is recommended by [CometBFT](https://github.com/cometbft/cometbft) to never expose ports that are not required to operate a node. When setting up a firewall there are a few ports that can be open when operating a Cosmos SDK node. There is the CometBFT json-RPC, prometheus, p2p, remote signer and Cosmos SDK GRPC and REST. If the node is being operated as a node that does not offer endpoints to be used for submission or querying then a max of three endpoints are needed. diff --git a/go.mod b/go.mod index 4f1b9026fd7a..fe3fcdb62703 100644 --- a/go.mod +++ b/go.mod @@ -41,7 +41,6 @@ require ( github.com/muesli/termenv v0.15.2 github.com/prometheus/client_golang v1.20.5 github.com/prometheus/common v0.61.0 - github.com/rs/zerolog v1.33.0 github.com/spf13/cast v1.7.1 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 @@ -136,6 +135,7 @@ require ( github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/rogpeppe/go-internal v1.13.1 // indirect + github.com/rs/zerolog v1.33.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sasha-s/go-deadlock v0.3.5 // indirect diff --git a/proto/cosmos/base/reflection/v1beta1/reflection.proto b/proto/cosmos/base/reflection/v1beta1/reflection.proto index 22670e72b883..2a79c438e433 100644 --- a/proto/cosmos/base/reflection/v1beta1/reflection.proto +++ b/proto/cosmos/base/reflection/v1beta1/reflection.proto @@ -33,7 +33,7 @@ message ListAllInterfacesResponse { // ListImplementationsRequest is the request type of the ListImplementations // RPC. message ListImplementationsRequest { - // interface_name defines the interface to query the implementations for. + // interface_name defines the interface to query the implementations. string interface_name = 1; } diff --git a/runtime/app.go b/runtime/app.go index 055b8ff3ea2f..b3952c2db139 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -18,13 +18,8 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" - nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/server/config" - servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth/ante/unorderedtx" @@ -221,22 +216,6 @@ func (a *App) RegisterTxService(clientCtx client.Context) { authtx.RegisterTxService(a.GRPCQueryRouter(), clientCtx, a.Simulate, a.interfaceRegistry) } -// RegisterTendermintService implements the Application.RegisterTendermintService method. -func (a *App) RegisterTendermintService(clientCtx client.Context) { - cmtApp := server.NewCometABCIWrapper(a) - cmtservice.RegisterTendermintService( - clientCtx, - a.GRPCQueryRouter(), - a.interfaceRegistry, - cmtApp.Query, - ) -} - -// RegisterNodeService registers the node gRPC service on the app gRPC router. -func (a *App) RegisterNodeService(clientCtx client.Context, cfg config.Config) { - nodeservice.RegisterNodeService(clientCtx, a.GRPCQueryRouter(), cfg) -} - // Configurator returns the app's configurator. func (a *App) Configurator() module.Configurator { //nolint:staticcheck // SA1019: Configurator is deprecated but still used in runtime v1. return a.configurator @@ -288,8 +267,6 @@ func (a *App) UnsafeFindStoreKey(storeKey string) storetypes.StoreKey { return a.storeKeys[i] } -var _ servertypes.Application = &App{} - // hasServicesV1 is the interface for registering service in baseapp Cosmos SDK. // This API is part of core/appmodule but commented out for dependencies. type hasServicesV1 interface { diff --git a/runtime/builder.go b/runtime/builder.go index f3de4da2dcbf..c0f76b346b32 100644 --- a/runtime/builder.go +++ b/runtime/builder.go @@ -8,12 +8,12 @@ import ( "github.com/spf13/cast" + "cosmossdk.io/core/server" corestore "cosmossdk.io/core/store" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" - servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth/ante/unorderedtx" @@ -25,7 +25,7 @@ import ( type AppBuilder struct { app *App - appOptions servertypes.AppOptions + appOptions server.DynamicConfig } // DefaultGenesis returns a default genesis from the registered modules. diff --git a/runtime/module.go b/runtime/module.go index 488bc6c93b8e..69b256533a9d 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/core/comet" "cosmossdk.io/core/registry" + "cosmossdk.io/core/server" "cosmossdk.io/core/store" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" @@ -24,7 +25,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/msgservice" @@ -161,7 +161,7 @@ type AppInputs struct { BaseAppOptions []BaseAppOption InterfaceRegistry codectypes.InterfaceRegistry LegacyAmino registry.AminoRegistrar - AppOptions servertypes.AppOptions `optional:"true"` // can be nil in client wiring + AppOptions server.DynamicConfig `optional:"true"` // can be nil in client wiring } func SetupAppBuilder(inputs AppInputs) { diff --git a/runtime/types.go b/runtime/types.go index 50c8884716a7..978dff99ec89 100644 --- a/runtime/types.go +++ b/runtime/types.go @@ -1,9 +1,11 @@ package runtime import ( + "encoding/json" + abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" + cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1" - "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" ) @@ -29,7 +31,20 @@ type AppI interface { LoadHeight(height int64) error // ExportAppStateAndValidators exports the state of the application for a genesis file. - ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs, modulesToExport []string) (types.ExportedApp, error) + ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs, modulesToExport []string) (ExportedApp, error) +} + +// ExportedApp represents an exported app state, along with +// validators, consensus params and latest app height. +type ExportedApp struct { + // AppState is the application state as JSON. + AppState json.RawMessage + // Validators is the exported validator set. + Validators []sdk.GenesisValidator + // Height is the app's latest block height. + Height int64 + // ConsensusParams are the exported consensus params for ABCI. + ConsensusParams cmtproto.ConsensusParams } // AppSimI implements the common methods for a Cosmos SDK-based application diff --git a/scripts/build/build.mk b/scripts/build/build.mk index 5bf479d98933..72683022f398 100644 --- a/scripts/build/build.mk +++ b/scripts/build/build.mk @@ -14,8 +14,6 @@ DOCKER := $(shell which docker) PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git) COSMOS_BUILD_OPTIONS += ' v2' -rocksdb_version=v9.7.3 - ifeq ($(findstring .,$(VERSION)),) VERSION := 0.0.0 endif diff --git a/scripts/go-lint-all.bash b/scripts/go-lint-all.bash index f643cc56aa46..2aea59dcd1a8 100755 --- a/scripts/go-lint-all.bash +++ b/scripts/go-lint-all.bash @@ -2,13 +2,10 @@ set -e -REPO_ROOT="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )" +REPO_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)" export REPO_ROOT LINT_TAGS="e2e,ledger,test_ledger_mock" -if [[ ! -z "${ROCKSDB:-}" ]]; then - LINT_TAGS+=",rocksdb" -fi export LINT_TAGS lint_module() { @@ -53,4 +50,4 @@ else echo "linting github.com/cosmos/cosmos-sdk [$(date -Iseconds -u)]" golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=${LINT_TAGS} fi -fi \ No newline at end of file +fi diff --git a/server/cmd/execute.go b/server/cmd/execute.go deleted file mode 100644 index 87a0161cc72d..000000000000 --- a/server/cmd/execute.go +++ /dev/null @@ -1,48 +0,0 @@ -package cmd - -import ( - "context" - "strings" - - "github.com/rs/zerolog" - "github.com/spf13/cobra" - "github.com/spf13/viper" - - "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 -// server context object with the appropriate server and client objects injected -// into the underlying stdlib Context. It also handles adding core CLI flags, -// specifically the logging flags. It returns an error upon execution failure. -func Execute(rootCmd *cobra.Command, envPrefix, defaultHome string) error { - // Create and set a client.Context on the command's Context. During the pre-run - // of the root command, a default initialized client.Context is provided to - // seed child command execution with values such as AccountRetriever, Keyring, - // and a CometBFT RPC. This requires the use of a pointer reference when - // getting and setting the client.Context. Ideally, we utilize - // https://github.com/spf13/cobra/pull/1118. - ctx := CreateExecuteContext(context.Background()) - - rootCmd.PersistentFlags().String(flags.FlagLogLevel, zerolog.InfoLevel.String(), "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:')") - rootCmd.PersistentFlags().String(flags.FlagLogFormat, "plain", "The logging format (json|plain)") - rootCmd.PersistentFlags().Bool(flags.FlagLogNoColor, false, "Disable colored logs") - rootCmd.PersistentFlags().StringP(flags.FlagHome, "", defaultHome, "directory for config and data") - rootCmd.PersistentFlags().Bool(server.FlagTrace, false, "print out full stack trace on errors") - - // update the global viper with the root command's configuration - viper.SetEnvPrefix(envPrefix) - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) - viper.AutomaticEnv() - - return rootCmd.ExecuteContext(ctx) -} - -// CreateExecuteContext returns a base Context with server and client context -// values initialized. -func CreateExecuteContext(ctx context.Context) context.Context { - ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{}) - return ctx -} diff --git a/server/config/config.go b/server/config/config.go deleted file mode 100644 index b75b5bd87f8c..000000000000 --- a/server/config/config.go +++ /dev/null @@ -1,282 +0,0 @@ -package config - -import ( - "fmt" - "math" - - "github.com/spf13/viper" - - pruningtypes "cosmossdk.io/store/pruning/types" - - "github.com/cosmos/cosmos-sdk/telemetry" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -const ( - defaultMinGasPrices = "" - - // DefaultAPIAddress defines the default address to bind the API server to. - DefaultAPIAddress = "tcp://localhost:1317" - - // DefaultGRPCAddress defines the default address to bind the gRPC server to. - DefaultGRPCAddress = "localhost:9090" - - // DefaultGRPCMaxRecvMsgSize defines the default gRPC max message size in - // bytes the server can receive. - DefaultGRPCMaxRecvMsgSize = 1024 * 1024 * 10 - - // DefaultGRPCMaxSendMsgSize defines the default gRPC max message size in - // bytes the server can send. - DefaultGRPCMaxSendMsgSize = math.MaxInt32 -) - -// BaseConfig defines the server's basic configuration -type BaseConfig struct { - // The minimum gas prices a validator is willing to accept for processing a - // transaction. A transaction's fees must meet the minimum of any denomination - // specified in this config (e.g. 0.25token1;0.0001token2). - MinGasPrices string `mapstructure:"minimum-gas-prices"` - - // The maximum amount of gas a grpc/Rest query may consume. - // If set to 0, it is unbounded. - QueryGasLimit uint64 `mapstructure:"query-gas-limit"` - - Pruning string `mapstructure:"pruning"` - PruningKeepRecent string `mapstructure:"pruning-keep-recent"` - PruningInterval string `mapstructure:"pruning-interval"` - - // HaltHeight contains a non-zero block height at which a node will gracefully - // halt and shutdown that can be used to assist upgrades and testing. - // - // Note: Commitment of state will be attempted on the corresponding block. - HaltHeight uint64 `mapstructure:"halt-height"` - - // HaltTime contains a non-zero minimum block time (in Unix seconds) at which - // a node will gracefully halt and shutdown that can be used to assist - // upgrades and testing. - // - // Note: Commitment of state will be attempted on the corresponding block. - HaltTime uint64 `mapstructure:"halt-time"` - - // MinRetainBlocks defines the minimum block height offset from the current - // block being committed, such that blocks past this offset may be pruned - // from CometBFT. It is used as part of the process of determining the - // ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates - // that no blocks should be pruned. - // - // This configuration value is only responsible for pruning CometBFT blocks. - // It has no bearing on application state pruning which is determined by the - // "pruning-*" configurations. - // - // Note: CometBFT block pruning is dependent on this parameter in conjunction - // with the unbonding (safety threshold) period, state pruning and state sync - // snapshot parameters to determine the correct minimum value of - // ResponseCommit.RetainHeight. - MinRetainBlocks uint64 `mapstructure:"min-retain-blocks"` - - // InterBlockCache enables inter-block caching. - InterBlockCache bool `mapstructure:"inter-block-cache"` - - // IndexEvents defines the set of events in the form {eventType}.{attributeKey}, - // which informs CometBFT what to index. If empty, all events will be indexed. - IndexEvents []string `mapstructure:"index-events"` - - // IavlCacheSize set the size of the iavl tree cache. - IAVLCacheSize uint64 `mapstructure:"iavl-cache-size"` - - // IAVLDisableFastNode enables or disables the fast sync node. - IAVLDisableFastNode bool `mapstructure:"iavl-disable-fastnode"` - - // AppDBBackend defines the type of Database to use for the application and snapshots databases. - // An empty string indicates that the CometBFT config's DBBackend value should be used. - AppDBBackend string `mapstructure:"app-db-backend"` -} - -// APIConfig defines the API listener configuration. -type APIConfig struct { - // Enable defines if the API server should be enabled. - Enable bool `mapstructure:"enable"` - - // Swagger defines if swagger documentation should automatically be registered. - Swagger bool `mapstructure:"swagger"` - - // EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk) - EnableUnsafeCORS bool `mapstructure:"enabled-unsafe-cors"` - - // Address defines the API server to listen on - Address string `mapstructure:"address"` - - // MaxOpenConnections defines the number of maximum open connections - MaxOpenConnections uint `mapstructure:"max-open-connections"` - - // RPCReadTimeout defines the CometBFT RPC read timeout (in seconds) - RPCReadTimeout uint `mapstructure:"rpc-read-timeout"` - - // RPCWriteTimeout defines the CometBFT RPC write timeout (in seconds) - RPCWriteTimeout uint `mapstructure:"rpc-write-timeout"` - - // RPCMaxBodyBytes defines the CometBFT maximum request body (in bytes) - RPCMaxBodyBytes uint `mapstructure:"rpc-max-body-bytes"` - - // TODO: TLS/Proxy configuration. - // - // Ref: https://github.com/cosmos/cosmos-sdk/issues/6420 -} - -// GRPCConfig defines configuration for the gRPC server. -type GRPCConfig struct { - // Enable defines if the gRPC server should be enabled. - Enable bool `mapstructure:"enable"` - - // Address defines the API server to listen on - Address string `mapstructure:"address"` - - // MaxRecvMsgSize defines the max message size in bytes the server can receive. - // The default value is 10MB. - MaxRecvMsgSize int `mapstructure:"max-recv-msg-size"` - - // MaxSendMsgSize defines the max message size in bytes the server can send. - // The default value is math.MaxInt32. - MaxSendMsgSize int `mapstructure:"max-send-msg-size"` -} - -// StateSyncConfig defines the state sync snapshot configuration. -type StateSyncConfig struct { - // SnapshotInterval sets the interval at which state sync snapshots are taken. - // 0 disables snapshots. - SnapshotInterval uint64 `mapstructure:"snapshot-interval"` - - // SnapshotKeepRecent sets the number of recent state sync snapshots to keep. - // 0 keeps all snapshots. - SnapshotKeepRecent uint32 `mapstructure:"snapshot-keep-recent"` -} - -// MempoolConfig defines the configurations for the SDK built-in app-side mempool -// implementations. -type MempoolConfig struct { - // MaxTxs defines the behavior of the mempool. A negative value indicates - // the mempool is disabled entirely, zero indicates that the mempool is - // unbounded in how many txs it may contain, and a positive value indicates - // the maximum amount of txs it may contain. - MaxTxs int `mapstructure:"max-txs"` -} - -// State Streaming configuration -type ( - // StreamingConfig defines application configuration for external streaming services - StreamingConfig struct { - ABCI ABCIListenerConfig `mapstructure:"abci"` - } - // ABCIListenerConfig defines application configuration for ABCIListener streaming service - ABCIListenerConfig struct { - Keys []string `mapstructure:"keys"` - Plugin string `mapstructure:"plugin"` - StopNodeOnErr bool `mapstructure:"stop-node-on-err"` - } -) - -// Config defines the server's top level configuration -type Config struct { - BaseConfig `mapstructure:",squash"` - - // Telemetry defines the application telemetry configuration - Telemetry telemetry.Config `mapstructure:"telemetry"` - API APIConfig `mapstructure:"api"` - GRPC GRPCConfig `mapstructure:"grpc"` - StateSync StateSyncConfig `mapstructure:"state-sync"` - Streaming StreamingConfig `mapstructure:"streaming"` - Mempool MempoolConfig `mapstructure:"mempool"` -} - -// SetMinGasPrices sets the validator's minimum gas prices. -func (c *Config) SetMinGasPrices(gasPrices sdk.DecCoins) { - c.MinGasPrices = gasPrices.String() -} - -// GetMinGasPrices returns the validator's minimum gas prices based on the set configuration. -func (c *Config) GetMinGasPrices() sdk.DecCoins { - if c.MinGasPrices == "" { - return sdk.DecCoins{} - } - - gasPrices, err := sdk.ParseDecCoins(c.MinGasPrices) - if err != nil { - panic(fmt.Sprintf("invalid minimum gas prices: %v", err)) - } - - return gasPrices -} - -// DefaultConfig returns server's default configuration. -func DefaultConfig() *Config { - return &Config{ - BaseConfig: BaseConfig{ - MinGasPrices: defaultMinGasPrices, - QueryGasLimit: 0, - InterBlockCache: true, - Pruning: pruningtypes.PruningOptionDefault, - PruningKeepRecent: "0", - PruningInterval: "0", - MinRetainBlocks: 0, - IndexEvents: make([]string, 0), - IAVLCacheSize: 781250, - IAVLDisableFastNode: false, - AppDBBackend: "", - }, - Telemetry: telemetry.Config{ - Enabled: false, - GlobalLabels: [][]string{}, - }, - API: APIConfig{ - Enable: false, - Swagger: false, - Address: DefaultAPIAddress, - MaxOpenConnections: 1000, - RPCReadTimeout: 10, - RPCMaxBodyBytes: 1000000, - }, - GRPC: GRPCConfig{ - Enable: true, - Address: DefaultGRPCAddress, - MaxRecvMsgSize: DefaultGRPCMaxRecvMsgSize, - MaxSendMsgSize: DefaultGRPCMaxSendMsgSize, - }, - StateSync: StateSyncConfig{ - SnapshotInterval: 0, - SnapshotKeepRecent: 2, - }, - Streaming: StreamingConfig{ - ABCI: ABCIListenerConfig{ - Keys: []string{}, - StopNodeOnErr: true, - }, - }, - Mempool: MempoolConfig{ - MaxTxs: -1, - }, - } -} - -// GetConfig returns a fully parsed Config object. -func GetConfig(v *viper.Viper) (Config, error) { - conf := DefaultConfig() - if err := v.Unmarshal(conf); err != nil { - return Config{}, fmt.Errorf("error extracting app config: %w", err) - } - return *conf, nil -} - -// ValidateBasic returns an error if min-gas-prices field is empty in BaseConfig. Otherwise, it returns nil. -func (c Config) ValidateBasic() error { - if c.BaseConfig.MinGasPrices == "" { - return sdkerrors.ErrAppConfig.Wrap("set min gas price in app.toml or flag or env variable") - } - if c.Pruning == pruningtypes.PruningOptionEverything && c.StateSync.SnapshotInterval > 0 { - return sdkerrors.ErrAppConfig.Wrapf( - "cannot enable state sync snapshots with '%s' pruning setting", pruningtypes.PruningOptionEverything, - ) - } - - return nil -} diff --git a/server/config/config.toml.tpl b/server/config/config.toml.tpl deleted file mode 100644 index 632fa8def933..000000000000 --- a/server/config/config.toml.tpl +++ /dev/null @@ -1,226 +0,0 @@ -# This is a TOML config file. -# For more information, see https://github.com/toml-lang/toml - -############################################################################### -### Base Configuration ### -############################################################################### - -# The minimum gas prices a validator is willing to accept for processing a -# transaction. A transaction's fees must meet the minimum of any denomination -# specified in this config (e.g. 0.25token1,0.0001token2). -minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}" - -# The maximum gas a query coming over rest/grpc may consume. -# If this is set to zero, the query can consume an unbounded amount of gas. -query-gas-limit = "{{ .BaseConfig.QueryGasLimit }}" - -# default: the last 362880 states are kept, pruning at 10 block intervals -# nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) -# everything: 2 latest states will be kept; pruning at 10 block intervals. -# custom: allow pruning options to be manually specified through 'pruning-keep-recent', and 'pruning-interval' -pruning = "{{ .BaseConfig.Pruning }}" - -# These are applied if and only if the pruning strategy is custom. -pruning-keep-recent = "{{ .BaseConfig.PruningKeepRecent }}" -pruning-interval = "{{ .BaseConfig.PruningInterval }}" - -# HaltHeight contains a non-zero block height at which a node will gracefully -# halt and shutdown that can be used to assist upgrades and testing. -# -# Note: Commitment of state will be attempted on the corresponding block. -halt-height = {{ .BaseConfig.HaltHeight }} - -# HaltTime contains a non-zero minimum block time (in Unix seconds) at which -# a node will gracefully halt and shutdown that can be used to assist upgrades -# and testing. -# -# Note: Commitment of state will be attempted on the corresponding block. -halt-time = {{ .BaseConfig.HaltTime }} - -# MinRetainBlocks defines the minimum block height offset from the current -# block being committed, such that all blocks past this offset are pruned -# from CometBFT. It is used as part of the process of determining the -# ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates -# that no blocks should be pruned. -# -# This configuration value is only responsible for pruning CometBFT blocks. -# It has no bearing on application state pruning which is determined by the -# "pruning-*" configurations. -# -# Note: CometBFT block pruning is dependent on this parameter in conjunction -# with the unbonding (safety threshold) period, state pruning and state sync -# snapshot parameters to determine the correct minimum value of -# ResponseCommit.RetainHeight. -min-retain-blocks = {{ .BaseConfig.MinRetainBlocks }} - -# InterBlockCache enables inter-block caching. -inter-block-cache = {{ .BaseConfig.InterBlockCache }} - -# IndexEvents defines the set of events in the form {eventType}.{attributeKey}, -# which informs CometBFT what to index. If empty, all events will be indexed. -# -# Example: -# ["message.sender", "message.recipient"] -index-events = [{{ range .BaseConfig.IndexEvents }}{{ printf "%q, " . }}{{end}}] - -# IavlCacheSize set the size of the iavl tree cache (in number of nodes). -iavl-cache-size = {{ .BaseConfig.IAVLCacheSize }} - -# IAVLDisableFastNode enables or disables the fast node feature of IAVL. -# Default is false. -iavl-disable-fastnode = {{ .BaseConfig.IAVLDisableFastNode }} - -# AppDBBackend defines the database backend type to use for the application and snapshots DBs. -# An empty string indicates that a fallback will be used. -# The fallback is the db_backend value set in CometBFT's config.toml. -app-db-backend = "{{ .BaseConfig.AppDBBackend }}" - -############################################################################### -### Telemetry Configuration ### -############################################################################### - -[telemetry] - -# Prefixed with keys to separate services. -service-name = "{{ .Telemetry.ServiceName }}" - -# Enabled enables the application telemetry functionality. When enabled, -# an in-memory sink is also enabled by default. Operators may also enabled -# other sinks such as Prometheus. -enabled = {{ .Telemetry.Enabled }} - -# Enable prefixing gauge values with hostname. -enable-hostname = {{ .Telemetry.EnableHostname }} - -# Enable adding hostname to labels. -enable-hostname-label = {{ .Telemetry.EnableHostnameLabel }} - -# Enable adding service to labels. -enable-service-label = {{ .Telemetry.EnableServiceLabel }} - -# PrometheusRetentionTime, when positive, enables a Prometheus metrics sink. -prometheus-retention-time = {{ .Telemetry.PrometheusRetentionTime }} - -# GlobalLabels defines a global set of name/value label tuples applied to all -# metrics emitted using the wrapper functions defined in telemetry package. -# -# Example: -# [["chain_id", "cosmoshub-1"]] -global-labels = [{{ range $k, $v := .Telemetry.GlobalLabels }} - ["{{index $v 0 }}", "{{ index $v 1}}"],{{ end }} -] - -# MetricsSink defines the type of metrics sink to use. -metrics-sink = "{{ .Telemetry.MetricsSink }}" - -# StatsdAddr defines the address of a statsd server to send metrics to. -# Only utilized if MetricsSink is set to "statsd" or "dogstatsd". -statsd-addr = "{{ .Telemetry.StatsdAddr }}" - -# DatadogHostname defines the hostname to use when emitting metrics to -# Datadog. Only utilized if MetricsSink is set to "dogstatsd". -datadog-hostname = "{{ .Telemetry.DatadogHostname }}" - -############################################################################### -### API Configuration ### -############################################################################### - -[api] - -# Enable defines if the API server should be enabled. -enable = {{ .API.Enable }} - -# Swagger defines if swagger documentation should automatically be registered. -swagger = {{ .API.Swagger }} - -# Address defines the API server to listen on. -address = "{{ .API.Address }}" - -# MaxOpenConnections defines the number of maximum open connections. -max-open-connections = {{ .API.MaxOpenConnections }} - -# RPCReadTimeout defines the CometBFT RPC read timeout (in seconds). -rpc-read-timeout = {{ .API.RPCReadTimeout }} - -# RPCWriteTimeout defines the CometBFT RPC write timeout (in seconds). -rpc-write-timeout = {{ .API.RPCWriteTimeout }} - -# RPCMaxBodyBytes defines the CometBFT maximum request body (in bytes). -rpc-max-body-bytes = {{ .API.RPCMaxBodyBytes }} - -# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk). -enabled-unsafe-cors = {{ .API.EnableUnsafeCORS }} - -############################################################################### -### gRPC Configuration ### -############################################################################### - -[grpc] - -# Enable defines if the gRPC server should be enabled. -enable = {{ .GRPC.Enable }} - -# Address defines the gRPC server address to bind to. -address = "{{ .GRPC.Address }}" - -# MaxRecvMsgSize defines the max message size in bytes the server can receive. -# The default value is 10MB. -max-recv-msg-size = "{{ .GRPC.MaxRecvMsgSize }}" - -# MaxSendMsgSize defines the max message size in bytes the server can send. -# The default value is math.MaxInt32. -max-send-msg-size = "{{ .GRPC.MaxSendMsgSize }}" - -############################################################################### -### State Sync Configuration ### -############################################################################### - -# State sync snapshots allow other nodes to rapidly join the network without replaying historical -# blocks, instead downloading and applying a snapshot of the application state at a given height. -[state-sync] - -# snapshot-interval specifies the block interval at which local state sync snapshots are -# taken (0 to disable). -snapshot-interval = {{ .StateSync.SnapshotInterval }} - -# snapshot-keep-recent specifies the number of recent snapshots to keep and serve (0 to keep all). -snapshot-keep-recent = {{ .StateSync.SnapshotKeepRecent }} - -############################################################################### -### State Streaming ### -############################################################################### - -# Streaming allows nodes to stream state to external systems. -[streaming] - -# streaming.abci specifies the configuration for the ABCI Listener streaming service. -[streaming.abci] - -# List of kv store keys to stream out via gRPC. -# The store key names MUST match the module's StoreKey name. -# -# Example: -# ["acc", "bank", "gov", "staking", "mint"[,...]] -# ["*"] to expose all keys. -keys = [{{ range .Streaming.ABCI.Keys }}{{ printf "%q, " . }}{{end}}] - -# The plugin name used for streaming via gRPC. -# Streaming is only enabled if this is set. -# Supported plugins: abci -plugin = "{{ .Streaming.ABCI.Plugin }}" - -# stop-node-on-err specifies whether to stop the node on message delivery error. -stop-node-on-err = {{ .Streaming.ABCI.StopNodeOnErr }} - -############################################################################### -### Mempool ### -############################################################################### - -[mempool] -# Setting max-txs to 0 will allow for a unbounded amount of transactions in the mempool. -# Setting max_txs to negative 1 (-1) will disable transactions from being inserted into the mempool (no-op mempool). -# Setting max_txs to a positive number (> 0) will limit the number of transactions in the mempool, by the specified amount. -# -# Note, this configuration only applies to SDK built-in app-side mempool -# implementations. -max-txs = {{ .Mempool.MaxTxs }} \ No newline at end of file diff --git a/server/config/config_test.go b/server/config/config_test.go deleted file mode 100644 index 6d827ec27dc7..000000000000 --- a/server/config/config_test.go +++ /dev/null @@ -1,293 +0,0 @@ -package config - -import ( - "bytes" - "os" - "path/filepath" - "testing" - - "github.com/spf13/viper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - pruningtypes "cosmossdk.io/store/pruning/types" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func TestDefaultConfig(t *testing.T) { - cfg := DefaultConfig() - require.True(t, cfg.GetMinGasPrices().IsZero()) -} - -func TestGetAndSetMinimumGas(t *testing.T) { - cfg := DefaultConfig() - - // Test case 1: Single coin - input := sdk.DecCoins{sdk.NewInt64DecCoin("foo", 5)} - cfg.SetMinGasPrices(input) - require.Equal(t, "5.000000000000000000foo", cfg.MinGasPrices) - require.EqualValues(t, cfg.GetMinGasPrices(), input) - - // Test case 2: Multiple coins - input = sdk.DecCoins{sdk.NewInt64DecCoin("bar", 1), sdk.NewInt64DecCoin("foo", 5)} - cfg.SetMinGasPrices(input) - require.Equal(t, "1.000000000000000000bar,5.000000000000000000foo", cfg.MinGasPrices) - require.EqualValues(t, cfg.GetMinGasPrices(), input) - - // Test case 4: Empty DecCoins - input = sdk.DecCoins{} - cfg.SetMinGasPrices(input) - require.Equal(t, "", cfg.MinGasPrices) - require.EqualValues(t, cfg.GetMinGasPrices(), input) - - // Test case 5: Invalid string (should panic) - cfg.MinGasPrices = "invalid,gas,prices" - require.Panics(t, func() { - cfg.GetMinGasPrices() - }, "GetMinGasPrices should panic with invalid input") -} - -func TestIndexEventsMarshalling(t *testing.T) { - expectedIn := `index-events = ["key1", "key2", ]` + "\n" - cfg := DefaultConfig() - cfg.IndexEvents = []string{"key1", "key2"} - var buffer bytes.Buffer - - err := configTemplate.Execute(&buffer, cfg) - require.NoError(t, err, "executing template") - actual := buffer.String() - require.Contains(t, actual, expectedIn, "config file contents") -} - -func TestStreamingConfig(t *testing.T) { - cfg := Config{ - Streaming: StreamingConfig{ - ABCI: ABCIListenerConfig{ - Keys: []string{"one", "two"}, - Plugin: "plugin-A", - StopNodeOnErr: false, - }, - }, - } - - testDir := t.TempDir() - cfgFile := filepath.Join(testDir, "app.toml") - err := WriteConfigFile(cfgFile, &cfg) - require.NoError(t, err) - - cfgFileBz, err := os.ReadFile(cfgFile) - require.NoError(t, err, "reading %s", cfgFile) - cfgFileContents := string(cfgFileBz) - t.Logf("Config file contents: %s:\n%s", cfgFile, cfgFileContents) - - expectedLines := []string{ - `keys = ["one", "two", ]`, - `plugin = "plugin-A"`, - `stop-node-on-err = false`, - } - - for _, line := range expectedLines { - assert.Contains(t, cfgFileContents, line+"\n", "config file contents") - } - - vpr := viper.New() - vpr.SetConfigFile(cfgFile) - err = vpr.ReadInConfig() - require.NoError(t, err, "reading config file into viper") - - var actual Config - err = vpr.Unmarshal(&actual) - require.NoError(t, err, "vpr.Unmarshal") - - assert.Equal(t, cfg.Streaming, actual.Streaming, "Streaming") -} - -func TestParseStreaming(t *testing.T) { - expectedKeys := `keys = ["*", ]` + "\n" - expectedPlugin := `plugin = "abci_v1"` + "\n" - expectedStopNodeOnErr := `stop-node-on-err = true` + "\n" - - cfg := DefaultConfig() - cfg.Streaming.ABCI.Keys = []string{"*"} - cfg.Streaming.ABCI.Plugin = "abci_v1" - cfg.Streaming.ABCI.StopNodeOnErr = true - - var buffer bytes.Buffer - err := configTemplate.Execute(&buffer, cfg) - require.NoError(t, err, "executing template") - actual := buffer.String() - require.Contains(t, actual, expectedKeys, "config file contents") - require.Contains(t, actual, expectedPlugin, "config file contents") - require.Contains(t, actual, expectedStopNodeOnErr, "config file contents") -} - -func TestReadConfig(t *testing.T) { - cfg := DefaultConfig() - tmpFile := filepath.Join(t.TempDir(), "config") - err := WriteConfigFile(tmpFile, cfg) - require.NoError(t, err) - - v := viper.New() - otherCfg, err := GetConfig(v) - require.NoError(t, err) - - require.Equal(t, *cfg, otherCfg) -} - -func TestIndexEventsWriteRead(t *testing.T) { - expected := []string{"key3", "key4"} - - // Create config with two IndexEvents entries, and write it to a file. - confFile := filepath.Join(t.TempDir(), "app.toml") - conf := DefaultConfig() - conf.IndexEvents = expected - - err := WriteConfigFile(confFile, conf) - require.NoError(t, err) - - // read the file into Viper - vpr := viper.New() - vpr.SetConfigFile(confFile) - - err = vpr.ReadInConfig() - require.NoError(t, err, "reading config file into viper") - - // Check that the raw viper value is correct. - actualRaw := vpr.GetStringSlice("index-events") - require.Equal(t, expected, actualRaw, "viper's index events") - - // Check that it is parsed into the config correctly. - cfg, perr := ParseConfig(vpr) - require.NoError(t, perr, "parsing config") - - actual := cfg.IndexEvents - require.Equal(t, expected, actual, "config value") -} - -func TestGlobalLabelsEventsMarshalling(t *testing.T) { - expectedIn := `global-labels = [ - ["labelname1", "labelvalue1"], - ["labelname2", "labelvalue2"], -]` - cfg := DefaultConfig() - cfg.Telemetry.GlobalLabels = [][]string{{"labelname1", "labelvalue1"}, {"labelname2", "labelvalue2"}} - var buffer bytes.Buffer - - err := configTemplate.Execute(&buffer, cfg) - require.NoError(t, err, "executing template") - actual := buffer.String() - require.Contains(t, actual, expectedIn, "config file contents") -} - -func TestGlobalLabelsWriteRead(t *testing.T) { - expected := [][]string{{"labelname3", "labelvalue3"}, {"labelname4", "labelvalue4"}} - expectedRaw := make([]interface{}, len(expected)) - for i, exp := range expected { - pair := make([]interface{}, len(exp)) - for j, s := range exp { - pair[j] = s - } - expectedRaw[i] = pair - } - - // Create config with two GlobalLabels entries, and write it to a file. - confFile := filepath.Join(t.TempDir(), "app.toml") - conf := DefaultConfig() - conf.Telemetry.GlobalLabels = expected - err := WriteConfigFile(confFile, conf) - require.NoError(t, err) - - // Read that file into viper. - vpr := viper.New() - vpr.SetConfigFile(confFile) - rerr := vpr.ReadInConfig() - require.NoError(t, rerr, "reading config file into viper") - // Check that the raw viper value is correct. - actualRaw := vpr.Get("telemetry.global-labels") - require.Equal(t, expectedRaw, actualRaw, "viper value") - // Check that it is parsed into the config correctly. - cfg, perr := ParseConfig(vpr) - require.NoError(t, perr, "parsing config") - actual := cfg.Telemetry.GlobalLabels - require.Equal(t, expected, actual, "config value") -} - -func TestSetConfigTemplate(t *testing.T) { - conf := DefaultConfig() - var initBuffer, setBuffer bytes.Buffer - - // Use the configTemplate defined during init() to create a config string. - ierr := configTemplate.Execute(&initBuffer, conf) - require.NoError(t, ierr, "initial configTemplate.Execute") - expected := initBuffer.String() - - // Set the template to the default one. - initTmpl := configTemplate - require.NotPanics(t, func() { - _ = SetConfigTemplate(DefaultConfigTemplate) - }, "SetConfigTemplate") - setTmpl := configTemplate - require.NotSame(t, initTmpl, setTmpl, "configTemplate after set") - - // Create the string again and make sure it's the same. - serr := configTemplate.Execute(&setBuffer, conf) - require.NoError(t, serr, "after SetConfigTemplate, configTemplate.Execute") - actual := setBuffer.String() - require.Equal(t, expected, actual, "resulting config strings") -} - -func TestAppConfig(t *testing.T) { - appConfigFile := filepath.Join(t.TempDir(), "app.toml") - defer func() { - _ = os.Remove(appConfigFile) - }() - - defAppConfig := DefaultConfig() - require.NoError(t, SetConfigTemplate(DefaultConfigTemplate)) - require.NoError(t, WriteConfigFile(appConfigFile, defAppConfig)) - - v := viper.New() - v.SetConfigFile(appConfigFile) - require.NoError(t, v.ReadInConfig()) - appCfg := new(Config) - require.NoError(t, v.Unmarshal(appCfg)) - require.EqualValues(t, appCfg, defAppConfig) -} - -func TestValidateBasic(t *testing.T) { - cfg := DefaultConfig() - - // Test case 1: Valid MinGasPrices - cfg.MinGasPrices = "0.01stake" - err := cfg.ValidateBasic() - require.NoError(t, err) - - // Test case 2: Default configuration (MinGasPrices is empty) - cfg.MinGasPrices = "" - err = cfg.ValidateBasic() - require.Error(t, err) - require.Contains(t, err.Error(), "set min gas price in app.toml or flag or env variable") - - // Test case 3: Invalid pruning and state sync combination - cfg = DefaultConfig() - cfg.MinGasPrices = "0.01stake" - cfg.Pruning = pruningtypes.PruningOptionEverything - cfg.StateSync.SnapshotInterval = 1000 - err = cfg.ValidateBasic() - require.Error(t, err) - require.Contains(t, err.Error(), "cannot enable state sync snapshots with 'everything' pruning setting") -} - -func TestGetConfig(t *testing.T) { - v := viper.New() - v.Set("minimum-gas-prices", "0.01stake") - v.Set("api.enable", true) - v.Set("grpc.max-recv-msg-size", 5*1024*1024) - - cfg, err := GetConfig(v) - require.NoError(t, err) - require.Equal(t, "0.01stake", cfg.MinGasPrices) - require.True(t, cfg.API.Enable) - require.Equal(t, 5*1024*1024, cfg.GRPC.MaxRecvMsgSize) -} diff --git a/server/config/toml.go b/server/config/toml.go deleted file mode 100644 index 758f59da6afa..000000000000 --- a/server/config/toml.go +++ /dev/null @@ -1,61 +0,0 @@ -package config - -import ( - "bytes" - _ "embed" - "fmt" - "os" - "text/template" - - "github.com/spf13/viper" -) - -//go:embed config.toml.tpl -var DefaultConfigTemplate string - -var configTemplate *template.Template - -func init() { - var err error - - tmpl := template.New("appConfigFileTemplate") - if configTemplate, err = tmpl.Parse(DefaultConfigTemplate); err != nil { - panic(err) - } -} - -// ParseConfig retrieves the default environment configuration for the application. -func ParseConfig(v *viper.Viper) (*Config, error) { - conf := DefaultConfig() - err := v.Unmarshal(conf) - - return conf, err -} - -// SetConfigTemplate sets the custom app config template for the application. -func SetConfigTemplate(customTemplate string) error { - var err error - - tmpl := template.New("appConfigFileTemplate") - - if configTemplate, err = tmpl.Parse(customTemplate); err != nil { - return err - } - - return nil -} - -// WriteConfigFile renders config using the template and writes it to configFilePath. -func WriteConfigFile(configFilePath string, config interface{}) error { - var buffer bytes.Buffer - - if err := configTemplate.Execute(&buffer, config); err != nil { - return err - } - - if err := os.WriteFile(configFilePath, buffer.Bytes(), 0o600); err != nil { - return fmt.Errorf("failed to write file: %w", err) - } - - return nil -} diff --git a/server/flags.go b/server/flags.go deleted file mode 100644 index 390a2466f4dd..000000000000 --- a/server/flags.go +++ /dev/null @@ -1,57 +0,0 @@ -package server - -const ( - // CometBFT full-node start flags - flagWithComet = "with-comet" - flagAddress = "address" - flagTransport = "transport" - flagTraceStore = "trace-store" - flagCPUProfile = "cpu-profile" - FlagMinGasPrices = "minimum-gas-prices" - FlagQueryGasLimit = "query-gas-limit" - FlagHaltHeight = "halt-height" - FlagHaltTime = "halt-time" - FlagInterBlockCache = "inter-block-cache" - FlagUnsafeSkipUpgrades = "unsafe-skip-upgrades" - FlagTrace = "trace" - FlagInvCheckPeriod = "inv-check-period" - - FlagPruning = "pruning" - FlagPruningKeepRecent = "pruning-keep-recent" - FlagPruningInterval = "pruning-interval" - FlagIndexEvents = "index-events" - FlagMinRetainBlocks = "min-retain-blocks" - FlagIAVLCacheSize = "iavl-cache-size" - FlagDisableIAVLFastNode = "iavl-disable-fastnode" - FlagIAVLSyncPruning = "iavl-sync-pruning" - FlagShutdownGrace = "shutdown-grace" - - // state sync-related flags - - FlagStateSyncSnapshotInterval = "state-sync.snapshot-interval" - FlagStateSyncSnapshotKeepRecent = "state-sync.snapshot-keep-recent" - - // api-related flags - - FlagAPIEnable = "api.enable" - FlagAPISwagger = "api.swagger" - FlagAPIAddress = "api.address" - FlagAPIMaxOpenConnections = "api.max-open-connections" - FlagRPCReadTimeout = "api.rpc-read-timeout" - FlagRPCWriteTimeout = "api.rpc-write-timeout" - FlagRPCMaxBodyBytes = "api.rpc-max-body-bytes" - FlagAPIEnableUnsafeCORS = "api.enabled-unsafe-cors" - - // mempool flags - - FlagMempoolMaxTxs = "mempool.max-txs" - - // testnet keys - - KeyIsTestnet = "is-testnet" - KeyNewChainID = "new-chain-ID" - KeyNewOpAddr = "new-operator-addr" - KeyNewValAddr = "new-validator-addr" - KeyUserPubKey = "user-pub-key" - KeyTriggerTestnetUpgrade = "trigger-testnet-upgrade" -) diff --git a/server/grpc/gogoreflection/doc.go b/server/grpc/gogoreflection/doc.go deleted file mode 100644 index 691e632d0ee1..000000000000 --- a/server/grpc/gogoreflection/doc.go +++ /dev/null @@ -1,5 +0,0 @@ -// Package gogoreflection implements gRPC reflection for gogoproto consumers -// the normal reflection library does not work as it points to a different -// singleton registry. The API and codebase is taken from the official gRPC -// reflection repository. -package gogoreflection diff --git a/server/grpc/gogoreflection/fix_registration.go b/server/grpc/gogoreflection/fix_registration.go deleted file mode 100644 index 5704f054ff61..000000000000 --- a/server/grpc/gogoreflection/fix_registration.go +++ /dev/null @@ -1,75 +0,0 @@ -package gogoreflection - -import ( - "reflect" - - _ "github.com/cosmos/cosmos-proto" // look above - _ "github.com/cosmos/gogoproto/gogoproto" // required so it does register the gogoproto file descriptor - gogoproto "github.com/cosmos/gogoproto/proto" - "github.com/golang/protobuf/proto" //nolint:staticcheck // migrate in a future pr -) - -func getFileDescriptor(filePath string) []byte { - // Since we got well known descriptors which are not registered into gogoproto - // registry but are instead registered into the proto one, we need to check both. - fd := gogoproto.FileDescriptor(filePath) - if len(fd) != 0 { - return fd - } - - return proto.FileDescriptor(filePath) //nolint:staticcheck // keep for backward compatibility -} - -func getMessageType(name string) reflect.Type { - typ := gogoproto.MessageType(name) - if typ != nil { - return typ - } - - return proto.MessageType(name) //nolint:staticcheck // keep for backward compatibility -} - -func getExtension(extID int32, m proto.Message) *gogoproto.ExtensionDesc { - // check first in gogoproto registry - for id, desc := range gogoproto.RegisteredExtensions(m) { - if id == extID { - return desc - } - } - - // check into proto registry - for id, desc := range proto.RegisteredExtensions(m) { //nolint:staticcheck // keep for backward compatibility - if id == extID { - return &gogoproto.ExtensionDesc{ - ExtendedType: desc.ExtendedType, - ExtensionType: desc.ExtensionType, - Field: desc.Field, - Name: desc.Name, - Tag: desc.Tag, - Filename: desc.Filename, - } - } - } - - return nil -} - -func getExtensionsNumbers(m proto.Message) []int32 { - gogoProtoExts := gogoproto.RegisteredExtensions(m) - - out := make([]int32, 0, len(gogoProtoExts)) - for id := range gogoProtoExts { - out = append(out, id) - } - if len(out) != 0 { - return out - } - - protoExts := proto.RegisteredExtensions(m) //nolint:staticcheck // kept for backwards compatibility - out = make([]int32, 0, len(protoExts)) - for id := range protoExts { - out = append(out, id) - } - - return out -} diff --git a/server/grpc/gogoreflection/fix_registration_test.go b/server/grpc/gogoreflection/fix_registration_test.go deleted file mode 100644 index 0693556688e7..000000000000 --- a/server/grpc/gogoreflection/fix_registration_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package gogoreflection - -import ( - "testing" - - "google.golang.org/protobuf/runtime/protoimpl" -) - -func TestRegistrationFix(t *testing.T) { - res := getFileDescriptor("gogoproto/gogo.proto") - rawDesc, err := decompress(res) - if err != nil { - t.Fatal(err) - } - fd := protoimpl.DescBuilder{ - RawDescriptor: rawDesc, - }.Build() - - if fd.File.Extensions().Len() == 0 { - t.Fatal("unexpected parsing") - } -} diff --git a/server/grpc/gogoreflection/serverreflection.go b/server/grpc/gogoreflection/serverreflection.go deleted file mode 100644 index 11213a19d82f..000000000000 --- a/server/grpc/gogoreflection/serverreflection.go +++ /dev/null @@ -1,473 +0,0 @@ -// Copyright 2016 gRPC authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package gogoreflection implements server reflection service. -// -// The service implemented is defined in: -// https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto. -// -// To register server reflection on a gRPC server: -// -// import "google.golang.org/grpc/reflection" -// -// s := grpc.NewServer() -// pb.RegisterYourOwnServer(s, &server{}) -// -// // Register reflection service on gRPC server. -// reflection.Register(s) -// -// s.Serve(lis) - -package gogoreflection - -import ( - "bytes" - "compress/gzip" - "errors" - "fmt" - "io" - "log" - "reflect" - "sort" - "sync" - - //nolint: staticcheck // keep this import for backward compatibility - "github.com/golang/protobuf/proto" - dpb "github.com/golang/protobuf/protoc-gen-go/descriptor" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - rpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha" - "google.golang.org/grpc/status" -) - -type serverReflectionServer struct { - rpb.UnimplementedServerReflectionServer - s *grpc.Server - - initSymbols sync.Once - serviceNames []string - symbols map[string]*dpb.FileDescriptorProto // map of fully-qualified names to files -} - -// Register registers the server reflection service on the given gRPC server. -func Register(s *grpc.Server) { - rpb.RegisterServerReflectionServer(s, &serverReflectionServer{ - s: s, - }) -} - -// protoMessage is used for type assertion on proto messages. -// Generated proto message implements function Descriptor(), but Descriptor() -// is not part of interface proto.Message. This interface is needed to -// call Descriptor(). -type protoMessage interface { - Descriptor() ([]byte, []int) -} - -func (s *serverReflectionServer) getSymbols() (svcNames []string, symbolIndex map[string]*dpb.FileDescriptorProto) { - s.initSymbols.Do(func() { - serviceInfo := s.s.GetServiceInfo() - - s.symbols = map[string]*dpb.FileDescriptorProto{} - s.serviceNames = make([]string, 0, len(serviceInfo)) - processed := map[string]struct{}{} - for svc, info := range serviceInfo { - s.serviceNames = append(s.serviceNames, svc) - fdenc, ok := parseMetadata(info.Metadata) - if !ok { - continue - } - fd, err := decodeFileDesc(fdenc) - if err != nil { - continue - } - s.processFile(fd, processed) - } - sort.Strings(s.serviceNames) - }) - - return s.serviceNames, s.symbols -} - -func (s *serverReflectionServer) processFile(fd *dpb.FileDescriptorProto, processed map[string]struct{}) { - filename := fd.GetName() - if _, ok := processed[filename]; ok { - return - } - processed[filename] = struct{}{} - - prefix := fd.GetPackage() - - for _, msg := range fd.MessageType { - s.processMessage(fd, prefix, msg) - } - for _, en := range fd.EnumType { - s.processEnum(fd, prefix, en) - } - for _, ext := range fd.Extension { - s.processField(fd, prefix, ext) - } - for _, svc := range fd.Service { - svcName := fqn(prefix, svc.GetName()) - s.symbols[svcName] = fd - for _, meth := range svc.Method { - name := fqn(svcName, meth.GetName()) - s.symbols[name] = fd - } - } - - for _, dep := range fd.Dependency { - fdenc := getFileDescriptor(dep) - fdDep, err := decodeFileDesc(fdenc) - if err != nil { - continue - } - s.processFile(fdDep, processed) - } -} - -func (s *serverReflectionServer) processMessage(fd *dpb.FileDescriptorProto, prefix string, msg *dpb.DescriptorProto) { - msgName := fqn(prefix, msg.GetName()) - s.symbols[msgName] = fd - - for _, nested := range msg.NestedType { - s.processMessage(fd, msgName, nested) - } - for _, en := range msg.EnumType { - s.processEnum(fd, msgName, en) - } - for _, ext := range msg.Extension { - s.processField(fd, msgName, ext) - } - for _, fld := range msg.Field { - s.processField(fd, msgName, fld) - } - for _, oneof := range msg.OneofDecl { - oneofName := fqn(msgName, oneof.GetName()) - s.symbols[oneofName] = fd - } -} - -func (s *serverReflectionServer) processEnum(fd *dpb.FileDescriptorProto, prefix string, en *dpb.EnumDescriptorProto) { - enName := fqn(prefix, en.GetName()) - s.symbols[enName] = fd - - for _, val := range en.Value { - valName := fqn(enName, val.GetName()) - s.symbols[valName] = fd - } -} - -func (s *serverReflectionServer) processField(fd *dpb.FileDescriptorProto, prefix string, fld *dpb.FieldDescriptorProto) { - fldName := fqn(prefix, fld.GetName()) - s.symbols[fldName] = fd -} - -func fqn(prefix, name string) string { - if prefix == "" { - return name - } - return prefix + "." + name -} - -// fileDescForType gets the file descriptor for the given type. -// The given type should be a proto message. -func (s *serverReflectionServer) fileDescForType(st reflect.Type) (*dpb.FileDescriptorProto, error) { - m, ok := reflect.Zero(reflect.PointerTo(st)).Interface().(protoMessage) - if !ok { - return nil, fmt.Errorf("failed to create message from type: %v", st) - } - enc, _ := m.Descriptor() - - return decodeFileDesc(enc) -} - -// decodeFileDesc does decompression and unmarshalling on the given -// file descriptor byte slice. -func decodeFileDesc(enc []byte) (*dpb.FileDescriptorProto, error) { - raw, err := decompress(enc) - if err != nil { - return nil, fmt.Errorf("failed to decompress enc: %w", err) - } - - fd := new(dpb.FileDescriptorProto) - if err := proto.Unmarshal(raw, fd); err != nil { - return nil, fmt.Errorf("bad descriptor: %w", err) - } - return fd, nil -} - -// decompress does gzip decompression. -func decompress(b []byte) ([]byte, error) { - r, err := gzip.NewReader(bytes.NewReader(b)) - if err != nil { - return nil, fmt.Errorf("bad gzipped descriptor: %w", err) - } - out, err := io.ReadAll(r) - if err != nil { - return nil, fmt.Errorf("bad gzipped descriptor: %w", err) - } - return out, nil -} - -func typeForName(name string) (reflect.Type, error) { - pt := getMessageType(name) - if pt == nil { - return nil, fmt.Errorf("unknown type: %q", name) - } - st := pt.Elem() - - return st, nil -} - -func fileDescContainingExtension(st reflect.Type, ext int32) (*dpb.FileDescriptorProto, error) { - m, ok := reflect.Zero(reflect.PointerTo(st)).Interface().(proto.Message) - if !ok { - return nil, fmt.Errorf("failed to create message from type: %v", st) - } - - extDesc := getExtension(ext, m) - - if extDesc == nil { - return nil, fmt.Errorf("failed to find registered extension for extension number %v", ext) - } - - return decodeFileDesc(getFileDescriptor(extDesc.Filename)) -} - -func (s *serverReflectionServer) allExtensionNumbersForType(st reflect.Type) ([]int32, error) { - m, ok := reflect.Zero(reflect.PointerTo(st)).Interface().(proto.Message) - if !ok { - return nil, fmt.Errorf("failed to create message from type: %v", st) - } - - out := getExtensionsNumbers(m) - return out, nil -} - -// fileDescWithDependencies returns a slice of serialized fileDescriptors in -// wire format ([]byte). The fileDescriptors will include fd and all the -// transitive dependencies of fd with names not in sentFileDescriptors. -func fileDescWithDependencies(fd *dpb.FileDescriptorProto, sentFileDescriptors map[string]bool) ([][]byte, error) { - r := [][]byte{} - queue := []*dpb.FileDescriptorProto{fd} - for len(queue) > 0 { - currentfd := queue[0] - queue = queue[1:] - if sent := sentFileDescriptors[currentfd.GetName()]; len(r) == 0 || !sent { - sentFileDescriptors[currentfd.GetName()] = true - currentfdEncoded, err := proto.Marshal(currentfd) - if err != nil { - return nil, err - } - r = append(r, currentfdEncoded) - } - for _, dep := range currentfd.Dependency { - fdenc := getFileDescriptor(dep) - fdDep, err := decodeFileDesc(fdenc) - if err != nil { - continue - } - queue = append(queue, fdDep) - } - } - return r, nil -} - -// fileDescEncodingByFilename finds the file descriptor for given filename, -// finds all of its previously unsent transitive dependencies, does marshaling -// on them, and returns the marshaled result. -func (s *serverReflectionServer) fileDescEncodingByFilename(name string, sentFileDescriptors map[string]bool) ([][]byte, error) { - enc := getFileDescriptor(name) - if enc == nil { - return nil, fmt.Errorf("unknown file: %v", name) - } - fd, err := decodeFileDesc(enc) - if err != nil { - return nil, err - } - return fileDescWithDependencies(fd, sentFileDescriptors) -} - -// parseMetadata finds the file descriptor bytes specified meta. -// For SupportPackageIsVersion4, m is the name of the proto file, we -// call proto.FileDescriptor to get the byte slice. -// For SupportPackageIsVersion3, m is a byte slice itself. -func parseMetadata(meta interface{}) ([]byte, bool) { - // Check if meta is the file name. - if fileNameForMeta, ok := meta.(string); ok { - return getFileDescriptor(fileNameForMeta), true - } - - // Check if meta is the byte slice. - if enc, ok := meta.([]byte); ok { - return enc, true - } - - return nil, false -} - -// fileDescEncodingContainingSymbol finds the file descriptor containing the -// given symbol, finds all of its previously unsent transitive dependencies, -// does marshaling on them, and returns the marshaled result. The given symbol -// can be a type, a service or a method. -func (s *serverReflectionServer) fileDescEncodingContainingSymbol(name string, sentFileDescriptors map[string]bool) ([][]byte, error) { - _, symbols := s.getSymbols() - fd := symbols[name] - if fd == nil { - // Check if it's a type name that was not present in the - // transitive dependencies of the registered services. - if st, err := typeForName(name); err == nil { - fd, err = s.fileDescForType(st) - if err != nil { - return nil, err - } - } - } - - if fd == nil { - return nil, fmt.Errorf("unknown symbol: %v", name) - } - - return fileDescWithDependencies(fd, sentFileDescriptors) -} - -// fileDescEncodingContainingExtension finds the file descriptor containing -// given extension, finds all of its previously unsent transitive dependencies, -// does marshaling on them, and returns the marshaled result. -func (s *serverReflectionServer) fileDescEncodingContainingExtension(typeName string, extNum int32, sentFileDescriptors map[string]bool) ([][]byte, error) { - st, err := typeForName(typeName) - if err != nil { - return nil, err - } - fd, err := fileDescContainingExtension(st, extNum) - if err != nil { - return nil, err - } - return fileDescWithDependencies(fd, sentFileDescriptors) -} - -// allExtensionNumbersForTypeName returns all extension numbers for the given type. -func (s *serverReflectionServer) allExtensionNumbersForTypeName(name string) ([]int32, error) { - st, err := typeForName(name) - if err != nil { - return nil, err - } - extNums, err := s.allExtensionNumbersForType(st) - if err != nil { - return nil, err - } - return extNums, nil -} - -// ServerReflectionInfo is the reflection service handler. -func (s *serverReflectionServer) ServerReflectionInfo(stream rpb.ServerReflection_ServerReflectionInfoServer) error { - sentFileDescriptors := make(map[string]bool) - for { - in, err := stream.Recv() - if errors.Is(err, io.EOF) { - return nil - } - if err != nil { - return err - } - - out := &rpb.ServerReflectionResponse{ //nolint:staticcheck // SA1019: we want to keep using v1alpha - ValidHost: in.Host, //nolint:staticcheck // SA1019: we want to keep using v1alpha - OriginalRequest: in, - } - switch req := in.MessageRequest.(type) { - case *rpb.ServerReflectionRequest_FileByFilename: - b, err := s.fileDescEncodingByFilename(req.FileByFilename, sentFileDescriptors) //nolint:staticcheck // SA1019: we want to keep using v1alpha - if err != nil { - out.MessageResponse = &rpb.ServerReflectionResponse_ErrorResponse{ - ErrorResponse: &rpb.ErrorResponse{ //nolint:staticcheck // SA1019: we want to keep using v1alpha - ErrorCode: int32(codes.NotFound), - ErrorMessage: err.Error(), - }, - } - } else { - out.MessageResponse = &rpb.ServerReflectionResponse_FileDescriptorResponse{ - FileDescriptorResponse: &rpb.FileDescriptorResponse{FileDescriptorProto: b}, //nolint:staticcheck // SA1019: we want to keep using v1alpha - } - } - case *rpb.ServerReflectionRequest_FileContainingSymbol: - b, err := s.fileDescEncodingContainingSymbol(req.FileContainingSymbol, sentFileDescriptors) //nolint:staticcheck // SA1019: we want to keep using v1alpha - if err != nil { - out.MessageResponse = &rpb.ServerReflectionResponse_ErrorResponse{ - ErrorResponse: &rpb.ErrorResponse{ //nolint:staticcheck // SA1019: we want to keep using v1alpha - ErrorCode: int32(codes.NotFound), - ErrorMessage: err.Error(), - }, - } - } else { - out.MessageResponse = &rpb.ServerReflectionResponse_FileDescriptorResponse{ - FileDescriptorResponse: &rpb.FileDescriptorResponse{FileDescriptorProto: b}, //nolint:staticcheck // SA1019: we want to keep using v1alpha - } - } - case *rpb.ServerReflectionRequest_FileContainingExtension: - typeName := req.FileContainingExtension.ContainingType //nolint:staticcheck // SA1019: we want to keep using v1alpha - extNum := req.FileContainingExtension.ExtensionNumber //nolint:staticcheck // SA1019: we want to keep using v1alpha - b, err := s.fileDescEncodingContainingExtension(typeName, extNum, sentFileDescriptors) - if err != nil { - out.MessageResponse = &rpb.ServerReflectionResponse_ErrorResponse{ - ErrorResponse: &rpb.ErrorResponse{ //nolint:staticcheck // SA1019: we want to keep using v1alpha - ErrorCode: int32(codes.NotFound), - ErrorMessage: err.Error(), - }, - } - } else { - out.MessageResponse = &rpb.ServerReflectionResponse_FileDescriptorResponse{ - FileDescriptorResponse: &rpb.FileDescriptorResponse{FileDescriptorProto: b}, //nolint:staticcheck // SA1019: we want to keep using v1alpha - } - } - case *rpb.ServerReflectionRequest_AllExtensionNumbersOfType: - extNums, err := s.allExtensionNumbersForTypeName(req.AllExtensionNumbersOfType) //nolint:staticcheck // SA1019: we want to keep using v1alpha - if err != nil { - out.MessageResponse = &rpb.ServerReflectionResponse_ErrorResponse{ - ErrorResponse: &rpb.ErrorResponse{ //nolint:staticcheck // SA1019: we want to keep using v1alpha - ErrorCode: int32(codes.NotFound), - ErrorMessage: err.Error(), - }, - } - log.Printf("OH NO: %s", err) - } else { - out.MessageResponse = &rpb.ServerReflectionResponse_AllExtensionNumbersResponse{ - AllExtensionNumbersResponse: &rpb.ExtensionNumberResponse{ //nolint:staticcheck // SA1019: we want to keep using v1alpha - BaseTypeName: req.AllExtensionNumbersOfType, //nolint:staticcheck // SA1019: we want to keep using v1alpha - ExtensionNumber: extNums, - }, - } - } - case *rpb.ServerReflectionRequest_ListServices: - svcNames, _ := s.getSymbols() - serviceResponses := make([]*rpb.ServiceResponse, len(svcNames)) //nolint:staticcheck // SA1019: we want to keep using v1alpha - for i, n := range svcNames { - serviceResponses[i] = &rpb.ServiceResponse{ //nolint:staticcheck // SA1019: we want to keep using v1alpha - Name: n, - } - } - out.MessageResponse = &rpb.ServerReflectionResponse_ListServicesResponse{ - ListServicesResponse: &rpb.ListServiceResponse{ //nolint:staticcheck // SA1019: we want to keep using v1alpha - Service: serviceResponses, - }, - } - default: - return status.Errorf(codes.InvalidArgument, "invalid MessageRequest: %v", in.MessageRequest) - } - if err := stream.Send(out); err != nil { - return err - } - } -} diff --git a/server/grpc/reflection/v2alpha1/reflection.go b/server/grpc/reflection/v2alpha1/reflection.go deleted file mode 100644 index fd1ffe4293f7..000000000000 --- a/server/grpc/reflection/v2alpha1/reflection.go +++ /dev/null @@ -1,197 +0,0 @@ -package v2alpha1 - -import ( - "context" - "errors" - "fmt" - - "github.com/cosmos/gogoproto/proto" - "google.golang.org/grpc" - - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/tx" -) - -type Config struct { - SigningModes map[string]int32 - ChainID string - InterfaceRegistry codectypes.InterfaceRegistry -} - -// Register registers the cosmos sdk reflection service -// to the provided *grpc.Server given a Config -func Register(srv *grpc.Server, conf Config) error { - reflectionServer, err := newReflectionServiceServer(srv, conf) - if err != nil { - return err - } - RegisterReflectionServiceServer(srv, reflectionServer) - return nil -} - -type reflectionServiceServer struct { - desc *AppDescriptor -} - -func (r reflectionServiceServer) GetAuthnDescriptor(_ context.Context, _ *GetAuthnDescriptorRequest) (*GetAuthnDescriptorResponse, error) { - return &GetAuthnDescriptorResponse{Authn: r.desc.Authn}, nil -} - -func (r reflectionServiceServer) GetChainDescriptor(_ context.Context, _ *GetChainDescriptorRequest) (*GetChainDescriptorResponse, error) { - return &GetChainDescriptorResponse{Chain: r.desc.Chain}, nil -} - -func (r reflectionServiceServer) GetCodecDescriptor(_ context.Context, _ *GetCodecDescriptorRequest) (*GetCodecDescriptorResponse, error) { - return &GetCodecDescriptorResponse{Codec: r.desc.Codec}, nil -} - -func (r reflectionServiceServer) GetConfigurationDescriptor(_ context.Context, _ *GetConfigurationDescriptorRequest) (*GetConfigurationDescriptorResponse, error) { - return nil, errors.New("this endpoint has been deprecated, please see auth/Bech32Prefix for the data you are seeking") -} - -func (r reflectionServiceServer) GetQueryServicesDescriptor(_ context.Context, _ *GetQueryServicesDescriptorRequest) (*GetQueryServicesDescriptorResponse, error) { - return &GetQueryServicesDescriptorResponse{Queries: r.desc.QueryServices}, nil -} - -func (r reflectionServiceServer) GetTxDescriptor(_ context.Context, _ *GetTxDescriptorRequest) (*GetTxDescriptorResponse, error) { - return &GetTxDescriptorResponse{Tx: r.desc.Tx}, nil -} - -func newReflectionServiceServer(grpcSrv *grpc.Server, conf Config) (reflectionServiceServer, error) { - // set chain descriptor - chainDescriptor := &ChainDescriptor{Id: conf.ChainID} - - // set codec descriptor - codecDescriptor, err := newCodecDescriptor(conf.InterfaceRegistry) - if err != nil { - return reflectionServiceServer{}, fmt.Errorf("unable to create codec descriptor: %w", err) - } - // set query service descriptor - queryServiceDescriptor := newQueryServiceDescriptor(grpcSrv) - // set deliver descriptor - txDescriptor, err := newTxDescriptor(conf.InterfaceRegistry) - if err != nil { - return reflectionServiceServer{}, fmt.Errorf("unable to create deliver descriptor: %w", err) - } - authnDescriptor := newAuthnDescriptor(conf.SigningModes) - desc := &AppDescriptor{ - Authn: authnDescriptor, - Chain: chainDescriptor, - Codec: codecDescriptor, - QueryServices: queryServiceDescriptor, - Tx: txDescriptor, - } - - ifaceList := make([]string, len(desc.Codec.Interfaces)) - ifaceImplementers := make(map[string][]string, len(desc.Codec.Interfaces)) - for i, iface := range desc.Codec.Interfaces { - ifaceList[i] = iface.Fullname - impls := make([]string, len(iface.InterfaceImplementers)) - for j, impl := range iface.InterfaceImplementers { - impls[j] = impl.TypeUrl - } - ifaceImplementers[iface.Fullname] = impls - } - return reflectionServiceServer{ - desc: desc, - }, nil -} - -// newCodecDescriptor describes the codec given the codectypes.InterfaceRegistry -func newCodecDescriptor(ir codectypes.InterfaceRegistry) (*CodecDescriptor, error) { - registeredInterfaces := ir.ListAllInterfaces() - interfaceDescriptors := make([]*InterfaceDescriptor, len(registeredInterfaces)) - - for i, iface := range registeredInterfaces { - implementers := ir.ListImplementations(iface) - interfaceImplementers := make([]*InterfaceImplementerDescriptor, len(implementers)) - for j, implementer := range implementers { - pb, err := ir.Resolve(implementer) - if err != nil { - return nil, fmt.Errorf("unable to resolve implementing type %s for interface %s", implementer, iface) - } - pbName := proto.MessageName(pb) - if pbName == "" { - return nil, fmt.Errorf("unable to get proto name for implementing type %s for interface %s", implementer, iface) - } - interfaceImplementers[j] = &InterfaceImplementerDescriptor{ - Fullname: pbName, - TypeUrl: implementer, - } - } - interfaceDescriptors[i] = &InterfaceDescriptor{ - Fullname: iface, - // NOTE(fdymylja): this could be filled, but it won't be filled as of now - // doing this would require us to fully rebuild in a (dependency) transitive way the proto - // registry of the supported proto.Messages for the application, this could be easily - // done if we weren't relying on gogoproto which does not allow us to iterate over the - // registry. Achieving this right now would mean to start slowly building descriptors - // getting their files dependencies, building those dependencies then rebuilding the - // descriptor builder. It's too much work as of now. - InterfaceAcceptingMessages: nil, - InterfaceImplementers: interfaceImplementers, - } - } - - return &CodecDescriptor{ - Interfaces: interfaceDescriptors, - }, nil -} - -func newQueryServiceDescriptor(srv *grpc.Server) *QueryServicesDescriptor { - svcInfo := srv.GetServiceInfo() - queryServices := make([]*QueryServiceDescriptor, 0, len(svcInfo)) - for name, info := range svcInfo { - methods := make([]*QueryMethodDescriptor, len(info.Methods)) - for i, svcMethod := range info.Methods { - methods[i] = &QueryMethodDescriptor{ - Name: svcMethod.Name, - FullQueryPath: fmt.Sprintf("/%s/%s", name, svcMethod.Name), - } - } - queryServices = append(queryServices, &QueryServiceDescriptor{ - Fullname: name, - Methods: methods, - }) - } - return &QueryServicesDescriptor{QueryServices: queryServices} -} - -func newTxDescriptor(ir codectypes.InterfaceRegistry) (*TxDescriptor, error) { - // get base tx type name - txPbName := proto.MessageName(&tx.Tx{}) - if txPbName == "" { - return nil, errors.New("unable to get *tx.Tx protobuf name") - } - // get msgs - sdkMsgImplementers := ir.ListImplementations(sdk.MsgInterfaceProtoName) - - msgsDesc := make([]*MsgDescriptor, 0, len(sdkMsgImplementers)) - - // process sdk.Msg - for _, msgTypeURL := range sdkMsgImplementers { - msgsDesc = append(msgsDesc, &MsgDescriptor{ - MsgTypeUrl: msgTypeURL, - }) - } - - return &TxDescriptor{ - Fullname: txPbName, - Msgs: msgsDesc, - }, nil -} - -func newAuthnDescriptor(signingModes map[string]int32) *AuthnDescriptor { - signModesDesc := make([]*SigningModeDescriptor, 0, len(signingModes)) - for i, m := range signingModes { - signModesDesc = append(signModesDesc, &SigningModeDescriptor{ - Name: i, - Number: m, - // NOTE(fdymylja): this cannot be filled as of now, auth and the sdk itself don't support as of now - // a service which allows to get authentication metadata for the provided sign mode. - AuthnInfoProviderMethodFullname: "", - }) - } - return &AuthnDescriptor{SignModes: signModesDesc} -} diff --git a/server/grpc/server.go b/server/grpc/server.go deleted file mode 100644 index ae4c376191d2..000000000000 --- a/server/grpc/server.go +++ /dev/null @@ -1,105 +0,0 @@ -package grpc - -import ( - "context" - "fmt" - "net" - - gogogrpcserver "github.com/cosmos/gogoproto/grpc" - "google.golang.org/grpc" - - "cosmossdk.io/log" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/server/config" - "github.com/cosmos/cosmos-sdk/server/grpc/gogoreflection" - reflection "github.com/cosmos/cosmos-sdk/server/grpc/reflection/v2alpha1" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" // Import amino.proto file for reflection -) - -// NewGRPCServer returns a correctly configured and initialized gRPC server. -// Note, the caller is responsible for starting the server. See StartGRPCServer. -func NewGRPCServer(clientCtx client.Context, app interface{ RegisterGRPCServer(gogogrpcserver.Server) }, cfg config.GRPCConfig) (*grpc.Server, error) { - maxSendMsgSize := cfg.MaxSendMsgSize - if maxSendMsgSize == 0 { - maxSendMsgSize = config.DefaultGRPCMaxSendMsgSize - } - - maxRecvMsgSize := cfg.MaxRecvMsgSize - if maxRecvMsgSize == 0 { - maxRecvMsgSize = config.DefaultGRPCMaxRecvMsgSize - } - - grpcSrv := grpc.NewServer( - grpc.ForceServerCodec(codec.NewProtoCodec(clientCtx.InterfaceRegistry).GRPCCodec()), - grpc.MaxSendMsgSize(maxSendMsgSize), - grpc.MaxRecvMsgSize(maxRecvMsgSize), - ) - - app.RegisterGRPCServer(grpcSrv) - - // Reflection allows consumers to build dynamic clients that can write to any - // Cosmos SDK application without relying on application packages at compile - // time. - err := reflection.Register(grpcSrv, reflection.Config{ - SigningModes: func() map[string]int32 { - supportedModes := clientCtx.TxConfig.SignModeHandler().SupportedModes() - modes := make(map[string]int32, len(supportedModes)) - for _, m := range supportedModes { - modes[m.String()] = (int32)(m) - } - - return modes - }(), - ChainID: clientCtx.ChainID, - InterfaceRegistry: clientCtx.InterfaceRegistry, - }) - if err != nil { - return nil, fmt.Errorf("failed to register reflection service: %w", err) - } - - // Reflection allows external clients to see what services and methods - // the gRPC server exposes. - gogoreflection.Register(grpcSrv) - - return grpcSrv, nil -} - -// StartGRPCServer starts the provided gRPC server on the address specified in cfg. -// -// Note, this creates a blocking process if the server is started successfully. -// Otherwise, an error is returned. The caller is expected to provide a Context -// that is properly canceled or closed to indicate the server should be stopped. -func StartGRPCServer(ctx context.Context, logger log.Logger, cfg config.GRPCConfig, grpcSrv *grpc.Server) error { - listener, err := net.Listen("tcp", cfg.Address) - if err != nil { - return fmt.Errorf("failed to listen on address %s: %w", cfg.Address, err) - } - - errCh := make(chan error) - - // Start the gRPC in an external goroutine as Serve is blocking and will return - // an error upon failure, which we'll send on the error channel that will be - // consumed by the for block below. - go func() { - logger.Info("starting gRPC server...", "address", cfg.Address) - errCh <- grpcSrv.Serve(listener) - }() - - // Start a blocking select to wait for an indication to stop the server or that - // the server failed to start properly. - select { - case <-ctx.Done(): - // The calling process canceled or closed the provided context, so we must - // gracefully stop the gRPC server. - logger.Info("stopping gRPC server...", "address", cfg.Address) - grpcSrv.GracefulStop() - - return nil - - case err := <-errCh: - logger.Error("failed to start gRPC server", "err", err) - return err - } -} diff --git a/server/log/cmt_logger.go b/server/log/cmt_logger.go deleted file mode 100644 index 9cc9380372e6..000000000000 --- a/server/log/cmt_logger.go +++ /dev/null @@ -1,23 +0,0 @@ -package server - -import ( - cmtlog "github.com/cometbft/cometbft/libs/log" - - "cosmossdk.io/log" -) - -var _ cmtlog.Logger = (*CometLoggerWrapper)(nil) - -// CometLoggerWrapper provides a wrapper around a cosmossdk.io/log instance. -// It implements CometBFT's Logger interface. -type CometLoggerWrapper struct { - log.Logger -} - -// With returns a new wrapped logger with additional context provided by a set -// of key/value tuples. The number of tuples must be even and the key of the -// tuple must be a string. -func (cmt CometLoggerWrapper) With(keyVals ...interface{}) cmtlog.Logger { - logger := cmt.Logger.With(keyVals...) - return CometLoggerWrapper{logger} -} diff --git a/server/mock/app.go b/server/mock/app.go deleted file mode 100644 index b7357d801638..000000000000 --- a/server/mock/app.go +++ /dev/null @@ -1,220 +0,0 @@ -package mock - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "path/filepath" - - abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" - dbm "github.com/cosmos/cosmos-db" - "google.golang.org/grpc" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protodesc" - "google.golang.org/protobuf/reflect/protoregistry" - "google.golang.org/protobuf/types/descriptorpb" - - "cosmossdk.io/log" - storetypes "cosmossdk.io/store/types" - - bam "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/testutil" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - sdk "github.com/cosmos/cosmos-sdk/types" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" -) - -// NewApp creates a simple mock kvstore app for testing. It should work -// similar to a real app. Make sure rootDir is empty before running the test, -// in order to guarantee consistent results. -func NewApp(rootDir string, logger log.Logger) (servertypes.ABCI, error) { - db, err := dbm.NewGoLevelDB("mock", filepath.Join(rootDir, "data"), nil) - if err != nil { - return nil, err - } - - capKeyMainStore := storetypes.NewKVStoreKey("main") - - baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx) - baseApp.MountStores(capKeyMainStore) - baseApp.SetInitChainer(InitChainer(capKeyMainStore)) - - interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() - interfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &KVStoreTx{}) - baseApp.SetInterfaceRegistry(interfaceRegistry) - - router := bam.NewMsgServiceRouter() - router.SetInterfaceRegistry(interfaceRegistry) - - newDesc := &grpc.ServiceDesc{ - ServiceName: "Test", - Methods: []grpc.MethodDesc{ - { - MethodName: "Test", - Handler: MsgTestHandler, - }, - }, - } - - router.RegisterService(newDesc, &MsgServerImpl{capKeyMainStore}) - baseApp.SetMsgServiceRouter(router) - - if err := baseApp.LoadLatestVersion(); err != nil { - return nil, err - } - - return baseApp, nil -} - -// KVStoreHandler is a simple handler that takes KVStoreTx and writes -// them to the db. -func KVStoreHandler(storeKey storetypes.StoreKey) bam.MsgServiceHandler { - return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - dTx, ok := msg.(*KVStoreTx) - if !ok { - return nil, errors.New("KVStoreHandler should only receive KVStoreTx") - } - - key := dTx.key - value := dTx.value - - store := ctx.KVStore(storeKey) - store.Set(key, value) - - return &sdk.Result{ - Log: fmt.Sprintf("set %s=%s", key, value), - }, nil - } -} - -// KV is a basic kv structure -type KV struct { - Key string `json:"key"` - Value string `json:"value"` -} - -// GenesisJSON what genesis JSON is formatted as -type GenesisJSON struct { - Values []KV `json:"values"` -} - -// InitChainer returns a function that can initialize the chain -// with key/value pairs -func InitChainer(key storetypes.StoreKey) func(sdk.Context, *abci.InitChainRequest) (*abci.InitChainResponse, error) { - return func(ctx sdk.Context, req *abci.InitChainRequest) (*abci.InitChainResponse, error) { - stateJSON := req.AppStateBytes - - genesisState := new(GenesisJSON) - err := json.Unmarshal(stateJSON, genesisState) - if err != nil { - return &abci.InitChainResponse{}, err - } - - for _, val := range genesisState.Values { - store := ctx.KVStore(key) - store.Set([]byte(val.Key), []byte(val.Value)) - } - return &abci.InitChainResponse{}, nil - } -} - -// AppGenState can be passed into InitCmd, returns a static string of a few -// key-values that can be parsed by InitChainer -func AppGenState(_ *codec.LegacyAmino, _ genutiltypes.AppGenesis, _ []json.RawMessage) (appState json.RawMessage, err error) { - appState = json.RawMessage(`{ - "values": [ - { - "key": "hello", - "value": "goodbye" - }, - { - "key": "foo", - "value": "bar" - } - ] -}`) - return -} - -// AppGenStateEmpty returns an empty transaction state for mocking. -func AppGenStateEmpty(_ *codec.LegacyAmino, _ genutiltypes.AppGenesis, _ []json.RawMessage) (appState json.RawMessage, err error) { - appState = json.RawMessage(``) - return -} - -// MsgServer manually write the handlers for this custom message -type MsgServer interface { - Test(ctx context.Context, msg *KVStoreTx) (*sdk.Result, error) -} - -type MsgServerImpl struct { - capKeyMainStore *storetypes.KVStoreKey -} - -func MsgTestHandler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(KVStoreTx) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).Test(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/KVStoreTx", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).Test(ctx, req.(*KVStoreTx)) - } - return interceptor(ctx, in, info, handler) -} - -func (m MsgServerImpl) Test(ctx context.Context, msg *KVStoreTx) (*sdk.Result, error) { - return KVStoreHandler(m.capKeyMainStore)(sdk.UnwrapSDKContext(ctx), msg) -} - -func init() { - err := registerFauxDescriptor() - if err != nil { - panic(err) - } -} - -func registerFauxDescriptor() error { - fauxDescriptor, err := protodesc.NewFile(&descriptorpb.FileDescriptorProto{ - Name: proto.String("faux_proto/test.proto"), - Dependency: nil, - PublicDependency: nil, - WeakDependency: nil, - MessageType: []*descriptorpb.DescriptorProto{ - { - Name: proto.String("KVStoreTx"), - }, - }, - EnumType: nil, - Service: []*descriptorpb.ServiceDescriptorProto{ - { - Name: proto.String("Test"), - Method: []*descriptorpb.MethodDescriptorProto{ - { - Name: proto.String("Test"), - InputType: proto.String("KVStoreTx"), - OutputType: proto.String("KVStoreTx"), - }, - }, - }, - }, - Extension: nil, - Options: nil, - SourceCodeInfo: nil, - Syntax: nil, - Edition: nil, - }, nil) - if err != nil { - return err - } - - return protoregistry.GlobalFiles.RegisterFile(fauxDescriptor) -} diff --git a/server/mock/app_test.go b/server/mock/app_test.go deleted file mode 100644 index c749927c0a8d..000000000000 --- a/server/mock/app_test.go +++ /dev/null @@ -1,99 +0,0 @@ -package mock - -import ( - "context" - "math/rand" - "testing" - "time" - - abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" - "github.com/stretchr/testify/require" - - "cosmossdk.io/log" - - servertypes "github.com/cosmos/cosmos-sdk/server/types" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" -) - -// SetupApp initializes a new application, -// failing t if initialization fails. -func SetupApp(t *testing.T) servertypes.ABCI { - t.Helper() - - logger := log.NewTestLogger(t) - - rootDir := t.TempDir() - - app, err := NewApp(rootDir, logger) - require.NoError(t, err) - - return app -} - -func TestInitApp(t *testing.T) { - app := SetupApp(t) - - appState, err := AppGenState(nil, genutiltypes.AppGenesis{}, nil) - require.NoError(t, err) - - req := abci.InitChainRequest{ - AppStateBytes: appState, - } - res, err := app.InitChain(&req) - require.NoError(t, err) - _, err = app.FinalizeBlock(&abci.FinalizeBlockRequest{ - Hash: res.AppHash, - Height: 1, - }) - require.NoError(t, err) - - _, err = app.Commit() - require.NoError(t, err) - - // make sure we can query these values - query := abci.QueryRequest{ - Path: "/store/main/key", - Data: []byte("foo"), - } - - qres, err := app.Query(context.Background(), &query) - require.NoError(t, err) - require.Equal(t, uint32(0), qres.Code, qres.Log) - require.Equal(t, []byte("bar"), qres.Value) -} - -func TestDeliverTx(t *testing.T) { - app := SetupApp(t) - - key := "my-special-key" - value := "top-secret-data!!" - - r := rand.New(rand.NewSource(time.Now().UnixNano())) - randomAccounts := simtypes.RandomAccounts(r, 1) - - tx := NewTx(key, value, randomAccounts[0].Address) - txBytes := tx.GetSignBytes() - - res, err := app.FinalizeBlock(&abci.FinalizeBlockRequest{ - Hash: []byte("apphash"), - Height: 1, - Txs: [][]byte{txBytes}, - }) - require.NoError(t, err) - require.NotEmpty(t, res.AppHash) - - _, err = app.Commit() - require.NoError(t, err) - - // make sure we can query these values - query := abci.QueryRequest{ - Path: "/store/main/key", - Data: []byte(key), - } - - qres, err := app.Query(context.Background(), &query) - require.NoError(t, err) - require.Equal(t, uint32(0), qres.Code, qres.Log) - require.Equal(t, []byte(value), qres.Value) -} diff --git a/server/mock/store.go b/server/mock/store.go deleted file mode 100644 index 12755c613731..000000000000 --- a/server/mock/store.go +++ /dev/null @@ -1,245 +0,0 @@ -package mock - -import ( - "io" - - protoio "github.com/cosmos/gogoproto/io" - - corestore "cosmossdk.io/core/store" - "cosmossdk.io/store/metrics" - pruningtypes "cosmossdk.io/store/pruning/types" - snapshottypes "cosmossdk.io/store/snapshots/types" - storetypes "cosmossdk.io/store/types" -) - -var _ storetypes.MultiStore = multiStore{} - -type multiStore struct { - kv map[storetypes.StoreKey]kvStore -} - -func (ms multiStore) CacheMultiStore() storetypes.CacheMultiStore { - panic("not implemented") -} - -func (ms multiStore) CacheMultiStoreWithVersion(_ int64) (storetypes.CacheMultiStore, error) { - panic("not implemented") -} - -func (ms multiStore) CacheWrap() storetypes.CacheWrap { - panic("not implemented") -} - -func (ms multiStore) CacheWrapWithTrace(_ io.Writer, _ storetypes.TraceContext) storetypes.CacheWrap { - panic("not implemented") -} - -func (ms multiStore) CacheWrapWithListeners(_ storetypes.StoreKey, _ []storetypes.MemoryListener) storetypes.CacheWrap { - panic("not implemented") -} - -func (ms multiStore) TracingEnabled() bool { - panic("not implemented") -} - -func (ms multiStore) SetTracingContext(tc storetypes.TraceContext) storetypes.MultiStore { - panic("not implemented") -} - -func (ms multiStore) SetTracer(w io.Writer) storetypes.MultiStore { - panic("not implemented") -} - -func (ms multiStore) AddListeners(keys []storetypes.StoreKey) { - panic("not implemented") -} - -func (ms multiStore) SetMetrics(metrics.StoreMetrics) { - panic("not implemented") -} - -func (ms multiStore) ListeningEnabled(key storetypes.StoreKey) bool { - panic("not implemented") -} - -func (ms multiStore) PopStateCache() []*storetypes.StoreKVPair { - panic("not implemented") -} - -func (ms multiStore) Commit() storetypes.CommitID { - panic("not implemented") -} - -func (ms multiStore) LastCommitID() storetypes.CommitID { - panic("not implemented") -} - -func (ms multiStore) SetPruning(opts pruningtypes.PruningOptions) { - panic("not implemented") -} - -func (ms multiStore) GetPruning() pruningtypes.PruningOptions { - panic("not implemented") -} - -func (ms multiStore) GetCommitKVStore(key storetypes.StoreKey) storetypes.CommitKVStore { - panic("not implemented") -} - -func (ms multiStore) GetCommitStore(key storetypes.StoreKey) storetypes.CommitStore { - panic("not implemented") -} - -func (ms multiStore) MountStoreWithDB(key storetypes.StoreKey, typ storetypes.StoreType, db corestore.KVStoreWithBatch) { - ms.kv[key] = kvStore{store: make(map[string][]byte)} -} - -func (ms multiStore) LoadLatestVersion() error { - return nil -} - -func (ms multiStore) LoadLatestVersionAndUpgrade(upgrades *storetypes.StoreUpgrades) error { - return nil -} - -func (ms multiStore) LoadVersionAndUpgrade(ver int64, upgrades *storetypes.StoreUpgrades) error { - panic("not implemented") -} - -func (ms multiStore) LoadVersion(ver int64) error { - panic("not implemented") -} - -func (ms multiStore) GetKVStore(key storetypes.StoreKey) storetypes.KVStore { - return ms.kv[key] -} - -func (ms multiStore) GetStore(key storetypes.StoreKey) storetypes.Store { - panic("not implemented") -} - -func (ms multiStore) GetStoreType() storetypes.StoreType { - panic("not implemented") -} - -func (ms multiStore) PruneSnapshotHeight(height int64) { - panic("not implemented") -} - -func (ms multiStore) SetSnapshotInterval(snapshotInterval uint64) { - panic("not implemented") -} - -func (ms multiStore) SetInterBlockCache(_ storetypes.MultiStorePersistentCache) { - panic("not implemented") -} - -func (ms multiStore) SetIAVLCacheSize(size int) { - panic("not implemented") -} - -func (ms multiStore) SetIAVLDisableFastNode(disable bool) { - panic("not implemented") -} - -func (ms multiStore) SetIAVLSyncPruning(syncPruning bool) { - panic("not implemented") -} - -func (ms multiStore) SetInitialVersion(version int64) error { - panic("not implemented") -} - -func (ms multiStore) Snapshot(height uint64, protoWriter protoio.Writer) error { - panic("not implemented") -} - -func (ms multiStore) Restore( - height uint64, format uint32, protoReader protoio.Reader, -) (snapshottypes.SnapshotItem, error) { - panic("not implemented") -} - -func (ms multiStore) RollbackToVersion(version int64) error { - panic("not implemented") -} - -func (ms multiStore) LatestVersion() int64 { - panic("not implemented") -} - -func (ms multiStore) WorkingHash() []byte { - panic("not implemented") -} - -var _ storetypes.KVStore = kvStore{} - -type kvStore struct { - store map[string][]byte -} - -func (kv kvStore) CacheWrap() storetypes.CacheWrap { - panic("not implemented") -} - -func (kv kvStore) CacheWrapWithTrace(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap { - panic("not implemented") -} - -func (kv kvStore) CacheWrapWithListeners(_ storetypes.StoreKey, _ []storetypes.MemoryListener) storetypes.CacheWrap { - panic("not implemented") -} - -func (kv kvStore) GetStoreType() storetypes.StoreType { - panic("not implemented") -} - -func (kv kvStore) Get(key []byte) []byte { - v, ok := kv.store[string(key)] - if !ok { - return nil - } - return v -} - -func (kv kvStore) Has(key []byte) bool { - _, ok := kv.store[string(key)] - return ok -} - -func (kv kvStore) Set(key, value []byte) { - storetypes.AssertValidKey(key) - kv.store[string(key)] = value -} - -func (kv kvStore) Delete(key []byte) { - delete(kv.store, string(key)) -} - -func (kv kvStore) Prefix(prefix []byte) storetypes.KVStore { - panic("not implemented") -} - -func (kv kvStore) Gas(meter storetypes.GasMeter, config storetypes.GasConfig) storetypes.KVStore { - panic("not implemented") -} - -func (kv kvStore) Iterator(start, end []byte) storetypes.Iterator { - panic("not implemented") -} - -func (kv kvStore) ReverseIterator(start, end []byte) storetypes.Iterator { - panic("not implemented") -} - -func (kv kvStore) SubspaceIterator(prefix []byte) storetypes.Iterator { - panic("not implemented") -} - -func (kv kvStore) ReverseSubspaceIterator(prefix []byte) storetypes.Iterator { - panic("not implemented") -} - -func NewCommitMultiStore() storetypes.CommitMultiStore { - return multiStore{kv: make(map[storetypes.StoreKey]kvStore)} -} diff --git a/server/mock/store_test.go b/server/mock/store_test.go deleted file mode 100644 index 7e1376ea6bcf..000000000000 --- a/server/mock/store_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package mock - -import ( - "testing" - - "github.com/stretchr/testify/require" - - coretesting "cosmossdk.io/core/testing" - storetypes "cosmossdk.io/store/types" -) - -func TestStore(t *testing.T) { - db := coretesting.NewMemDB() - - cms := NewCommitMultiStore() - - key := storetypes.NewKVStoreKey("test") - cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) - err := cms.LoadLatestVersion() - require.Nil(t, err) - - store := cms.GetKVStore(key) - require.NotNil(t, store) - - k := []byte("hello") - v := []byte("world") - require.False(t, store.Has(k)) - store.Set(k, v) - require.True(t, store.Has(k)) - require.Equal(t, v, store.Get(k)) - store.Delete(k) - require.False(t, store.Has(k)) - require.Panics(t, func() { store.Set([]byte(""), v) }, "setting an empty key should panic") - require.Panics(t, func() { store.Set(nil, v) }, "setting a nil key should panic") -} diff --git a/server/mock/tx.go b/server/mock/tx.go deleted file mode 100644 index 22a709452b0a..000000000000 --- a/server/mock/tx.go +++ /dev/null @@ -1,163 +0,0 @@ -package mock - -import ( - "bytes" - "fmt" - - "google.golang.org/protobuf/reflect/protoreflect" - - bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" - "cosmossdk.io/core/transaction" - errorsmod "cosmossdk.io/errors" - - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - txsigning "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/cosmos/cosmos-sdk/x/auth/signing" -) - -// KVStoreTx is an sdk.Tx which is its own sdk.Msg. -type KVStoreTx struct { - key []byte - value []byte - bytes []byte - address sdk.AccAddress -} - -// testPubKey is a dummy implementation of PubKey used for testing. -type testPubKey struct { - address sdk.AccAddress -} - -func (t testPubKey) Reset() { panic("not implemented") } - -func (t testPubKey) String() string { panic("not implemented") } - -func (t testPubKey) ProtoMessage() { panic("not implemented") } - -func (t testPubKey) Address() cryptotypes.Address { return t.address.Bytes() } - -func (t testPubKey) Bytes() []byte { panic("not implemented") } - -func (t testPubKey) VerifySignature(msg, sig []byte) bool { panic("not implemented") } - -func (t testPubKey) Equals(key cryptotypes.PubKey) bool { panic("not implemented") } - -func (t testPubKey) Type() string { panic("not implemented") } - -func (msg *KVStoreTx) GetSignaturesV2() (res []txsigning.SignatureV2, err error) { - res = append(res, txsigning.SignatureV2{ - PubKey: testPubKey{address: msg.address}, - Data: nil, - Sequence: 1, - }) - - return res, nil -} - -func (msg *KVStoreTx) VerifySignature(msgByte, sig []byte) bool { - panic("implement me") -} - -func (msg *KVStoreTx) Address() cryptotypes.Address { - panic("implement me") -} - -func (msg *KVStoreTx) Bytes() []byte { - panic("implement me") -} - -func (msg *KVStoreTx) Equals(key cryptotypes.PubKey) bool { - panic("implement me") -} - -// dummy implementation of proto.Message - -func (msg *KVStoreTx) Reset() {} -func (msg *KVStoreTx) String() string { return "TODO" } -func (msg *KVStoreTx) ProtoMessage() {} - -var ( - _ sdk.Tx = &KVStoreTx{} - _ sdk.Msg = &KVStoreTx{} - _ signing.SigVerifiableTx = &KVStoreTx{} - _ cryptotypes.PubKey = &KVStoreTx{} - _ cryptotypes.PubKey = &testPubKey{} -) - -func NewTx(key, value string, accAddress sdk.AccAddress) *KVStoreTx { - bytes := fmt.Sprintf("%s=%s=%s", key, value, accAddress) - return &KVStoreTx{ - key: []byte(key), - value: []byte(value), - bytes: []byte(bytes), - address: accAddress, - } -} - -func (msg *KVStoreTx) Hash() [32]byte { - return [32]byte{} -} - -func (msg *KVStoreTx) GetGasLimit() (uint64, error) { - return 0, nil -} - -func (msg *KVStoreTx) GetMessages() ([]transaction.Msg, error) { - return nil, nil -} - -func (msg *KVStoreTx) GetSenders() ([][]byte, error) { - return nil, nil -} - -func (msg *KVStoreTx) Type() string { - return "kvstore_tx" -} - -func (msg *KVStoreTx) GetMsgs() []sdk.Msg { - return []sdk.Msg{msg} -} - -func (msg *KVStoreTx) GetReflectMessages() ([]protoreflect.Message, error) { - return []protoreflect.Message{(&bankv1beta1.MsgSend{FromAddress: msg.address.String()}).ProtoReflect()}, nil // this is a hack for tests -} - -func (msg *KVStoreTx) GetSignBytes() []byte { - return msg.bytes -} - -// ValidateBasic should the app be calling this? or only handlers? -func (msg *KVStoreTx) ValidateBasic() error { - return nil -} - -func (msg *KVStoreTx) GetSigners() ([][]byte, error) { - return nil, nil -} - -func (msg *KVStoreTx) GetPubKeys() ([]cryptotypes.PubKey, error) { panic("GetPubKeys not implemented") } - -// takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has -// all the signatures and can be used to authenticate. -func decodeTx(txBytes []byte) (sdk.Tx, error) { - var tx sdk.Tx - - split := bytes.Split(txBytes, []byte("=")) - switch len(split) { - case 1: - k := split[0] - tx = &KVStoreTx{k, k, txBytes, nil} - case 2: - k, v := split[0], split[1] - tx = &KVStoreTx{k, v, txBytes, nil} - case 3: - k, v, addr := split[0], split[1], split[2] - tx = &KVStoreTx{k, v, txBytes, addr} - default: - return nil, errorsmod.Wrap(sdkerrors.ErrTxDecode, "too many '='") - } - - return tx, nil -} diff --git a/server/types/abci.go b/server/types/abci.go deleted file mode 100644 index 33e73a4938bb..000000000000 --- a/server/types/abci.go +++ /dev/null @@ -1,49 +0,0 @@ -package types - -import ( - "context" - - abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" -) - -// ABCI is an interface that enables any finite, deterministic state machine -// to be driven by a blockchain-based replication engine via the ABCI. -type ABCI interface { - // Info/Query Connection - - // Info returns application info - Info(*abci.InfoRequest) (*abci.InfoResponse, error) - // Query returns application state - Query(context.Context, *abci.QueryRequest) (*abci.QueryResponse, error) - - // Mempool Connection - - // CheckTx validate a tx for the mempool - CheckTx(*abci.CheckTxRequest) (*abci.CheckTxResponse, error) - - // Consensus Connection - - // InitChain Initialize blockchain w validators/other info from CometBFT - InitChain(*abci.InitChainRequest) (*abci.InitChainResponse, error) - PrepareProposal(*abci.PrepareProposalRequest) (*abci.PrepareProposalResponse, error) - ProcessProposal(*abci.ProcessProposalRequest) (*abci.ProcessProposalResponse, error) - // FinalizeBlock deliver the decided block with its txs to the Application - FinalizeBlock(*abci.FinalizeBlockRequest) (*abci.FinalizeBlockResponse, error) - // ExtendVote create application specific vote extension - ExtendVote(context.Context, *abci.ExtendVoteRequest) (*abci.ExtendVoteResponse, error) - // VerifyVoteExtension verify application's vote extension data - VerifyVoteExtension(*abci.VerifyVoteExtensionRequest) (*abci.VerifyVoteExtensionResponse, error) - // Commit the state and return the application Merkle root hash - Commit() (*abci.CommitResponse, error) - - // State Sync Connection - - // ListSnapshots list available snapshots - ListSnapshots(*abci.ListSnapshotsRequest) (*abci.ListSnapshotsResponse, error) - // OfferSnapshot offer a snapshot to the application - OfferSnapshot(*abci.OfferSnapshotRequest) (*abci.OfferSnapshotResponse, error) - // LoadSnapshotChunk load a snapshot chunk - LoadSnapshotChunk(*abci.LoadSnapshotChunkRequest) (*abci.LoadSnapshotChunkResponse, error) - // ApplySnapshotChunk apply a snapshot chunk - ApplySnapshotChunk(*abci.ApplySnapshotChunkRequest) (*abci.ApplySnapshotChunkResponse, error) -} diff --git a/server/types/app.go b/server/types/app.go deleted file mode 100644 index 38a96c19a9a3..000000000000 --- a/server/types/app.go +++ /dev/null @@ -1,95 +0,0 @@ -package types - -import ( - "encoding/json" - "io" - - cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1" - cmtcrypto "github.com/cometbft/cometbft/crypto" - "github.com/cosmos/gogoproto/grpc" - - "cosmossdk.io/core/server" - corestore "cosmossdk.io/core/store" - "cosmossdk.io/log" - "cosmossdk.io/store/snapshots" - storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/server/config" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type ( - // AppOptions defines an interface that is passed into an application - // constructor, typically used to set BaseApp options that are either supplied - // via config file or through CLI arguments/flags. The underlying implementation - // is defined by the server package and is typically implemented via a Viper - // literal defined on the server Context. Note, casting Get calls may not yield - // the expected types and could result in type assertion errors. It is recommend - // to either use the cast package or perform manual conversion for safety. - AppOptions = server.DynamicConfig - - // Application defines an application interface that wraps abci.Application. - // The interface defines the necessary contracts to be implemented in order - // to fully bootstrap and start an application. - Application interface { - ABCI - - // RegisterGRPCServer registers gRPC services directly with the gRPC - // server. - RegisterGRPCServer(grpc.Server) - - // RegisterTxService registers the gRPC Query service for tx (such as tx - // simulation, fetching txs by hash...). - RegisterTxService(client.Context) - - // RegisterTendermintService registers the gRPC Query service for CometBFT queries. - RegisterTendermintService(client.Context) - - // RegisterNodeService registers the node gRPC Query service. - RegisterNodeService(client.Context, config.Config) - - // CommitMultiStore return the multistore instance - CommitMultiStore() storetypes.CommitMultiStore - - // SnapshotManager return the snapshot manager - SnapshotManager() *snapshots.Manager - - // ValidatorKeyProvider returns a function that generates a validator key - ValidatorKeyProvider() func() (cmtcrypto.PrivKey, error) - - // Close is called in start cmd to gracefully cleanup resources. - // Must be safe to be called multiple times. - Close() error - } - - // AppCreator is a function that allows us to lazily initialize an - // application using various configurations. - AppCreator[T Application] func(log.Logger, corestore.KVStoreWithBatch, io.Writer, AppOptions) T - - // ExportedApp represents an exported app state, along with - // validators, consensus params and latest app height. - ExportedApp struct { - // AppState is the application state as JSON. - AppState json.RawMessage - // Validators is the exported validator set. - Validators []sdk.GenesisValidator - // Height is the app's latest block height. - Height int64 - // ConsensusParams are the exported consensus params for ABCI. - ConsensusParams cmtproto.ConsensusParams - } - - // AppExporter is a function that dumps all app state to - // JSON-serializable structure and returns the current validator set. - AppExporter func( - logger log.Logger, - db corestore.KVStoreWithBatch, - traceWriter io.Writer, - height int64, - forZeroHeight bool, - jailAllowedAddrs []string, - opts AppOptions, - modulesToExport []string, - ) (ExportedApp, error) -) diff --git a/server/v2/store/commands.go b/server/v2/store/commands.go index efb6b9b7b66b..3ebe6e6ecba6 100644 --- a/server/v2/store/commands.go +++ b/server/v2/store/commands.go @@ -26,8 +26,8 @@ The pruning option is provided via the 'pruning' argument or alternatively with - custom: allow pruning options to be manually specified through 'pruning-keep-recent' Note: When the --app-db-backend flag is not specified, the default backend type is 'goleveldb'. -Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, - Example: fmt.Sprintf("%s prune custom --pruning-keep-recent 100 --app-db-backend 'goleveldb'", ""), +Supported app-db-backend types include 'goleveldb', 'pebbledb'.`, + Example: " prune custom --pruning-keep-recent 100 --app-db-backend 'goleveldb'", Args: cobra.RangeArgs(0, 1), RunE: func(cmd *cobra.Command, args []string) error { // bind flags to the Context's Viper so we can get pruning options. diff --git a/server/v2/testdata/config.toml b/server/v2/testdata/config.toml index d42fa7f98d3c..0d4d4a0939d2 100644 --- a/server/v2/testdata/config.toml +++ b/server/v2/testdata/config.toml @@ -21,25 +21,13 @@ proxy_app = "tcp://127.0.0.1:26658" # A custom human readable name for this node moniker = "aurn-node" -# Database backend: goleveldb | cleveldb | boltdb | rocksdb | badgerdb +# Database backend: goleveldb | pebbledb # * goleveldb (github.com/syndtr/goleveldb - most popular implementation) # - pure go # - stable -# * cleveldb (uses levigo wrapper) -# - fast -# - requires gcc -# - use cleveldb build tag (go build -tags cleveldb) -# * boltdb (uses etcd's fork of bolt - github.com/etcd-io/bbolt) -# - EXPERIMENTAL -# - may be faster is some use-cases (random reads - indexer) -# - use boltdb build tag (go build -tags boltdb) -# * rocksdb (uses github.com/tecbot/gorocksdb) -# - EXPERIMENTAL -# - requires gcc -# - use rocksdb build tag (go build -tags rocksdb) -# * badgerdb (uses github.com/dgraph-io/badger) -# - EXPERIMENTAL -# - use badgerdb build tag (go build -tags badgerdb) +# * pebbledb (uses github.com/cockroachdb/pebble) +# - stable +# - pure go db_backend = "goleveldb" # Database directory diff --git a/simsx/runner.go b/simsx/runner.go index 83d6a0b292dd..86992617eac0 100644 --- a/simsx/runner.go +++ b/simsx/runner.go @@ -11,6 +11,7 @@ import ( dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" + "cosmossdk.io/core/server" corestore "cosmossdk.io/core/store" "cosmossdk.io/log" @@ -19,8 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/server" - servertypes "github.com/cosmos/cosmos-sdk/server/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -77,7 +76,7 @@ func Run[T SimulationApp]( db corestore.KVStoreWithBatch, traceStore io.Writer, loadLatest bool, - appOpts servertypes.AppOptions, + appOpts server.DynamicConfig, baseAppOptions ...func(*baseapp.BaseApp), ) T, setupStateFactory func(app T) SimStateFactory, @@ -103,7 +102,7 @@ func RunWithSeeds[T SimulationApp]( db corestore.KVStoreWithBatch, traceStore io.Writer, loadLatest bool, - appOpts servertypes.AppOptions, + appOpts server.DynamicConfig, baseAppOptions ...func(*baseapp.BaseApp), ) T, setupStateFactory func(app T) SimStateFactory, @@ -123,7 +122,7 @@ func RunWithSeedsAndRandAcc[T SimulationApp]( db corestore.KVStoreWithBatch, traceStore io.Writer, loadLatest bool, - appOpts servertypes.AppOptions, + appOpts server.DynamicConfig, baseAppOptions ...func(*baseapp.BaseApp), ) T, setupStateFactory func(app T) SimStateFactory, @@ -153,7 +152,7 @@ func RunWithSeedsAndRandAcc[T SimulationApp]( func RunWithSeed[T SimulationApp]( tb testing.TB, cfg simtypes.Config, - appFactory func(logger log.Logger, db corestore.KVStoreWithBatch, traceStore io.Writer, loadLatest bool, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp)) T, + appFactory func(logger log.Logger, db corestore.KVStoreWithBatch, traceStore io.Writer, loadLatest bool, appOpts server.DynamicConfig, baseAppOptions ...func(*baseapp.BaseApp)) T, setupStateFactory func(app T) SimStateFactory, seed int64, fuzzSeed []byte, @@ -167,7 +166,7 @@ func RunWithSeed[T SimulationApp]( func RunWithSeedAndRandAcc[T SimulationApp]( tb testing.TB, cfg simtypes.Config, - appFactory func(logger log.Logger, db corestore.KVStoreWithBatch, traceStore io.Writer, loadLatest bool, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp)) T, + appFactory func(logger log.Logger, db corestore.KVStoreWithBatch, traceStore io.Writer, loadLatest bool, appOpts server.DynamicConfig, baseAppOptions ...func(*baseapp.BaseApp)) T, setupStateFactory func(app T) SimStateFactory, seed int64, fuzzSeed []byte, @@ -330,7 +329,7 @@ func prepareWeightedOps( func NewSimulationAppInstance[T SimulationApp]( tb testing.TB, tCfg simtypes.Config, - appFactory func(logger log.Logger, db corestore.KVStoreWithBatch, traceStore io.Writer, loadLatest bool, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp)) T, + appFactory func(logger log.Logger, db corestore.KVStoreWithBatch, traceStore io.Writer, loadLatest bool, appOpts server.DynamicConfig, baseAppOptions ...func(*baseapp.BaseApp)) T, ) TestInstance[T] { tb.Helper() workDir := tb.TempDir() @@ -350,7 +349,7 @@ func NewSimulationAppInstance[T SimulationApp]( }) appOptions := make(simtestutil.AppOptionsMap) appOptions[flags.FlagHome] = workDir - appOptions[server.FlagInvCheckPeriod] = cli.FlagPeriodValue + appOptions[flags.FlagInvCheckPeriod] = cli.FlagPeriodValue opts := []func(*baseapp.BaseApp){baseapp.SetChainID(tCfg.ChainID)} if tCfg.FauxMerkle { opts = append(opts, FauxMerkleModeOpt) diff --git a/store/v2/CHANGELOG.md b/store/v2/CHANGELOG.md index ccc53fee4ded..82c6488d3709 100644 --- a/store/v2/CHANGELOG.md +++ b/store/v2/CHANGELOG.md @@ -25,6 +25,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### API Breaking + +* [#23157](https://github.com/cosmos/cosmos-sdk/pull/23157) Remove support for RocksDB. + ## [v2.0.0-beta.1](https://github.com/cosmos/cosmos-sdk/releases/tag/store/v2.0.0-beta.1) Initial tag of `cosmossdk.io/store/v2`. diff --git a/store/v2/db/pebbledb.go b/store/v2/db/pebbledb.go index e6f4d67a97bd..62f35b47e485 100644 --- a/store/v2/db/pebbledb.go +++ b/store/v2/db/pebbledb.go @@ -228,6 +228,9 @@ func (itr *pebbleDBIterator) Error() error { } func (itr *pebbleDBIterator) Close() error { + if itr.source == nil { + return nil + } err := itr.source.Close() itr.source = nil itr.valid = false diff --git a/server/cmt_abci.go b/tests/integration/genutil/cmt_abci.go similarity index 91% rename from server/cmt_abci.go rename to tests/integration/genutil/cmt_abci.go index 2e2ca9f0a8ca..e0ba7707504f 100644 --- a/server/cmt_abci.go +++ b/tests/integration/genutil/cmt_abci.go @@ -1,20 +1,14 @@ -package server +package genutil import ( "context" - abci "github.com/cometbft/cometbft/abci/types" abciproto "github.com/cometbft/cometbft/api/cometbft/abci/v1" - - servertypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/runtime" ) type cometABCIWrapper struct { - app servertypes.ABCI -} - -func NewCometABCIWrapper(app servertypes.ABCI) abci.Application { - return cometABCIWrapper{app: app} + app *runtime.App } func (w cometABCIWrapper) Info(_ context.Context, req *abciproto.InfoRequest) (*abciproto.InfoResponse, error) { diff --git a/tests/integration/genutil/init_test.go b/tests/integration/genutil/init_test.go index a1027a56fe1a..01414b118f81 100644 --- a/tests/integration/genutil/init_test.go +++ b/tests/integration/genutil/init_test.go @@ -1,12 +1,9 @@ package genutil import ( - "bytes" "context" "fmt" - "io" "net" - "os" "testing" "time" @@ -15,7 +12,11 @@ import ( "github.com/stretchr/testify/require" corectx "cosmossdk.io/core/context" + "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" + _ "cosmossdk.io/x/bank" + _ "cosmossdk.io/x/consensus" "cosmossdk.io/x/staking" "github.com/cosmos/cosmos-sdk/client" @@ -24,16 +25,16 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - "github.com/cosmos/cosmos-sdk/server" - servercmtlog "github.com/cosmos/cosmos-sdk/server/log" - "github.com/cosmos/cosmos-sdk/server/mock" "github.com/cosmos/cosmos-sdk/testutil" + "github.com/cosmos/cosmos-sdk/testutil/configurator" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" genutilhelpers "github.com/cosmos/cosmos-sdk/testutil/x/genutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + _ "github.com/cosmos/cosmos-sdk/x/validate" ) var testMbm = module.NewManager( @@ -159,76 +160,88 @@ func TestInitDefaultBondDenom(t *testing.T) { } func TestEmptyState(t *testing.T) { - home := t.TempDir() - logger := log.NewNopLogger() - viper := viper.New() - - err := writeAndTrackDefaultConfig(viper, home) - require.NoError(t, err) - interfaceRegistry := types.NewInterfaceRegistry() - marshaler := codec.NewProtoCodec(interfaceRegistry) - clientCtx := client.Context{}. - WithCodec(marshaler). - WithLegacyAmino(makeAminoCodec()). - WithHomeDir(home) - - ctx := context.Background() - ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) - - cmd := genutilcli.InitCmd(testMbm) - cmd.SetArgs([]string{"appnode-test"}) - - require.NoError(t, cmd.ExecuteContext(ctx)) - - old := os.Stdout - r, w, _ := os.Pipe() - os.Stdout = w - - cmd = genutilcli.ExportCmd(nil) - require.NoError(t, cmd.ExecuteContext(ctx)) - - outC := make(chan string) - go func() { - var buf bytes.Buffer - _, err := io.Copy(&buf, r) - require.NoError(t, err) - - outC <- buf.String() - }() - - w.Close() - os.Stdout = old - out := <-outC - - require.Contains(t, out, "genesis_time") - require.Contains(t, out, "chain_id") - require.Contains(t, out, "consensus") - require.Contains(t, out, "app_hash") - require.Contains(t, out, "app_state") + // TODO: rewrite for v2: https://github.com/cosmos/cosmos-sdk/issues/20799 + + // home := t.TempDir() + // logger := log.NewNopLogger() + // viper := viper.New() + + // err := writeAndTrackDefaultConfig(viper, home) + // require.NoError(t, err) + // interfaceRegistry := types.NewInterfaceRegistry() + // marshaler := codec.NewProtoCodec(interfaceRegistry) + // clientCtx := client.Context{}. + // WithCodec(marshaler). + // WithLegacyAmino(makeAminoCodec()). + // WithHomeDir(home) + + // ctx := context.Background() + // ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) + // ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + // ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + + // cmd := genutilcli.InitCmd(testMbm) + // cmd.SetArgs([]string{"appnode-test"}) + + // require.NoError(t, cmd.ExecuteContext(ctx)) + + // old := os.Stdout + // r, w, _ := os.Pipe() + // os.Stdout = w + + // cmd = genutilcli.ExportCmd(nil) + // require.NoError(t, cmd.ExecuteContext(ctx)) + + // outC := make(chan string) + // go func() { + // var buf bytes.Buffer + // _, err := io.Copy(&buf, r) + // require.NoError(t, err) + + // outC <- buf.String() + // }() + + // w.Close() + // os.Stdout = old + // out := <-outC + + // require.Contains(t, out, "genesis_time") + // require.Contains(t, out, "chain_id") + // require.Contains(t, out, "consensus") + // require.Contains(t, out, "app_hash") + // require.Contains(t, out, "app_state") } func TestStartStandAlone(t *testing.T) { home := t.TempDir() - logger := log.NewNopLogger() interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) err := genutilhelpers.ExecInitCmd(testMbm, home, marshaler) require.NoError(t, err) - app, err := mock.NewApp(home, logger) + app, err := simtestutil.SetupWithConfiguration( + depinject.Configs( + configurator.NewAppConfig( + configurator.AccountsModule(), + configurator.AuthModule(), + configurator.StakingModule(), + configurator.TxModule(), + configurator.ValidateModule(), + configurator.ConsensusModule(), + configurator.BankModule(), + ), + depinject.Supply(log.NewNopLogger()), + ), simtestutil.DefaultStartUpConfig()) require.NoError(t, err) svrAddr, _, closeFn, err := freeTCPAddr() require.NoError(t, err) require.NoError(t, closeFn()) - cmtApp := server.NewCometABCIWrapper(app) + cmtApp := cometABCIWrapper{app} svr, err := abci_server.NewServer(svrAddr, "socket", cmtApp) require.NoError(t, err, "error creating listener") - svr.SetLogger(servercmtlog.CometLoggerWrapper{Logger: logger.With("module", "abci-server")}) err = svr.Start() require.NoError(t, err) @@ -253,51 +266,53 @@ func TestInitNodeValidatorFiles(t *testing.T) { } func TestInitConfig(t *testing.T) { - home := t.TempDir() - logger := log.NewNopLogger() - viper := viper.New() - - err := writeAndTrackDefaultConfig(viper, home) - require.NoError(t, err) - interfaceRegistry := types.NewInterfaceRegistry() - marshaler := codec.NewProtoCodec(interfaceRegistry) - clientCtx := client.Context{}. - WithCodec(marshaler). - WithLegacyAmino(makeAminoCodec()). - WithChainID("foo"). // add chain-id to clientCtx - WithHomeDir(home) - - ctx := context.Background() - ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) - ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) - ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) - - cmd := genutilcli.InitCmd(testMbm) - cmd.SetArgs([]string{"testnode"}) - - err = cmd.ExecuteContext(ctx) - require.NoError(t, err) - - old := os.Stdout - r, w, _ := os.Pipe() - os.Stdout = w - - cmd = genutilcli.ExportCmd(nil) - require.NoError(t, cmd.ExecuteContext(ctx)) - - outC := make(chan string) - go func() { - var buf bytes.Buffer - _, err := io.Copy(&buf, r) - require.NoError(t, err) - outC <- buf.String() - }() - - w.Close() - os.Stdout = old - out := <-outC - - require.Contains(t, out, "\"chain_id\": \"foo\"") + // TODO: rewrite for v2: https://github.com/cosmos/cosmos-sdk/issues/20799 + + // home := t.TempDir() + // logger := log.NewNopLogger() + // viper := viper.New() + + // err := writeAndTrackDefaultConfig(viper, home) + // require.NoError(t, err) + // interfaceRegistry := types.NewInterfaceRegistry() + // marshaler := codec.NewProtoCodec(interfaceRegistry) + // clientCtx := client.Context{}. + // WithCodec(marshaler). + // WithLegacyAmino(makeAminoCodec()). + // WithChainID("foo"). // add chain-id to clientCtx + // WithHomeDir(home) + + // ctx := context.Background() + // ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) + // ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + // ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + + // cmd := genutilcli.InitCmd(testMbm) + // cmd.SetArgs([]string{"testnode"}) + + // err = cmd.ExecuteContext(ctx) + // require.NoError(t, err) + + // old := os.Stdout + // r, w, _ := os.Pipe() + // os.Stdout = w + + // cmd = genutilcli.ExportCmd(nil) + // require.NoError(t, cmd.ExecuteContext(ctx)) + + // outC := make(chan string) + // go func() { + // var buf bytes.Buffer + // _, err := io.Copy(&buf, r) + // require.NoError(t, err) + // outC <- buf.String() + // }() + + // w.Close() + // os.Stdout = old + // out := <-outC + + // require.Contains(t, out, "\"chain_id\": \"foo\"") } func TestInitWithHeight(t *testing.T) { diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index ca8ea20b31e1..f975783a946c 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -11,6 +11,7 @@ import ( cmtjson "github.com/cometbft/cometbft/libs/json" cmttypes "github.com/cometbft/cometbft/types" + "cosmossdk.io/core/server" corestore "cosmossdk.io/core/store" coretesting "cosmossdk.io/core/testing" "cosmossdk.io/depinject" @@ -24,7 +25,6 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" - servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/testutil/mock" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -312,7 +312,7 @@ func (m AppOptionsMap) GetString(key string) string { return v.(string) } -func NewAppOptionsWithFlagHome(homePath string) servertypes.AppOptions { +func NewAppOptionsWithFlagHome(homePath string) server.DynamicConfig { return AppOptionsMap{ flags.FlagHome: homePath, } diff --git a/tools/confix/CHANGELOG.md b/tools/confix/CHANGELOG.md index fcc19640386a..7cbc348c71ab 100644 --- a/tools/confix/CHANGELOG.md +++ b/tools/confix/CHANGELOG.md @@ -31,6 +31,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +* [#23238](https://github.com/cosmos/cosmos-sdk/pull/23238) Loosen `app.toml` validation for consistency between baseapp chains and v2 chains. + ## [v0.2.0-rc.1](https://github.com/cosmos/cosmos-sdk/releases/tag/tools/confix/v0.2.0-rc.1) - 2024-12-18 * [#21052](https://github.com/cosmos/cosmos-sdk/pull/21052) Add a migration to v2 config. diff --git a/tools/confix/upgrade.go b/tools/confix/upgrade.go index d0ced95da66f..29fdb51111e1 100644 --- a/tools/confix/upgrade.go +++ b/tools/confix/upgrade.go @@ -14,7 +14,6 @@ import ( "github.com/spf13/viper" clientcfg "github.com/cosmos/cosmos-sdk/client/config" - srvcfg "github.com/cosmos/cosmos-sdk/server/config" ) // Upgrade reads the configuration file at configPath and applies any @@ -43,11 +42,8 @@ func Upgrade(ctx context.Context, plan transform.Plan, doc *tomledit.Document, c return fmt.Errorf("formatting config: %w", err) } - // ignore validation for serverv2 by checking any default field found in doc - isServerV2 := doc.First(strings.Split("store.options.sc-pruning-option", ".")...) != nil - // allow to skip validation - if !skipValidate && !isServerV2 { + if !skipValidate { // verify that file is valid after applying fixes if err := CheckValid(configPath, buf.Bytes()); err != nil { return fmt.Errorf("updated config is invalid: %w", err) @@ -76,14 +72,8 @@ func CheckValid(fileName string, data []byte) error { switch { case strings.HasSuffix(fileName, AppConfig): - var cfg srvcfg.Config - if err := v.Unmarshal(&cfg); err != nil { - return fmt.Errorf("failed to unmarshal as server config: %w", err) - } - - if err := cfg.ValidateBasic(); err != nil { - return fmt.Errorf("server config invalid: %w", err) - } + // no validation of server config as v1 and v2 configs are both valid. + // any app.toml is simply considered as a server config. case strings.HasSuffix(fileName, ClientConfig): var cfg clientcfg.ClientConfig if err := v.Unmarshal(&cfg); err != nil { diff --git a/tools/confix/upgrade_test.go b/tools/confix/upgrade_test.go index 3a6cbafee6ef..6583e41bc67a 100644 --- a/tools/confix/upgrade_test.go +++ b/tools/confix/upgrade_test.go @@ -35,9 +35,6 @@ func TestCheckValid(t *testing.T) { err = confix.CheckValid("client.toml", []byte{}) assert.Error(t, err, "client config invalid: chain-id is empty") - err = confix.CheckValid("app.toml", []byte{}) - assert.ErrorContains(t, err, "server config invalid") - err = confix.CheckValid("app.toml", mustReadConfig(t, "data/v0.45-app.toml")) assert.NilError(t, err) diff --git a/x/accounts/cli/cli_test.go b/x/accounts/cli/cli_test.go index a1074464ee6d..d65ef7063df1 100644 --- a/x/accounts/cli/cli_test.go +++ b/x/accounts/cli/cli_test.go @@ -19,7 +19,6 @@ import ( addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" - svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" @@ -120,14 +119,12 @@ func (s *CLITestSuite) TestTxInitCmd() { for _, tc := range testCases { s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - var args []string args = append(args, tc.accountType) args = append(args, tc.jsonMsg) args = append(args, tc.extraArgs...) - cmd.SetContext(ctx) + cmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &client.Context{})) cmd.SetArgs(args) out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, args) diff --git a/x/bank/client/cli/tx_test.go b/x/bank/client/cli/tx_test.go index 8f18458f79de..a4ed267c87cb 100644 --- a/x/bank/client/cli/tx_test.go +++ b/x/bank/client/cli/tx_test.go @@ -17,7 +17,6 @@ import ( addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" - svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" @@ -149,15 +148,13 @@ func (s *CLITestSuite) TestMultiSendTxCmd() { for _, tc := range testCases { s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - var args []string args = append(args, tc.from) args = append(args, tc.to...) args = append(args, tc.amount.String()) args = append(args, tc.extraArgs...) - cmd.SetContext(ctx) + cmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &client.Context{})) cmd.SetArgs(args) s.Require().NoError(client.SetCmdClientContextHandler(tc.ctxGen(), cmd)) diff --git a/x/genutil/client/cli/export.go b/x/genutil/client/cli/export.go deleted file mode 100644 index e858d57a1c4e..000000000000 --- a/x/genutil/client/cli/export.go +++ /dev/null @@ -1,149 +0,0 @@ -package cli - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "os" - "path/filepath" - - dbm "github.com/cosmos/cosmos-db" - "github.com/spf13/cast" - "github.com/spf13/cobra" - - corestore "cosmossdk.io/core/store" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/cosmos/cosmos-sdk/version" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" -) - -const ( - flagTraceStore = "trace-store" - flagHeight = "height" - flagForZeroHeight = "for-zero-height" - flagJailAllowedAddrs = "jail-allowed-addrs" - flagModulesToExport = "modules-to-export" -) - -// ExportCmd dumps app state to JSON. -func ExportCmd(appExporter servertypes.AppExporter) *cobra.Command { - cmd := &cobra.Command{ - Use: "export", - Short: "Export state to JSON", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, _ []string) error { - 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 := openDB(config.RootDir, getAppDBBackend(viper)) - if err != nil { - return err - } - - if appExporter == nil { - if _, err := fmt.Fprintln(cmd.ErrOrStderr(), "WARNING: App exporter not defined. Returning genesis file."); err != nil { - return err - } - - // Open file in read-only mode so we can copy it to stdout. - // 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(config.GenesisFile(), os.O_RDONLY, 0) - if err != nil { - return err - } - defer f.Close() - - if _, err := io.Copy(cmd.OutOrStdout(), f); err != nil { - return err - } - - return nil - } - - height, _ := cmd.Flags().GetInt64(flagHeight) - forZeroHeight, _ := cmd.Flags().GetBool(flagForZeroHeight) - jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(flagJailAllowedAddrs) - modulesToExport, _ := cmd.Flags().GetStringSlice(flagModulesToExport) - outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument) - - exported, err := appExporter(logger, db, nil, height, forZeroHeight, jailAllowedAddrs, viper, modulesToExport) - if err != nil { - return fmt.Errorf("error exporting state: %w", err) - } - - appGenesis, err := genutiltypes.AppGenesisFromFile(config.GenesisFile()) - if err != nil { - return err - } - - // set current binary version - appGenesis.AppName = version.AppName - appGenesis.AppVersion = version.Version - - appGenesis.AppState = exported.AppState - appGenesis.InitialHeight = exported.Height - appGenesis.Consensus = genutiltypes.NewConsensusGenesis(exported.ConsensusParams, exported.Validators) - - out, err := json.Marshal(appGenesis) - if err != nil { - return err - } - - if outputDocument == "" { - // Copy the entire genesis file to stdout. - _, err := io.Copy(cmd.OutOrStdout(), bytes.NewReader(out)) - return err - } - - if err = appGenesis.SaveAs(outputDocument); err != nil { - return err - } - - return nil - }, - } - - cmd.Flags().Int64(flagHeight, -1, "Export state from a particular height (-1 means latest height)") - cmd.Flags().Bool(flagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)") - cmd.Flags().StringSlice(flagJailAllowedAddrs, []string{}, "Comma-separated list of operator addresses of jailed validators to unjail") - cmd.Flags().StringSlice(flagModulesToExport, []string{}, "Comma-separated list of modules to export. If empty, will export all modules") - cmd.Flags().String(flags.FlagOutputDocument, "", "Exported state is written to the given file instead of STDOUT") - - return cmd -} - -// OpenDB opens the application database using the appropriate driver. -func openDB(rootDir string, backendType dbm.BackendType) (corestore.KVStoreWithBatch, error) { - dataDir := filepath.Join(rootDir, "data") - return dbm.NewDB("application", backendType, dataDir) -} - -// GetAppDBBackend gets the backend type to use for the application DBs. -func getAppDBBackend(opts servertypes.AppOptions) dbm.BackendType { - rv := cast.ToString(opts.Get("app-db-backend")) - if len(rv) == 0 { - rv = cast.ToString(opts.Get("db_backend")) - } - - // Cosmos SDK has migrated to cosmos-db which does not support all the backends which tm-db supported - if rv == "cleveldb" || rv == "badgerdb" || rv == "boltdb" { - panic(fmt.Sprintf("invalid app-db-backend %q, use %q, %q, %q instead", rv, dbm.GoLevelDBBackend, dbm.PebbleDBBackend, dbm.RocksDBBackend)) - } - - if len(rv) != 0 { - return dbm.BackendType(rv) - } - - return dbm.GoLevelDBBackend -} diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index 4c176a409a89..a3b3146faeb8 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -18,7 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" "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/version" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" @@ -33,7 +32,7 @@ type genesisMM interface { // GenTxCmd builds the application's gentx command. func GenTxCmd(genMM genesisMM, genBalIterator types.GenesisBalancesIterator) *cobra.Command { - ipDefault, _ := server.ExternalIP() + ipDefault, _ := ExternalIP() fsCreateValidator, defaultsDesc := cli.CreateValidatorMsgFlagSet(ipDefault) cmd := &cobra.Command{ diff --git a/x/genutil/client/cli/gentx_test.go b/x/genutil/client/cli/gentx_test.go index f3cd97a01844..26b94ea2f6b4 100644 --- a/x/genutil/client/cli/gentx_test.go +++ b/x/genutil/client/cli/gentx_test.go @@ -17,7 +17,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" - svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -116,10 +115,9 @@ func (s *CLITestSuite) TestGenTxCmd() { s.Run(tc.name, func() { clientCtx := s.clientCtx - ctx := svrcmd.CreateExecuteContext(context.Background()) cmd := cli.GenTxCmd(module.NewManager(), banktypes.GenesisBalancesIterator{}) - cmd.SetContext(ctx) + cmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &client.Context{})) cmd.SetArgs(tc.args) s.Require().NoError(client.SetCmdClientContextHandler(clientCtx, cmd)) diff --git a/server/util.go b/x/genutil/client/cli/util.go similarity index 98% rename from server/util.go rename to x/genutil/client/cli/util.go index d093a95b8980..562b5ffe4fbd 100644 --- a/server/util.go +++ b/x/genutil/client/cli/util.go @@ -1,4 +1,4 @@ -package server +package cli import ( "errors" diff --git a/x/group/client/cli/tx_test.go b/x/group/client/cli/tx_test.go index 2ad9ad76479c..277c4d52a1fb 100644 --- a/x/group/client/cli/tx_test.go +++ b/x/group/client/cli/tx_test.go @@ -23,7 +23,6 @@ import ( codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" - svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" @@ -221,8 +220,7 @@ func (s *CLITestSuite) TestTxCreateGroup() { for _, tc := range testCases { s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - cmd.SetContext(ctx) + cmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &client.Context{})) cmd.SetArgs(tc.args) s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd)) @@ -335,9 +333,7 @@ func (s *CLITestSuite) TestTxUpdateGroupMembers() { for _, tc := range testCases { s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - - cmd.SetContext(ctx) + cmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &client.Context{})) cmd.SetArgs(tc.args) s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd)) @@ -457,9 +453,7 @@ func (s *CLITestSuite) TestTxCreateGroupWithPolicy() { } for _, tc := range testCases { s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - - cmd.SetContext(ctx) + cmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &client.Context{})) cmd.SetArgs(tc.args) s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd)) @@ -592,9 +586,7 @@ func (s *CLITestSuite) TestTxCreateGroupPolicy() { for _, tc := range testCases { s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - - cmd.SetContext(ctx) + cmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &client.Context{})) cmd.SetArgs(tc.args) s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd)) @@ -697,9 +689,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { for _, tc := range testCases { s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - - cmd.SetContext(ctx) + cmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &client.Context{})) cmd.SetArgs(tc.args) s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd)) @@ -799,9 +789,7 @@ func (s *CLITestSuite) TestTxSubmitProposal() { for _, tc := range testCases { s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - - cmd.SetContext(ctx) + cmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &client.Context{})) cmd.SetArgs(tc.args) s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd)) diff --git a/x/upgrade/depinject.go b/x/upgrade/depinject.go index d12c0ea9a3b3..9d385e224157 100644 --- a/x/upgrade/depinject.go +++ b/x/upgrade/depinject.go @@ -14,14 +14,18 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) -// flagUnsafeSkipUpgradesV2 is a custom flag that allows the user to skip upgrades -// It is used in a v2 chain. -const flagUnsafeSkipUpgradesV2 = "server.unsafe-skip-upgrades" +const ( + // flagUnsafeSkipUpgrades is a custom flag that allows the user to skip upgrades + // It is used in a baseapp chain. + flagUnsafeSkipUpgrades = "unsafe-skip-upgrades" + // flagUnsafeSkipUpgradesV2 is a custom flag that allows the user to skip upgrades + // It is used in a v2 chain. + flagUnsafeSkipUpgradesV2 = "server.unsafe-skip-upgrades" +) var _ depinject.OnePerModuleType = AppModule{} @@ -39,9 +43,9 @@ func ProvideConfig(key depinject.OwnModuleKey) coreserver.ModuleConfigMap { return coreserver.ModuleConfigMap{ Module: depinject.ModuleKey(key).Name(), Config: coreserver.ConfigMap{ - server.FlagUnsafeSkipUpgrades: []int{}, - flagUnsafeSkipUpgradesV2: []int{}, - flags.FlagHome: "", + flagUnsafeSkipUpgrades: []int{}, + flagUnsafeSkipUpgradesV2: []int{}, + flags.FlagHome: "", }, } } @@ -73,7 +77,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { skipUpgrades, ok := in.ConfigMap[flagUnsafeSkipUpgradesV2] // check v2 if !ok || skipUpgrades == nil { - skipUpgrades, ok = in.ConfigMap[server.FlagUnsafeSkipUpgrades] // check v1 + skipUpgrades, ok = in.ConfigMap[flagUnsafeSkipUpgrades] // check v1 if !ok || skipUpgrades == nil { skipUpgrades = []int{} }