loadtest

package
v0.1.105 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: AGPL-3.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRandomAddress

func GetRandomAddress(randSrc *rand.Rand) *common.Address

GetRandomAddress generates a random Ethereum address.

func LightSummary

func LightSummary(results []Sample, startTime, endTime time.Time, rl *rate.Limiter)

LightSummary prints a quick summary of load test results.

func NewHexwordReader

func NewHexwordReader(randSrc *rand.Rand) io.Reader

NewHexwordReader creates a new hexword reader with the given random source.

func OutputRawBytes

func OutputRawBytes(rawTx []byte) error

OutputRawBytes outputs raw bytes as a 0x-prefixed hex string.

func OutputRawTransaction

func OutputRawTransaction(tx *ethtypes.Transaction) error

OutputRawTransaction outputs a raw signed transaction as hex.

func Run

func Run(ctx context.Context, cfg *config.Config) error

Run is a convenience function that creates a runner, initializes it, and runs the load test. This allows both the main loadtest command and subcommands to use the same entry point.

func SummarizeResults

func SummarizeResults(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client, cfg *config.Config, ap *AccountPool, results []Sample, startBlockNumber, lastBlockNumber uint64) error

SummarizeResults handles the post-load-test summarization.

Types

type Account

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

Account represents a single account used by the load test.

func (*Account) Address

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

Address returns the address of the account.

func (*Account) Nonce

func (a *Account) Nonce() uint64

Nonce returns the current nonce of the account.

func (*Account) PrivateKey

func (a *Account) PrivateKey() *ecdsa.PrivateKey

PrivateKey returns the private key of the account.

type AccountPool

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

AccountPool manages a pool of accounts used for sending transactions.

func NewAccountPool

func NewAccountPool(ctx context.Context, client *ethclient.Client, cfg *AccountPoolConfig) (*AccountPool, error)

NewAccountPool creates a new account pool with the given configuration.

func (*AccountPool) Add

func (ap *AccountPool) Add(ctx context.Context, privateKey *ecdsa.PrivateKey, startNonce *uint64) error

Add adds an account to the pool with the given private key.

func (*AccountPool) AddN

func (ap *AccountPool) AddN(ctx context.Context, privateKeys ...*ecdsa.PrivateKey) error

AddN adds multiple accounts to the pool with the given private keys.

func (*AccountPool) AddRandom

func (ap *AccountPool) AddRandom(ctx context.Context) error

AddRandom adds a random account to the pool.

func (*AccountPool) AddRandomN

func (ap *AccountPool) AddRandomN(ctx context.Context, n uint64) error

AddRandomN adds N random accounts to the pool.

func (*AccountPool) AddReusableNonce

func (ap *AccountPool) AddReusableNonce(ctx context.Context, address common.Address, nonce uint64) error

AddReusableNonce adds a reusable nonce to the account with the given address.

func (*AccountPool) AllAccountsReady

func (ap *AccountPool) AllAccountsReady() (bool, int, int)

AllAccountsReady returns whether all accounts are ready for use.

func (*AccountPool) FundAccounts

func (ap *AccountPool) FundAccounts(ctx context.Context) error

FundAccounts funds all accounts in the pool.

func (*AccountPool) GetPrivateKeys added in v0.1.104

func (ap *AccountPool) GetPrivateKeys() []*ecdsa.PrivateKey

GetPrivateKeys returns the private keys of all accounts in the pool.

func (*AccountPool) Next

func (ap *AccountPool) Next(ctx context.Context) (Account, error)

Next returns the next account in the pool.

func (*AccountPool) Nonces

func (ap *AccountPool) Nonces(ctx context.Context, onlyUsed bool) *sync.Map

Nonces returns the nonces of all accounts in the pool.

func (*AccountPool) NoncesOf

func (ap *AccountPool) NoncesOf(address common.Address) (startNonce, nonce uint64)

NoncesOf returns the start nonce and current nonce for a given address.

func (*AccountPool) NumberOfPendingTxs

func (ap *AccountPool) NumberOfPendingTxs(ctx context.Context) (uint64, error)

NumberOfPendingTxs returns the difference between the internal nonce and the network pending nonce for all accounts in the pool.

func (*AccountPool) RefreshNonce

func (ap *AccountPool) RefreshNonce(ctx context.Context, address common.Address) error

RefreshNonce refreshes the nonce for the given address.

func (*AccountPool) ReturnFunds

func (ap *AccountPool) ReturnFunds(ctx context.Context) error

ReturnFunds returns funds from all accounts back to the funding account.

func (*AccountPool) SetFundingAmount

func (ap *AccountPool) SetFundingAmount(amount *big.Int)

SetFundingAmount updates the funding amount for the pool.

type AccountPoolConfig

type AccountPoolConfig struct {
	FundingPrivateKey         *ecdsa.PrivateKey
	FundingAmount             *big.Int
	RateLimit                 float64
	EthCallOnly               bool
	RefundRemainingFunds      bool
	CheckBalanceBeforeFunding bool
	LegacyTxMode              bool
	AccountsPerFundingTx      uint64
	// Gas override settings
	ForceGasPrice         uint64
	ForcePriorityGasPrice uint64
	GasPriceMultiplier    *big.Float
	ChainSupportBaseFee   bool
}

AccountPoolConfig holds configuration for the account pool.

type BlobCommitment

type BlobCommitment struct {
	Blob          [131072]byte // kzg4844.Blob size
	Commitment    [48]byte     // kzg4844.Commitment size
	Proof         [48]byte     // kzg4844.Proof size
	VersionedHash common.Hash
}

BlobCommitment holds blob transaction commitment data.

type BlockSummary

type BlockSummary struct {
	Block     *rpctypes.RawBlockResponse
	Receipts  map[common.Hash]rpctypes.RawTxReceipt
	Latencies map[uint64]time.Duration
}

