simulation

package
v0.50.11 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 18 Imported by: 5,285

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeriveRand

func DeriveRand(r *rand.Rand) *rand.Rand

DeriveRand derives a new Rand deterministically from another random source. Unlike rand.New(rand.NewSource(seed)), the result is "more random" depending on the source and state of r.

NOTE: not crypto safe.

func NewStoreDecoderFuncFromCollectionsSchema added in v0.50.0

func NewStoreDecoderFuncFromCollectionsSchema(schema collections.Schema) func(kvA, kvB kv.Pair) string

func RandIntBetween

func RandIntBetween(r *rand.Rand, min, max int) int

RandIntBetween returns a random int in the range [min, max) using a given source of randomness.

func RandPositiveInt

func RandPositiveInt(r *rand.Rand, max math.Int) (math.Int, error)

RandPositiveInt get a rand positive math.Int

func RandStringOfLength

func RandStringOfLength(r *rand.Rand, n int) string

RandStringOfLength generates a random string of a particular length.

func RandSubsetCoins

func RandSubsetCoins(r *rand.Rand, coins sdk.Coins) sdk.Coins

RandSubsetCoins returns random subset of the provided coins will return at least one coin unless coins argument is empty or malformed i.e. 0 amt in coins

func RandTimestamp

func RandTimestamp(r *rand.Rand) time.Time

RandTimestamp generates a random timestamp

func RandomAmount

func RandomAmount(r *rand.Rand, max math.Int) math.Int

RandomAmount generates a random amount Note: The range of RandomAmount includes max, and is, in fact, biased to return max as well as 0.

func RandomDecAmount

func RandomDecAmount(r *rand.Rand, max math.LegacyDec) math.LegacyDec

RandomDecAmount generates a random decimal amount Note: The range of RandomDecAmount includes max, and is, in fact, biased to return max as well as 0.

func RandomFees

func RandomFees(r *rand.Rand, ctx sdk.Context, spendableCoins sdk.Coins) (sdk.Coins, error)

RandomFees returns a random fee by selecting a random coin denomination and amount from the account's available balance. If the user doesn't have enough funds for paying fees, it returns empty coins.

Types

type Account

type Account struct {
	PrivKey cryptotypes.PrivKey
	PubKey  cryptotypes.PubKey
	Address sdk.AccAddress
	ConsKey cryptotypes.PrivKey
}

Account contains a privkey, pubkey, address tuple eventually more useful data can be placed in here. (e.g. number of coins)

func FindAccount

func FindAccount(accs []Account, address sdk.Address) (Account, bool)

FindAccount iterates over all the simulation accounts to find the one that matches the given address

func RandomAcc

func RandomAcc(r *rand.Rand, accs []Account) (Account, int)

RandomAcc picks and returns a random account and its index from an array.

func RandomAccounts

func RandomAccounts(r *rand.Rand, n int) []Account

RandomAccounts generates n random accounts

func (Account) Equals

func (acc Account) Equals(acc2 Account) bool

Equals returns true if two accounts are equal

type AppParams

type AppParams map[string]json.RawMessage

AppParams defines a flat JSON of key/values for all possible configurable simulation parameters. It might contain: operation weights, simulation parameters and flattened module state parameters (i.e not stored under it's respective module name).

func (AppParams) GetOrGenerate

func (sp AppParams) GetOrGenerate(key string, ptr interface{}, r *rand.Rand, ps ParamSimulator)

GetOrGenerate attempts to get a given parameter by key from the AppParams object. If it exists, it'll be decoded and returned. Otherwise, the provided ParamSimulator is used to generate a random value or default value (eg: in the case of operation weights where Rand is not used).

type AppStateFn

type AppStateFn func(r *rand.Rand, accs []Account, config Config) (
	appState json.RawMessage, accounts []Account, chainId string, genesisTimestamp time.Time,
)

AppStateFn returns the app state json bytes and the genesis accounts

type Config

type Config struct {
	GenesisFile string // custom simulation genesis file; cannot be used with params file
	ParamsFile  string // custom simulation params file which overrides any random params; cannot be used with genesis

	ExportParamsPath   string // custom file path to save the exported params JSON
	ExportParamsHeight int    // height to which export the randomly generated params
	ExportStatePath    string // custom file path to save the exported app state JSON
	ExportStatsPath    string // custom file path to save the exported simulation statistics JSON

	Seed               int64  // simulation random seed
	InitialBlockHeight int    // initial block to start the simulation
	NumBlocks          int    // number of new blocks to simulate from the initial block height
	BlockSize          int    // operations per block
	ChainID            string // chain-id used on the simulation

	Lean   bool // lean simulation log output
	Commit bool // have the simulation commit

	OnOperation   bool // run slow invariants every operation
	AllInvariants bool // print all failed invariants if a broken invariant is found

	DBBackend   string // custom db backend type
	BlockMaxGas int64  // custom max gas for block
}

Config contains the necessary configuration flags for the simulator

type Content deprecated

type Content interface {
	GetTitle() string
	GetDescription() string
	ProposalRoute() string
	ProposalType() string
	ValidateBasic() error
	String() string
}

Deprecated: Use MsgSimulatorFn instead.

type ContentSimulatorFn deprecated

type ContentSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account) Content

