forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
op-deployer: Custom gas price estimator (ethereum-optimism#12239)
* op-deployer: Custom gas price estimator Sepolia's fees are super high and extremely volatile right now. As a result, it became difficult for users to deploy new chains using op-deployer. The OPCM's deploy transaction buys most of the gas in the block, and the default gas price estimation logic in the transaction manager wasn't aggressive enough for the transactions to land on chain in a timely manner. This PR adds the ability to customize the transaction manager with a custom `GasPriceEstimator` function that returns the tip, base fee, and blob fee. I extracted the original logic in the transaction manager into a default estimator that will be used if one isn't specified. For op-deployer, I built a custom estimator that pads the head block's base fee by 20%, and multiplies the suggested tip by 10. After testing this, I was able to get transactions onto Sepolia reliably. The algorithm is pretty simple and overpays for transactions by a lot, but for op-deployer's use case it's more important that transactions land quickly than it is they be cheap. Deployments are a one-time thing. * code review updates * better default support * specific test for extension
- Loading branch information
Showing
7 changed files
with
127 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package broadcaster | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum-optimism/optimism/op-service/txmgr" | ||
) | ||
|
||
var ( | ||
// baseFeePadFactor = 20% as a divisor | ||
baseFeePadFactor = big.NewInt(5) | ||
// tipMulFactor = 10 as a multiplier | ||
tipMulFactor = big.NewInt(10) | ||
// dummyBlobFee is a dummy value for the blob fee. Since this gas estimator will never | ||
// post blobs, it's just set to 1. | ||
dummyBlobFee = big.NewInt(1) | ||
) | ||
|
||
// DeployerGasPriceEstimator is a custom gas price estimator for use with op-deployer. | ||
// It pads the base fee by 20% and multiplies the suggested tip by 10. | ||
func DeployerGasPriceEstimator(ctx context.Context, client txmgr.ETHBackend) (*big.Int, *big.Int, *big.Int, error) { | ||
chainHead, err := client.HeaderByNumber(ctx, nil) | ||
if err != nil { | ||
return nil, nil, nil, fmt.Errorf("failed to get block: %w", err) | ||
} | ||
|
||
tip, err := client.SuggestGasTipCap(ctx) | ||
if err != nil { | ||
return nil, nil, nil, fmt.Errorf("failed to get gas tip cap: %w", err) | ||
} | ||
|
||
baseFeePad := new(big.Int).Div(chainHead.BaseFee, baseFeePadFactor) | ||
paddedBaseFee := new(big.Int).Add(chainHead.BaseFee, baseFeePad) | ||
paddedTip := new(big.Int).Mul(tip, tipMulFactor) | ||
return paddedTip, paddedBaseFee, dummyBlobFee, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters