Skip to content

Commit

Permalink
[DVT-146] Add force contract deploy flag (#6)
Browse files Browse the repository at this point in the history
* add force contract deploy flag

* update readme
  • Loading branch information
minhd-vu authored Oct 10, 2022
1 parent 78bc5a6 commit 25ecd83
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 99 deletions.
59 changes: 33 additions & 26 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -202,32 +202,39 @@ Usage:
polycli loadtest rpc-endpoint [flags]

Flags:
--chain-id uint The chain id for the transactions that we're going to send (default 1256)
-c, --concurrency int Number of multiple requests to perform at a time. Default is one request at a time. (default 1)
--del-address string A pre-deployed delegator contract address
--lt-address string A pre-deployed load test contract address
-f, --function --mode f A specific function to be called if running with --mode f (default 1)
-h, --help help for loadtest
-i, --iterations uint If we're making contract calls, this controls how many times the contract will execute the instruction in a loop (default 100)
-m, --mode string t - sending transactions
d - deploy contract
c - call random contract functions
f - call specific contract function (default "t")
--pretty-logs Should we log in pretty format or JSON (default true)
--private-key string The hex encoded private key that we'll use to sending transactions (default "42b6e34dc21598a807dc19d7784c71b2a7a01f6480dc6f58258f78e539f1a1fa")
--rate-limit float An overall limit to the number of requests per second. Give a number less than zero to remove this limit all together (default 4)
-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)
--send-amount string The amount of wei that we'll send every transaction (default "0x38D7EA4C68000")
-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 timelimit. (default -1)
--to-address string The address that we're going to send to (default "0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF")
-v, --verbosity int 0 - Silent
100 Fatals
200 Errors
300 Warnings
400 INFO
500 Debug
600 Trace (default 200)

