Skip to content

Commit 9985b49

Browse files
committed
loadtest: use feeHistory to define maxFeePerGas
1 parent 0e0f4c1 commit 9985b49

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

cmd/loadtest/account.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,7 @@ func (ap *AccountPool) ReturnFunds(ctx context.Context) error {
460460
}
461461
pricePerGas = gasPrice
462462
} else {
463-
header, iErr := ap.client.HeaderByNumber(ctx, nil)
464-
if iErr != nil {
465-
log.Error().Err(iErr).Msg("Unable to get header")
466-
return iErr
467-
}
468-
pricePerGas = header.BaseFee
463+
pricePerGas = ltp.MaxFeePerGas
469464
}
470465
txFee := new(big.Int).Mul(ethTransferGas, pricePerGas)
471466
// double the txFee to account for gas price fluctuations and

cmd/loadtest/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type (
9999
ContractETHAddress *ethcommon.Address
100100
SendAmount *big.Int
101101
CurrentBaseFee *big.Int
102+
MaxFeePerGas *big.Int
102103
ChainSupportBaseFee bool
103104
Mode loadTestMode
104105
ParsedModes []loadTestMode

cmd/loadtest/loadtest.go

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,21 +284,44 @@ func initializeLoadTestParams(ctx context.Context, c *ethclient.Client) error {
284284
*inputLoadTestParams.ChainID = chainID.Uint64()
285285
}
286286
inputLoadTestParams.CurrentBaseFee = header.BaseFee
287+
inputLoadTestParams.MaxFeePerGas = header.BaseFee
287288
go func(c *ethclient.Client, lbn uint64) {
288289
latestBlockNumber := lbn
289290
for {
291+
loopInterval := time.Second
292+
290293
iHeader, iErr := c.HeaderByNumber(ctx, nil)
291-
if iErr == nil {
292-
if iHeader.Number.Uint64() > latestBlockNumber {
293-
inputLoadTestParams.CurrentBaseFee = iHeader.BaseFee
294-
latestBlockNumber = iHeader.Number.Uint64()
295-
log.Trace().
296-
Uint64("latestBlockNumber", latestBlockNumber).
297-
Str("baseFee", iHeader.BaseFee.String()).
298-
Msg("Base fee updated")
299-
}
294+
if iErr != nil {
295+
time.Sleep(loopInterval)
296+
continue
297+
}
298+
299+
if latestBlockNumber >= iHeader.Number.Uint64() {
300+
time.Sleep(loopInterval)
301+
continue
302+
}
303+
304+
feeHistory, iErr := c.FeeHistory(ctx, 5, nil, []float64{0.5})
305+
if iErr != nil {
306+
time.Sleep(loopInterval)
307+
continue
300308
}
301-
time.Sleep(time.Second)
309+
310+
priorityFee := feeHistory.Reward[len(feeHistory.Reward)-1][0] // 50th percentile of most recent block
311+
baseFee := feeHistory.BaseFee[len(feeHistory.BaseFee)-1] // base fee of next block
312+
inputLoadTestParams.MaxFeePerGas.Mul(big.NewInt(2), priorityFee)
313+
inputLoadTestParams.MaxFeePerGas.Add(inputLoadTestParams.MaxFeePerGas, baseFee)
314+
inputLoadTestParams.CurrentBaseFee = baseFee
315+
316+
latestBlockNumber = iHeader.Number.Uint64()
317+
log.Trace().
318+
Uint64("latestBlockNumber", latestBlockNumber).
319+
Str("priorityFee", priorityFee.String()).
320+
Str("baseFee", baseFee.String()).
321+
Str("maxFee", inputLoadTestParams.MaxFeePerGas.String()).
322+
Msg("fees updated")
323+
324+
time.Sleep(loopInterval)
302325
}
303326
}(c, header.Number.Uint64())
304327

@@ -1857,7 +1880,7 @@ func configureTransactOpts(ctx context.Context, c *ethclient.Client, tops *bind.
18571880

18581881
tops.GasPrice = nil
18591882
tops.GasTipCap = gasTipCap
1860-
tops.GasFeeCap = ltp.CurrentBaseFee
1883+
tops.GasFeeCap = ltp.MaxFeePerGas
18611884

18621885
if ltp.ForcePriorityGasPrice != nil && *ltp.ForcePriorityGasPrice != 0 {
18631886
tops.GasTipCap = big.NewInt(0).SetUint64(*ltp.ForcePriorityGasPrice)

0 commit comments

Comments
 (0)