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 8 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
101 changes: 66 additions & 35 deletions cmd/loadtest/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,16 @@ type (
ForceGasPrice *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 @@ -305,6 +307,7 @@ r - random modes
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 +324,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 @@ -363,6 +373,7 @@ func initializeLoadTestParams(ctx context.Context, c *ethclient.Client) error {
inputLoadTestParams.CurrentNonce = &nonce
inputLoadTestParams.ECDSAPrivateKey = privateKey
inputLoadTestParams.FromETHAddress = &ethAddress
inputLoadTestParams.CurrentGasTipCap = gasTipCap

rand.Seed(*inputLoadTestParams.Seed)

Expand Down Expand Up @@ -587,6 +598,7 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
mode := *ltp.Mode
steadyStateTxPoolSize := *ltp.SteadyStateTxPoolSize
adaptiveRateLimitIncrement := *ltp.AdaptiveRateLimitIncrement
legacyTransactionMode := *ltp.LegacyTransactionMode
var rl *rate.Limiter
rl = rate.NewLimiter(rate.Limit(*ltp.RateLimit), 1)
if *ltp.RateLimit <= 0.0 {
Expand All @@ -599,8 +611,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 +679,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 +730,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 @@ -813,27 +821,27 @@ 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, legacyTransactionMode)
gatsbyz marked this conversation as resolved.
Show resolved Hide resolved
case loadTestModeDeploy:
startReq, endReq, err = loadtestDeploy(ctx, c, myNonceValue)
startReq, endReq, err = loadtestDeploy(ctx, c, myNonceValue, legacyTransactionMode)
case loadTestModeCall:
startReq, endReq, err = loadtestCall(ctx, c, myNonceValue, ltContract)
startReq, endReq, err = loadtestCall(ctx, c, myNonceValue, ltContract, legacyTransactionMode)
case loadTestModeFunction:
startReq, endReq, err = loadtestFunction(ctx, c, myNonceValue, ltContract)
startReq, endReq, err = loadtestFunction(ctx, c, myNonceValue, ltContract, legacyTransactionMode)
case loadTestModeInc:
startReq, endReq, err = loadtestInc(ctx, c, myNonceValue, ltContract)
startReq, endReq, err = loadtestInc(ctx, c, myNonceValue, ltContract, legacyTransactionMode)
case loadTestModeStore:
startReq, endReq, err = loadtestStore(ctx, c, myNonceValue, ltContract)
startReq, endReq, err = loadtestStore(ctx, c, myNonceValue, ltContract, legacyTransactionMode)
case loadTestModeLong:
startReq, endReq, err = loadtestLong(ctx, c, myNonceValue, delegatorContract, ltAddr)
startReq, endReq, err = loadtestLong(ctx, c, myNonceValue, delegatorContract, ltAddr, legacyTransactionMode)
case loadTestModeERC20:
startReq, endReq, err = loadtestERC20(ctx, c, myNonceValue, erc20Contract, ltAddr)
startReq, endReq, err = loadtestERC20(ctx, c, myNonceValue, erc20Contract, ltAddr, legacyTransactionMode)
case loadTestModeERC721:
startReq, endReq, err = loadtestERC721(ctx, c, myNonceValue, erc721Contract, ltAddr)
startReq, endReq, err = loadtestERC721(ctx, c, myNonceValue, erc721Contract, ltAddr, legacyTransactionMode)
case loadTestModePrecompiledContract:
startReq, endReq, err = loadtestCallPrecompiledContracts(ctx, c, myNonceValue, ltContract, true)
startReq, endReq, err = loadtestCallPrecompiledContracts(ctx, c, myNonceValue, ltContract, true, legacyTransactionMode)
case loadTestModePrecompiledContracts:
startReq, endReq, err = loadtestCallPrecompiledContracts(ctx, c, myNonceValue, ltContract, false)
startReq, endReq, err = loadtestCallPrecompiledContracts(ctx, c, myNonceValue, ltContract, false, legacyTransactionMode)
default:
log.Error().Str("mode", mode).Msg("We've arrived at a load test mode that we don't recognize")
}
Expand Down Expand Up @@ -949,7 +957,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, legacy bool) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

gasPrice := ltp.CurrentGas
Expand All @@ -963,9 +971,32 @@ func loadtestTransaction(ctx context.Context, c *ethclient.Client, nonce uint64)
chainID := new(big.Int).SetUint64(*ltp.ChainID)
privateKey := ltp.ECDSAPrivateKey

head, err := c.HeaderByNumber(ctx, nil)
if err != nil {
gatsbyz marked this conversation as resolved.
Show resolved Hide resolved
log.Error().Err(err).Msg("Unable to get head")
return
}
gatsbyz marked this conversation as resolved.
Show resolved Hide resolved

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 legacy {
tx = ethtypes.NewTransaction(nonce, *to, amount, gasLimit, gasPrice, nil)
} else {
gasTipCap := ltp.CurrentGasTipCap
gasFeeCap := new(big.Int).Add(gasTipCap, new(big.Int).Mul(head.BaseFee, big.NewInt(2)))
gatsbyz marked this conversation as resolved.
Show resolved Hide resolved
baseTx := &ethtypes.DynamicFeeTx{
ChainID: chainID,
Nonce: nonce,
To: to,
Gas: gasLimit,
GasFeeCap: gasFeeCap,
GasTipCap: gasTipCap,
Data: nil,
Value: amount,
}
tx = ethtypes.NewTx(baseTx)
}
stx, err := ethtypes.SignTx(tx, ethtypes.NewLondonSigner(chainID), privateKey)
if err != nil {
log.Error().Err(err).Msg("Unable to sign transaction")
return
Expand All @@ -977,7 +1008,7 @@ func loadtestTransaction(ctx context.Context, c *ethclient.Client, nonce uint64)
return
}

