refactor(core,stf): complete gas service + simplify deps (#21166)
This commit is contained in:
parent
7dacef600f
commit
7040177316
@ -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
|
||||
)
|
||||
|
||||
@ -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=
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
10
core/go.mod
10
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
|
||||
)
|
||||
|
||||
|
||||
11
core/go.sum
11
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=
|
||||
|
||||
@ -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=
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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=
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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")
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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=
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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=
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -577,5 +577,4 @@ func (MockCoreAppModule) ExportGenesis(ctx context.Context, target appmodule.Gen
|
||||
var (
|
||||
_ appmodule.AppModule = MockCoreAppModule{}
|
||||
_ appmodule.HasGenesisAuto = MockCoreAppModule{}
|
||||
_ appmodule.HasServices = MockCoreAppModule{}
|
||||
)
|
||||
|
||||
@ -29,7 +29,6 @@ var ModuleAccountAddress = address.Module(ModuleName)
|
||||
|
||||
var (
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
_ appmodule.HasConsensusVersion = AppModule{}
|
||||
)
|
||||
|
||||
@ -36,7 +36,6 @@ var (
|
||||
|
||||
_ appmodulev2.HasGenesis = AppModule{}
|
||||
_ appmodulev2.AppModule = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodulev2.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
|
||||
@ -36,7 +36,6 @@ var (
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasBeginBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
)
|
||||
|
||||
|
||||
@ -34,7 +34,6 @@ var (
|
||||
_ module.HasInvariants = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
|
||||
@ -25,7 +25,6 @@ var (
|
||||
_ module.HasGRPCGateway = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
)
|
||||
|
||||
@ -35,7 +35,6 @@ var (
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasBeginBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
|
||||
@ -30,7 +30,6 @@ var (
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasEndBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
|
||||
@ -37,7 +37,6 @@ var (
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasEndBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
|
||||
@ -36,7 +36,6 @@ var (
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasEndBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
|
||||
@ -31,7 +31,6 @@ var (
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasBeginBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
|
||||
@ -23,7 +23,6 @@ var (
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
)
|
||||
|
||||
|
||||
@ -26,7 +26,6 @@ var (
|
||||
_ module.AppModuleSimulation = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
_ appmodule.HasBeginBlocker = AppModule{}
|
||||
|
||||
@ -33,7 +33,6 @@ var (
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasBeginBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
|
||||
@ -36,7 +36,6 @@ var (
|
||||
_ module.HasABCIEndBlock = AppModule{}
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
|
||||
|
||||
@ -29,7 +29,6 @@ var (
|
||||
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasPreBlocker = AppModule{}
|
||||
_ appmodule.HasServices = AppModule{}
|
||||
_ appmodule.HasMigrations = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user