feat(sender): add min gas tip (#1331)

This commit is contained in:
colin
2024-05-08 12:52:37 +08:00
committed by GitHub
parent 320ab56d1d
commit 1c7c30c9ae
4 changed files with 23 additions and 3 deletions

View File

@@ -5,7 +5,7 @@ import (
"runtime/debug"
)
var tag = "v4.4.4"
var tag = "v4.4.5"
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {

View File

@@ -15,7 +15,8 @@
"escalate_multiple_den": 1,
"max_gas_price": 1000000000000,
"tx_type": "LegacyTx",
"check_pending_time": 1
"check_pending_time": 1,
"min_gas_tip": 100000000
},
"gas_oracle_config": {
"min_gas_price": 0,
@@ -42,7 +43,8 @@
"max_gas_price": 1000000000000,
"max_blob_gas_price": 10000000000000,
"tx_type": "DynamicFeeTx",
"check_pending_time": 1
"check_pending_time": 1,
"min_gas_tip": 100000000
},
"gas_oracle_config": {
"min_gas_price": 0,

View File

@@ -26,6 +26,8 @@ type SenderConfig struct {
EscalateMultipleDen uint64 `json:"escalate_multiple_den"`
// The maximum gas price can be used to send transaction.
MaxGasPrice uint64 `json:"max_gas_price"`
// The minimum gas tip can be used to send transaction.
MinGasTip uint64 `json:"min_gas_tip"`
// The maximum blob gas price can be used to send transaction.
MaxBlobGasPrice uint64 `json:"max_blob_gas_price"`
// The transaction type to use: LegacyTx, DynamicFeeTx, BlobTx

View File

@@ -17,6 +17,12 @@ func (s *Sender) estimateLegacyGas(to *common.Address, data []byte, fallbackGasL
log.Error("estimateLegacyGas SuggestGasPrice failure", "error", err)
return nil, err
}
minGasTip := new(big.Int).SetUint64(s.config.MinGasTip)
if gasPrice.Cmp(minGasTip) < 0 {
gasPrice = minGasTip
}
gasLimit, _, err := s.estimateGasLimit(to, data, nil, gasPrice, nil, nil, nil)
if err != nil {
log.Error("estimateLegacyGas estimateGasLimit failure", "gas price", gasPrice, "from", s.auth.From.String(),
@@ -41,6 +47,11 @@ func (s *Sender) estimateDynamicGas(to *common.Address, data []byte, baseFee uin
return nil, err
}
minGasTip := new(big.Int).SetUint64(s.config.MinGasTip)
if gasTipCap.Cmp(minGasTip) < 0 {
gasTipCap = minGasTip
}
gasFeeCap := getGasFeeCap(new(big.Int).SetUint64(baseFee), gasTipCap)
gasLimit, accessList, err := s.estimateGasLimit(to, data, nil, nil, gasTipCap, gasFeeCap, nil)
if err != nil {
@@ -72,6 +83,11 @@ func (s *Sender) estimateBlobGas(to *common.Address, data []byte, sidecar *gethT
return nil, err
}
minGasTip := new(big.Int).SetUint64(s.config.MinGasTip)
if gasTipCap.Cmp(minGasTip) < 0 {
gasTipCap = minGasTip
}
gasFeeCap := getGasFeeCap(new(big.Int).SetUint64(baseFee), gasTipCap)
blobGasFeeCap := getBlobGasFeeCap(new(big.Int).SetUint64(blobBaseFee))
gasLimit, accessList, err := s.estimateGasLimit(to, data, sidecar, nil, gasTipCap, gasFeeCap, blobGasFeeCap)