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

chore: upstream runtime/v2 #20320

Merged
merged 23 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
2,909 changes: 2,909 additions & 0 deletions api/cosmos/app/runtime/v2/module.pulsar.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions core/appmodule/v2/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ type HasGenesis interface {
InitGenesis(ctx context.Context, data json.RawMessage) error
ExportGenesis(ctx context.Context) (json.RawMessage, error)
}
type HasABCIGenesis interface {
InitGenesis(ctx context.Context, data json.RawMessage) ([]ValidatorUpdate, error)
}
4 changes: 1 addition & 3 deletions core/appmodule/v2/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package appmodule
import (
gogoproto "github.com/cosmos/gogoproto/proto"
protov2 "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/runtime/protoiface"
)

// Message aliases protoiface.MessageV1 for convenience.
type Message = protoiface.MessageV1
type Message = gogoproto.Message

func messageName[M Message]() string {
switch m := any(*new(M)).(type) {
Expand Down
7 changes: 6 additions & 1 deletion core/context/context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package appmodule
package context

// ExecMode defines the execution mode which can be set on a Context.
type ExecMode uint8
Expand All @@ -14,3 +14,8 @@ const (
ExecModeVerifyVoteExtension
ExecModeFinalize
)

const (
ExecModeKey = iota
CometInfoKey
)
6 changes: 3 additions & 3 deletions core/transaction/transaction.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package transaction

import (
"github.com/cosmos/gogoproto/proto"
gogoproto "github.com/cosmos/gogoproto/proto"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tac0turtle is it possible to decouple

cosmossdk.io/core and gogoproto dependency tree wise?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gogoproto is already a type within core. Since it's directly related to how the system works it's not needed to decouple. This import also does not prevent compiling down to rv32. What is the reason you would want to avoid this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see why it can't be

type Marshallalable interface {
Marshal()
Unmarshal()
}

Having core abstracted from any implementation details around serialization seems like good practice.

cosmossdk.io/core should be over the wire agnostic imo.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we continue on the path of enshrining protobuf into base types of the system we will never get rid of the nightmares.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proto.message is an interface,

type Message interface {
	Reset()
	String() string
	ProtoMessage()
}

its annoying I understand but this isn't defining serialisation either.

Marshal and unmarshal dont work here since you cant assume a type has those

)

type (
Msg = proto.Message
Msg = gogoproto.Message
Identity = []byte
)

Expand All @@ -22,7 +22,7 @@ type Tx interface {
// Hash returns the unique identifier for the Tx.
Hash() [32]byte
// GetMessages returns the list of state transitions of the Tx.
GetMessages() []Msg
GetMessages() ([]Msg, error)
// GetSenders returns the tx state transition sender.
GetSenders() ([]Identity, error) // TODO reduce this to a single identity if accepted
// GetGasLimit returns the gas limit of the tx. Must return math.MaxUint64 for infinite gas
Expand Down
6 changes: 4 additions & 2 deletions go.work.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
go 1.22
go 1.22.2

toolchain go1.22
toolchain go1.22.2

use (
.
Expand All @@ -16,8 +16,10 @@ use (
./simapp
./tests
./server/v2/stf
./server/v2/appmanager
./store
./store/v2
./runtime/v2
./tools/cosmovisor
./tools/confix
./tools/hubl
Expand Down
73 changes: 73 additions & 0 deletions proto/cosmos/app/runtime/v2/module.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
syntax = "proto3";

package cosmos.app.runtime.v2;

import "cosmos/app/v1alpha1/module.proto";

// Module is the config object for the runtime module.
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "cosmossdk.io/runtime/v2"
use_package: {name: "cosmos.app.v1alpha1"}
};

// app_name is the name of the app.
string app_name = 1;

// pre_blockers specifies the module names of pre blockers
// to call in the order in which they should be called. If this is left empty
// no pre blocker will be registered.
repeated string pre_blockers = 2;

// begin_blockers specifies the module names of begin blockers
// to call in the order in which they should be called. If this is left empty
// no begin blocker will be registered.
repeated string begin_blockers = 3;

// end_blockers specifies the module names of the end blockers
// to call in the order in which they should be called. If this is left empty
// no end blocker will be registered.
repeated string end_blockers = 4;

// tx_validators specifies the module names for tx validators
// If this is left empty, no tx validation will be registered.
repeated string tx_validators = 5;

// init_genesis specifies the module names of init genesis functions
// to call in the order in which they should be called. If this is left empty
// no init genesis function will be registered.
repeated string init_genesis = 6;

// export_genesis specifies the order in which to export module genesis data.
// If this is left empty, the init_genesis order will be used for export genesis
// if it is specified.
repeated string export_genesis = 7;

// order_migrations defines the order in which module migrations are performed.
// If this is left empty, it uses the default migration order (alphabeticaly).
repeated string order_migrations = 8;

// GasConfig is the config object for gas limits.
GasConfig gas_config = 9;

// override_store_keys is an optional list of overrides for the module store keys
// to be used in keeper construction.
repeated StoreKeyConfig override_store_keys = 10;
}

// GasConfig is the config object for gas limits.
message GasConfig {
uint64 validate_tx_gas_limit = 1;
uint64 query_gas_limit = 2;
uint64 simulation_gas_limit = 3;
}

// StoreKeyConfig may be supplied to override the default module store key, which
// is the module name.
message StoreKeyConfig {
// name of the module to override the store key of
string module_name = 1;

// the kv store key to use instead of the module name.
string kv_store_key = 2;
}
146 changes: 146 additions & 0 deletions runtime/v2/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package runtime

import (
"context"
"encoding/json"
"errors"

"golang.org/x/exp/slices"

runtimev2 "cosmossdk.io/api/cosmos/app/runtime/v2"
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
coreappmanager "cosmossdk.io/core/app"
"cosmossdk.io/core/store"
"cosmossdk.io/core/transaction"
"cosmossdk.io/log"
"cosmossdk.io/server/v2/appmanager"
"cosmossdk.io/server/v2/stf"

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

var _ AppI[transaction.Tx] = (*App)(nil)

// AppI is an interface that defines the methods required by the App.
type AppI[T transaction.Tx] interface {
DeliverBlock(
ctx context.Context,
block *coreappmanager.BlockRequest[T],
) (*coreappmanager.BlockResponse, store.WriterMap, error)
ValidateTx(ctx context.Context, tx T) (coreappmanager.TxResult, error)
Simulate(ctx context.Context, tx T) (coreappmanager.TxResult, store.WriterMap, error)
Query(ctx context.Context, version uint64, request transaction.Msg) (transaction.Msg, error)
QueryWithState(ctx context.Context, state store.ReaderMap, request transaction.Msg) (transaction.Msg, error)

Logger() log.Logger
ModuleManager() *MM
Close() error
}

// App is a wrapper around AppManager and ModuleManager that can be used in hybrid
// app.go/app config scenarios or directly as a servertypes.Application instance.
// To get an instance of *App, *AppBuilder must be requested as a dependency
// in a container which declares the runtime module and the AppBuilder.Build()
// method must be called.
//
// App can be used to create a hybrid app.go setup where some configuration is
// done declaratively with an app config and the rest of it is done the old way.
// See simapp/app_.go for an example of this setup.
type App struct {
*appmanager.AppManager[transaction.Tx]

// app manager dependencies
stf *stf.STF[transaction.Tx]
msgRouterBuilder *stf.MsgRouterBuilder
queryRouterBuilder *stf.MsgRouterBuilder
db Store

// app configuration
logger log.Logger
config *runtimev2.Module
appConfig *appv1alpha1.Config

// modules configuration
storeKeys []string
interfaceRegistry codectypes.InterfaceRegistry
cdc codec.Codec
amino *codec.LegacyAmino
moduleManager *MM
}

// Logger returns the app logger.
func (a *App) Logger() log.Logger {
return a.logger
}

// ModuleManager returns the module manager.
func (a *App) ModuleManager() *MM {
return a.moduleManager
}

// DefaultGenesis returns a default genesis from the registered modules.
func (a *App) DefaultGenesis() map[string]json.RawMessage {
return a.moduleManager.DefaultGenesis()
}

// LoadLatest loads the latest version.
func (a *App) LoadLatest() error {
return a.db.LoadLatestVersion()
}

// LoadHeight loads a particular height
func (a *App) LoadHeight(height uint64) error {
return a.db.LoadVersion(height)
}

// Close is called in start cmd to gracefully cleanup resources.
func (a *App) Close() error {
return nil
}

// RegisterStores registers the provided store keys.
// This method should only be used for registering extra stores
// wiich is necessary for modules that not registered using the app config.
// To be used in combination of RegisterModules.
func (a *App) RegisterStores(keys ...string) error {
a.storeKeys = append(a.storeKeys, keys...)

return nil
}

// GetStoreKeys returns all the stored store keys.
func (a *App) GetStoreKeys() []string {
return a.storeKeys
}

// UnsafeFindStoreKey fetches a registered StoreKey from the App in linear time.
// NOTE: This should only be used in testing.
func (a *App) UnsafeFindStoreKey(storeKey string) (string, error) {
i := slices.IndexFunc(a.storeKeys, func(s string) bool { return s == storeKey })
if i == -1 {
return "", errors.New("store key not found")
}

return a.storeKeys[i], nil
}

func (a *App) GetStore() Store {
return a.db
}

func (a *App) GetLogger() log.Logger {
return a.logger
}

func (a *App) ExecuteGenesisTx(_ []byte) error {
panic("not implemented")
}

func (a *App) SetAppVersion(context.Context, uint64) error {
panic("not implemented")
}

func (a *App) AppVersion(context.Context) (uint64, error) {
panic("not implemented")
}
Loading
Loading