txsim

package
v2.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SendGasLimit     = 100000
	FeegrantGasLimit = 800000
)
View Source
const (
	// Set the default gas limit to cover the costs of most transactions.
	// At 0.1 utia per gas, this equates to 20_000utia per transaction.
	DefaultGasLimit = 200_000
)
View Source
const DefaultSeed = 900183116

Variables

View Source
var ErrEndOfSequence = errors.New("end of sequence")

ErrEndOfSequence is a special error which indicates that the sequence has been terminated

Functions

func Run

func Run(
	ctx context.Context,
	grpcEndpoint string,
	keys keyring.Keyring,
	encCfg encoding.Config,
	opts *Options,
	sequences ...Sequence,
) error

Run is the entrypoint function for starting the txsim client. The lifecycle of the client is managed through the context. At least one grpc and rpc endpoint must be provided. The client relies on a single funded master account present in the keyring. The client allocates subaccounts for sequences at runtime. A seed can be provided for deterministic randomness. The pollTime dictates the frequency that the client should check for updates from state and that transactions have been committed.

This should be used for testing purposes only.

All sequences can be scaled up using the `Clone` method. This allows for a single sequence that repeatedly sends random PFBs to be scaled up to 1000 accounts sending PFBs.

Types

type AccountAllocator

type AccountAllocator func(n, balance int) []types.AccAddress

AccountAllocator reserves and funds a series of accounts to be used exclusively by the Sequence.

type AccountManager

type AccountManager struct {
	// contains filtered or unexported fields
}

func NewAccountManager

func NewAccountManager(
	ctx context.Context,
	keys keyring.Keyring,
	encCfg encoding.Config,
	masterAccName string,
	conn *grpc.ClientConn,
	pollTime time.Duration,
	useFeegrant bool,
) (*AccountManager, error)

func (*AccountManager) AllocateAccounts

func (am *AccountManager) AllocateAccounts(n, balance int) []types.AccAddress

AllocateAccounts is used by sequences to specify the number of accounts and the balance of each of those accounts. Not concurrently safe.

func (*AccountManager) GenerateAccounts

func (am *AccountManager) GenerateAccounts(ctx context.Context) error

Generate the pending accounts by sending the adequate funds. This operation is not concurrently safe.

func (*AccountManager) Submit

func (am *AccountManager) Submit(ctx context.Context, op Operation) error

Submit executes on an operation. This is thread safe.

type BlobSequence

type BlobSequence struct {
	// contains filtered or unexported fields
}

BlobSequence defines a pattern whereby a single user repeatedly sends a pay for blob message roughly every height. The PFB may consist of several blobs

func NewBlobSequence

func NewBlobSequence(sizes, blobsPerPFB Range) *BlobSequence

func (*BlobSequence) Clone

func (s *BlobSequence) Clone(n int) []Sequence

func (*BlobSequence) Init

func (s *BlobSequence) Init(_ context.Context, _ grpc.ClientConn, allocateAccounts AccountAllocator, _ *rand.Rand, useFeegrant bool)

func (*BlobSequence) Next

func (*BlobSequence) WithNamespace

func (s *BlobSequence) WithNamespace(namespace ns.Namespace) *BlobSequence

WithNamespace provides the option of fixing a predefined namespace for all blobs.

type Operation

type Operation struct {
	Msgs     []types.Msg
	Blobs    []*blob.Blob
	Delay    uint64
	GasLimit uint64
	GasPrice float64
}

Operation represents a series of messages and blobs that are to be bundled in a single transaction. A delay (in heights) may also be set before the transaction is sent. The gas limit and price can also be set. If left at 0, the DefaultGasLimit will be used.

type Options

type Options struct {
	// contains filtered or unexported fields
}

func DefaultOptions

func DefaultOptions() *Options

func (*Options) Fill

func (o *Options) Fill()

func (*Options) SpecifyMasterAccount

func (o *Options) SpecifyMasterAccount(name string) *Options

func (*Options) SuppressLogs

func (o *Options) SuppressLogs() *Options

func (*Options) UseFeeGrant

func (o *Options) UseFeeGrant() *Options

func (*Options) WithPollTime

func (o *Options) WithPollTime(pollTime time.Duration) *Options

func (*Options) WithSeed

func (o *Options) WithSeed(seed int64) *Options

type Range

type Range struct {
	Min int
	Max int
}

func NewRange

func NewRange(min, max int) Range

func (Range) Rand

func (r Range) Rand(rand *rand.Rand) int

Rand returns a random number between min (inclusive) and max (exclusive).

type SendSequence

type SendSequence struct {
	// contains filtered or unexported fields
}

SendSequence sets up an endless sequence of send transactions, moving tokens between a set of accounts

func NewSendSequence

func NewSendSequence(numAccounts, sendAmount, numIterations int) *SendSequence

func (*SendSequence) Clone

func (s *SendSequence) Clone(n int) []Sequence

func (*SendSequence) Init

func (s *SendSequence) Init(_ context.Context, _ grpc.ClientConn, allocateAccounts AccountAllocator, _ *rand.Rand, _ bool)

Init sets up the accounts involved in the sequence. It calculates the necessary balance as the fees per transaction multiplied by the number of expected iterations plus the amount to be sent from one account to another

func (*SendSequence) Next

Next submits a transaction to remove funds from one account to the next

type Sequence

type Sequence interface {
	// Clone replicates n instances of the sequence for scaling up the load
	// on a network. This is called before `Init`
	Clone(n int) []Sequence

	// Init allows the sequence to initialize itself. It may read the current state of
	// the chain and provision accounts for usage throughout the sequence.
	// For any randomness, use the rand source provided.
	Init(ctx context.Context, querier grpc.ClientConn, accountAllocator AccountAllocator, rand *rand.Rand, useFeegrant bool)

	// Next returns the next operation in the sequence. It returns EndOfSequence
	// when the sequence has been exhausted. The sequence may make use of the
	// grpc connection to query the state of the network as well as the deterministic
	// random number generator. Any error will abort the rest of the sequence.
	Next(ctx context.Context, querier grpc.ClientConn, rand *rand.Rand) (Operation, error)
}

Sequence is the basic unit for programmatic transaction generation. It embodies a pattern of transactions which are executed among a group of accounts in isolation from the rest of the state machine.

type StakeSequence

type StakeSequence struct {
	// contains filtered or unexported fields
}

StakeSequence sets up an endless sequence whereby an account delegates to a validator, continuously claims the reward, and occasionally redelegates to another validator at random. The account only ever delegates to a single validator at a time. TODO: Allow for multiple delegations

func NewStakeSequence

func NewStakeSequence(initialStake int) *StakeSequence

func (*StakeSequence) Clone

func (s *StakeSequence) Clone(n int) []Sequence

func (*StakeSequence) Init

func (s *StakeSequence) Init(_ context.Context, _ grpc.ClientConn, allocateAccounts AccountAllocator, _ *rand.Rand, useFeegrant bool)

func (*StakeSequence) Next

func (s *StakeSequence) Next(ctx context.Context, querier grpc.ClientConn, rand *rand.Rand) (Operation, error)

Jump to

Keyboard shortcuts

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