txsim

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 33 Imported by: 1

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 (
	// how often to poll the network for the latest height
	DefaultPollTime = 3 * time.Second
)

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,
	rpcEndpoints, grpcEndpoints []string,
	keys keyring.Keyring,
	masterAccName string,
	seed int64,
	pollTime time.Duration,
	useFeegrant bool,
	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 Account

type Account struct {
	Address       types.AccAddress
	PubKey        cryptotypes.PubKey
	Sequence      uint64
	AccountNumber uint64
	Balance       int64
}

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,
	masterAccName string,
	txClient *TxClient,
	queryClient *QueryClient,
	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    int64
	GasLimit uint64
	GasPrice float64
}

An 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 QueryClient

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

QueryClient multiplexes requests across multiple running gRPC connections. It does this in a round-robin fashion.

func NewQueryClient

func NewQueryClient(grpcEndpoints []string) (*QueryClient, error)

func (*QueryClient) Auth

func (qc *QueryClient) Auth() auth.QueryClient

func (*QueryClient) Bank

func (qc *QueryClient) Bank() bank.QueryClient

func (*QueryClient) Close

func (qc *QueryClient) Close() error

func (*QueryClient) Conn

func (qc *QueryClient) Conn() protogrpc.ClientConn

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 sumbits 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)

type TxClient

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

TxClient is a client for submitting transactions to one of several nodes. It uses a round-robin algorithm for multiplexing requests across multiple clients.

func NewTxClient

func NewTxClient(ctx context.Context, encCfg encoding.Config, pollTime time.Duration, rpcEndpoints []string) (*TxClient, error)

func (*TxClient) Broadcast

func (tc *TxClient) Broadcast(ctx context.Context, txBuilder sdkclient.TxBuilder, blobs []*blob.Blob) (*coretypes.ResultTx, error)

Broadcast encodes and broadcasts a transaction to the network. If CheckTx fails, the error will be returned. The method does not wait for the transaction to be included in a block.

func (*TxClient) ChainID

func (tc *TxClient) ChainID() string

func (*TxClient) Client

func (tc *TxClient) Client() *http.HTTP

Client multiplexes the RPC clients

func (*TxClient) Height

func (tc *TxClient) Height() int64

func (*TxClient) LastUpdated

func (tc *TxClient) LastUpdated() time.Time

func (*TxClient) Tx

func (tc *TxClient) Tx() sdkclient.TxBuilder

func (*TxClient) WaitForHeight

func (tc *TxClient) WaitForHeight(ctx context.Context, height int64) error

WaitForHeight continually polls the network for the latest height. It is concurrently safe.

func (*TxClient) WaitForNBlocks

func (tc *TxClient) WaitForNBlocks(ctx context.Context, blocks int64) error

WaitForNBlocks uses WaitForHeight to wait for the given number of blocks to be produced.

func (*TxClient) WaitForTx

func (tc *TxClient) WaitForTx(ctx context.Context, txID []byte) (*coretypes.ResultTx, error)

Jump to

Keyboard shortcuts

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