Deprecated: Use MsgSimulatorFn instead.

type FutureOperation

type FutureOperation struct {
	BlockHeight int
	BlockTime   time.Time
	Op          Operation
}

FutureOperation is an operation which will be ran at the beginning of the provided BlockHeight. If both a BlockHeight and BlockTime are specified, it will use the BlockHeight. In the (likely) event that multiple operations are queued at the same block height, they will execute in a FIFO pattern.

type LegacyParamChange added in v0.47.0

type LegacyParamChange interface {
	Subspace() string
	Key() string
	SimValue() SimValFn
	ComposedKey() string
}

type MsgSimulatorFn added in v0.47.0

type MsgSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account) sdk.Msg

type Operation

type Operation func(r *rand.Rand, app *baseapp.BaseApp,
	ctx sdk.Context, accounts []Account, chainID string) (
	OperationMsg OperationMsg, futureOps []FutureOperation, err error)

Operation runs a state machine transition, and ensures the transition happened as expected. The operation could be running and testing a fuzzed transaction, or doing the same for a message.

For ease of debugging, an operation returns a descriptive message "action", which details what this fuzzed state machine transition actually did.

Operations can optionally provide a list of "FutureOperations" to run later These will be ran at the beginning of the corresponding block.

type OperationMsg

type OperationMsg struct {
	Route   string `json:"route" yaml:"route"`     // msg route (i.e module name)
	Name    string `json:"name" yaml:"name"`       // operation name (msg Type or "no-operation")
	Comment string `json:"comment" yaml:"comment"` // additional comment
	OK      bool   `json:"ok" yaml:"ok"`           // success
	Msg     []byte `json:"msg" yaml:"msg"`         // protobuf encoded msg
}

OperationMsg - structure for operation output

func NewOperationMsg

func NewOperationMsg(msg sdk.Msg, ok bool, comment string) OperationMsg

NewOperationMsg - create a new operation message from sdk.Msg

func NewOperationMsgBasic

func NewOperationMsgBasic(moduleName, msgType, comment string, ok bool, msg []byte) OperationMsg

NewOperationMsgBasic creates a new operation message from raw input.

func NoOpMsg

func NoOpMsg(moduleName, msgType, comment string) OperationMsg

NoOpMsg - create a no-operation message

func (OperationMsg) LogEvent

func (om OperationMsg) LogEvent(eventLogger func(route, op, evResult string))

LogEvent adds an event for the events stats

func (OperationMsg) MustMarshal

func (om OperationMsg) MustMarshal() json.RawMessage

MustMarshal Marshals the operation msg, panic on error

func (OperationMsg) String

func (om OperationMsg) String() string

log entry text for this operation msg

type ParamSimulator

type ParamSimulator func(r *rand.Rand)

type Params

type Params interface {
	PastEvidenceFraction() float64
	NumKeys() int
	EvidenceFraction() float64
	InitialLivenessWeightings() []int
	LivenessTransitionMatrix() TransitionMatrix
	BlockSizeTransitionMatrix() TransitionMatrix
}

type RandomAccountFn added in v0.40.0

type RandomAccountFn func(r *rand.Rand, n int) []Account

RandomAccountFn returns a slice of n random simulation accounts

type SelectOpFn

type SelectOpFn func(r *rand.Rand) Operation

type SimValFn

type SimValFn func(r *rand.Rand) string

type StoreDecoderRegistry added in v0.50.0

type StoreDecoderRegistry map[string]func(kvA, kvB kv.Pair) string

StoreDecoderRegistry defines each of the modules store decoders. Used for ImportExport simulation.

type TransitionMatrix

type TransitionMatrix interface {
	NextState(r *rand.Rand, i int) int
}

TransitionMatrix is _almost_ a left stochastic matrix. It is technically not one due to not normalizing the column values. In the future, if we want to find the steady state distribution, it will be quite easy to normalize these values to get a stochastic matrix. Floats aren't currently used as the default due to non-determinism across architectures

type WeightedOperation

type WeightedOperation interface {
	Weight() int
	Op() Operation
}

type WeightedProposalContent deprecated

type WeightedProposalContent interface {
	AppParamsKey() string                   // key used to retrieve the value of the weight from the simulation application params
	DefaultWeight() int                     // default weight
	ContentSimulatorFn() ContentSimulatorFn // content simulator function
}

Deprecated: Use WeightedProposalMsg instead.

type WeightedProposalMsg added in v0.47.0

type WeightedProposalMsg interface {
	AppParamsKey() string           // key used to retrieve the value of the weight from the simulation application params
	DefaultWeight() int             // default weight
	MsgSimulatorFn() MsgSimulatorFn // msg simulator function
}

Jump to

Keyboard shortcuts

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