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,
)
}
// 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,
locals []string,
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) {
return miner.worker.BuildTransactionsLists(
beneficiary,
@ -43,5 +65,6 @@ func (miner *Miner) BuildTransactionsLists(
maxBytesPerTxList,
locals,
maxTransactionsLists,
minTip,
)
}

View file

@ -6,8 +6,6 @@ import (
"errors"
"fmt"
"math/big"
"os"
"strconv"
"time"
"github.com/ethereum/go-ethereum/beacon/engine"
@ -34,6 +32,7 @@ func (w *worker) BuildTransactionsLists(
maxBytesPerTxList uint64,
localAccounts []string,
maxTransactionsLists uint64,
minTip uint64,
) ([]*PreBuiltTxList, error) {
var (
txsLists []*PreBuiltTxList
@ -96,6 +95,7 @@ func (w *worker) BuildTransactionsLists(
newTransactionsByPriceAndNonce(signer, locals, baseFee),
newTransactionsByPriceAndNonce(signer, remotes, baseFee),
maxBytesPerTxList,
minTip,
)
b, err := encodeAndComporeessTxList(env.txs)
@ -243,6 +243,7 @@ func (w *worker) commitL2Transactions(
txsLocal *transactionsByPriceAndNonce,
txsRemote *transactionsByPriceAndNonce,
maxBytesPerTxList uint64,
minTip uint64,
) *types.Transaction {
var (
txs = txsLocal
@ -280,17 +281,10 @@ loop:
continue
}
if os.Getenv("TAIKO_MIN_TIP") != "" {
minTip, err := strconv.Atoi(os.Getenv("TAIKO_MIN_TIP"))
if err != nil {
log.Error("Failed to parse TAIKO_MIN_TIP", "err", err)
} 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
}
}
if tx.GasTipCapIntCmp(new(big.Int).SetUint64(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