From b14f642be0454c70dc34d8ee8c659ef48a26e088 Mon Sep 17 00:00:00 2001 From: leovct Date: Tue, 28 Nov 2023 09:13:27 +0100 Subject: [PATCH] chore: convert `polycli loadtest --send-amount` flag from wei in hex format to eth in float format --- cmd/loadtest/app.go | 8 ++++---- cmd/loadtest/loadtest.go | 6 +----- doc/polycli_loadtest.md | 2 +- doc/polycli_loadtest_uniswapv3.md | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/cmd/loadtest/app.go b/cmd/loadtest/app.go index f89a18fb..5a7c41ac 100644 --- a/cmd/loadtest/app.go +++ b/cmd/loadtest/app.go @@ -3,7 +3,7 @@ package loadtest import ( "crypto/ecdsa" _ "embed" - "fmt" + "errors" "math/big" "math/rand" "sync" @@ -47,7 +47,7 @@ type ( ChainID *uint64 PrivateKey *string ToAddress *string - HexSendAmount *string + SendAmountInEth *float64 RateLimit *float64 AdaptiveRateLimit *bool SteadyStateTxPoolSize *uint64 @@ -179,7 +179,7 @@ func checkLoadtestFlags() error { } if ltp.AdaptiveBackoffFactor != nil && *ltp.AdaptiveBackoffFactor <= 0.0 { - return fmt.Errorf("the backoff factor needs to be non-zero positive") + return errors.New("the backoff factor needs to be non-zero positive") } return nil @@ -204,7 +204,7 @@ func initFlags() { ltp.ToRandom = LoadtestCmd.PersistentFlags().Bool("to-random", false, "When doing a transfer test, should we send to random addresses rather than DEADBEEFx5") 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.") 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") - ltp.HexSendAmount = LoadtestCmd.PersistentFlags().String("send-amount", "0x38D7EA4C68000", "The amount of wei that we'll send every transaction") + ltp.SendAmountInEth = LoadtestCmd.PersistentFlags().Float64("eth-send-amount", 0.001, "The amount of wei that we'll send every transaction") 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") ltp.AdaptiveRateLimit = LoadtestCmd.PersistentFlags().Bool("adaptive-rate-limit", false, "Enable AIMD-style congestion control to automatically adjust request rate") 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.") diff --git a/cmd/loadtest/loadtest.go b/cmd/loadtest/loadtest.go index f8cc67b6..ddc57d77 100644 --- a/cmd/loadtest/loadtest.go +++ b/cmd/loadtest/loadtest.go @@ -180,11 +180,7 @@ func initializeLoadTestParams(ctx context.Context, c *ethclient.Client) error { toAddr := ethcommon.HexToAddress(*inputLoadTestParams.ToAddress) - amt, err := util.HexToBigInt(*inputLoadTestParams.HexSendAmount) - if err != nil { - log.Error().Err(err).Msg("Couldn't parse send amount") - return err - } + amt := util.EthToWei(*inputLoadTestParams.SendAmountInEth) header, err := c.HeaderByNumber(ctx, nil) if err != nil { diff --git a/doc/polycli_loadtest.md b/doc/polycli_loadtest.md index 097b2c77..e345c433 100644 --- a/doc/polycli_loadtest.md +++ b/doc/polycli_loadtest.md @@ -114,6 +114,7 @@ The codebase has a contract that used for load testing. It's written in Yul and -c, --concurrency int Number of requests to perform concurrently. Default is one request at a time. (default 1) --erc20-address string The address of a pre-deployed ERC20 contract --erc721-address string The address of a pre-deployed ERC721 contract + --eth-send-amount float The amount of wei that we'll send every transaction (default 0.001) --force-contract-deploy 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. -f, --function --mode f A specific function to be called if running with --mode f or a specific precompiled contract when running with `--mode a` (default 1) --gas-limit uint 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 @@ -144,7 +145,6 @@ The codebase has a contract that used for load testing. It's written in Yul and -n, --requests int Number of requests to perform for the benchmarking session. The default is to just perform a single request which usually leads to non-representative benchmarking results. (default 1) -r, --rpc-url string The RPC endpoint url (default "http://localhost:8545") --seed int A seed for generating random values and addresses (default 123456) - --send-amount string The amount of wei that we'll send every transaction (default "0x38D7EA4C68000") --steady-state-tx-pool-size uint 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. (default 1000) --summarize Should we produce an execution summary after the load test has finished. If you're running a large load test, this can take a long time -t, --time-limit int Maximum number of seconds to spend for benchmarking. Use this to benchmark within a fixed total amount of time. Per default there is no time limit. (default -1) diff --git a/doc/polycli_loadtest_uniswapv3.md b/doc/polycli_loadtest_uniswapv3.md index b16a87f6..805b5879 100644 --- a/doc/polycli_loadtest_uniswapv3.md +++ b/doc/polycli_loadtest_uniswapv3.md @@ -86,6 +86,7 @@ The command also inherits flags from parent commands. --chain-id uint The chain id for the transactions. -c, --concurrency int Number of requests to perform concurrently. Default is one request at a time. (default 1) --config string config file (default is $HOME/.polygon-cli.yaml) + --eth-send-amount float The amount of wei that we'll send every transaction (default 0.001) --gas-limit uint 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 --gas-price uint In environments where the gas price can't be determined automatically, we can specify it manually -i, --iterations uint 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 (default 1) @@ -98,7 +99,6 @@ The command also inherits flags from parent commands. -n, --requests int Number of requests to perform for the benchmarking session. The default is to just perform a single request which usually leads to non-representative benchmarking results. (default 1) -r, --rpc-url string The RPC endpoint url (default "http://localhost:8545") --seed int A seed for generating random values and addresses (default 123456) - --send-amount string The amount of wei that we'll send every transaction (default "0x38D7EA4C68000") --steady-state-tx-pool-size uint 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. (default 1000) --summarize Should we produce an execution summary after the load test has finished. If you're running a large load test, this can take a long time -t, --time-limit int Maximum number of seconds to spend for benchmarking. Use this to benchmark within a fixed total amount of time. Per default there is no time limit. (default -1)