func loadtestDeploy(ctx context.Context, c *ethclient.Client, nonce uint64) (t1 time.Time, t2 time.Time, err error) {
func loadtestDeploy(ctx context.Context, c *ethclient.Client, nonce uint64, legacyTransactionMode bool) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

chainID := new(big.Int).SetUint64(*ltp.ChainID)
Expand All @@ -997,7 +1028,7 @@ func loadtestDeploy(ctx context.Context, c *ethclient.Client, nonce uint64) (t1
return
}

func loadtestFunction(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester) (t1 time.Time, t2 time.Time, err error) {
func loadtestFunction(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester, legacyTransactionMode bool) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

chainID := new(big.Int).SetUint64(*ltp.ChainID)
Expand All @@ -1019,7 +1050,7 @@ func loadtestFunction(ctx context.Context, c *ethclient.Client, nonce uint64, lt
return
}

func loadtestCall(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester) (t1 time.Time, t2 time.Time, err error) {
func loadtestCall(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester, legacyTransactionMode bool) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

chainID := new(big.Int).SetUint64(*ltp.ChainID)
Expand All @@ -1041,7 +1072,7 @@ func loadtestCall(ctx context.Context, c *ethclient.Client, nonce uint64, ltCont
return
}

func loadtestCallPrecompiledContracts(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester, useSelectedAddress bool) (t1 time.Time, t2 time.Time, err error) {
func loadtestCallPrecompiledContracts(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester, useSelectedAddress bool, legacyTransactionMode bool) (t1 time.Time, t2 time.Time, err error) {
var f int
ltp := inputLoadTestParams

Expand All @@ -1068,7 +1099,7 @@ func loadtestCallPrecompiledContracts(ctx context.Context, c *ethclient.Client,
return
}

func loadtestInc(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester) (t1 time.Time, t2 time.Time, err error) {
func loadtestInc(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester, legacyTransactionMode bool) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

chainID := new(big.Int).SetUint64(*ltp.ChainID)
Expand All @@ -1088,7 +1119,7 @@ func loadtestInc(ctx context.Context, c *ethclient.Client, nonce uint64, ltContr
return
}

func loadtestStore(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester) (t1 time.Time, t2 time.Time, err error) {
func loadtestStore(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester, legacyTransactionMode bool) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

chainID := new(big.Int).SetUint64(*ltp.ChainID)
Expand All @@ -1110,7 +1141,7 @@ func loadtestStore(ctx context.Context, c *ethclient.Client, nonce uint64, ltCon
return
}

func loadtestLong(ctx context.Context, c *ethclient.Client, nonce uint64, delegatorContract *contracts.Delegator, ltAddress ethcommon.Address) (t1 time.Time, t2 time.Time, err error) {
func loadtestLong(ctx context.Context, c *ethclient.Client, nonce uint64, delegatorContract *contracts.Delegator, ltAddress ethcommon.Address, legacyTransactionMode bool) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

chainID := new(big.Int).SetUint64(*ltp.ChainID)
Expand All @@ -1134,7 +1165,7 @@ func loadtestLong(ctx context.Context, c *ethclient.Client, nonce uint64, delega
return
}

func loadtestERC20(ctx context.Context, c *ethclient.Client, nonce uint64, erc20Contract *contracts.ERC20, ltAddress ethcommon.Address) (t1 time.Time, t2 time.Time, err error) {
func loadtestERC20(ctx context.Context, c *ethclient.Client, nonce uint64, erc20Contract *contracts.ERC20, ltAddress ethcommon.Address, legacyTransactionMode bool) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

to := ltp.ToETHAddress
Expand All @@ -1160,7 +1191,7 @@ func loadtestERC20(ctx context.Context, c *ethclient.Client, nonce uint64, erc20
return
}

func loadtestERC721(ctx context.Context, c *ethclient.Client, nonce uint64, erc721Contract *contracts.ERC721, ltAddress ethcommon.Address) (t1 time.Time, t2 time.Time, err error) {
func loadtestERC721(ctx context.Context, c *ethclient.Client, nonce uint64, erc721Contract *contracts.ERC721, ltAddress ethcommon.Address, legacyTransactionMode bool) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams
iterations := ltp.Iterations

Expand Down Expand Up @@ -1488,7 +1519,7 @@ 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 {
if *ltp.LegacyTransactionMode && ltp.ForceGasPrice != nil && *ltp.ForceGasPrice != 0 {
tops.GasPrice = big.NewInt(0).SetUint64(*ltp.ForceGasPrice)
}
if ltp.ForceGasLimit != nil && *ltp.ForceGasLimit != 0 {
Expand Down