--app-id uint32 The AppID used for avail
-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)
--chain-id uint The chain id for the transactions that we're going to send (default 1256)
-c, --concurrency int Number of multiple requests to perform at a time. Default is one request at a time. (default 1)
--data-avail Is this a test of avail rather than an EVM / Geth Chain
--del-address string A pre-deployed delegator contract address
--force-contract-deploy Some loadtest modes don't require a contract deployment. Set this flag to true to force contract deployments. This will still respect the --del-address and --il-address flags.
-f, --function --mode f A specific function to be called if running with --mode f (default 1)
-h, --help help for loadtest
-i, --iterations uint If we're making contract calls, this controls how many times the contract will execute the instruction in a loop (default 100)
--lt-address string A pre-deployed load test contract address
-m, --mode string t - sending transactions
d - deploy contract
c - call random contract functions
f - call specific contract function
s - store mode
l - long running mode (default "t")
--pretty-logs Should we log in pretty format or JSON (default true)
--private-key string The hex encoded private key that we'll use to sending transactions (default "42b6e34dc21598a807dc19d7784c71b2a7a01f6480dc6f58258f78e539f1a1fa")
--rate-limit float An overall limit to the number of requests per second. Give a number less than zero to remove this limit all together (default 4)
-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)
--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")
-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 timelimit. (default -1)
--to-address string The address that we're going to send to (default "0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF")
--to-random When doing a transfer test, should we send to random addresses rather than DEADBEEFx5 (default true)
-v, --verbosity int 0 - Silent
100 Fatals
200 Errors
300 Warnings
400 INFO
500 Debug
600 Trace (default 200)
Global Flags:
--config string config file (default is $HOME/.polygon-cli.yaml)
#+end_example
Expand Down
164 changes: 91 additions & 73 deletions cmd/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,27 +207,28 @@ type (
}
loadTestParams struct {
// inputs
Requests *int64
Concurrency *int64
TimeLimit *int64
Verbosity *int64
PrettyLogs *bool
ToRandom *bool
URL *url.URL
ChainID *uint64
PrivateKey *string
ToAddress *string
HexSendAmount *string
RateLimit *float64
Mode *string
Function *uint64
Iterations *uint64
ByteCount *uint64
Seed *int64
IsAvail *bool
AvailAppID *uint32
LtAddress *string
DelAddress *string
Requests *int64
Concurrency *int64
TimeLimit *int64
Verbosity *int64
PrettyLogs *bool
ToRandom *bool
URL *url.URL
ChainID *uint64
PrivateKey *string
ToAddress *string
HexSendAmount *string
RateLimit *float64
Mode *string
Function *uint64
Iterations *uint64
ByteCount *uint64
Seed *int64
IsAvail *bool
AvailAppID *uint32
LtAddress *string
DelAddress *string
ForceContractDeploy *bool

// Computed
CurrentGas *big.Int
Expand Down Expand Up @@ -271,6 +272,7 @@ func init() {
ltp.AvailAppID = loadtestCmd.PersistentFlags().Uint32("app-id", 0, "The AppID used for avail")
ltp.LtAddress = loadtestCmd.PersistentFlags().String("lt-address", "", "A pre-deployed load test contract address")
ltp.DelAddress = loadtestCmd.PersistentFlags().String("del-address", "", "A pre-deployed delegator contract address")
ltp.ForceContractDeploy = loadtestCmd.PersistentFlags().Bool("force-contract-deploy", false, "Some loadtest modes don't require a contract deployment. Set this flag to true to force contract deployments. This will still respect the --del-address and --il-address flags.")

inputLoadTestParams = *ltp

Expand Down Expand Up @@ -511,74 +513,90 @@ func mainLoop(ctx context.Context, c *ethclient.Client) error {
}
cops := new(bind.CallOpts)

// deploy and instantiate the load tester contract
var ltAddr ethcommon.Address
if *inputLoadTestParams.ToAddress == "" {
ltAddr, _, _, err = contracts.DeployLoadTester(tops, c)
if err != nil {
log.Error().Err(err).Msg("Failed to create the load testing contract. Do you have the right chain id? Do you have enough funds?")
return err
var ltContract *contracts.LoadTester
if strings.ContainsAny(mode, "rcfisl") || *inputLoadTestParams.ForceContractDeploy {
if *inputLoadTestParams.LtAddress == "" {
ltAddr, _, _, err = contracts.DeployLoadTester(tops, c)
if err != nil {
log.Error().Err(err).Msg("Failed to create the load testing contract. Do you have the right chain id? Do you have enough funds?")
return err
}
} else {
ltAddr = ethcommon.HexToAddress(*inputLoadTestParams.LtAddress)
}
} else {
ltAddr = ethcommon.HexToAddress(*inputLoadTestParams.LtAddress)
}
log.Trace().Interface("contractaddress", ltAddr).Msg("Load test contract address")
// bump the nonce since deploying a contract should cause it to increase
currentNonce = currentNonce + 1
log.Trace().Interface("contractaddress", ltAddr).Msg("Load test contract address")
// bump the nonce since deploying a contract should cause it to increase
currentNonce = currentNonce + 1

var delegatorAddr ethcommon.Address
if *inputLoadTestParams.ToAddress == "" {
delegatorAddr, _, _, err = contracts.DeployDelegator(tops, c)
ltContract, err = contracts.NewLoadTester(ltAddr, c)
if err != nil {
log.Error().Err(err).Msg("Failed to create the load testing contract. Do you have the right chain id? Do you have enough funds?")
log.Error().Err(err).Msg("Unable to instantiate new contract")
return err
}
} else {
delegatorAddr = ethcommon.HexToAddress(*inputLoadTestParams.DelAddress)
}
if err != nil {
log.Error().Err(err).Msg("Failed to create the delegator contract. Do you have the right chain id? Do you have enough funds?")
return err
}
log.Trace().Interface("contractaddress", delegatorAddr).Msg("Delegator contract address")
currentNonce = currentNonce + 1

ltContract, err := contracts.NewLoadTester(ltAddr, c)
if err != nil {
log.Error().Err(err).Msg("Unable to instantiate new contract")
return err
}
// block while the contract is pending
waitCounter := 30
for {
ltCounter, err := ltContract.GetCallCounter(cops)

delegatorContract, err := contracts.NewDelegator(delegatorAddr, c)
if err != nil {
log.Error().Err(err).Msg("Unable to instantiate new contract")
return err
if err != nil {
log.Trace().Msg("Waiting for Load Test contract to deploy")
time.Sleep(time.Second)
if waitCounter < 1 {
log.Error().Err(err).Msg("Exhausted waiting period for contract deployment")
return err
}
waitCounter = waitCounter - 1
continue
}
log.Trace().Interface("counter", ltCounter).Msg("Number of contract calls")
break
}
}

// block while the contract is pending
waitCounter := 30
for {
ltCounter, err := ltContract.GetCallCounter(cops)
// deploy and instantiate the delegator contract
var delegatorContract *contracts.Delegator
if strings.ContainsAny(mode, "rl") || *inputLoadTestParams.ForceContractDeploy {
var delegatorAddr ethcommon.Address
if *inputLoadTestParams.DelAddress == "" {
delegatorAddr, _, _, err = contracts.DeployDelegator(tops, c)
if err != nil {
log.Error().Err(err).Msg("Failed to create the load testing contract. Do you have the right chain id? Do you have enough funds?")
return err
}
} else {
delegatorAddr = ethcommon.HexToAddress(*inputLoadTestParams.DelAddress)
}
log.Trace().Interface("contractaddress", delegatorAddr).Msg("Delegator contract address")
currentNonce = currentNonce + 1

delegatorContract, err = contracts.NewDelegator(delegatorAddr, c)
if err != nil {
log.Trace().Msg("Waiting for contract to deploy")
time.Sleep(time.Second)
if waitCounter < 1 {
log.Error().Err(err).Msg("Exhausted waiting period for contract deployment")
return err
log.Error().Err(err).Msg("Unable to instantiate new contract")
return err
}

// block while the contract is pending
waitCounter := 30
for {
_, err = delegatorContract.Call(tops, ltAddr, []byte{0x12, 0x87, 0xa6, 0x8c})
if err != nil {
log.Trace().Msg("Waiting for Delegator contract to deploy")
time.Sleep(time.Second)
if waitCounter < 1 {
log.Error().Err(err).Msg("Exhausted waiting period for contract deployment")
return err
}
waitCounter = waitCounter - 1
continue
}
waitCounter = waitCounter - 1
continue
break
}
log.Trace().Interface("counter", ltCounter).Msg("Number of contract calls")
break
}

_, err = delegatorContract.Call(tops, ltAddr, []byte{0x12, 0x87, 0xa6, 0x8c})
if err != nil {
log.Error().Err(err).Msg("Load Test contract deployed successfully, but delegator contract failed.")
return err
currentNonce = currentNonce + 1
}
currentNonce = currentNonce + 1

var currentNonceMutex sync.Mutex
var i int64
Expand Down

0 comments on commit 25ecd83

Please sign in to comment.