diff --git a/collections/go.mod b/collections/go.mod index 3aceac378f3e..fb56f597d84e 100644 --- a/collections/go.mod +++ b/collections/go.mod @@ -16,11 +16,6 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/tidwall/btree v1.7.0 // indirect golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect - golang.org/x/net v0.27.0 // indirect - golang.org/x/sys v0.22.0 // indirect - golang.org/x/text v0.16.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect - google.golang.org/grpc v1.64.1 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/collections/go.sum b/collections/go.sum index 0a20b8cfe165..04009cf3e6a6 100644 --- a/collections/go.sum +++ b/collections/go.sum @@ -14,16 +14,6 @@ github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ= golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= -golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= -golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 h1:SbSDUWW1PAO24TNpLdeheoYPd7kllICcLU52x6eD4kQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= -google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= -google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index bd95f6aabc02..37c2dbf82037 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* [#21166](https://github.com/cosmos/cosmos-sdk/pull/21166) Comment out `appmodule.HasServices` to simplify dependencies. This interface is however still supported. * [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Add transaction service. * [#18379](https://github.com/cosmos/cosmos-sdk/pull/18379) Add branch service. * [#18457](https://github.com/cosmos/cosmos-sdk/pull/18457) Add branch.ExecuteWithGasLimit. diff --git a/core/appmodule/module.go b/core/appmodule/module.go index 7aef44a9b8ac..7caca9987072 100644 --- a/core/appmodule/module.go +++ b/core/appmodule/module.go @@ -3,8 +3,6 @@ package appmodule import ( "context" - "google.golang.org/grpc" - "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/legacy" ) @@ -35,23 +33,24 @@ type ValidatorUpdate = appmodule.ValidatorUpdate // HasServices is the extension interface that modules should implement to register // implementations of services defined in .proto files. -type HasServices interface { - AppModule +// This API is supported by the Cosmos SDK module managers but is excluded from core to limit dependencies. +// type HasServices interface { +// AppModule - // RegisterServices registers the module's services with the app's service - // registrar. - // - // Two types of services are currently supported: - // - read-only gRPC query services, which are the default. - // - transaction message services, which must have the protobuf service - // option "cosmos.msg.v1.service" (defined in "cosmos/msg/v1/service.proto") - // set to true. - // - // The service registrar will figure out which type of service you are - // implementing based on the presence (or absence) of protobuf options. You - // do not need to specify this in golang code. - RegisterServices(grpc.ServiceRegistrar) error -} +// // RegisterServices registers the module's services with the app's service +// // registrar. +// // +// // Two types of services are currently supported: +// // - read-only gRPC query services, which are the default. +// // - transaction message services, which must have the protobuf service +// // option "cosmos.msg.v1.service" (defined in "cosmos/msg/v1/service.proto") +// // set to true. +// // +// // The service registrar will figure out which type of service you are +// // implementing based on the presence (or absence) of protobuf options. You +// // do not need to specify this in golang code. +// RegisterServices(grpc.ServiceRegistrar) error +// } // HasPrepareCheckState is an extension interface that contains information about the AppModule // and PrepareCheckState. diff --git a/core/gas/service.go b/core/gas/service.go index dbd4f099b60c..8903b4686bb5 100644 --- a/core/gas/service.go +++ b/core/gas/service.go @@ -29,11 +29,6 @@ type Service interface { // will be returned. GasMeter(context.Context) Meter - // BlockGasMeter returns the current block-level gas meter. A non-nil meter - // is always returned. When one is unavailable in the context an infinite gas meter - // will be returned. - BlockGasMeter(context.Context) Meter - // GasConfig returns the gas costs. GasConfig(ctx context.Context) GasConfig } diff --git a/core/go.mod b/core/go.mod index d6dc5f94cd27..5ebeb0ad31bf 100644 --- a/core/go.mod +++ b/core/go.mod @@ -2,18 +2,12 @@ module cosmossdk.io/core go 1.20 -require ( - github.com/cosmos/gogoproto v1.5.0 - google.golang.org/grpc v1.64.1 -) +require github.com/cosmos/gogoproto v1.5.0 require ( + github.com/golang/protobuf v1.5.4 // indirect github.com/google/go-cmp v0.6.0 // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect - golang.org/x/net v0.27.0 // indirect - golang.org/x/sys v0.22.0 // indirect - golang.org/x/text v0.16.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect google.golang.org/protobuf v1.34.2 // indirect ) diff --git a/core/go.sum b/core/go.sum index d1734cd1d560..76a6d57e9ebd 100644 --- a/core/go.sum +++ b/core/go.sum @@ -1,19 +1,10 @@ github.com/cosmos/gogoproto v1.5.0 h1:SDVwzEqZDDBoslaeZg+dGE55hdzHfgUA40pEanMh52o= github.com/cosmos/gogoproto v1.5.0/go.mod h1:iUM31aofn3ymidYG6bUR5ZFrk+Om8p5s754eMUcyp8I= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= -golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= -golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 h1:SbSDUWW1PAO24TNpLdeheoYPd7kllICcLU52x6eD4kQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= -google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= -google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= diff --git a/core/testing/go.sum b/core/testing/go.sum index a0259a4a7133..48d8d7f73f8c 100644 --- a/core/testing/go.sum +++ b/core/testing/go.sum @@ -1,6 +1,6 @@ github.com/cosmos/gogoproto v1.5.0 h1:SDVwzEqZDDBoslaeZg+dGE55hdzHfgUA40pEanMh52o= github.com/cosmos/gogoproto v1.5.0/go.mod h1:iUM31aofn3ymidYG6bUR5ZFrk+Om8p5s754eMUcyp8I= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= diff --git a/runtime/app.go b/runtime/app.go index 185278511e00..2481da380995 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -6,6 +6,7 @@ import ( "slices" abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" + "google.golang.org/grpc" runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" "cosmossdk.io/core/appmodule" @@ -77,7 +78,7 @@ func (a *App) RegisterModules(modules ...module.AppModule) error { if mod, ok := appModule.(module.HasServices); ok { mod.RegisterServices(a.configurator) - } else if module, ok := appModule.(appmodule.HasServices); ok { + } else if module, ok := appModule.(hasServicesV1); ok { if err := module.RegisterServices(a.configurator); err != nil { return err } @@ -271,3 +272,9 @@ func (a *App) UnsafeFindStoreKey(storeKey string) storetypes.StoreKey { } 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 { + RegisterServices(grpc.ServiceRegistrar) error +} diff --git a/runtime/services/autocli.go b/runtime/services/autocli.go index b130af0f1c11..c6b66e510d62 100644 --- a/runtime/services/autocli.go +++ b/runtime/services/autocli.go @@ -54,7 +54,9 @@ func ExtractAutoCLIOptions(appModules map[string]appmodule.AppModule) map[string mod.RegisterServices(cfg) } - if mod, ok := mod.(appmodule.HasServices); ok { + if mod, ok := mod.(interface { + RegisterServices(grpc.ServiceRegistrar) error + }); ok { err := mod.RegisterServices(cfg) if err != nil { panic(err) diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go index 244353674c5a..d1261966a1fb 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -425,7 +425,7 @@ func (m *MM[T]) RunMigrations(ctx context.Context, fromVM appmodulev2.VersionMap func (m *MM[T]) RegisterServices(app *App[T]) error { for _, module := range m.modules { // register msg + query - if services, ok := module.(appmodule.HasServices); ok { + if services, ok := module.(hasServicesV1); ok { if err := registerServices(services, app, protoregistry.GlobalFiles); err != nil { return err } @@ -554,7 +554,7 @@ func (m *MM[T]) assertNoForgottenModules( return nil } -func registerServices[T transaction.Tx](s appmodule.HasServices, app *App[T], registry *protoregistry.Files) error { +func registerServices[T transaction.Tx](s hasServicesV1, app *App[T], registry *protoregistry.Files) error { c := &configurator{ grpcQueryDecoders: map[string]func() gogoproto.Message{}, stfQueryRouter: app.queryRouterBuilder, @@ -710,3 +710,9 @@ func defaultMigrationsOrder(modules []string) []string { } return out } + +// 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 { + RegisterServices(grpc.ServiceRegistrar) error +} diff --git a/runtime/v2/module.go b/runtime/v2/module.go index fbcf391b1f68..d4a99f49a0d2 100644 --- a/runtime/v2/module.go +++ b/runtime/v2/module.go @@ -16,7 +16,6 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" "cosmossdk.io/core/app" - "cosmossdk.io/core/appmodule" appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/comet" "cosmossdk.io/core/genesis" @@ -33,7 +32,7 @@ import ( var ( _ appmodulev2.AppModule = appModule[transaction.Tx]{} - _ appmodule.HasServices = appModule[transaction.Tx]{} + _ hasServicesV1 = appModule[transaction.Tx]{} ) type appModule[T transaction.Tx] struct { @@ -176,7 +175,12 @@ func ProvideModuleManager[T transaction.Tx]( } // ProvideEnvironment provides the environment for keeper modules, while maintaining backward compatibility and provide services directly as well. -func ProvideEnvironment[T transaction.Tx](logger log.Logger, config *runtimev2.Module, key depinject.ModuleKey, appBuilder *AppBuilder[T]) ( +func ProvideEnvironment[T transaction.Tx]( + logger log.Logger, + config *runtimev2.Module, + key depinject.ModuleKey, + appBuilder *AppBuilder[T], +) ( appmodulev2.Environment, store.KVStoreService, store.MemoryStoreService, diff --git a/runtime/v2/services/autocli.go b/runtime/v2/services/autocli.go index 85aeb20b702d..208b922a0c37 100644 --- a/runtime/v2/services/autocli.go +++ b/runtime/v2/services/autocli.go @@ -51,7 +51,10 @@ func ExtractAutoCLIOptions(appModules map[string]appmodule.AppModule) (map[strin // try to auto-discover options based on the last msg and query // services registered for the module - if mod, ok := mod.(appmodule.HasServices); ok { + // this supports the legacy core/appmodule v1 service registration + if mod, ok := mod.(interface { + RegisterServices(grpc.ServiceRegistrar) error + }); ok { err := mod.RegisterServices(autoCliRegistrar) if err != nil { return nil, err diff --git a/server/v2/appmanager/go.sum b/server/v2/appmanager/go.sum index f9ca7916a774..c7edf3fceb8a 100644 --- a/server/v2/appmanager/go.sum +++ b/server/v2/appmanager/go.sum @@ -1,7 +1,7 @@ github.com/cosmos/gogoproto v1.5.0 h1:SDVwzEqZDDBoslaeZg+dGE55hdzHfgUA40pEanMh52o= github.com/cosmos/gogoproto v1.5.0/go.mod h1:iUM31aofn3ymidYG6bUR5ZFrk+Om8p5s754eMUcyp8I= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f h1:3CW0unweImhOzd5FmYuRsD4Y4oQFKZIjAnKbjV4WIrw= diff --git a/server/v2/stf/README.md b/server/v2/stf/README.md index 48c40ca75b67..0c88ec66ec18 100644 --- a/server/v2/stf/README.md +++ b/server/v2/stf/README.md @@ -1,13 +1,12 @@ -# State Transition Function (STF) - -STF is a function that takes a state and an action as input and returns the next state. It does not assume the execution model of the application nor consensus. +# State Transition Function (STF) +STF is a function that takes a state and an action as input and returns the next state. It does not assume the execution model of the application nor consensus. The state transition function receives a read only instance of state. It does not directly write to disk, instead it will return the state changes which has undergone within the application. The state transition function is deterministic, meaning that given the same input, it will always produce the same output. ## BranchDB -BranchDB is a cache of all the reads done within a block, simulation or transaction validation. It takes a read-only instance of state and creates its own write instance using a btree. After all state transitions are done, the new change sets are returned to the caller. +BranchDB is a cache of all the reads done within a block, simulation or transaction validation. It takes a read-only instance of state and creates its own write instance using a btree. After all state transitions are done, the new change sets are returned to the caller. The BranchDB can be replaced and optimized for specific use cases. The implementation is as follows @@ -17,19 +16,19 @@ The BranchDB can be replaced and optimized for specific use cases. The implement ## GasMeter -GasMeter is a utility that keeps track of the gas consumed by the state transition function. It is used to limit the amount of computation that can be done within a block. +GasMeter is a utility that keeps track of the gas consumed by the state transition function. It is used to limit the amount of computation that can be done within a block. The GasMeter can be replaced and optimized for specific use cases. The implementation is as follows: ```go type ( - // gasMeter is a function type that takes a gas limit as input and returns a gas.Meter. - // It is used to measure and limit the amount of gas consumed during the execution of a function. - gasMeter func(gasLimit uint64) gas.Meter + // gasMeter is a function type that takes a gas limit as input and returns a gas.Meter. + // It is used to measure and limit the amount of gas consumed during the execution of a function. + gasMeter func(gasLimit uint64) gas.Meter - // wrapGasMeter is a function type that wraps a gas meter and a store writer map. - wrapGasMeter func(meter gas.Meter, store store.WriterMap) store.WriterMap + // wrapGasMeter is a function type that wraps a gas meter and a store writer map. + wrapGasMeter func(meter gas.Meter, store store.WriterMap) store.WriterMap ) ``` -THe wrappGasMeter is used in order to consume gas. Application developers can seamlsessly replace the gas meter with their own implementation in order to customize consumption of gas. +THe wrappGasMeter is used in order to consume gas. Application developers can seamlsessly replace the gas meter with their own implementation in order to customize consumption of gas. diff --git a/server/v2/stf/core_gas_service.go b/server/v2/stf/core_gas_service.go index 7378d126576b..d61859791772 100644 --- a/server/v2/stf/core_gas_service.go +++ b/server/v2/stf/core_gas_service.go @@ -5,6 +5,7 @@ import ( "cosmossdk.io/core/gas" "cosmossdk.io/core/store" + stfgas "cosmossdk.io/server/v2/stf/gas" ) type ( @@ -25,21 +26,9 @@ type gasService struct{} // GasConfig implements gas.Service. func (g gasService) GasConfig(ctx context.Context) gas.GasConfig { - panic("unimplemented") + return stfgas.DefaultConfig } func (g gasService) GasMeter(ctx context.Context) gas.Meter { return ctx.(*executionContext).meter } - -func (g gasService) BlockGasMeter(ctx context.Context) gas.Meter { - panic("stf has no block gas meter") -} - -func (g gasService) WithGasMeter(ctx context.Context, meter gas.Meter) context.Context { - panic("unimplemented") -} - -func (g gasService) WithBlockGasMeter(ctx context.Context, meter gas.Meter) context.Context { - panic("unimplemented") -} diff --git a/server/v2/stf/gas/defaults.go b/server/v2/stf/gas/defaults.go index 8906e31da627..5b032e81da7e 100644 --- a/server/v2/stf/gas/defaults.go +++ b/server/v2/stf/gas/defaults.go @@ -23,9 +23,11 @@ func DefaultGasMeter(gasLimit uint64) coregas.Meter { return NewMeter(gasLimit) } -var DefaultConfig = StoreConfig{ +// DefaultGasConfig returns the default gas config. +// Unless overridden, the default gas costs are: +var DefaultConfig = coregas.GasConfig{ HasCost: 1000, - DeleteCostFlat: 1000, + DeleteCost: 1000, ReadCostFlat: 1000, ReadCostPerByte: 3, WriteCostFlat: 2000, diff --git a/server/v2/stf/gas/store.go b/server/v2/stf/gas/store.go index 8ea15f12dd12..f0cb5f912909 100644 --- a/server/v2/stf/gas/store.go +++ b/server/v2/stf/gas/store.go @@ -17,19 +17,13 @@ const ( DescDelete = "Delete" ) -type StoreConfig struct { - ReadCostFlat, ReadCostPerByte, HasCost gas.Gas - WriteCostFlat, WriteCostPerByte, DeleteCostFlat gas.Gas - IterNextCostFlat gas.Gas -} - type Store struct { parent store.Writer gasMeter gas.Meter - gasConfig StoreConfig + gasConfig gas.GasConfig } -func NewStore(gc StoreConfig, meter gas.Meter, parent store.Writer) *Store { +func NewStore(gc gas.GasConfig, meter gas.Meter, parent store.Writer) *Store { return &Store{ parent: parent, gasMeter: meter, @@ -76,7 +70,7 @@ func (s *Store) Set(key, value []byte) error { } func (s *Store) Delete(key []byte) error { - if err := s.gasMeter.Consume(s.gasConfig.DeleteCostFlat, DescDelete); err != nil { + if err := s.gasMeter.Consume(s.gasConfig.DeleteCost, DescDelete); err != nil { return err } @@ -113,11 +107,11 @@ var _ store.Iterator = (*iterator)(nil) type iterator struct { gasMeter gas.Meter - gasConfig StoreConfig + gasConfig gas.GasConfig parent store.Iterator } -func newIterator(parent store.Iterator, gm gas.Meter, gc StoreConfig) store.Iterator { +func newIterator(parent store.Iterator, gm gas.Meter, gc gas.GasConfig) store.Iterator { return &iterator{ parent: parent, gasConfig: gc, diff --git a/server/v2/stf/gas/writer_map.go b/server/v2/stf/gas/writer_map.go index cd5fa406d175..5c2bead12912 100644 --- a/server/v2/stf/gas/writer_map.go +++ b/server/v2/stf/gas/writer_map.go @@ -7,7 +7,7 @@ import ( "cosmossdk.io/core/store" ) -func NewMeteredWriterMap(conf StoreConfig, meter gas.Meter, state store.WriterMap) MeteredWriterMap { +func NewMeteredWriterMap(conf gas.GasConfig, meter gas.Meter, state store.WriterMap) MeteredWriterMap { return MeteredWriterMap{ config: conf, meter: meter, @@ -20,7 +20,7 @@ func NewMeteredWriterMap(conf StoreConfig, meter gas.Meter, state store.WriterMa // version of it. Since the gas meter is shared across different // writers, the metered writers are memoized. type MeteredWriterMap struct { - config StoreConfig + config gas.GasConfig meter gas.Meter state store.WriterMap cacheMeteredStores map[string]*Store diff --git a/server/v2/stf/go.sum b/server/v2/stf/go.sum index fe0851fd9401..3d15a6545051 100644 --- a/server/v2/stf/go.sum +++ b/server/v2/stf/go.sum @@ -2,8 +2,8 @@ github.com/cosmos/gogoproto v1.5.0 h1:SDVwzEqZDDBoslaeZg+dGE55hdzHfgUA40pEanMh52 github.com/cosmos/gogoproto v1.5.0/go.mod h1:iUM31aofn3ymidYG6bUR5ZFrk+Om8p5s754eMUcyp8I= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/simapp/app_test.go b/simapp/app_test.go index 5f953788a4d2..56adf2c04721 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "google.golang.org/grpc" "cosmossdk.io/core/appmodule" "cosmossdk.io/log" @@ -107,7 +108,9 @@ func TestRunMigrations(t *testing.T) { mod.RegisterServices(configurator) } - if mod, ok := mod.(appmodule.HasServices); ok { + if mod, ok := mod.(interface { + RegisterServices(grpc.ServiceRegistrar) error + }); ok { err := mod.RegisterServices(configurator) require.NoError(t, err) } diff --git a/simapp/go.mod b/simapp/go.mod index 51c3a25b670c..f164962b11c8 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -48,6 +48,8 @@ require ( google.golang.org/protobuf v1.34.2 ) +require google.golang.org/grpc v1.64.1 + require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect @@ -222,7 +224,6 @@ require ( google.golang.org/genproto v0.0.0-20240617180043-68d350f18fd4 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect - google.golang.org/grpc v1.64.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gotest.tools/v3 v3.5.1 // indirect diff --git a/store/v2/go.mod b/store/v2/go.mod index 07e90eaf7c99..fc9bbcdafb2c 100644 --- a/store/v2/go.mod +++ b/store/v2/go.mod @@ -37,7 +37,6 @@ require ( github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/getsentry/sentry-go v0.27.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect diff --git a/store/v2/go.sum b/store/v2/go.sum index eb679dc64340..3d7e4f18c716 100644 --- a/store/v2/go.sum +++ b/store/v2/go.sum @@ -241,8 +241,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= -golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/types/module/core_module.go b/types/module/core_module.go index 34274d35f2c4..104ea1aab924 100644 --- a/types/module/core_module.go +++ b/types/module/core_module.go @@ -208,7 +208,7 @@ func (c coreAppModuleAdaptor) RegisterLegacyAminoCodec(amino legacy.Amino) { // RegisterServices implements HasServices func (c coreAppModuleAdaptor) RegisterServices(cfg Configurator) { - if module, ok := c.module.(appmodule.HasServices); ok { + if module, ok := c.module.(hasServicesV1); ok { err := module.RegisterServices(cfg) if err != nil { panic(err) diff --git a/types/module/module.go b/types/module/module.go index 7ea5db116bc5..06be7817eb14 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -30,6 +30,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" "golang.org/x/exp/maps" + "google.golang.org/grpc" "cosmossdk.io/core/appmodule" appmodulev2 "cosmossdk.io/core/appmodule/v2" @@ -92,6 +93,14 @@ type HasServices interface { RegisterServices(Configurator) } +// 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 { + appmodule.AppModule + + RegisterServices(grpc.ServiceRegistrar) error +} + // MigrationHandler is the migration function that each module registers. type MigrationHandler func(sdk.Context) error @@ -383,7 +392,7 @@ func (m *Manager) RegisterServices(cfg Configurator) error { module.RegisterServices(cfg) } - if module, ok := module.(appmodule.HasServices); ok { + if module, ok := module.(hasServicesV1); ok { err := module.RegisterServices(cfg) if err != nil { return err diff --git a/types/module/module_test.go b/types/module/module_test.go index ad8ff8178464..990dc0d2a711 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -577,5 +577,4 @@ func (MockCoreAppModule) ExportGenesis(ctx context.Context, target appmodule.Gen var ( _ appmodule.AppModule = MockCoreAppModule{} _ appmodule.HasGenesisAuto = MockCoreAppModule{} - _ appmodule.HasServices = MockCoreAppModule{} ) diff --git a/x/accounts/module.go b/x/accounts/module.go index 8a848141923e..1ed89d87d8dd 100644 --- a/x/accounts/module.go +++ b/x/accounts/module.go @@ -29,7 +29,6 @@ var ModuleAccountAddress = address.Module(ModuleName) var ( _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasGenesis = AppModule{} _ appmodule.HasConsensusVersion = AppModule{} ) diff --git a/x/auth/module.go b/x/auth/module.go index d440c8756990..ae028ab5fcda 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -36,7 +36,6 @@ var ( _ appmodulev2.HasGenesis = AppModule{} _ appmodulev2.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodulev2.HasMigrations = AppModule{} ) diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 7cdfe4ae7143..03e6dddf2302 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -36,7 +36,6 @@ var ( _ appmodule.HasGenesis = AppModule{} _ appmodule.AppModule = AppModule{} _ appmodule.HasBeginBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasMigrations = AppModule{} ) diff --git a/x/bank/module.go b/x/bank/module.go index 66e5ffc6950b..763bc69056f7 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -34,7 +34,6 @@ var ( _ module.HasInvariants = AppModule{} _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasMigrations = AppModule{} _ appmodule.HasGenesis = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} diff --git a/x/circuit/module.go b/x/circuit/module.go index 7223b74b8ce5..3f2d74fa3d7e 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -25,7 +25,6 @@ var ( _ module.HasGRPCGateway = AppModule{} _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasGenesis = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} ) diff --git a/x/distribution/module.go b/x/distribution/module.go index 82e991069335..869c8aa5cfe7 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -35,7 +35,6 @@ var ( _ appmodule.AppModule = AppModule{} _ appmodule.HasBeginBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasMigrations = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} _ appmodule.HasGenesis = AppModule{} diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 9be56adea2f7..134160422723 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -30,7 +30,6 @@ var ( _ appmodule.AppModule = AppModule{} _ appmodule.HasEndBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasMigrations = AppModule{} _ appmodule.HasGenesis = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} diff --git a/x/gov/module.go b/x/gov/module.go index b64042321d0d..abdb888e0d73 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -37,7 +37,6 @@ var ( _ appmodule.AppModule = AppModule{} _ appmodule.HasEndBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasMigrations = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} _ appmodule.HasGenesis = AppModule{} diff --git a/x/group/module/module.go b/x/group/module/module.go index a27854829d7f..85599e6d5daa 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -36,7 +36,6 @@ var ( _ appmodule.AppModule = AppModule{} _ appmodule.HasEndBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasMigrations = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} _ appmodule.HasGenesis = AppModule{} diff --git a/x/mint/module.go b/x/mint/module.go index 0c5fea08dafb..b0f6b2a14ec9 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -31,7 +31,6 @@ var ( _ appmodule.AppModule = AppModule{} _ appmodule.HasBeginBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasMigrations = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} _ appmodule.HasGenesis = AppModule{} diff --git a/x/params/module.go b/x/params/module.go index 097056bcd4a6..9d4aba372fa2 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -23,7 +23,6 @@ var ( _ module.AppModuleSimulation = AppModule{} _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} ) diff --git a/x/protocolpool/module.go b/x/protocolpool/module.go index 2e88385d54f9..f594459d1756 100644 --- a/x/protocolpool/module.go +++ b/x/protocolpool/module.go @@ -26,7 +26,6 @@ var ( _ module.AppModuleSimulation = AppModule{} _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasGenesis = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} _ appmodule.HasBeginBlocker = AppModule{} diff --git a/x/slashing/module.go b/x/slashing/module.go index 5b6534fd529b..c8aabf12bad2 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -33,7 +33,6 @@ var ( _ appmodule.AppModule = AppModule{} _ appmodule.HasBeginBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasMigrations = AppModule{} _ appmodule.HasGenesis = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} diff --git a/x/staking/module.go b/x/staking/module.go index 927c4f5d7873..30435bed7b9c 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -36,7 +36,6 @@ var ( _ module.HasABCIEndBlock = AppModule{} _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasMigrations = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} diff --git a/x/upgrade/module.go b/x/upgrade/module.go index f18b426c473d..3b5967adba44 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -29,7 +29,6 @@ var ( _ appmodule.AppModule = AppModule{} _ appmodule.HasPreBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} _ appmodule.HasMigrations = AppModule{} _ appmodule.HasGenesis = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{}