feat(taiko_miner): add BuildTransactionsListsWithMinTip method (#283)

* fix(taiko_worker): fix a `maxBytesPerTxList` check issue

* feat(taiko_miner): add `BuildTransactionsListsWithMinTip` method

* update
This commit is contained in:
David 2024-07-03 13:09:45 +08:00 committed by GitHub
parent 47893aead4
commit c777d24af1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 61 additions and 13 deletions

View file

@ -102,3 +102,34 @@ func (a *TaikoAuthAPIBackend) TxPoolContent(
maxTransactionsLists, maxTransactionsLists,
) )
} }
// TxPoolContentWithMinTip retrieves the transaction pool content with the given upper limits and minimum tip.
func (a *TaikoAuthAPIBackend) TxPoolContentWithMinTip(
beneficiary common.Address,
baseFee *big.Int,
blockMaxGasLimit uint64,
maxBytesPerTxList uint64,
locals []string,
maxTransactionsLists uint64,
minTip uint64,
) ([]*miner.PreBuiltTxList, error) {
log.Debug(
"Fetching L2 pending transactions finished",
"baseFee", baseFee,
"blockMaxGasLimit", blockMaxGasLimit,
"maxBytesPerTxList", maxBytesPerTxList,
"maxTransactions", maxTransactionsLists,
"locals", locals,
"minTip", minTip,
)
return a.eth.Miner().BuildTransactionsListsWithMinTip(
beneficiary,
baseFee,
blockMaxGasLimit,
maxBytesPerTxList,
locals,
maxTransactionsLists,
minTip,
)
}

View file

@ -35,6 +35,28 @@ func (miner *Miner) BuildTransactionsLists(
maxBytesPerTxList uint64, maxBytesPerTxList uint64,
locals []string, locals []string,
maxTransactionsLists uint64, maxTransactionsLists uint64,
) ([]*PreBuiltTxList, error) {
return miner.BuildTransactionsListsWithMinTip(
beneficiary,
baseFee,
blockMaxGasLimit,
maxBytesPerTxList,
locals,
maxTransactionsLists,
0,
)
}
// BuildTransactionsListsWithMinTip builds multiple transactions lists which satisfy all
// the given limits and minimum tip.
func (miner *Miner) BuildTransactionsListsWithMinTip(
beneficiary common.Address,
baseFee *big.Int,
blockMaxGasLimit uint64,
maxBytesPerTxList uint64,
locals []string,
maxTransactionsLists uint64,
minTip uint64,
) ([]*PreBuiltTxList, error) { ) ([]*PreBuiltTxList, error) {
return miner.worker.BuildTransactionsLists( return miner.worker.BuildTransactionsLists(
beneficiary, beneficiary,
@ -43,5 +65,6 @@ func (miner *Miner) BuildTransactionsLists(
maxBytesPerTxList, maxBytesPerTxList,
locals, locals,
maxTransactionsLists, maxTransactionsLists,
minTip,
) )
} }

View file

@ -6,8 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"math/big" "math/big"
"os"
"strconv"
"time" "time"
"github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/beacon/engine"
@ -34,6 +32,7 @@ func (w *worker) BuildTransactionsLists(
maxBytesPerTxList uint64, maxBytesPerTxList uint64,
localAccounts []string, localAccounts []string,
maxTransactionsLists uint64, maxTransactionsLists uint64,
minTip uint64,
) ([]*PreBuiltTxList, error) { ) ([]*PreBuiltTxList, error) {
var ( var (
txsLists []*PreBuiltTxList txsLists []*PreBuiltTxList
@ -96,6 +95,7 @@ func (w *worker) BuildTransactionsLists(
newTransactionsByPriceAndNonce(signer, locals, baseFee), newTransactionsByPriceAndNonce(signer, locals, baseFee),
newTransactionsByPriceAndNonce(signer, remotes, baseFee), newTransactionsByPriceAndNonce(signer, remotes, baseFee),
maxBytesPerTxList, maxBytesPerTxList,
minTip,
) )
b, err := encodeAndComporeessTxList(env.txs) b, err := encodeAndComporeessTxList(env.txs)
@ -243,6 +243,7 @@ func (w *worker) commitL2Transactions(
txsLocal *transactionsByPriceAndNonce, txsLocal *transactionsByPriceAndNonce,
txsRemote *transactionsByPriceAndNonce, txsRemote *transactionsByPriceAndNonce,
maxBytesPerTxList uint64, maxBytesPerTxList uint64,
minTip uint64,
) *types.Transaction { ) *types.Transaction {
var ( var (
txs = txsLocal txs = txsLocal
@ -280,17 +281,10 @@ loop:
continue continue
} }
if os.Getenv("TAIKO_MIN_TIP") != "" { if tx.GasTipCapIntCmp(new(big.Int).SetUint64(minTip)) < 0 {
minTip, err := strconv.Atoi(os.Getenv("TAIKO_MIN_TIP")) log.Trace("Ignoring transaction with low tip", "hash", tx.Hash(), "tip", tx.GasTipCap(), "minTip", minTip)
if err != nil { txs.Pop()
log.Error("Failed to parse TAIKO_MIN_TIP", "err", err) continue
} else {
if tx.GasTipCapIntCmp(new(big.Int).SetUint64(uint64(minTip))) < 0 {
log.Trace("Ignoring transaction with low tip", "hash", tx.Hash(), "tip", tx.GasTipCap(), "minTip", minTip)
txs.Pop()
continue
}
}
} }
// Error may be ignored here. The error has already been checked // Error may be ignored here. The error has already been checked