forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathestimator.go
33 lines (26 loc) · 819 Bytes
/
estimator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package txmgr
import (
"context"
"errors"
"math/big"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
)
type GasPriceEstimatorFn func(ctx context.Context, backend ETHBackend) (*big.Int, *big.Int, *big.Int, error)
func DefaultGasPriceEstimatorFn(ctx context.Context, backend ETHBackend) (*big.Int, *big.Int, *big.Int, error) {
tip, err := backend.SuggestGasTipCap(ctx)
if err != nil {
return nil, nil, nil, err
}
head, err := backend.HeaderByNumber(ctx, nil)
if err != nil {
return nil, nil, nil, err
}
if head.BaseFee == nil {
return nil, nil, nil, errors.New("txmgr does not support pre-london blocks that do not have a base fee")
}
var blobFee *big.Int
if head.ExcessBlobGas != nil {
blobFee = eip4844.CalcBlobFee(*head.ExcessBlobGas)
}
return tip, head.BaseFee, blobFee, nil
}