forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: upstream runtime/v2 (cosmos#20320)
Co-authored-by: Julien Robert <[email protected]>
- Loading branch information
1 parent
b4f8815
commit 7ae23e2
Showing
37 changed files
with
5,864 additions
and
66 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
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_v2.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 | ||
} | ||
|
||
// GetStoreKeys returns all the app 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 | ||
} | ||
|
||
// GetStore returns the app store. | ||
func (a *App) GetStore() Store { | ||
return a.db | ||
} | ||
|
||
// GetLogger returns the app logger. | ||
func (a *App) GetLogger() log.Logger { | ||
return a.logger | ||
} | ||
|
||
func (a *App) ExecuteGenesisTx(_ []byte) error { | ||
panic("not implemented") | ||
} |
Oops, something went wrong.