Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core,runtime): transaction service (exec mode) #19953

Merged
merged 7 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

### Features

* (runtime) [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Implement `core/transaction.Service` in runtime.
* (client) [#19905](https://github.com/cosmos/cosmos-sdk/pull/19905) Add grpc client config to `client.toml`.
* (runtime) [#19571](https://github.com/cosmos/cosmos-sdk/pull/19571) Implement `core/router.Service` it in runtime. This service is present in all modules (when using depinject).
* (runtime) [#19571](https://github.com/cosmos/cosmos-sdk/pull/19571) Implement `core/router.Service` in runtime. This service is present in all modules (when using depinject).
* (types) [#19164](https://github.com/cosmos/cosmos-sdk/pull/19164) Add a ValueCodec for the math.Uint type that can be used in collections maps.
* (types) [#19281](https://github.com/cosmos/cosmos-sdk/pull/19281) Added a new method, `IsGT`, for `types.Coin`. This method is used to check if a `types.Coin` is greater than another `types.Coin`.
* (client) [#18557](https://github.com/cosmos/cosmos-sdk/pull/18557) Add `--qrcode` flag to `keys show` command to support displaying keys address QR code.
Expand Down
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Add transaction service.
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
* [#18379](https://github.com/cosmos/cosmos-sdk/pull/18379) Add branch service.
* [#18457](https://github.com/cosmos/cosmos-sdk/pull/18457) Add branch.ExecuteWithGasLimit.
* [#19041](https://github.com/cosmos/cosmos-sdk/pull/19041) Add `appmodule.Environment` interface to fetch different services
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
12 changes: 7 additions & 5 deletions core/appmodule/v2/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ import (
"cosmossdk.io/core/header"
"cosmossdk.io/core/router"
"cosmossdk.io/core/store"
"cosmossdk.io/core/transaction"
"cosmossdk.io/log"
)

// Environment is used to get all services to their respective module
type Environment struct {
Logger log.Logger

BranchService branch.Service
EventService event.Service
GasService gas.Service
HeaderService header.Service
RouterService router.Service
BranchService branch.Service
EventService event.Service
GasService gas.Service
HeaderService header.Service
RouterService router.Service
TransactionService transaction.Service

KVStoreService store.KVStoreService
MemStoreService store.MemoryStoreService
Expand Down
24 changes: 24 additions & 0 deletions core/transaction/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package transaction

import "context"

// ExecMode defines the execution mode
type ExecMode uint8

// All possible execution modes.
// For backwards compatibility and easier casting, the exec mode values must be the same as in cosmos/cosmos-sdk/types package.
const (
ExecModeCheck ExecMode = iota
_
ExecModeSimulate
_
_
_
_
ExecModeFinalize
)

// Service creates a transaction service.
type Service interface {
ExecMode(ctx context.Context) ExecMode
}
33 changes: 0 additions & 33 deletions runtime/autocli.go

This file was deleted.

13 changes: 7 additions & 6 deletions runtime/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ func NewEnvironment(
opts ...EnvOption,
) appmodule.Environment {
env := appmodule.Environment{
Logger: logger,
EventService: EventService{},
HeaderService: HeaderService{},
BranchService: BranchService{},
GasService: GasService{},
KVStoreService: kvService,
Logger: logger,
EventService: EventService{},
HeaderService: HeaderService{},
BranchService: BranchService{},
GasService: GasService{},
TransactionService: TransactionService{},
KVStoreService: kvService,
}

for _, opt := range opts {
Expand Down
34 changes: 32 additions & 2 deletions runtime/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1"
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule"
Expand All @@ -31,19 +33,47 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

// appModule defines runtime as an AppModule
type appModule struct {
app *App
}

func (m appModule) IsOnePerModuleType() {}
func (m appModule) IsAppModule() {}

func (m appModule) RegisterServices(configurator module.Configurator) { // nolint:staticcheck // SA1019: Configurator is deprecated but still used in runtime v1.
err := m.app.registerRuntimeServices(configurator)
if err != nil {
panic(err)
}
}

func (m appModule) IsOnePerModuleType() {}
func (m appModule) IsAppModule() {}
func (m appModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: &autocliv1.ServiceCommandDescriptor{
SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{
"autocli": {
Service: autocliv1.Query_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "AppOptions",
Short: "Query the custom autocli options",
},
},
},
"reflection": {
Service: reflectionv1.ReflectionService_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "FileDescriptors",
Short: "Query the app's protobuf file descriptors",
},
},
},
},
},
}
}

var (
_ appmodule.AppModule = appModule{}
Expand Down
19 changes: 19 additions & 0 deletions runtime/transaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package runtime

import (
"context"

"cosmossdk.io/core/transaction"

sdk "github.com/cosmos/cosmos-sdk/types"
)

var _ transaction.Service = TransactionService{}

type TransactionService struct{}

// ExecMode implements transaction.Service.
func (t TransactionService) ExecMode(ctx context.Context) transaction.ExecMode {
sdkCtx := sdk.UnwrapSDKContext(ctx)
return transaction.ExecMode(sdkCtx.ExecMode())
}
Loading