Skip to content

Commit

Permalink
collect all errors for tx sending and just log them
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Apr 10, 2024
1 parent 96c8143 commit 1a8ae5d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
13 changes: 11 additions & 2 deletions loadtest/runner/base_load_test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func (r *BaseLoadTestRunner) calculateTPS(blockInfos map[uint64]blockInfo, txnSt
// Finally, the function prints the time taken to send the transactions
// and returns the transaction hashes and nil error.
func (r *BaseLoadTestRunner) sendTransactions(
sendFn func(*account, *big.Int, *progressbar.ProgressBar) ([]types.Hash, error)) ([]types.Hash, error) {
sendFn func(*account, *big.Int, *progressbar.ProgressBar) ([]types.Hash, []error, error)) ([]types.Hash, error) {
fmt.Println("=============================================================")

chainID, err := r.client.ChainID()
Expand All @@ -445,6 +445,7 @@ func (r *BaseLoadTestRunner) sendTransactions(

start := time.Now().UTC()
totalTxs := r.cfg.VUs * r.cfg.TxsPerUser
foundErrs := make([]error, 0)

bar := progressbar.Default(int64(totalTxs), "Sending transactions")
defer bar.Close()
Expand All @@ -462,11 +463,12 @@ func (r *BaseLoadTestRunner) sendTransactions(
return ctx.Err()

default:
txnHashes, err := sendFn(vu, chainID, bar)
txnHashes, sendErrors, err := sendFn(vu, chainID, bar)
if err != nil {
return err
}

foundErrs = append(foundErrs, sendErrors...)
allTxnHashes = append(allTxnHashes, txnHashes...)

return nil
Expand All @@ -480,5 +482,12 @@ func (r *BaseLoadTestRunner) sendTransactions(

fmt.Println("Sending transactions took", time.Since(start))

if len(foundErrs) > 0 {
fmt.Println("Errors found while sending transactions:")
for _, err := range foundErrs {

Check failure on line 487 in loadtest/runner/base_load_test_runner.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

ranges should only be cuddled with assignments used in the iteration (wsl)
fmt.Println(err)
}
}

return allTxnHashes, nil
}
16 changes: 9 additions & 7 deletions loadtest/runner/eoa_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (e *EOARunner) sendTransactions() ([]types.Hash, error) {
// For each transaction, it increments the account's nonce and returns the transaction hashes.
// If an error occurs during the transaction sending process, it returns the error.
func (e *EOARunner) sendTransactionsForUser(account *account, chainID *big.Int,
bar *progressbar.ProgressBar) ([]types.Hash, error) {
bar *progressbar.ProgressBar) ([]types.Hash, []error, error) {
txRelayer, err := txrelayer.NewTxRelayer(
txrelayer.WithClient(e.client),
txrelayer.WithChainID(chainID),
Expand All @@ -79,7 +79,7 @@ func (e *EOARunner) sendTransactionsForUser(account *account, chainID *big.Int,
txrelayer.WithoutNonceGet(),
)
if err != nil {
return nil, err
return nil, nil, err
}

var (
Expand All @@ -91,14 +91,14 @@ func (e *EOARunner) sendTransactionsForUser(account *account, chainID *big.Int,
if e.cfg.DynamicTxs {
mpfpg, err := e.client.MaxPriorityFeePerGas()
if err != nil {
return nil, err
return nil, nil, err
}

maxPriorityFeePerGas = new(big.Int).Mul(mpfpg, big.NewInt(2))

feeHistory, err := e.client.FeeHistory(1, jsonrpc.LatestBlockNumber, nil)
if err != nil {
return nil, err
return nil, nil, err
}

baseFee := big.NewInt(0)
Expand All @@ -112,12 +112,14 @@ func (e *EOARunner) sendTransactionsForUser(account *account, chainID *big.Int,
} else {
gp, err := e.client.GasPrice()
if err != nil {
return nil, err
return nil, nil, err
}

gasPrice = new(big.Int).SetUint64(gp + (gp * 20 / 100))
}

sendErrs := make([]error, 0)

for i := 0; i < e.cfg.TxsPerUser; i++ {
var err error
if e.cfg.DynamicTxs {
Expand All @@ -143,12 +145,12 @@ func (e *EOARunner) sendTransactionsForUser(account *account, chainID *big.Int,
}

if err != nil {
return nil, err
sendErrs = append(sendErrs, err)
}

account.nonce++
bar.Add(1)
}

return txRelayer.GetTxnHashes(), nil
return txRelayer.GetTxnHashes(), sendErrs, nil
}
21 changes: 12 additions & 9 deletions loadtest/runner/erc20_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (e *ERC20Runner) deployERC20Token() error {
// If any error occurs during the minting process, an error is returned.
func (e *ERC20Runner) mintERC20TokenToVUs() error {
fmt.Println("=============================================================")

start := time.Now().UTC()

bar := progressbar.Default(int64(e.cfg.VUs), "Minting ERC20 tokens to VUs")
Expand Down Expand Up @@ -222,7 +223,7 @@ func (e *ERC20Runner) sendTransactions() ([]types.Hash, error) {
// It takes an account pointer and a chainID as input parameters.
// It returns a slice of transaction hashes and an error if any.
func (e *ERC20Runner) sendTransactionsForUser(account *account, chainID *big.Int,
bar *progressbar.ProgressBar) ([]types.Hash, error) {
bar *progressbar.ProgressBar) ([]types.Hash, []error, error) {
txRelayer, err := txrelayer.NewTxRelayer(
txrelayer.WithClient(e.client),
txrelayer.WithChainID(chainID),
Expand All @@ -232,7 +233,7 @@ func (e *ERC20Runner) sendTransactionsForUser(account *account, chainID *big.Int
txrelayer.WithoutNonceGet(),
)
if err != nil {
return nil, err
return nil, nil, err
}

var (
Expand All @@ -244,14 +245,14 @@ func (e *ERC20Runner) sendTransactionsForUser(account *account, chainID *big.Int
if e.cfg.DynamicTxs {
mpfpg, err := e.client.MaxPriorityFeePerGas()
if err != nil {
return nil, err
return nil, nil, err
}

maxPriorityFeePerGas = new(big.Int).Mul(mpfpg, big.NewInt(2))

feeHistory, err := e.client.FeeHistory(1, jsonrpc.LatestBlockNumber, nil)
if err != nil {
return nil, err
return nil, nil, err
}

baseFee := big.NewInt(0)
Expand All @@ -265,19 +266,21 @@ func (e *ERC20Runner) sendTransactionsForUser(account *account, chainID *big.Int
} else {
gp, err := e.client.GasPrice()
if err != nil {
return nil, err
return nil, nil, err
}

gasPrice = new(big.Int).SetUint64(gp + (gp * 20 / 100))
gasPrice = new(big.Int).SetUint64(gp * 2)
}

sendErrs := make([]error, 0)

for i := 0; i < e.cfg.TxsPerUser; i++ {
input, err := e.erc20TokenArtifact.Abi.Methods["transfer"].Encode(map[string]interface{}{
"receiver": receiverAddr,
"numTokens": big.NewInt(1),
})
if err != nil {
return nil, err
return nil, nil, err
}

if e.cfg.DynamicTxs {
Expand All @@ -301,12 +304,12 @@ func (e *ERC20Runner) sendTransactionsForUser(account *account, chainID *big.Int
}

if err != nil {
return nil, err
sendErrs = append(sendErrs, err)
}

account.nonce++
bar.Add(1)
}

return txRelayer.GetTxnHashes(), nil
return txRelayer.GetTxnHashes(), sendErrs, nil
}

0 comments on commit 1a8ae5d

Please sign in to comment.