Skip to content

Commit

Permalink
use transactOpts function to determine signer
Browse files Browse the repository at this point in the history
  • Loading branch information
gatsbyz committed Jun 28, 2023
1 parent 04d51bf commit 04e19a4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cmd/loadtest/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,11 @@ 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)
startReq, endReq, err = loadtestTransaction(ctx, c, myNonceValue, header)
case loadTestModeDeploy:
startReq, endReq, err = loadtestDeploy(ctx, c, myNonceValue)
case loadTestModeCall:
Expand Down Expand Up @@ -956,7 +958,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 @@ -982,7 +984,7 @@ func loadtestTransaction(ctx context.Context, c *ethclient.Client, nonce uint64)
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)))
gasFeeCap := new(big.Int).Add(gasTipCap, head.BaseFee)
baseTx := &ethtypes.DynamicFeeTx{
ChainID: chainID,
Nonce: nonce,
Expand All @@ -995,7 +997,15 @@ func loadtestTransaction(ctx context.Context, c *ethclient.Client, nonce uint64)
}
tx = ethtypes.NewTx(baseTx)
}
stx, err := ethtypes.SignTx(tx, ethtypes.NewLondonSigner(chainID), privateKey)

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)
if err != nil {
log.Error().Err(err).Msg("Unable to sign transaction")
return
Expand Down

0 comments on commit 04e19a4

Please sign in to comment.