runtime

package module
v2.0.0-...-0f7a4ef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2025 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModuleName = "runtime"
)

Variables

This section is empty.

Functions

func DefaultServiceBindings

func DefaultServiceBindings() depinject.Config

DefaultServiceBindings provides default services for the following service interfaces: - store.KVStoreServiceFactory - header.Service - comet.Service - event.Service - store/v2/root.Builder - branch.Service - RouterServiceBuilder

They are all required. For most use cases these default services bindings should be sufficient. Power users (or tests) may wish to provide their own services bindings, in which case they must supply implementations for each of the above interfaces.

func DefaultStoreLoader

func DefaultStoreLoader(store Store) error

DefaultStoreLoader just calls LoadLatestVersion on the store

func NewKVStoreService

func NewKVStoreService(storeKey string) store.KVStoreService

NewKVStoreService creates a new KVStoreService. This wrapper is kept for backwards compatibility. When migrating from runtime to runtime/v2, use runtimev2.NewKVStoreService(storeKey.Name()) instead of runtime.NewKVStoreService(storeKey).

func ProvideEnvironment

func ProvideEnvironment(
	logger log.Logger,
	key depinject.ModuleKey,
	kvService store.KVStoreService,
	memKvService store.MemoryStoreService,
	headerService header.Service,
	gasService gas.Service,
	eventService event.Service,
	branchService branch.Service,
	routerBuilder RouterServiceBuilder,
) appmodulev2.Environment

ProvideEnvironment provides the environment for keeper modules, while maintaining backward compatibility and provide services directly as well.

func ProvideKVService

func ProvideKVService(
	config *runtimev2.Module,
	key depinject.ModuleKey,
	kvFactory store.KVStoreServiceFactory,
	storeBuilder root.Builder,
) (store.KVStoreService, store.MemoryStoreService)

func ProvideModuleScopedConfigMap

func ProvideModuleScopedConfigMap(
	key depinject.ModuleKey,
	moduleConfigs ModuleConfigMaps,
) server.ConfigMap

func SetupAppBuilder

func SetupAppBuilder(inputs AppInputs)

Types

type App

type App[T transaction.Tx] struct {
	appmanager.AppManager[T]
	// contains filtered or unexported fields
}

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/v2/app.go for an example of this setup.

func (*App[T]) Close

func (a *App[T]) Close() error

Close is called in start cmd to gracefully cleanup resources.

func (*App[T]) DefaultGenesis

func (a *App[T]) DefaultGenesis() map[string]json.RawMessage

DefaultGenesis returns a default genesis from the registered modules.

func (*App[T]) GetApp

func (a *App[T]) GetApp() *App[T]

GetApp return self

func (*App[T]) LoadHeight

func (a *App[T]) LoadHeight(height uint64) error

LoadHeight loads a particular height

func (*App[T]) LoadLatest

func (a *App[T]) LoadLatest() error

LoadLatest loads the latest version.

func (*App[T]) LoadLatestHeight

func (a *App[T]) LoadLatestHeight() (uint64, error)

LoadLatestHeight loads the latest height.

func (*App[T]) Logger

func (a *App[T]) Logger() log.Logger

Logger returns the app logger.

func (*App[T]) ModuleManager

func (a *App[T]) ModuleManager() *MM[T]

ModuleManager returns the module manager.

func (*App[T]) Name

func (a *App[T]) Name() string

Name returns the app name.

func (*App[T]) QueryHandlers

func (a *App[T]) QueryHandlers() map[string]appmodulev2.Handler

QueryHandlers returns the query handlers.

func (*App[T]) SchemaDecoderResolver

func (a *App[T]) SchemaDecoderResolver() decoding.DecoderResolver

SchemaDecoderResolver returns the module schema resolver.

func (*App[T]) SetStoreLoader

func (a *App[T]) SetStoreLoader(loader StoreLoader)

SetStoreLoader sets the store loader.

type AppBuilder

type AppBuilder[T transaction.Tx] struct {
	// contains filtered or unexported fields
}

AppBuilder is a type that is injected into a container by the runtime/v2 module (as *AppBuilder) which can be used to create an app which is compatible with the existing app.go initialization conventions.

func (*AppBuilder[T]) Build

func (a *AppBuilder[T]) Build(opts ...AppBuilderOption[T]) (*App[T], error)

Build builds an *App instance.

func (*AppBuilder[T]) RegisterModules

func (a *AppBuilder[T]) RegisterModules(modules map[string]appmodulev2.AppModule) error

RegisterModules registers the provided modules with the module manager. This is the primary hook for integrating with modules which are not registered using the app config.

type AppBuilderOption

type AppBuilderOption[T transaction.Tx] func(*AppBuilder[T])

AppBuilderOption is a function that can be passed to AppBuilder.Build to customize the resulting app.

func AppBuilderWithBranch

