Skip to content

Commit

Permalink
feat(taiko_miner): add BuildTransactionsListsWithMinTip method (#283)
Browse files Browse the repository at this point in the history
* fix(taiko_worker): fix a `maxBytesPerTxList` check issue

* feat(taiko_miner): add `BuildTransactionsListsWithMinTip` method

* update
  • Loading branch information
davidtaikocha authored Jul 3, 2024
1 parent 47893ae commit c777d24
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
31 changes: 31 additions & 0 deletions eth/taiko_api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
23 changes: 23 additions & 0 deletions miner/taiko_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -43,5 +65,6 @@ func (miner *Miner) BuildTransactionsLists(
maxBytesPerTxList,
locals,
maxTransactionsLists,
minTip,
)
}
20 changes: 7 additions & 13 deletions miner/taiko_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"errors"
"fmt"
"math/big"
"os"
"strconv"
"time"

"github.com/ethereum/go-ethereum/beacon/engine"
Expand All @@ -34,6 +32,7 @@ func (w *worker) BuildTransactionsLists(
maxBytesPerTxList uint64,
localAccounts []string,
maxTransactionsLists uint64,
minTip uint64,
) ([]*PreBuiltTxList, error) {
var (
txsLists []*PreBuiltTxList
Expand Down Expand Up @@ -96,6 +95,7 @@ func (w *worker) BuildTransactionsLists(
newTransactionsByPriceAndNonce(signer, locals, baseFee),
newTransactionsByPriceAndNonce(signer, remotes, baseFee),
maxBytesPerTxList,
minTip,
)

b, err := encodeAndComporeessTxList(env.txs)
Expand Down Expand Up @@ -243,6 +243,7 @@ func (w *worker) commitL2Transactions(
txsLocal *transactionsByPriceAndNonce,
txsRemote *transactionsByPriceAndNonce,
maxBytesPerTxList uint64,
minTip uint64,
) *types.Transaction {
var (
txs = txsLocal
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c777d24

Please sign in to comment.