types

package
v1.132.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("timeout")

ErrTimeout is returned when an actor times out.

Functions

This section is empty.

Types

type Account

type Account struct {
	// Thorchain is the thorchain client for the account.
	Thorchain thorclient.ThorchainBridge

	// ChainClients is a map of chain to the corresponding client for the account.
	ChainClients map[common.Chain]LiteChainClient
	// contains filtered or unexported fields
}

Account holds a set of chain clients configured with a given private key.

func NewAccount

func NewAccount(mnemonic string, constructors map[common.Chain]LiteChainClientConstructor) *Account

NewAccount returns a new client using the private key from the given mnemonic.

func (*Account) Acquire

func (a *Account) Acquire() bool

Acquire will attempt to acquire the lock. If the lock is already acquired, it will return false. If true is returned, the caller has locked and must release when done.

func (*Account) Name

func (a *Account) Name() string

Name returns the name of the account.

func (*Account) PubKey

func (a *Account) PubKey() common.PubKey

PubKey returns the public key of the client.

func (*Account) Release

func (a *Account) Release()

Release will release the lock.

type Actor

type Actor struct {
	// Name is the name of the actor.
	Name string

	// Timeout is the maximum amount of time the actor is allowed to execute.
	Timeout time.Duration

	// Interval is the amount of time to wait between operations.
	Interval time.Duration

	// Ops is the set of operations to execute.
	Ops []Op `json:"-"`

	// Children is the set of children to execute after the operations have completed.
	Children map[*Actor]bool `json:"-"`
	// contains filtered or unexported fields
}

Actor is a node in the actor tree, which is processed as a DAG. Each actor has a set of operations to execute and a set of children. The actor will execute each operation in order until the operation returns Continue = false. If the operation returns Finish = true, the actor will stop executing and return the error. Once an actor has finished, the children of the actor will be executed. Actors may be appended to other actors, which results in the final descendants of the actor being parents of the appended actor - blocking the execution of the appended actor until all parents have completed, allowing for "fan in" of the execution DAG.

func NewActor

func NewActor(name string) *Actor

NewActor will create a new actor with the provided name.

func (*Actor) Append

func (a *Actor) Append(b *Actor)

Append will append the provided actor - all descendants of the actor will be parents of the provided actor (the provided actor and descendants will not be executed until all parents have completed).

func (*Actor) Execute

func (a *Actor) Execute(c *OpConfig) (err error)

Execute will execute the actor.

func (*Actor) Finished

func (a *Actor) Finished() bool

Finished returns true if the actor has finished executing.

func (*Actor) InitRoot

func (a *Actor) InitRoot()

InitRoot will initialize the entire actor tree.

func (*Actor) Log

func (a *Actor) Log() *zerolog.Logger

Log will return the logger for the actor.

func (*Actor) Parents

func (a *Actor) Parents() map[*Actor]bool

Parents returns the parents of the actor.

func (*Actor) SetLogger

func (a *Actor) SetLogger(l zerolog.Logger)

SetLogger will set the logger for the actor.

func (*Actor) Start

func (a *Actor) Start()

Start will mark the actor as started.

func (*Actor) Started

func (a *Actor) Started() bool

Started returns true if the actor has started executing.

func (*Actor) WalkDepthFirst

func (a *Actor) WalkDepthFirst(f func(*Actor) bool) (cont bool)

WalkDepthFirst will walk the actor tree depth first and execute the provided function on each actor. If the function returns false, the walk will stop.

type LiteChainClient

type LiteChainClient interface {
	// GetAccount returns the account for the given public key. If the key is nil, it
	// returns the account for the client's configured key.
	GetAccount(_ *common.PubKey) (*common.Account, error)

	// SignTx returns the signed transaction.
	SignTx(tx SimTx) ([]byte, error)

	// BroadcastTx broadcasts the transaction and returns the hash.
	BroadcastTx([]byte) (string, error)
}

LiteChainClient is a subset of the ChainClient interface used for simulation tests.

type LiteChainClientConstructor

type LiteChainClientConstructor func(_ common.Chain, _ *thorclient.Keys) (LiteChainClient, error)

LiteChainClientConstructor is a function that creates a new LiteChainClient.

type Op

type Op func(config *OpConfig) OpResult

Op is an operation that can be executed by an actor.

type OpConfig

type OpConfig struct {
	// AdminAccount is the client for the mimir admin account.
	AdminAccount *Account

	// NodeAccounts is a slice clients for simulation validator keys.
	NodeAccounts []*Account

	// UserAccounts is a slice of clients for simulation user keys.
	UserAccounts []*Account
}

OpConfig is the configuration passed to each operation during execution.

type OpResult

type OpResult struct {
	// Continue indicates that actor should continue to the next operation.
	Continue bool

	// Finish indicates that the actor should stop executing and return the error.
	Finish bool

	// Error is the error returned by the operation.
	Error error
}

OpResult is the result of an operation.

type SimTx

type SimTx struct {
	Chain     common.Chain
	ToAddress common.Address
	Coin      common.Coin
	Memo      string
}

SimTx is a struct used for simulation transactions.

type Watcher

type Watcher struct {
	// Name is the name of the watcher.
	Name string

	// Interval is the interval at which the watcher will be executed.
	Interval time.Duration

	// Fn is the function to execute.
	Fn func(config *OpConfig) error
}

Watcher wraps a function that will be executed on some interval in the background for the duration of the simulation. The function is passed the same OpConfig as the operations in the actor tree so it is able to access the clients and accounts used by the actors. If it returns an error or panics, the simulation will be aborted.

func (*Watcher) Execute

func (w *Watcher) Execute(c *OpConfig, l zerolog.Logger) (err error)

Execute will execute the watcher.

Jump to

Keyboard shortcuts

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