func AppBuilderWithBranch[T transaction.Tx](branch func(state store.ReaderMap) store.WriterMap) AppBuilderOption[T]

AppBuilderWithBranch sets a custom branch implementation for the app.

func AppBuilderWithPostTxExec

func AppBuilderWithPostTxExec[T transaction.Tx](
	postTxExec func(
		ctx context.Context, tx T, success bool,
	) error,
) AppBuilderOption[T]

AppBuilderWithPostTxExec sets logic that will be executed after each transaction. When not provided, a no-op function will be used.

func AppBuilderWithPreblocker

func AppBuilderWithPreblocker[T transaction.Tx](
	preblocker func(
		ctx context.Context, txs []T, mmPreblocker func() error,
	) error,
) AppBuilderOption[T]

AppBuilderWithPreblocker sets logic that will be executed before each block. mmPreblocker can be used to call module manager's preblocker, so that it can be called before or after depending on the app's logic. This is especially useful when implementing vote extensions.

func AppBuilderWithTxValidator

func AppBuilderWithTxValidator[T transaction.Tx](
	txValidators func(
		ctx context.Context, tx T,
	) error,
) AppBuilderOption[T]

AppBuilderWithTxValidator sets the tx validator for the app. It overrides all default tx validators defined by modules.

type AppInputs

type AppInputs struct {
	depinject.In

	Config             *runtimev2.Module
	AppBuilder         *AppBuilder[transaction.Tx]
	ModuleManager      *MM[transaction.Tx]
	InterfaceRegistrar registry.InterfaceRegistrar
	LegacyAmino        registry.AminoRegistrar
	Logger             log.Logger
	StoreBuilder       root.Builder
}

type GlobalConfig

type GlobalConfig server.ConfigMap

GlobalConfig is a recursive configuration map containing configuration key-value pairs parsed from the configuration file, flags, or other input sources.

It is aliased to server.ConfigMap so that DI can distinguish between module-scoped and global configuration maps. In the DI container `server.ConfigMap` objects are module-scoped and `GlobalConfig` is global-scoped.

type MM

type MM[T transaction.Tx] struct {
	// contains filtered or unexported fields
}

func NewModuleManager

func NewModuleManager[T transaction.Tx](
	logger log.Logger,
	config *runtimev2.Module,
	modules map[string]appmodulev2.AppModule,
) *MM[T]

NewModuleManager is the constructor for the module manager It handles all the interactions between the modules and the application

func ProvideModuleManager

func ProvideModuleManager[T transaction.Tx](
	logger log.Logger,
	config *runtimev2.Module,
	modules map[string]appmodulev2.AppModule,
) *MM[T]

func (*MM[T]) BeginBlock

func (m *MM[T]) BeginBlock() func(ctx context.Context) error

BeginBlock runs the begin-block logic of all modules

func (*MM[T]) DefaultGenesis

func (m *MM[T]) DefaultGenesis() map[string]json.RawMessage

DefaultGenesis provides default genesis information for all modules

func (*MM[T]) EndBlock

func (m *MM[T]) EndBlock() (
	endBlockFunc func(ctx context.Context) error,
	valUpdateFunc func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error),
)

EndBlock runs the end-block logic of all modules and tx validator updates

func (*MM[T]) ExportGenesisForModules

func (m *MM[T]) ExportGenesisForModules(
	ctx context.Context,
	stateFactory func() store.WriterMap,
	modulesToExport ...string,
) (map[string]json.RawMessage, error)

ExportGenesisForModules performs export genesis functionality for modules

func (*MM[T]) InitGenesisJSON

func (m *MM[T]) InitGenesisJSON(
	ctx context.Context,
	genesisData map[string]json.RawMessage,
	txHandler func(json.RawMessage) error,
) ([]appmodulev2.ValidatorUpdate, error)

InitGenesisJSON performs init genesis functionality for modules from genesis data in JSON format

func (*MM[T]) Modules

func (m *MM[T]) Modules() map[string]appmodulev2.AppModule

Modules returns the modules registered in the module manager

func (*MM[T]) PreBlocker

func (m *MM[T]) PreBlocker() func(ctx context.Context, txs []T) error

PreBlocker runs the pre-block logic of all modules

func (*MM[T]) RegisterInterfaces

func (m *MM[T]) RegisterInterfaces(registry registry.InterfaceRegistrar)

RegisterInterfaces registers all module interface types

func (*MM[T]) RegisterLegacyAminoCodec

func (m *MM[T]) RegisterLegacyAminoCodec(registrar registry.AminoRegistrar)

RegisterLegacyAminoCodec registers all module codecs

func (*MM[T]) RegisterServices

func (m *MM[T]) RegisterServices(app *App[T]) error

RegisterServices registers all module services.

func (*MM[T]) RunMigrations

func (m *MM[T]) RunMigrations(ctx context.Context, fromVM appmodulev2.VersionMap) (appmodulev2.VersionMap, error)

