Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(loadtest): uniswapv3 loadtest #137

Merged
merged 189 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
62fa6b0
doc: document how to generate new loadtest mode string
leovct Sep 19, 2023
399cc6c
chore: build uniswap v3 contracts
leovct Sep 19, 2023
56d0a5c
chore: remove avail cmds
leovct Sep 19, 2023
62d916e
chore: generate go bindings for uniswap contracts
leovct Sep 19, 2023
46681dd
doc: document how to build uniswap contracts and how to generate go b…
leovct Sep 19, 2023
d1abfca
feat: add uniswap v3 loadtest mode
leovct Sep 19, 2023
69c6ea7
doc: update doc
leovct Sep 19, 2023
ec4f016
chore: define deployment config for uniswap
leovct Sep 19, 2023
752822e
chore: lint
leovct Sep 19, 2023
1dbb6b2
feat: enable 1 bp fee tier
leovct Sep 19, 2023
596adf9
chore: remove unused contracts and deploy multicall
leovct Sep 19, 2023
e079493
feat: deploy ProxyAdmin
leovct Sep 19, 2023
4845b25
chore: clean up
leovct Sep 19, 2023
1fab4dc
chore: make lint
leovct Sep 19, 2023
ffd9f04
feat: deploy TickLens
leovct Sep 19, 2023
f2393a7
chore: minor change
leovct Sep 19, 2023
7b375f2
chore: refactor to use generics
leovct Sep 20, 2023
7539cc5
chore: clean up
leovct Sep 20, 2023
380cb1a
chore: rename lib contract
leovct Sep 20, 2023
04ea6fd
feat: deploy NFTDescriptor and WETH9
leovct Sep 20, 2023
f39503c
feat: deploy TransparentUpgradeableProxy
leovct Sep 20, 2023
8e7e46e
chore: generate NonfungiblePositionManager go binding
leovct Sep 20, 2023
e0b26fe
feat: deploy NonfungiblePositionManager contract
leovct Sep 20, 2023
b15d753
chore: generate go binding for V3Migrator
leovct Sep 20, 2023
da6a379
feat: deploy V3Migrator
leovct Sep 20, 2023
f198cf9
chore: raise geth gas limit and send more funds to the loadtest account
leovct Sep 20, 2023
74f96a8
chore: update build process
leovct Sep 20, 2023
576cd1f
chore: update contract bytecode
leovct Sep 20, 2023
4ab1fde
feat: transfer factory ownership
leovct Sep 20, 2023
3b922ce
chore: generate go binding for UniswapV3Staker
leovct Sep 20, 2023
f90231e
chore: update build process
leovct Sep 20, 2023
71e05d4
fix: build process
leovct Sep 20, 2023
dd8ba18
feat: deploy staker
leovct Sep 20, 2023
b60b661
chore: generate go bindings for QuoterV2
leovct Sep 20, 2023
33245b1
feat: deploy QuoterV2
leovct Sep 20, 2023
dc2cba2
chore: generate go bindings for SwapRouter02
leovct Sep 20, 2023
2ea1130
chore: clean up build process
leovct Sep 20, 2023
d2dc571
chore: update bindings
leovct Sep 20, 2023
15b6176
chore: clean up
leovct Sep 20, 2023
016c709
fix: build issues
leovct Sep 20, 2023
d49b37c
chore: new bytecodes
leovct Sep 20, 2023
5e87cb6
doc: update doc
leovct Sep 20, 2023
8418c09
feat: deploy SwapRouter02
leovct Sep 20, 2023
176ffc7
feat: transfer ProxyAdmin ownership
leovct Sep 20, 2023
8f72995
chore: update debug msgs
leovct Sep 20, 2023
acb0f75
fix: update owner address
leovct Sep 20, 2023
26dfdc0
chore: clean up
leovct Sep 20, 2023
74189d2
chore: forge init
leovct Sep 20, 2023
c8a5802
forge install: forge-std
leovct Sep 20, 2023
573ad78
chore: forge init
leovct Sep 20, 2023
de3d208
forge install: forge-std
leovct Sep 20, 2023
de9267f
chore: add ERC20 contracts
leovct Sep 20, 2023
3591976
fix: remove quotes from ERC20 bytecode
leovct Sep 20, 2023
96b2985
feat: generate go bindings for ERC20
leovct Sep 20, 2023
fd7d5b7
feat: deploy the two ERC20 contracts
leovct Sep 20, 2023
e22c472
feat: approve erc20 spendings
leovct Sep 20, 2023
2a58173
feat: create pool between the erc20 contracts
leovct Sep 20, 2023
6f7fea8
chore: make sure pool is deployed before moving on
leovct Sep 20, 2023
f687992
chore: generate go binding for UniswapV3Pool
leovct Sep 20, 2023
2ef0f6c
feat: initialize, provied liquidity and swap tokens
leovct Sep 20, 2023
b9de3d9
chore: clean up
leovct Sep 20, 2023
c522675
chore: lint
leovct Sep 20, 2023
d3ac524
doc: update `polycli loadtest` doc
leovct Sep 20, 2023
34332cd
fix: build process
leovct Sep 20, 2023
e03575e
chore: update sqrtX96price computation
leovct Sep 20, 2023
9f33d98
chore: refactor
leovct Sep 20, 2023
61e0397
chore: new bytecode
leovct Sep 20, 2023
f09d5b3
chore: remove unused code
leovct Sep 20, 2023
817db0f
chore: minor update to build process
leovct Sep 20, 2023
8249d23
chore: document script
leovct Sep 20, 2023
f57ef32
fix: shadowed vars
leovct Sep 20, 2023
059e47b
chore: test remove artefacts
leovct Sep 20, 2023
3e748d6
chore: nit
leovct Sep 20, 2023
77cc519
chore: only upload relevant v3-core contracts
leovct Sep 20, 2023
f696882
chore: remove all v3-periphery contracts
leovct Sep 20, 2023
7705aea
chore: upload only relevant v3-periphery contracts
leovct Sep 20, 2023
31b3eec
chore: remove the rest of the contracts
leovct Sep 20, 2023
7c64c02
chore: only upload relevant contracts
leovct Sep 20, 2023
b51c1a3
chore: update bytecode
leovct Sep 20, 2023
a59ac4f
chore: build script name option change
leovct Sep 20, 2023
3984b4a
chore: bindings script nit
leovct Sep 20, 2023
ead8fbd
chore: new bytecode
leovct Sep 20, 2023
8cdd208
chore: refactor
leovct Sep 20, 2023
ca13026
chore: small nits
leovct Sep 20, 2023
0d9dba9
chore: remove unused field
leovct Sep 20, 2023
f52cd77
feat: enable pre-deployed contract mode for uniswap
leovct Sep 21, 2023
59b8299
fix: retrieve pool instead of creating a new one
leovct Sep 21, 2023
4bad8b9
fix: issue with initializing a pool twice
leovct Sep 21, 2023
1424ba6
feat: add loadtest fn
leovct Sep 21, 2023
d45186a
doc: gen
leovct Sep 21, 2023
8841536
chore: make lint
leovct Sep 21, 2023
1945b0c
Merge branch 'main' into feat/uniswap-loadtest
leovct Oct 2, 2023
b8eef8b
chore: `go mod tidy`
leovct Oct 2, 2023
8f2cac5
chore: update ERC20 contract
leovct Oct 3, 2023
aa8641e
chore: generate new bindings for ERC20
leovct Oct 3, 2023
6eb456d
chore: fix some issues with Swapper and ERC20
leovct Oct 3, 2023
783a871
chore: rename ERC20 contract to Swapper
leovct Oct 3, 2023
18cc742
chore: fix the pool initialization issue
leovct Oct 3, 2023
7d70acd
chore: specify the amount of tokens to mint
leovct Oct 3, 2023
10a5ce1
chore: rename contract
leovct Oct 3, 2023
e21b489
chore: update build process
leovct Oct 4, 2023
c81ffca
chore: update `Swapper` contract
leovct Oct 4, 2023
55bb5d9
chore: don't commit tmp/
leovct Oct 4, 2023
531c255
chore: hack to update the NonfungibleTokenPositionDescriptorMetaData …
leovct Oct 4, 2023
ba3039e
chore: document how to update the deploy fn of NFTPositionDescriptor
leovct Oct 4, 2023
7d5ccdd
chore: add a warning in the script
leovct Oct 4, 2023
6a247b1
chore: more debug
leovct Oct 4, 2023
80a69c1
chore: rename TokenA and TokenB into Token0 and Token1
leovct Oct 4, 2023
1c31daf
chore: add debug
leovct Oct 4, 2023
b945031
chore: update debug msgs
leovct Oct 4, 2023
695dc26
feat: move uniswapv3 loadtest to subcommand
leovct Oct 4, 2023
6216001
chore: nits
leovct Oct 4, 2023
50a11b6
chore: remove `fmt.Sprintf()`
leovct Oct 4, 2023
756a9ba
chore: clean up
leovct Oct 4, 2023
be715ee
chore: rename contracts
leovct Oct 4, 2023
df5cd97
chore: update steps
leovct Oct 4, 2023
7ca3a9f
fix: proxy data
leovct Oct 4, 2023
ebddf14
chore: nit
leovct Oct 4, 2023
60f8a5d
chore: clean up
leovct Oct 4, 2023
05cb287
chore: update `uniswapv3` cmd usage
leovct Oct 4, 2023
0b6de0f
Merge branch 'main' into feat/uniswap-loadtest
leovct Oct 5, 2023
78c9a18
chore: update build process
leovct Oct 5, 2023
0f4cec8
chore: update binding process
leovct Oct 5, 2023
94b646d
chore: save nft descriptor lib address to file
leovct Oct 5, 2023
fa1b434
chore: update nftdescriptor lib address
leovct Oct 5, 2023
5d2614d
chore: hack
leovct Oct 5, 2023
835c4b7
fix: issues
leovct Oct 5, 2023
a0958f5
chore: clean up
leovct Oct 6, 2023
70b54b1
chore: diplay tx hashes in trace mode
leovct Oct 10, 2023
30f89db
chore: use swap-router v1.1.0 instead of v1.3.0
leovct Oct 10, 2023
3c4a4a7
Merge branch 'main' into feat/uniswap-loadtest
leovct Oct 12, 2023
ab3dda4
fix: `blockUntilSuccessful` default case return a nil error
leovct Oct 12, 2023
7e3362a
fix: `TransparentUpgradeableProxy` deployment
leovct Oct 12, 2023
4a0decb
chore: nit
leovct Oct 12, 2023
b8a8dc4
chore: solve lint issue
leovct Oct 12, 2023
5ab9ec0
feat: adding more logging
praetoriansentry Oct 16, 2023
e74c21e
refactor: minor changes to the setup
praetoriansentry Oct 17, 2023
b2a3834
chore: nit
leovct Oct 17, 2023
10e0dbe
chore: go mod tidy
leovct Oct 17, 2023
e9985c2
fix: swap issue
leovct Oct 17, 2023
75bbddb
chore: clean up
leovct Oct 18, 2023
77f7755
chore: nit
leovct Oct 18, 2023
3678bed
chore: update help msg
leovct Oct 18, 2023
09a213f
chore: update help msg once again
leovct Oct 18, 2023
8483f50
chore: add fn to validate url
leovct Oct 18, 2023
0d7612a
doc: document swap method
leovct Oct 18, 2023
a411f58
doc: nit
leovct Oct 18, 2023
b166f3a
chore: rename swap method
leovct Oct 18, 2023
ffdb3f1
chore: nit
leovct Oct 18, 2023
2c8f74b
doc: document `createPool`
leovct Oct 18, 2023
68948eb
chore: refactor pool logic
leovct Oct 18, 2023
520361b
chore: swap file
leovct Oct 18, 2023
4013a70
chore: same thing with deloy logic
leovct Oct 18, 2023
ea01a82
chore: same thing with swapper logic
leovct Oct 18, 2023
180e39f
chore: go mod tidy
leovct Oct 18, 2023
adb52a6
chore: clean up loadtest
leovct Oct 18, 2023
c7f184e
chore: nit
leovct Oct 18, 2023
8da3ca1
Merge branch 'main' into jhilliard/feat/uniswap-loadtest
leovct Oct 18, 2023
69c0f66
chore: gen doc
leovct Oct 18, 2023
7dbc5d7
fix: lint issues
leovct Oct 18, 2023
f5b0099
chore: nit
leovct Oct 18, 2023
a8a0b42
chore: more nit
leovct Oct 18, 2023
27dd235
chore: differentiat between local and persistent flags
leovct Oct 18, 2023
4e847e1
chore: gen doc
leovct Oct 18, 2023
702ec59
chore: document `deploy.go`
leovct Oct 19, 2023
4b837fc
chore: nit
leovct Oct 19, 2023
04f3f82
chore: document `pool.go`
leovct Oct 19, 2023
c6c8e74
lint: transform `fmt.Errorf` into `errors.New`
leovct Oct 19, 2023
25ab60d
chore: document `swap.go`
leovct Oct 19, 2023
ba30e53
chore: nit
leovct Oct 19, 2023
6416f62
chore: document `swapper.go`
leovct Oct 19, 2023
560f4ff
chore: nit
leovct Oct 19, 2023
e81e592
doc: document `types.go`
leovct Oct 19, 2023
0985075
chore: remove tx hash logs
leovct Oct 19, 2023
1362e72
chore: nit
leovct Oct 19, 2023
0a44edc
chore: display name of spenders
leovct Oct 19, 2023
4465b22
chore: nit
leovct Oct 19, 2023
d9dc28d
chore: add ERC20 contract name
leovct Oct 19, 2023
3e77e4c
chore: more nit
leovct Oct 19, 2023
250b1dc
chore: update `setUniswapV3Allowances` method
leovct Oct 19, 2023
0e79568
feat: add flag to set the pool fee and the swap amount
leovct Oct 19, 2023
985e848
chore: check pool fees flag
leovct Oct 19, 2023
c3e98f0
chore: nit
leovct Oct 19, 2023
2cd6c51
chore: use fees as percentage as it's easier to type for users
leovct Oct 19, 2023
9583a10
fix: conversion issue
leovct Oct 19, 2023
a29a122
chore: gen-doc
leovct Oct 19, 2023
35986cc
chore: update `Swapper.sol` and specify the amount of token to mint i…
leovct Oct 19, 2023
bc0ec38
chore: lint
leovct Oct 19, 2023
f401890
Merge branch 'main' into jhilliard/feat/uniswap-loadtest
leovct Oct 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 4 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ We run a lot of different blockchain technologies. Different tools often have in
- [Features](#features)
- [Testing](#testing)
- [Contributing](#contributing)
- [References](#references)
- [Reference](#reference)

## Install

Expand Down Expand Up @@ -148,43 +148,11 @@ You can then generate some load to make sure that blocks with transactions are b
$ polycli loadtest --verbosity 700 --chain-id 1337 --concurrency 1 --requests 1000 --rate-limit 5 --mode c http://127.0.0.1:8545
```

## Contributing
# Contributing

The `Makefile` is here to assist you to build the project, run tests, generate documentation or go bindings, etc.
- If you add a new loadtest mode, don't forget to update the loadtest mode string by running the following command: `cd cmd/loadtest && stringer -type=loadTestMode`. You can install [stringer](https://pkg.go.dev/golang.org/x/tools/cmd/stringer) with `go install golang.org/x/tools/cmd/stringer@latest`.

```sh
$ make
Usage:
make <target>
help Display this help.

Build
generate Generate protobuf stubs.
build Build go binary.
install Install the go binary.
cross Cross-compile go binaries using CGO.
simplecross Cross-compile go binaries without using CGO.
clean Clean the binary folder.

Test
test Run tests.

Generation
gen-doc Generate documentation for `polycli`.
gen-loadtest-modes Generate loadtest modes strings.
gen-go-bindings Generate go bindings for smart contracts.

Lint
lint Run linters.

Clients
geth Start a local geth node.
avail Start a local avail node.
geth-loadtest Fund test account with 5k ETH and run loadtest against an EVM/Geth chain.
avail-loadtest Run loadtest against an Avail chain.
```

## References
# Reference

Sending some value to the default load testing account.

Expand Down
67 changes: 41 additions & 26 deletions cmd/loadtest/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package loadtest
import (
"crypto/ecdsa"
_ "embed"
"errors"
"fmt"
"math/big"
"math/rand"
Expand Down Expand Up @@ -92,8 +93,8 @@ type (
)

var (
//go:embed usage.md
usage string
//go:embed loadtestUsage.md
loadtestUsage string
inputLoadTestParams loadTestParams
loadTestResults []loadTestSample
loadTestResutsMutex sync.RWMutex
Expand Down Expand Up @@ -157,7 +158,7 @@ var (
var LoadtestCmd = &cobra.Command{
Use: "loadtest url",
Short: "Run a generic load test against an Eth/EVM style JSON-RPC endpoint.",
Long: usage,
Long: loadtestUsage,
RunE: func(cmd *cobra.Command, args []string) error {
err := runLoadTest(cmd.Context())
if err != nil {
Expand All @@ -170,7 +171,7 @@ var LoadtestCmd = &cobra.Command{
zerolog.DurationFieldInteger = true

if len(args) != 1 {
return fmt.Errorf("expected exactly one argument")
return errors.New("expected exactly one argument")
}
url, err := url.Parse(args[0])
if err != nil {
Expand All @@ -183,20 +184,26 @@ var LoadtestCmd = &cobra.Command{
inputLoadTestParams.URL = url

if *inputLoadTestParams.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")
}

if *inputLoadTestParams.ContractCallBlockInterval == 0 {
return fmt.Errorf("the contract call block interval must be strictly positive")
return errors.New("the contract call block interval must be strictly positive")
}

return nil
},
}

func init() {
initFlags()
initSubCommands()
}

func initFlags() {
ltp := new(loadTestParams)

// Persistent flags.
ltp.Requests = LoadtestCmd.PersistentFlags().Int64P("requests", "n", 1, "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.")
ltp.Concurrency = LoadtestCmd.PersistentFlags().Int64P("concurrency", "c", 1, "Number of requests to perform concurrently. Default is one request at a time.")
ltp.TimeLimit = LoadtestCmd.PersistentFlags().Int64P("time-limit", "t", -1, "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.")
Expand All @@ -213,38 +220,46 @@ func init() {
ltp.AdaptiveRateLimitIncrement = LoadtestCmd.PersistentFlags().Uint64("adaptive-rate-limit-increment", 50, "When using adaptive rate limiting, this flag controls the size of the additive increases.")
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")
ltp.AdaptiveBackoffFactor = LoadtestCmd.PersistentFlags().Float64("adaptive-backoff-factor", 2, "When using adaptive rate limiting, this flag controls our multiplicative decrease value.")
ltp.Modes = LoadtestCmd.PersistentFlags().StringSliceP("mode", "m", []string{"t"}, `The testing mode to use. It can be multiple like: "t,c,d,f"
t - sending transactions
d - deploy contract
c - call random contract functions
f - call specific contract function
p - call random precompiled contracts
a - call a specific precompiled contract address
s - store mode
r - random modes
2 - ERC20 Transfers
7 - ERC721 Mints
R - total recall
rpc - call random rpc methods`)
ltp.Function = LoadtestCmd.PersistentFlags().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`")
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")
ltp.ByteCount = LoadtestCmd.PersistentFlags().Uint64P("byte-count", "b", 1024, "If we're in store mode, this controls how many bytes we'll try to store in our contract")
ltp.Seed = LoadtestCmd.PersistentFlags().Int64("seed", 123456, "A seed for generating random values and addresses")
ltp.LtAddress = LoadtestCmd.PersistentFlags().String("lt-address", "", "The address of a pre-deployed load test contract")
ltp.ERC20Address = LoadtestCmd.PersistentFlags().String("erc20-address", "", "The address of a pre-deployed erc 20 contract")
ltp.ERC721Address = LoadtestCmd.PersistentFlags().String("erc721-address", "", "The address of a pre-deployed erc 721 contract")
ltp.ContractCallNumberOfBlocksToWaitFor = LoadtestCmd.PersistentFlags().Uint64("contract-call-nb-blocks-to-wait-for", 30, "The number of blocks to wait for before giving up on a contract deployment")
ltp.ContractCallBlockInterval = LoadtestCmd.PersistentFlags().Uint64("contract-call-block-interval", 1, "During deployment, this flag controls if we should check every block, every other block, or every nth block to determine that the contract has been deployed")
ltp.ForceContractDeploy = LoadtestCmd.PersistentFlags().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.")
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")
ltp.ForceGasPrice = LoadtestCmd.PersistentFlags().Uint64("gas-price", 0, "In environments where the gas price can't be determined automatically, we can specify it manually")
ltp.ForcePriorityGasPrice = LoadtestCmd.PersistentFlags().Uint64("priority-gas-price", 0, "Specify Gas Tip Price in the case of EIP-1559")
ltp.ShouldProduceSummary = LoadtestCmd.PersistentFlags().Bool("summarize", false, "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")
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.")
ltp.SummaryOutputMode = LoadtestCmd.PersistentFlags().String("output-mode", "text", "Format mode for summary output (json | text)")
ltp.LegacyTransactionMode = LoadtestCmd.PersistentFlags().Bool("legacy", false, "Send a legacy transaction instead of an EIP1559 transaction.")
ltp.RecallLength = LoadtestCmd.PersistentFlags().Uint64("recall-blocks", 50, "The number of blocks that we'll attempt to fetch for recall")

// Local flags.
ltp.Modes = LoadtestCmd.Flags().StringSliceP("mode", "m", []string{"t"}, `The testing mode to use. It can be multiple like: "t,c,d,f"
t - sending transactions
d - deploy contract
c - call random contract functions
f - call specific contract function
p - call random precompiled contracts
a - call a specific precompiled contract address
s - store mode
r - random modes
2 - ERC20 transfers
7 - ERC721 mints
v3 - UniswapV3 swaps
R - total recall
rpc - call random rpc methods`)
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`")
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")
ltp.LtAddress = LoadtestCmd.Flags().String("lt-address", "", "The address of a pre-deployed load test contract")
ltp.ERC20Address = LoadtestCmd.Flags().String("erc20-address", "", "The address of a pre-deployed ERC20 contract")
ltp.ERC721Address = LoadtestCmd.Flags().String("erc721-address", "", "The address of a pre-deployed ERC721 contract")
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.")
ltp.RecallLength = LoadtestCmd.Flags().Uint64("recall-blocks", 50, "The number of blocks that we'll attempt to fetch for recall")

inputLoadTestParams = *ltp

// TODO Compression
}

func initSubCommands() {
LoadtestCmd.AddCommand(uniswapV3LoadTestCmd)
}
50 changes: 42 additions & 8 deletions cmd/loadtest/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
"sync"
"time"

uniswapv3loadtest "github.com/maticnetwork/polygon-cli/cmd/loadtest/uniswapv3"
"github.com/maticnetwork/polygon-cli/contracts"
"github.com/maticnetwork/polygon-cli/contracts/tokens"

"github.com/maticnetwork/polygon-cli/metrics"
"github.com/maticnetwork/polygon-cli/rpctypes"
"github.com/maticnetwork/polygon-cli/util"
Expand Down Expand Up @@ -51,6 +53,7 @@ const (
loadTestModeERC721
loadTestModePrecompiledContracts
loadTestModePrecompiledContract
loadTestModeUniswapV3

// All the modes AFTER random mode will not be used when mode random is selected
loadTestModeRandom
Expand All @@ -61,6 +64,8 @@ const (
codeQualityPrivateKey = "42b6e34dc21598a807dc19d7784c71b2a7a01f6480dc6f58258f78e539f1a1fa"
)

var errWaitingPeriodExhausted = errors.New("waiting period exhausted")

func characterToLoadTestMode(mode string) (loadTestMode, error) {
switch mode {
case "t", "transaction":
Expand All @@ -87,6 +92,8 @@ func characterToLoadTestMode(mode string) (loadTestMode, error) {
return loadTestModePrecompiledContracts, nil
case "R", "recall":
return loadTestModeRecall, nil
case "v3", "uniswapv3":
return loadTestModeUniswapV3, nil
case "rpc":
return loadTestModeRPC, nil
default:
Expand Down Expand Up @@ -222,7 +229,7 @@ func initializeLoadTestParams(ctx context.Context, c *ethclient.Client) error {

modes := *inputLoadTestParams.Modes
if len(modes) == 0 {
return fmt.Errorf("expected at least one mode")
return errors.New("expected at least one mode")
}

inputLoadTestParams.ParsedModes = make([]loadTestMode, 0)
Expand All @@ -242,18 +249,18 @@ func initializeLoadTestParams(ctx context.Context, c *ethclient.Client) error {
}

if hasMode(loadTestModeRandom, inputLoadTestParams.ParsedModes) && inputLoadTestParams.MultiMode {
return fmt.Errorf("random mode can't be used in combinations with any other modes")
return errors.New("random mode can't be used in combinations with any other modes")
}
if hasMode(loadTestModeRPC, inputLoadTestParams.ParsedModes) && inputLoadTestParams.MultiMode && !*inputLoadTestParams.CallOnly {
return fmt.Errorf("rpc mode must be called with call-only when multiple modes are used")
return errors.New("rpc mode must be called with call-only when multiple modes are used")
} else if hasMode(loadTestModeRPC, inputLoadTestParams.ParsedModes) {
log.Trace().Msg("setting call only mode since we're doing RPC testing")
*inputLoadTestParams.CallOnly = true
}
// TODO check for duplicate modes?

if *inputLoadTestParams.CallOnly && *inputLoadTestParams.AdaptiveRateLimit {
return fmt.Errorf("using call only with adaptive rate limit doesn't make sense")
return errors.New("using call only with adaptive rate limit doesn't make sense")
}

randSrc = rand.New(rand.NewSource(*inputLoadTestParams.Seed))
Expand Down Expand Up @@ -477,14 +484,38 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
log.Debug().Str("erc721Addr", erc721Addr.String()).Msg("Obtained erc 721 contract address")
}

uniswapAddresses := uniswapv3loadtest.UniswapV3Addresses{
FactoryV3: ethcommon.HexToAddress(*uniswapv3LoadTestParams.UniswapFactoryV3),
Multicall: ethcommon.HexToAddress(*uniswapv3LoadTestParams.UniswapMulticall),
ProxyAdmin: ethcommon.HexToAddress(*uniswapv3LoadTestParams.UniswapProxyAdmin),
TickLens: ethcommon.HexToAddress(*uniswapv3LoadTestParams.UniswapTickLens),
NFTDescriptorLib: ethcommon.HexToAddress(*uniswapv3LoadTestParams.UniswapNFTLibDescriptor),
NonfungibleTokenPositionDescriptor: ethcommon.HexToAddress(*uniswapv3LoadTestParams.UniswapNonfungibleTokenPositionDescriptor),
TransparentUpgradeableProxy: ethcommon.HexToAddress(*uniswapv3LoadTestParams.UniswapUpgradeableProxy),
NonfungiblePositionManager: ethcommon.HexToAddress(*uniswapv3LoadTestParams.UniswapNonfungiblePositionManager),
Migrator: ethcommon.HexToAddress(*uniswapv3LoadTestParams.UniswapMigrator),
Staker: ethcommon.HexToAddress(*uniswapv3LoadTestParams.UniswapStaker),
QuoterV2: ethcommon.HexToAddress(*uniswapv3LoadTestParams.UniswapQuoterV2),
SwapRouter02: ethcommon.HexToAddress(*uniswapv3LoadTestParams.UniswapSwapRouter),
WETH9: ethcommon.HexToAddress(*uniswapv3LoadTestParams.WETH9),
}
var uniswapV3Config uniswapv3loadtest.UniswapV3Config
var poolConfig uniswapv3loadtest.PoolConfig
if mode == loadTestModeUniswapV3 || mode == loadTestModeRandom {
uniswapV3Config, poolConfig, err = initUniswapV3Loadtest(ctx, c, tops, cops, uniswapAddresses, *ltp.FromETHAddress)
if err != nil {
return err
}
}

var recallTransactions []rpctypes.PolyTransaction
if mode == loadTestModeRecall {
recallTransactions, err = getRecallTransactions(ctx, c, rpc)
if err != nil {
return err
}
if len(recallTransactions) == 0 {
return fmt.Errorf("we weren't able to fetch any recall transactions")
return errors.New("we weren't able to fetch any recall transactions")
}
log.Debug().Int("txs", len(recallTransactions)).Msg("retrieved transactions for total recall")
}
Expand Down Expand Up @@ -570,6 +601,9 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
startReq, endReq, tErr = loadTestCallPrecompiledContracts(ctx, c, myNonceValue, ltContract, false)
case loadTestModeRecall:
startReq, endReq, tErr = loadTestRecall(ctx, c, myNonceValue, recallTransactions[int(currentNonce)%len(recallTransactions)])
case loadTestModeUniswapV3:
swapAmountIn := big.NewInt(int64(*uniswapv3LoadTestParams.SwapAmountInput))
startReq, endReq, tErr = runUniswapV3Loadtest(ctx, c, myNonceValue, uniswapV3Config, poolConfig, swapAmountIn)
case loadTestModeRPC:
startReq, endReq, tErr = loadTestRPC(ctx, c, myNonceValue, indexedActivity)
default:
Expand Down Expand Up @@ -676,7 +710,7 @@ func getERC20Contract(ctx context.Context, c *ethclient.Client, tops *bind.Trans
return err
}
if balance.Uint64() == 0 {
err = fmt.Errorf("ERC20 Balance is Zero")
err = errors.New("ERC20 Balance is Zero")
return err
}
return nil
Expand Down Expand Up @@ -750,8 +784,8 @@ func blockUntilSuccessful(ctx context.Context, c *ethclient.Client, f func() err
blockDiff = currentBlockNumber % currStartBlockNumber
}
if blockDiff > numberOfBlocksToWaitFor {
log.Error().Err(err).Dur("elapsedTimeSeconds", elapsed).Msg("Exhausted waiting period")
return err
log.Error().Err(err).Dur("elapsedTimeSeconds", elapsed).Msg("waiting period exhausted")
return errWaitingPeriodExhausted
}

currentBlockNumber, err = c.BlockNumber(ctx)
Expand Down
File renamed without changes.
11 changes: 6 additions & 5 deletions cmd/loadtest/loadtestmode_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading