Skip to content

Commit 2b5ea3a

Browse files
authored
chore!: loadtest clean-up (#658)
* loadtest: remove modes function, random-precompile and specific-precompile * rename flag --lt-address to --loadtest-contract-address * rename flag -b, --byte-count to --store-data-size * rename flag --steady-state-tx-pool-size to --adaptive-target-size * rename flag --send-only to --fire-and-forget * rename flag --call-only to --eth-call-only * remove flag -i, --iterations * rename flag --to-random to --random-recipients * rename --force-contract-deploy to --skip-contract-deploy (inverted logic); rename --keep-funded-amount to --keep-funds-after-test * remove loadtest deploy flag * make gen * review docs * make gen-doc * rename multi-account flags from addresses to accounts * fix typos * add --send-only alias to --fire-and-forget flag * make gen-doc * fix send-only alias flag name
1 parent 717ab2e commit 2b5ea3a

File tree

12 files changed

+172
-337
lines changed

12 files changed

+172
-337
lines changed

cmd/flag_loader/flag_loader.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package flag_loader
22

33
import (
44
"fmt"
5-
"os"
65
"math/big"
6+
"os"
77

88
"github.com/spf13/cobra"
99
)
@@ -14,24 +14,24 @@ const (
1414
)
1515

1616
type BigIntValue struct {
17-
Val *big.Int
17+
Val *big.Int
1818
}
1919

2020
func (b *BigIntValue) String() string {
21-
// Return the decimal representation
22-
return b.Val.String()
21+
// Return the decimal representation
22+
return b.Val.String()
2323
}
2424

2525
func (b *BigIntValue) Set(s string) error {
26-
// Parse the string in base 10
27-
if _, ok := b.Val.SetString(s, 10); !ok {
28-
return fmt.Errorf("invalid big integer: %q", s)
29-
}
30-
return nil
26+
// Parse the string in base 10
27+
if _, ok := b.Val.SetString(s, 10); !ok {
28+
return fmt.Errorf("invalid big integer: %q", s)
29+
}
30+
return nil
3131
}
3232

3333
func (b *BigIntValue) Type() string {
34-
return "big.Int"
34+
return "big.Int"
3535
}
3636

3737
func GetRpcUrlFlagValue(cmd *cobra.Command) *string {

cmd/fund/cmd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ type cmdFundParams struct {
3636

3737
var (
3838
//go:embed usage.md
39-
usage string
40-
params cmdFundParams
39+
usage string
40+
params cmdFundParams
4141
defaultFundingInWei = big.NewInt(50000000000000000) // 0.05 ETH
4242
)
4343

@@ -70,7 +70,7 @@ func init() {
7070
p.UseHDDerivation = flagSet.Bool("hd-derivation", true, "Derive wallets to fund from the private key in a deterministic way")
7171
p.WalletAddresses = flagSet.StringSlice("addresses", nil, "Comma-separated list of wallet addresses to fund")
7272
p.FundingAmountInWei = defaultFundingInWei
73-
flagSet.Var(&flag_loader.BigIntValue{Val: p.FundingAmountInWei }, "eth-amount", "The amount of wei to send to each wallet")
73+
flagSet.Var(&flag_loader.BigIntValue{Val: p.FundingAmountInWei}, "eth-amount", "The amount of wei to send to each wallet")
7474

7575
p.OutputFile = flagSet.StringP("file", "f", "wallets.json", "The output JSON file path for storing the addresses and private keys of funded wallets")
7676

cmd/loadtest/account.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func NewAccountPool(ctx context.Context, client *ethclient.Client, fundingPrivat
143143
// Debug log for when fundingAmount==0.
144144
if fundingAmount.Cmp(big.NewInt(0)) == 0 {
145145
log.Debug().
146-
Msg("address-funding-amount is zero - account funding disabled")
146+
Msg("account-funding-amount is zero - account funding disabled")
147147
}
148148

149149
return &AccountPool{
@@ -383,7 +383,7 @@ func (ap *AccountPool) FundAccounts(ctx context.Context) error {
383383
}
384384
balance, err := ap.client.BalanceAt(ctx, tops.From, nil)
385385
if err != nil {
386-
log.Error().Err(err).Msg("Unable to get funding address balance")
386+
log.Error().Err(err).Msg("Unable to get funding account balance")
387387
}
388388

389389
totalBalanceNeeded := new(big.Int).Mul(ap.fundingAmount, big.NewInt(int64(len(ap.accounts))))
@@ -484,7 +484,7 @@ func (ap *AccountPool) ReturnFunds(ctx context.Context) error {
484484
defer ap.mu.Unlock()
485485

486486
log.Debug().
487-
Msg("Returning funds from sending addresses to funding address")
487+
Msg("Returning funds from sending accounts to funding account")
488488

489489
ethTransferGas := big.NewInt(21000)
490490
err := ap.clientRateLimiter.Wait(ctx)
@@ -513,7 +513,7 @@ func (ap *AccountPool) ReturnFunds(ctx context.Context) error {
513513
}
514514
balanceBefore, err := ap.client.BalanceAt(ctx, fundingAddress, nil)
515515
if err != nil {
516-
log.Error().Err(err).Msg("Unable to get funding address balance")
516+
log.Error().Err(err).Msg("Unable to get funding account balance")
517517
return err
518518
}
519519
log.Debug().
@@ -687,7 +687,7 @@ func (ap *AccountPool) ReturnFunds(ctx context.Context) error {
687687
}
688688
balanceAfter, err := ap.client.BalanceAt(ctx, fundingAddress, nil)
689689
if err != nil {
690-
log.Error().Err(err).Msg("Unable to get funding address balance")
690+
log.Error().Err(err).Msg("Unable to get funding account balance")
691691
return err
692692
}
693693

@@ -744,7 +744,7 @@ func (ap *AccountPool) Next(ctx context.Context) (Account, error) {
744744
account := ap.accounts[ap.currentAccountIndex]
745745

746746
// if test is call only, there is no need to fund accounts, return it
747-
if !*inputLoadTestParams.CallOnly {
747+
if !*inputLoadTestParams.EthCallOnly {
748748
_, err := ap.fundAccountIfNeeded(ctx, account, nil, true)
749749
if err != nil {
750750
return Account{}, err

cmd/loadtest/app.go

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,33 @@ type (
4242
Concurrency *int64
4343
BatchSize *uint64
4444
TimeLimit *int64
45-
ToRandom *bool
46-
CallOnly *bool
47-
CallOnlyLatestBlock *bool
45+
RandomRecipients *bool
46+
EthCallOnly *bool
47+
EthCallOnlyLatestBlock *bool
4848
ChainID *uint64
4949
PrivateKey *string
5050
ToAddress *string
5151
EthAmountInWei *uint64
5252
RateLimit *float64
5353
AdaptiveRateLimit *bool
54-
SteadyStateTxPoolSize *uint64
54+
AdaptiveTargetSize *uint64
5555
AdaptiveRateLimitIncrement *uint64
5656
AdaptiveCycleDuration *uint64
5757
AdaptiveBackoffFactor *float64
5858
Modes *[]string
59-
Function *uint64
60-
Iterations *uint64
61-
ByteCount *uint64
59+
StoreDataSize *uint64
6260
Seed *int64
63-
LtAddress *string
61+
LoadtestContractAddress *string
6462
ERC20Address *string
6563
ERC721Address *string
6664
DelAddress *string
67-
ForceContractDeploy *bool
6865
ForceGasLimit *uint64
6966
ForceGasPrice *uint64
7067
ForcePriorityGasPrice *uint64
7168
ShouldProduceSummary *bool
7269
SummaryOutputMode *string
7370
LegacyTransactionMode *bool
74-
SendOnly *bool
71+
FireAndForget *bool
7572
RecallLength *uint64
7673
ContractAddress *string
7774
ContractCallData *string
@@ -82,11 +79,11 @@ type (
8279
BlobFeeCap *uint64
8380
StartNonce *uint64
8481
GasPriceMultiplier *float64
85-
SendingAddressCount *uint64
86-
AddressFundingAmount *big.Int
87-
PreFundSendingAddresses *bool
88-
KeepFundedAmount *bool
89-
SendingAddressesFile *string
82+
SendingAccountsCount *uint64
83+
AccountFundingAmount *big.Int
84+
PreFundSendingAccounts *bool
85+
KeepFundsAfterTest *bool
86+
SendingAccountsFile *string
9087
Proxy *string
9188
WaitForReceipt *bool
9289
ReceiptRetryMax *uint
@@ -166,8 +163,8 @@ var (
166163
0xF0, 0x0D, 0xBA, 0xBE,
167164
}
168165

169-
randSrc *rand.Rand
170-
defaultFunding = new(big.Int).SetUint64(0) // 1 ETH
166+
randSrc *rand.Rand
167+
defaultAccountFundingAmount = new(big.Int).SetUint64(0) // 1 ETH
171168
)
172169

173170
// LoadtestCmd represents the loadtest command
@@ -225,18 +222,17 @@ func initFlags() {
225222
ltp.PrivateKey = LoadtestCmd.PersistentFlags().String("private-key", codeQualityPrivateKey, "The hex encoded private key that we'll use to send transactions")
226223
ltp.ChainID = LoadtestCmd.PersistentFlags().Uint64("chain-id", 0, "The chain id for the transactions.")
227224
ltp.ToAddress = LoadtestCmd.PersistentFlags().String("to-address", "0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF", "The address that we're going to send to")
228-
ltp.ToRandom = LoadtestCmd.PersistentFlags().Bool("to-random", false, "When doing a transfer test, should we send to random addresses rather than DEADBEEFx5")
229-
ltp.CallOnly = LoadtestCmd.PersistentFlags().Bool("call-only", false, "When using this mode, rather than sending a transaction, we'll just call. This mode is incompatible with adaptive rate limiting, summarization, and a few other features.")
230-
ltp.CallOnlyLatestBlock = LoadtestCmd.PersistentFlags().Bool("call-only-latest", false, "When using call only mode with recall, should we execute on the latest block or on the original block")
225+
ltp.RandomRecipients = LoadtestCmd.PersistentFlags().Bool("random-recipients", false, "When doing a transfer test, should we send to random addresses rather than DEADBEEFx5")
226+
ltp.EthCallOnly = LoadtestCmd.PersistentFlags().Bool("eth-call-only", false, "When using this mode, rather than sending a transaction, we'll just call. This mode is incompatible with adaptive rate limiting, summarization, and a few other features.")
227+
ltp.EthCallOnlyLatestBlock = LoadtestCmd.PersistentFlags().Bool("eth-call-only-latest", false, "When using call only mode with recall, should we execute on the latest block or on the original block")
231228
ltp.EthAmountInWei = LoadtestCmd.PersistentFlags().Uint64("eth-amount-in-wei", 0, "The amount of ether in wei to send on every transaction")
232229
ltp.RateLimit = LoadtestCmd.PersistentFlags().Float64("rate-limit", 4, "An overall limit to the number of requests per second. Give a number less than zero to remove this limit all together")
233230
ltp.AdaptiveRateLimit = LoadtestCmd.PersistentFlags().Bool("adaptive-rate-limit", false, "Enable AIMD-style congestion control to automatically adjust request rate")
234-
ltp.SteadyStateTxPoolSize = LoadtestCmd.PersistentFlags().Uint64("steady-state-tx-pool-size", 1000, "When using adaptive rate limiting, this value sets the target queue size. If the queue is smaller than this value, we'll speed up. If the queue is smaller than this value, we'll back off.")
231+
ltp.AdaptiveTargetSize = LoadtestCmd.PersistentFlags().Uint64("adaptive-target-size", 1000, "When using adaptive rate limiting, this value sets the target queue size. If the queue is smaller than this value, we'll speed up. If the queue is smaller than this value, we'll back off.")
235232
ltp.AdaptiveRateLimitIncrement = LoadtestCmd.PersistentFlags().Uint64("adaptive-rate-limit-increment", 50, "When using adaptive rate limiting, this flag controls the size of the additive increases.")
236233
ltp.AdaptiveCycleDuration = LoadtestCmd.PersistentFlags().Uint64("adaptive-cycle-duration-seconds", 10, "When using adaptive rate limiting, this flag controls how often we check the queue size and adjust the rates")
237234
ltp.AdaptiveBackoffFactor = LoadtestCmd.PersistentFlags().Float64("adaptive-backoff-factor", 2, "When using adaptive rate limiting, this flag controls our multiplicative decrease value.")
238235
ltp.GasPriceMultiplier = LoadtestCmd.PersistentFlags().Float64("gas-price-multiplier", 1, "A multiplier to increase or decrease the gas price")
239-
ltp.Iterations = LoadtestCmd.PersistentFlags().Uint64P("iterations", "i", 1, "If we're making contract calls, this controls how many times the contract will execute the instruction in a loop. If we are making ERC721 Mints, this indicates the minting batch size")
240236
ltp.Seed = LoadtestCmd.PersistentFlags().Int64("seed", 123456, "A seed for generating random values and addresses")
241237
ltp.ForceGasLimit = LoadtestCmd.PersistentFlags().Uint64("gas-limit", 0, "In environments where the gas limit can't be computed on the fly, we can specify it manually. This can also be used to avoid eth_estimateGas")
242238
ltp.ForceGasPrice = LoadtestCmd.PersistentFlags().Uint64("gas-price", 0, "In environments where the gas price can't be determined automatically, we can specify it manually")
@@ -246,40 +242,35 @@ func initFlags() {
246242
ltp.BatchSize = LoadtestCmd.PersistentFlags().Uint64("batch-size", 999, "Number of batches to perform at a time for receipt fetching. Default is 999 requests at a time.")
247243
ltp.SummaryOutputMode = LoadtestCmd.PersistentFlags().String("output-mode", "text", "Format mode for summary output (json | text)")
248244
ltp.LegacyTransactionMode = LoadtestCmd.PersistentFlags().Bool("legacy", false, "Send a legacy transaction instead of an EIP1559 transaction.")
249-
ltp.SendOnly = LoadtestCmd.PersistentFlags().Bool("send-only", false, "Send transactions and load without waiting for it to be mined.")
245+
ltp.FireAndForget = LoadtestCmd.PersistentFlags().Bool("fire-and-forget", false, "Send transactions and load without waiting for it to be mined.")
246+
LoadtestCmd.PersistentFlags().BoolVar(ltp.FireAndForget, "send-only", false, "Alias for --fire-and-forget.")
250247
ltp.BlobFeeCap = LoadtestCmd.Flags().Uint64("blob-fee-cap", 100000, "The blob fee cap, or the maximum blob fee per chunk, in Gwei.")
251-
ltp.SendingAddressCount = LoadtestCmd.Flags().Uint64("sending-address-count", 1, "The number of sending addresses to use. This is useful for avoiding pool account queue.")
252-
ltp.AddressFundingAmount = defaultFunding
253-
LoadtestCmd.Flags().Var(&flag_loader.BigIntValue{Val: ltp.AddressFundingAmount}, "address-funding-amount", "The amount in wei to fund the sending addresses with. Set to 0 to disable account funding (useful for call-only mode or pre-funded addresses).")
254-
ltp.PreFundSendingAddresses = LoadtestCmd.Flags().Bool("pre-fund-sending-addresses", false, "If set to true, the sending addresses will be funded at the start of the execution, otherwise all addresses will be funded when used for the first time.")
255-
ltp.KeepFundedAmount = LoadtestCmd.Flags().Bool("keep-funded-amount", false, "If set to true, the funded amount will be kept in the sending addresses. Otherwise, the funded amount will be refunded back to the account used to fund the account.")
256-
ltp.SendingAddressesFile = LoadtestCmd.Flags().String("sending-addresses-file", "", "The file containing the sending addresses private keys, one per line. This is useful for avoiding pool account queue but also to keep the same sending addresses for different execution cycles.")
248+
ltp.SendingAccountsCount = LoadtestCmd.Flags().Uint64("sending-accounts-count", 1, "The number of sending accounts to use. This is useful for avoiding pool account queue.")
249+
ltp.AccountFundingAmount = defaultAccountFundingAmount
250+
LoadtestCmd.Flags().Var(&flag_loader.BigIntValue{Val: ltp.AccountFundingAmount}, "account-funding-amount", "The amount in wei to fund the sending accounts with. Set to 0 to disable account funding (useful for eth-call-only mode or pre-funded accounts).")
251+
ltp.PreFundSendingAccounts = LoadtestCmd.Flags().Bool("pre-fund-sending-accounts", false, "If set to true, the sending accounts will be funded at the start of the execution, otherwise all accounts will be funded when used for the first time.")
252+
ltp.KeepFundsAfterTest = LoadtestCmd.Flags().Bool("keep-funds-after-test", false, "If set to true, the funded amount will be kept in the sending accounts. Otherwise, the funded amount will be refunded back to the account used to fund the account.")
253+
ltp.SendingAccountsFile = LoadtestCmd.Flags().String("sending-accounts-file", "", "The file containing the sending accounts private keys, one per line. This is useful for avoiding pool account queue but also to keep the same sending accounts for different execution cycles.")
257254

258255
// Local flags.
259-
ltp.Modes = LoadtestCmd.Flags().StringSliceP("mode", "m", []string{"t"}, `The testing mode to use. It can be multiple like: "c,d,f,t"
256+
ltp.Modes = LoadtestCmd.Flags().StringSliceP("mode", "m", []string{"t"}, `The testing mode to use. It can be multiple like: "d,t"
260257
2, erc20 - Send ERC20 tokens
261258
7, erc721 - Mint ERC721 tokens
262259
b, blob - Send blob transactions
263-
c, call - Call random contract functions
264260
cc, contract-call - Make contract calls
265261
d, deploy - Deploy contracts
266-
f, function - Call random contract functions
267262
i, inscription - Send inscription transactions
268263
inc, increment - Increment a counter
269-
pr, random-precompile - Call random precompiled contracts
270-
px, specific-precompile - Call specific precompiled contracts
271264
r, random - Random modes (does not include the following modes: blob, call, inscription, recall, rpc, uniswapv3)
272265
R, recall - Replay or simulate transactions
273266
rpc - Call random rpc methods
274267
s, store - Store bytes in a dynamic byte array
275268
t, transaction - Send transactions
276269
v3, uniswapv3 - Perform UniswapV3 swaps`)
277-
ltp.Function = LoadtestCmd.Flags().Uint64P("function", "f", 1, "A specific function to be called if running with --mode f or a specific precompiled contract when running with --mode a")
278-
ltp.ByteCount = LoadtestCmd.Flags().Uint64P("byte-count", "b", 1024, "If we're in store mode, this controls how many bytes we'll try to store in our contract")
279-
ltp.LtAddress = LoadtestCmd.Flags().String("lt-address", "", "The address of a pre-deployed load test contract")
270+
ltp.StoreDataSize = LoadtestCmd.Flags().Uint64("store-data-size", 1024, "If we're in store mode, this controls how many bytes we'll try to store in our contract")
271+
ltp.LoadtestContractAddress = LoadtestCmd.Flags().String("loadtest-contract-address", "", "The address of a pre-deployed load test contract")
280272
ltp.ERC20Address = LoadtestCmd.Flags().String("erc20-address", "", "The address of a pre-deployed ERC20 contract")
281273
ltp.ERC721Address = LoadtestCmd.Flags().String("erc721-address", "", "The address of a pre-deployed ERC721 contract")
282-
ltp.ForceContractDeploy = LoadtestCmd.Flags().Bool("force-contract-deploy", false, "Some load test modes don't require a contract deployment. Set this flag to true to force contract deployments. This will still respect the --lt-address flags.")
283274
ltp.RecallLength = LoadtestCmd.Flags().Uint64("recall-blocks", 50, "The number of blocks that we'll attempt to fetch for recall")
284275
ltp.ContractAddress = LoadtestCmd.Flags().String("contract-address", "", "The address of the contract that will be used in --mode contract-call. This must be paired up with --mode contract-call and --calldata")
285276
ltp.ContractCallData = LoadtestCmd.Flags().String("calldata", "", "The hex encoded calldata passed in. The format is function signature + arguments encoded together. This must be paired up with --mode contract-call and --contract-address")

0 commit comments

Comments
 (0)