RunMigrations performs in-place store migrations for all modules. This function MUST be called inside an x/upgrade UpgradeHandler.

Recall that in an upgrade handler, the `fromVM` VersionMap is retrieved from x/upgrade's store, and the function needs to return the target VersionMap that will in turn be persisted to the x/upgrade's store. In general, returning RunMigrations should be enough:

Example:

app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx context.Context, plan upgradetypes.Plan, fromVM appmodule.VersionMap) (appmodule.VersionMap, error) {
    return app.ModuleManager().RunMigrations(ctx, fromVM)
})

Internally, RunMigrations will perform the following steps:

  • create an `updatedVM` VersionMap of module with their latest ConsensusVersion
  • if module implements `HasConsensusVersion` interface get the consensus version as `toVersion`, if not `toVersion` is set to 0.
  • get `fromVersion` from `fromVM` with module's name.
  • if the module's name exists in `fromVM` map, then run in-place store migrations for that module between `fromVersion` and `toVersion`.
  • if the module does not exist in the `fromVM` (which means that it's a new module, because it was not in the previous x/upgrade's store), then run `InitGenesis` on that module.

- return the `updatedVM` to be persisted in the x/upgrade's store.

Migrations are run in an order defined by `mm.config.OrderMigrations`.

As an app developer, if you wish to skip running InitGenesis for your new module "foo", you need to manually pass a `fromVM` argument to this function foo's module version set to its latest ConsensusVersion. That way, the diff between the function's `fromVM` and `updatedVM` will be empty, hence not running anything for foo.

Example:

app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
    // Assume "foo" is a new module.
    // `fromVM` is fetched from existing x/upgrade store. Since foo didn't exist
    // before this upgrade, `v, exists := fromVM["foo"]; exists == false`, and RunMigration will by default
    // run InitGenesis on foo.
    // To skip running foo's InitGenesis, you need set `fromVM`'s foo to its latest
    // consensus version:
    fromVM["foo"] = foo.AppModule{}.ConsensusVersion()

    return app.ModuleManager().RunMigrations(ctx, fromVM)
})

Please also refer to https://docs.cosmos.network/main/core/upgrade for more information.

func (*MM[T]) StoreKeys

func (m *MM[T]) StoreKeys() map[string]string

StoreKeys returns a map containing modules to their store keys

func (*MM[T]) TxValidators

func (m *MM[T]) TxValidators() func(ctx context.Context, tx T) error

TxValidators validates incoming transactions

func (*MM[T]) ValidateGenesis

func (m *MM[T]) ValidateGenesis(genesisData map[string]json.RawMessage) error

ValidateGenesis performs genesis state validation for all modules

type ModuleConfigMaps

type ModuleConfigMaps map[string]server.ConfigMap

ModuleConfigMaps is a map module scoped ConfigMaps

func ProvideModuleConfigMaps

func ProvideModuleConfigMaps(
	moduleConfigs []server.ModuleConfigMap,
	globalConfig GlobalConfig,
) ModuleConfigMaps

ProvideModuleConfigMaps returns a map of module name to module config map. The module config map is a map of flag to value.

type RouterServiceBuilder

type RouterServiceBuilder interface {
	// BuildMsgRouter return a msg router service.
	// - actor is the module store key.
	BuildMsgRouter(actor []byte) router.Service
	BuildQueryRouter() router.Service
}

RouterServiceBuilder builds the msg router and query router service during app initialization. this is mainly use for testing to override message router service in the environment and not in stf.

func NewRouterBuilder

func NewRouterBuilder(
	msgRouterServiceFactory RouterServiceFactory,
	queryRouter router.Service,
) RouterServiceBuilder

type RouterServiceFactory

type RouterServiceFactory func([]byte) router.Service

type Store

type Store interface {
	// GetLatestVersion returns the latest version that consensus has been made on
	GetLatestVersion() (uint64, error)
	// StateLatest returns a readonly view over the latest
	// committed state of the store. Alongside the version
	// associated with it.
	StateLatest() (uint64, store.ReaderMap, error)

	// StateAt returns a readonly view over the provided
	// version. Must error when the version does not exist.
	StateAt(version uint64) (store.ReaderMap, error)

	// LoadVersion loads the RootStore to the given version.
	LoadVersion(version uint64) error

	// LoadLatestVersion behaves identically to LoadVersion except it loads the
	// latest version implicitly.
	LoadLatestVersion() error
}

type StoreLoader

type StoreLoader func(store Store) error

StoreLoader allows for custom loading of the store, this is useful when upgrading the store from a previous version

func UpgradeStoreLoader

func UpgradeStoreLoader(upgradeHeight int64, storeUpgrades *store.StoreUpgrades) StoreLoader

UpgradeStoreLoader upgrades the store if the upgrade height matches the current version, it is used as a replacement for the DefaultStoreLoader when there are store upgrades

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL