scenario

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const SecondsPerSlot uint64 = 12

Variables

This section is empty.

Functions

func RunTransactionScenario

func RunTransactionScenario(ctx context.Context, options TransactionScenarioOptions) error

RunTransactionScenario executes a controlled transaction scenario with rate limiting and concurrency management. It processes transactions according to the specified options until either context cancellation or reaching TotalCount (if > 0).

Features: - Rate-limited execution based on Throughput - Optional dynamic throughput increases - Concurrency control via MaxPending - Sequential logging via transaction chaining

Returns an error only if the scenario cannot be started. Transaction failures should be handled within ProcessNextTxFn.

Types

type Descriptor

type Descriptor struct {
	Name           string
	Description    string
	DefaultOptions any
	NewScenario    func(logger logrus.FieldLogger) Scenario
}

Descriptor describes a scenario.

type Options

type Options struct {
	WalletPool *spamoor.WalletPool
	Config     string
	GlobalCfg  map[string]any
}

Options contains the options for the scenario initialization.

type Scenario

type Scenario interface {
	// Flags registers the scenario's flags with the given flag set.
	Flags(flags *pflag.FlagSet) error
	// Init initializes the scenario with the given options.
	Init(options *Options) error
	// Run runs the scenario.
	Run(ctx context.Context) error
}

type TransactionScenarioOptions

type TransactionScenarioOptions struct {
	TotalCount                  uint64
	Throughput                  uint64
	MaxPending                  uint64
	ThroughputIncrementInterval uint64
	Timeout                     time.Duration // Maximum duration for scenario execution (0 = no timeout)
	WalletPool                  *spamoor.WalletPool

	// Logger for scenario execution information
	Logger *logrus.Entry

	// ProcessNextTxFn handles transaction execution with the given index
	// It should return:
	// - A callback function to log transaction results (can be nil)
	// - An error if transaction creation failed
	// - The onComplete callback must be called when transaction processing is complete
	ProcessNextTxFn func(ctx context.Context, txIdx uint64, onComplete func()) (func(), error)
}

TransactionScenarioOptions configures how the transaction scenario is executed.

Jump to

Keyboard shortcuts

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