BlockSummary holds data about a single block's transactions.

type Latency

type Latency struct {
	Min    float64
	Median float64
	Max    float64
}

Latency holds min, median, and max latency values.

type Percentiles added in v0.1.104

type Percentiles struct {
	P50 float64
	P75 float64
	P90 float64
	P95 float64
	P99 float64
}

Percentiles holds p50, p75, p90, p95, p99 values.

type PreconfStats added in v0.1.104

type PreconfStats struct {
	Summary      PreconfSummary    `json:"summary"`
	Transactions []PreconfTxResult `json:"transactions"`
}

PreconfStats is the JSON output structure containing summary and per-tx data.

type PreconfSummary added in v0.1.104

type PreconfSummary struct {
	TotalTasks         uint64 `json:"total_tasks"`
	PreconfSuccess     uint64 `json:"preconf_success"`
	PreconfFail        uint64 `json:"preconf_fail"`
	BothFailed         uint64 `json:"both_failed"`
	IneffectivePreconf uint64 `json:"ineffective_preconf"`
	FalsePositives     uint64 `json:"false_positives"`
	Confidence         uint64 `json:"confidence"`
	ReceiptSuccess     uint64 `json:"receipt_success"`
	ReceiptFail        uint64 `json:"receipt_fail"`
	TotalGasUsed       uint64 `json:"total_gas_used"`

	// Preconf duration percentiles (milliseconds)
	PreconfP50 float64 `json:"preconf_p50,omitempty"`
	PreconfP75 float64 `json:"preconf_p75,omitempty"`
	PreconfP90 float64 `json:"preconf_p90,omitempty"`
	PreconfP95 float64 `json:"preconf_p95,omitempty"`
	PreconfP99 float64 `json:"preconf_p99,omitempty"`

	// Receipt duration percentiles (milliseconds)
	ReceiptP50 float64 `json:"receipt_p50,omitempty"`
	ReceiptP75 float64 `json:"receipt_p75,omitempty"`
	ReceiptP90 float64 `json:"receipt_p90,omitempty"`
	ReceiptP95 float64 `json:"receipt_p95,omitempty"`
	ReceiptP99 float64 `json:"receipt_p99,omitempty"`
}

PreconfSummary holds aggregate stats from the preconf tracker.

type PreconfTracker added in v0.1.104

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

func NewPreconfTracker added in v0.1.104

func NewPreconfTracker(client *ethclient.Client, statsFilePath string) *PreconfTracker

func (*PreconfTracker) Start added in v0.1.104

func (pt *PreconfTracker) Start(ctx context.Context)

Start begins periodic stats file writing every 2 seconds until context is cancelled.

func (*PreconfTracker) Stats added in v0.1.104

func (pt *PreconfTracker) Stats()

Stats logs the final summary and writes the stats file.

func (*PreconfTracker) Track added in v0.1.104

func (pt *PreconfTracker) Track(txHash common.Hash)

type PreconfTxResult added in v0.1.104

type PreconfTxResult struct {
	TxHash            string `json:"tx_hash"`
	PreconfDurationMs int64  `json:"preconf_duration_ms,omitempty"`
	ReceiptDurationMs int64  `json:"receipt_duration_ms,omitempty"`
	BlockDiff         uint64 `json:"block_diff,omitempty"`
	GasUsed           uint64 `json:"gas_used,omitempty"`
	Status            uint64 `json:"status,omitempty"` // 1 = success, 0 = fail
}

PreconfTxResult holds per-transaction preconf and receipt data.

type Runner

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

Runner handles the execution of a load test.

func NewRunner

func NewRunner(cfg *config.Config) (*Runner, error)

NewRunner creates a new Runner with the given configuration.

func (*Runner) Close

func (r *Runner) Close()

Close cleans up runner resources.

func (*Runner) GetAccountPool

func (r *Runner) GetAccountPool() *AccountPool

GetAccountPool returns the account pool.

func (*Runner) GetClient

func (r *Runner) GetClient() *ethclient.Client

GetClient returns the ethclient.

func (*Runner) GetConfig

func (r *Runner) GetConfig() *config.Config

GetConfig returns the configuration.

func (*Runner) GetDependencies

func (r *Runner) GetDependencies() *mode.Dependencies

GetDependencies returns the mode dependencies.

func (*Runner) GetResults

func (r *Runner) GetResults() []Sample

GetResults returns all recorded samples.

func (*Runner) Init

func (r *Runner) Init(ctx context.Context) error

Init sets up the runner, including clients and account pool.

func (*Runner) RecordSample

func (r *Runner) RecordSample(goRoutineID, requestID int64, err error, start, end time.Time, nonce uint64)

RecordSample records a load test sample.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

Run executes the load test.

func (*Runner) SetModes

func (r *Runner) SetModes(m []mode.Runner)

SetModes sets the modes to be used during load testing.

type Sample

type Sample struct {
	GoRoutineID int64
	RequestID   int64
	RequestTime time.Time
	WaitTime    time.Duration
	Receipt     string
	IsError     bool
	Nonce       uint64
}

Sample represents a single load test request/response.

type Summary

type Summary struct {
	BlockNumber uint64
	Time        time.Time
	GasLimit    uint64
	GasUsed     uint64
	NumTx       int
	Utilization float64
	Latencies   Latency
}

Summary holds summary data for a single block.

type SummaryOutput

type SummaryOutput struct {
	Summaries          []Summary
	SuccessfulTx       int64
	TotalTx            int64
	TotalMiningTime    time.Duration
	TotalGasUsed       uint64
	TransactionsPerSec float64
	GasPerSecond       float64
	Latencies          Latency
}

SummaryOutput holds the complete summary output data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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