Skip to content

Commit c927216

Browse files
fix: disable sample recording if send-only is enabled for load testing and use big.Int for funding amounts (#647)
* fix: Disable light summary if SendOnly is enabled for load testing * Made funding-amount big.Int not uint64 * chore: `make gen` --------- Co-authored-by: leovct <[email protected]>
1 parent d300623 commit c927216

File tree

7 files changed

+44
-12
lines changed

7 files changed

+44
-12
lines changed

cmd/flag_loader/flag_loader.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package flag_loader
33
import (
44
"fmt"
55
"os"
6+
"math/big"
67

78
"github.com/spf13/cobra"
89
)
@@ -12,6 +13,27 @@ const (
1213
privateKeyFlagName, privateKeyEnvVar = "private-key", "PRIVATE_KEY"
1314
)
1415

16+
type BigIntValue struct {
17+
Val *big.Int
18+
}
19+
20+
func (b *BigIntValue) String() string {
21+
// Return the decimal representation
22+
return b.Val.String()
23+
}
24+
25+
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
31+
}
32+
33+
func (b *BigIntValue) Type() string {
34+
return "big.Int"
35+
}
36+
1537
func GetRpcUrlFlagValue(cmd *cobra.Command) *string {
1638
v, _ := getFlagValue(cmd, rpcUrlFlagName, rpcUrlEnvVar, false)
1739
return v

cmd/fund/cmd.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fund
22

33
import (
44
"errors"
5+
"math/big"
56

67
_ "embed"
78

@@ -27,7 +28,7 @@ type cmdFundParams struct {
2728
WalletsNumber *uint64
2829
UseHDDerivation *bool
2930
WalletAddresses *[]string
30-
FundingAmountInWei *uint64
31+
FundingAmountInWei *big.Int
3132
OutputFile *string
3233

3334
FunderAddress *string
@@ -37,6 +38,7 @@ var (
3738
//go:embed usage.md
3839
usage string
3940
params cmdFundParams
41+
defaultFundingInWei = big.NewInt(50000000000000000) // 0.05 ETH
4042
)
4143

4244
// FundCmd represents the fund command.
@@ -67,7 +69,9 @@ func init() {
6769
p.WalletsNumber = flagSet.Uint64P("number", "n", 10, "The number of wallets to fund")
6870
p.UseHDDerivation = flagSet.Bool("hd-derivation", true, "Derive wallets to fund from the private key in a deterministic way")
6971
p.WalletAddresses = flagSet.StringSlice("addresses", nil, "Comma-separated list of wallet addresses to fund")
70-
p.FundingAmountInWei = flagSet.Uint64P("eth-amount", "a", 50000000000000000, "The amount of wei to send to each wallet")
72+
p.FundingAmountInWei = defaultFundingInWei
73+
flagSet.Var(&flag_loader.BigIntValue{Val: p.FundingAmountInWei }, "eth-amount", "The amount of wei to send to each wallet")
74+
7175
p.OutputFile = flagSet.StringP("file", "f", "wallets.json", "The output JSON file path for storing the addresses and private keys of funded wallets")
7276

7377
// Marking flags as mutually exclusive
@@ -98,7 +102,8 @@ func checkFlags() error {
98102
if params.WalletsNumber != nil && *params.WalletsNumber == 0 {
99103
return errors.New("the number of wallets to fund is set to zero")
100104
}
101-
if params.FundingAmountInWei != nil && *params.FundingAmountInWei <= 1000000000 {
105+
minValue := big.NewInt(1000000000)
106+
if params.FundingAmountInWei != nil && params.FundingAmountInWei.Cmp(minValue) <= 0 {
102107
return errors.New("the funding amount must be greater than 1000000000")
103108
}
104109
if params.OutputFile != nil && *params.OutputFile == "" {

cmd/fund/fund.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func deployOrInstantiateFunderContract(ctx context.Context, c *ethclient.Client,
128128
if *params.FunderAddress == "" {
129129
// Deploy the Funder contract.
130130
// Note: `fundingAmountInWei` reprensents the amount the Funder contract will send to each newly generated wallets.
131-
fundingAmountInWei := new(big.Int).SetUint64(*params.FundingAmountInWei)
131+
fundingAmountInWei := params.FundingAmountInWei
132132
contractAddress, _, _, err = funder.DeployFunder(tops, c, fundingAmountInWei)
133133
if err != nil {
134134
log.Error().Err(err).Msg("Unable to deploy Funder contract")

cmd/loadtest/app.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"golang.org/x/time/rate"
1919
)
2020

21+
2122
type (
2223
blockSummary struct {
2324
Block *rpctypes.RawBlockResponse
@@ -83,7 +84,7 @@ type (
8384
StartNonce *uint64
8485
GasPriceMultiplier *float64
8586
SendingAddressCount *uint64
86-
AddressFundingAmount *uint64
87+
AddressFundingAmount *big.Int
8788
PreFundSendingAddresses *bool
8889
KeepFundedAmount *bool
8990
SendingAddressesFile *string
@@ -164,6 +165,7 @@ var (
164165
}
165166

166167
randSrc *rand.Rand
168+
defaultFunding = new(big.Int).SetUint64(1000000000000000000) // 1 ETH
167169
)
168170

169171
// LoadtestCmd represents the loadtest command
@@ -245,7 +247,8 @@ func initFlags() {
245247
ltp.SendOnly = LoadtestCmd.PersistentFlags().Bool("send-only", false, "Send transactions and load without waiting for it to be mined.")
246248
ltp.BlobFeeCap = LoadtestCmd.Flags().Uint64("blob-fee-cap", 100000, "The blob fee cap, or the maximum blob fee per chunk, in Gwei.")
247249
ltp.SendingAddressCount = LoadtestCmd.Flags().Uint64("sending-address-count", 1, "The number of sending addresses to use. This is useful for avoiding pool account queue.")
248-
ltp.AddressFundingAmount = LoadtestCmd.Flags().Uint64("address-funding-amount", 1000000000000000000, "The amount in wei to fund the sending addresses with.")
250+
ltp.AddressFundingAmount = defaultFunding
251+
LoadtestCmd.Flags().Var(&flag_loader.BigIntValue{Val: ltp.AddressFundingAmount},"address-funding-amount", "The amount in wei to fund the sending addresses with.")
249252
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.")
250253
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.")
251254
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.")

cmd/loadtest/loadtest.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,10 @@ func initializeLoadTestParams(ctx context.Context, c *ethclient.Client) error {
331331
randSrc = rand.New(rand.NewSource(*inputLoadTestParams.Seed))
332332

333333
// setup account pool
334-
fundingAmount := *inputLoadTestParams.AddressFundingAmount
334+
fundingAmount := inputLoadTestParams.AddressFundingAmount
335335
sendingAddressCount := *inputLoadTestParams.SendingAddressCount
336336
sendingAddressesFile := *inputLoadTestParams.SendingAddressesFile
337-
accountPool, err = NewAccountPool(ctx, c, privateKey, big.NewInt(0).SetUint64(fundingAmount))
337+
accountPool, err = NewAccountPool(ctx, c, privateKey, fundingAmount)
338338
if err != nil {
339339
log.Error().Err(err).Msg("Unable to create account pool")
340340
return fmt.Errorf("unable to create account pool. %w", err)
@@ -386,7 +386,7 @@ func initializeLoadTestParams(ctx context.Context, c *ethclient.Client) error {
386386
}
387387

388388
preFundSendingAddresses := *inputLoadTestParams.PreFundSendingAddresses
389-
if preFundSendingAddresses && *inputLoadTestParams.AddressFundingAmount > 0 {
389+
if preFundSendingAddresses && inputLoadTestParams.AddressFundingAmount.Cmp(new(big.Int)) > 0 {
390390
err := accountPool.FundAccounts(ctx)
391391
if err != nil {
392392
log.Error().Err(err).Msg("Unable to fund sending addresses")
@@ -885,7 +885,9 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
885885
default:
886886
log.Error().Str("mode", mode.String()).Msg("We've arrived at a load test mode that we don't recognize")
887887
}
888-
recordSample(routineID, requestID, tErr, startReq, endReq, sendingTops.Nonce.Uint64())
888+
if !*inputLoadTestParams.SendOnly {
889+
recordSample(routineID, requestID, tErr, startReq, endReq, sendingTops.Nonce.Uint64())
890+
}
889891
if tErr != nil {
890892
log.Error().
891893
Int64("routineID", routineID).

doc/polycli_fund.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ $ cast balance 0x5D8121cf716B70d3e345adB58157752304eED5C3
7979
```bash
8080
--addresses strings Comma-separated list of wallet addresses to fund
8181
--contract-address string The address of a pre-deployed Funder contract
82-
-a, --eth-amount uint The amount of wei to send to each wallet (default 50000000000000000)
82+
--eth-amount big.Int The amount of wei to send to each wallet (default 50000000000000000)
8383
-f, --file string The output JSON file path for storing the addresses and private keys of funded wallets (default "wallets.json")
8484
--hd-derivation Derive wallets to fund from the private key in a deterministic way (default true)
8585
-h, --help help for fund

doc/polycli_loadtest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ The codebase has a contract that used for load testing. It's written in Solidity
104104
--adaptive-cycle-duration-seconds uint When using adaptive rate limiting, this flag controls how often we check the queue size and adjust the rates (default 10)
105105
--adaptive-rate-limit Enable AIMD-style congestion control to automatically adjust request rate
106106
--adaptive-rate-limit-increment uint When using adaptive rate limiting, this flag controls the size of the additive increases. (default 50)
107-
--address-funding-amount uint The amount in wei to fund the sending addresses with. (default 1000000000000000000)
107+
--address-funding-amount big.Int The amount in wei to fund the sending addresses with. (default 1000000000000000000)
108108
--batch-size uint Number of batches to perform at a time for receipt fetching. Default is 999 requests at a time. (default 999)
109109
--blob-fee-cap uint The blob fee cap, or the maximum blob fee per chunk, in Gwei. (default 100000)
110110
-b, --byte-count uint If we're in store mode, this controls how many bytes we'll try to store in our contract (default 1024)

0 commit comments

Comments
 (0)