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

Jesse/loadtest legacy mode #92

Merged
merged 30 commits into from
Jun 30, 2023
Merged
Changes from 17 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a19d196
default to dynamic tx with legacy flag as option
gatsbyz Jun 26, 2023
d2a5014
uncomment nonce
gatsbyz Jun 26, 2023
6e2285f
suggest gas tip cap and calculate fee cap
gatsbyz Jun 26, 2023
1322373
use london signer
gatsbyz Jun 26, 2023
c851d1f
remove test line
gatsbyz Jun 26, 2023
ac95579
only legacy mode control force gas price
gatsbyz Jun 26, 2023
105a1d6
pass in legacy flag to wisely force gas prices
gatsbyz Jun 26, 2023
0848f13
remove redundant option configure call & refractor
gatsbyz Jun 28, 2023
290803c
remove some redundant arguments
gatsbyz Jun 28, 2023
04d51bf
clean up
gatsbyz Jun 28, 2023
04e19a4
use transactOpts function to determine signer
gatsbyz Jun 28, 2023
48024aa
remove header stuff
gatsbyz Jun 28, 2023
08423e3
just use transact opts
gatsbyz Jun 28, 2023
2372100
push
gatsbyz Jun 28, 2023
2b8778c
minor fix: legacy mode and priority gas fee
gatsbyz Jun 28, 2023
404bc56
revert fuzz
gatsbyz Jun 28, 2023
7bca43b
variable name change for lint
gatsbyz Jun 28, 2023
ada49f5
remove error catch
gatsbyz Jun 29, 2023
3abfe68
gas tip price estimation only for non legacy
gatsbyz Jun 29, 2023
f822912
lint :)
gatsbyz Jun 29, 2023
b923b60
hello
gatsbyz Jun 29, 2023
da3148b
swap again
gatsbyz Jun 29, 2023
8f1a55e
real gucci
gatsbyz Jun 29, 2023
e5ca5dc
real fix
gatsbyz Jun 29, 2023
925470e
feat: adding tx type to monitor
praetoriansentry Jun 29, 2023
305577d
Jesse/loadtest chain id query (#95)
gatsbyz Jun 29, 2023
d48dadd
last changes for logic
gatsbyz Jun 29, 2023
9738186
gas price logic
gatsbyz Jun 29, 2023
ed0432d
remove empty if statement
gatsbyz Jun 30, 2023
938396a
1559 aware monitor variables (#97)
gatsbyz Jun 30, 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
88 changes: 71 additions & 17 deletions cmd/loadtest/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/ecdsa"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -236,16 +237,19 @@ type (
ForceContractDeploy *bool
ForceGasLimit *uint64
ForceGasPrice *uint64
ForcePriorityGasPrice *uint64
ShouldProduceSummary *bool
SummaryOutputMode *string
LegacyTransactionMode *bool

// Computed
CurrentGas *big.Int
CurrentNonce *uint64
ECDSAPrivateKey *ecdsa.PrivateKey
FromETHAddress *ethcommon.Address
ToETHAddress *ethcommon.Address
SendAmount *big.Int
CurrentGas *big.Int
CurrentGasTipCap *big.Int
CurrentNonce *uint64
ECDSAPrivateKey *ecdsa.PrivateKey
FromETHAddress *ethcommon.Address
ToETHAddress *ethcommon.Address
SendAmount *big.Int

ToAvailAddress *gstypes.MultiAddress
FromAvailAddress *gssignature.KeyringPair
Expand Down Expand Up @@ -302,9 +306,11 @@ r - random modes
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.")
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")
ltp.ForceGasPrice = LoadtestCmd.PersistentFlags().Uint64("gas-price", 0, "In environments where the gas price can't be estimated, 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 loadtest, 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.")
inputLoadTestParams = *ltp

// TODO batch size
Expand All @@ -321,6 +327,13 @@ func initializeLoadTestParams(ctx context.Context, c *ethclient.Client) error {
}
log.Trace().Interface("gasprice", gas).Msg("Retreived current gas price")

gasTipCap, err := c.SuggestGasTipCap(ctx)
if err != nil {
log.Error().Err(err).Msg("Unable to retrieve gas tip cap")
return err
}
log.Trace().Interface("gastipcap", gasTipCap).Msg("Retreived current gas tip cap")

privateKey, err := ethcrypto.HexToECDSA(*inputLoadTestParams.PrivateKey)
if err != nil {
log.Error().Err(err).Msg("Couldn't process the hex private key")
Expand Down Expand Up @@ -357,12 +370,18 @@ func initializeLoadTestParams(ctx context.Context, c *ethclient.Client) error {
return err
}

if *inputLoadTestParams.LegacyTransactionMode && *inputLoadTestParams.ForcePriorityGasPrice > 0 {
log.Error().Msg("Cannot set priority gas price in legacy mode")
return errors.New("cannot set priority gas price in legacy mode")
}

inputLoadTestParams.ToETHAddress = &toAddr
inputLoadTestParams.SendAmount = amt
inputLoadTestParams.CurrentGas = gas
inputLoadTestParams.CurrentNonce = &nonce
inputLoadTestParams.ECDSAPrivateKey = privateKey
inputLoadTestParams.FromETHAddress = &ethAddress
inputLoadTestParams.CurrentGasTipCap = gasTipCap

rand.Seed(*inputLoadTestParams.Seed)

Expand Down Expand Up @@ -599,8 +618,8 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
}

tops, err := bind.NewKeyedTransactorWithChainID(privateKey, chainID)
tops = configureTransactOpts(tops)
tops.GasLimit = 10000000
tops = configureTransactOpts(tops)

if err != nil {
log.Error().Err(err).Msg("Unable create transaction signer")
Expand Down Expand Up @@ -667,8 +686,6 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
}

tops.Nonce = new(big.Int).SetUint64(currentNonce)
tops = configureTransactOpts(tops)
tops.GasLimit = 10000000

_, err = erc20Contract.Mint(tops, metrics.UnitMegaether)
if err != nil {
Expand Down Expand Up @@ -720,8 +737,6 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
}

tops.Nonce = new(big.Int).SetUint64(currentNonce)
tops = configureTransactOpts(tops)
tops.GasLimit = 10000000

err = blockUntilSuccessful(ctx, c, func() error {
_, err = erc721Contract.MintBatch(tops, *ltp.FromETHAddress, new(big.Int).SetUint64(1))
Expand Down Expand Up @@ -785,6 +800,12 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
var retryForNonce bool = false
var myNonceValue uint64

header, _err := c.HeaderByNumber(ctx, nil)
if _err != nil {
log.Error().Err(err).Msg("Unable to get head")
return
}

gatsbyz marked this conversation as resolved.
Show resolved Hide resolved
for j = 0; j < requests; j = j + 1 {
if rl != nil {
err = rl.Wait(ctx)
Expand Down Expand Up @@ -813,7 +834,7 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
}
switch localMode {
case loadTestModeTransaction:
startReq, endReq, err = loadtestTransaction(ctx, c, myNonceValue)
startReq, endReq, err = loadtestTransaction(ctx, c, myNonceValue, header)
case loadTestModeDeploy:
startReq, endReq, err = loadtestDeploy(ctx, c, myNonceValue)
case loadTestModeCall:
Expand Down Expand Up @@ -949,7 +970,7 @@ func blockUntilSuccessful(ctx context.Context, c *ethclient.Client, f func() err
}
}

func loadtestTransaction(ctx context.Context, c *ethclient.Client, nonce uint64) (t1 time.Time, t2 time.Time, err error) {
func loadtestTransaction(ctx context.Context, c *ethclient.Client, nonce uint64, header *ethtypes.Header) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

gasPrice := ltp.CurrentGas
Expand All @@ -964,8 +985,37 @@ func loadtestTransaction(ctx context.Context, c *ethclient.Client, nonce uint64)
privateKey := ltp.ECDSAPrivateKey

gasLimit := uint64(21000)
tx := ethtypes.NewTransaction(nonce, *to, amount, gasLimit, gasPrice, nil)
stx, err := ethtypes.SignTx(tx, ethtypes.NewEIP155Signer(chainID), privateKey)
var tx *ethtypes.Transaction
if err != nil {
gatsbyz marked this conversation as resolved.
Show resolved Hide resolved
log.Error().Err(err).Msg("Unable to get head")
return
}
if *ltp.LegacyTransactionMode {
tx = ethtypes.NewTransaction(nonce, *to, amount, gasLimit, gasPrice, nil)
} else {
gasTipCap := ltp.CurrentGasTipCap
gasFeeCap := new(big.Int).Add(gasTipCap, header.BaseFee)
dynamicFeeTx := &ethtypes.DynamicFeeTx{
ChainID: chainID,
Nonce: nonce,
To: to,
Gas: gasLimit,
GasFeeCap: gasFeeCap,
GasTipCap: gasTipCap,
Data: nil,
Value: amount,
}
tx = ethtypes.NewTx(dynamicFeeTx)
}

tops, err := bind.NewKeyedTransactorWithChainID(privateKey, chainID)
if err != nil {
log.Error().Err(err).Msg("Unable create transaction signer")
return
}
tops = configureTransactOpts(tops)

stx, err := tops.Signer(*ltp.FromETHAddress, tx)
if err != nil {
log.Error().Err(err).Msg("Unable to sign transaction")
return
Expand Down Expand Up @@ -1488,8 +1538,12 @@ func loadtestAvailStore(ctx context.Context, c *gsrpc.SubstrateAPI, nonce uint64

func configureTransactOpts(tops *bind.TransactOpts) *bind.TransactOpts {
ltp := inputLoadTestParams
if ltp.ForceGasPrice != nil && *ltp.ForceGasPrice != 0 {
tops.GasPrice = big.NewInt(0).SetUint64(*ltp.ForceGasPrice)
if *ltp.LegacyTransactionMode {
if ltp.ForceGasPrice != nil && *ltp.ForceGasPrice != 0 {
tops.GasPrice = big.NewInt(0).SetUint64(*ltp.ForceGasPrice)
} else {
tops.GasPrice = ltp.CurrentGas
}
}
if ltp.ForceGasLimit != nil && *ltp.ForceGasLimit != 0 {
tops.GasLimit = *ltp.ForceGasLimit
Expand Down