Skip to content

Commit

Permalink
just use transact opts
Browse files Browse the repository at this point in the history
  • Loading branch information
gatsbyz committed Jun 28, 2023
1 parent 48024aa commit 08423e3
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions cmd/loadtest/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,9 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
if localMode == loadTestModeRandom {
localMode = validLoadTestModes[int(i+j)%(len(validLoadTestModes)-1)]
}

header, err := c.HeaderByNumber(ctx, nil)
switch localMode {
case loadTestModeTransaction:
startReq, endReq, err = loadtestTransaction(ctx, c, myNonceValue, header)
startReq, endReq, err = loadtestTransaction(ctx, c, myNonceValue)
case loadTestModeDeploy:
startReq, endReq, err = loadtestDeploy(ctx, c, myNonceValue)
case loadTestModeCall:
Expand Down Expand Up @@ -958,7 +956,7 @@ func blockUntilSuccessful(ctx context.Context, c *ethclient.Client, f func() err
}
}

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

gasPrice := ltp.CurrentGas
Expand All @@ -974,32 +972,21 @@ func loadtestTransaction(ctx context.Context, c *ethclient.Client, nonce uint64,

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

tx = ethtypes.NewTransaction(nonce, *to, amount, gasLimit, gasPrice, nil)

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(*to, tx)
stx, err := tops.Signer(*ltp.FromETHAddress, tx)
if err != nil {
log.Error().Err(err).Msg("Unable to sign transaction")
return
Expand Down

0 comments on commit 08423e3

Please sign in to comment.