appmanager

package module
v0.0.0-...-ffc3f76 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppManager

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

AppManager is a coordinator for all things related to an application TODO: add exportGenesis function

func (AppManager[T]) DeliverBlock

func (AppManager[T]) ExportGenesis

func (a AppManager[T]) ExportGenesis(ctx context.Context, version uint64) ([]byte, error)

ExportGenesis exports the genesis state of the application.

func (AppManager[T]) InitGenesis

func (a AppManager[T]) InitGenesis(
	ctx context.Context,
	blockRequest *appmanager.BlockRequest[T],
	initGenesisJSON []byte,
	txDecoder transaction.Codec[T],
) (*appmanager.BlockResponse, corestore.WriterMap, error)

func (AppManager[T]) Query

func (a AppManager[T]) Query(ctx context.Context, version uint64, request transaction.Msg) (transaction.Msg, error)

Query queries the application at the provided version. CONTRACT: Version must always be provided, if 0, get latest

func (AppManager[T]) QueryWithState

func (a AppManager[T]) QueryWithState(
	ctx context.Context,
	state corestore.ReaderMap,
	request transaction.Msg,
) (transaction.Msg, error)

QueryWithState executes a query with the provided state. This allows to process a query independently of the db state. For example, it can be used to process a query with temporary and uncommitted state

func (AppManager[T]) Simulate

func (a AppManager[T]) Simulate(ctx context.Context, tx T) (appmanager.TxResult, corestore.WriterMap, error)

Simulate runs validation and execution flow of a Tx.

func (AppManager[T]) ValidateTx

func (a AppManager[T]) ValidateTx(ctx context.Context, tx T) (appmanager.TxResult, error)

ValidateTx will validate the tx against the latest storage state. This means that only the stateful validation will be run, not the execution portion of the tx. If full execution is needed, Simulate must be used.

type Builder

type Builder[T transaction.Tx] struct {
	STF StateTransitionFunction[T] // The state transition function for processing transactions.
	DB  store.Store                // The database for storing application data.

	// Gas limits for validating, querying, and simulating transactions.
	ValidateTxGasLimit uint64
	QueryGasLimit      uint64
	SimulationGasLimit uint64

	// InitGenesis is a function that initializes the application state from a genesis file.
	// It takes a context, a source reader for the genesis file, and a transaction handler function.
	InitGenesis InitGenesis
	// ExportGenesis is a function that exports the application state to a genesis file.
	// It takes a context and a version number for the genesis file.
	ExportGenesis ExportGenesis
}

Builder is a struct that represents the application builder for managing transactions. It contains various fields and methods for initializing the application and handling transactions.

func (Builder[T]) Build

func (b Builder[T]) Build() (*AppManager[T], error)

Build creates a new instance of AppManager with the provided configuration and returns it. It initializes the AppManager with the given database, export state, import state, initGenesis function, and state transition function.

type Config

type Config struct {
	ValidateTxGasLimit uint64 `mapstructure:"validate-tx-gas-limit"` // TODO: check how this works on app mempool
	QueryGasLimit      uint64 `mapstructure:"query-gas-limit"`
	SimulationGasLimit uint64 `mapstructure:"simulation-gas-limit"`
}

Config represents the configuration options for the app manager. TODO: implement comments for toml

type ExportGenesis

type ExportGenesis func(ctx context.Context, version uint64) ([]byte, error)

exportGenesis is a function type that represents the export of the genesis state.

type InitGenesis

type InitGenesis func(ctx context.Context, src io.Reader, txHandler func(json.RawMessage) error) error

InitGenesis is a function type that represents the initialization of the genesis state.

type StateTransitionFunction

type StateTransitionFunction[T transaction.Tx] interface {
	// DeliverBlock executes a block of transactions.
	DeliverBlock(
		ctx context.Context,
		block *appmanager.BlockRequest[T],
		state store.ReaderMap,
	) (blockResult *appmanager.BlockResponse, newState store.WriterMap, err error)

	// ValidateTx validates a transaction.
	ValidateTx(
		ctx context.Context,
		state store.ReaderMap,
		gasLimit uint64,
		tx T,
	) appmanager.TxResult

	// Simulate executes a transaction in simulation mode.
	Simulate(
		ctx context.Context,
		state store.ReaderMap,
		gasLimit uint64,
		tx T,
	) (appmanager.TxResult, store.WriterMap)

	// Query executes a query on the application.
	Query(
		ctx context.Context,
		state store.ReaderMap,
		gasLimit uint64,
		req transaction.Msg,
	) (transaction.Msg, error)

	// TODO: remove
	RunWithCtx(
		ctx context.Context,
		state store.ReaderMap,
		closure func(ctx context.Context) error,
	) (store.WriterMap, error)
}

StateTransitionFunction is an interface for processing transactions and blocks.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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