Skip to content

Commit

Permalink
fix: update fillTransactionsAndBundles
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Apr 22, 2024
1 parent eff6508 commit 9fdda1f
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,40 @@ var (
// fillTransactions retrieves the pending bundles and transactions from the txpool and fills them
// into the given sealing block. The selection and ordering strategy can be extended in the future.
func (w *worker) fillTransactionsAndBundles(interruptCh chan int32, env *environment, stopTimer *time.Timer) error {
env.state.StopPrefetcher() // no need to prefetch txs for a builder

var (
localPlainTxs map[common.Address][]*txpool.LazyTransaction
remotePlainTxs map[common.Address][]*txpool.LazyTransaction
localBlobTxs map[common.Address][]*txpool.LazyTransaction
remoteBlobTxs map[common.Address][]*txpool.LazyTransaction
bundles []*types.Bundle
)

{
bundles = w.eth.TxPool().PendingBundles(env.header.Number.Uint64(), env.header.Time)

// if no bundles, not necessary to fill transactions
if len(bundles) == 0 {
return errors.New("no bundles in bundle pool")
}

log.Info("fill bundles and transactions", "bundles_count", len(bundles))

txs, bundle, err := w.generateOrderedBundles(env, bundles)
if err != nil {
log.Error("fail to generate ordered bundles", "err", err)
return err
}

if err = w.commitBundles(env, txs, interruptCh, stopTimer); err != nil {
log.Error("fail to commit bundles", "err", err)
return err
}

env.profit.Add(env.profit, bundle.EthSentToSystem)
}

{
w.mu.RLock()
tip := w.tip
Expand Down Expand Up @@ -71,34 +98,8 @@ func (w *worker) fillTransactionsAndBundles(interruptCh chan int32, env *environ
localBlobTxs[account] = txs
}
}

bundles = w.eth.TxPool().PendingBundles(env.header.Number.Uint64(), env.header.Time)

log.Info("fill bundles and transactions", "bundles_count", len(bundles), "plain_tx_count", len(localPlainTxs)+len(remotePlainTxs), "blob_tx_count", len(localBlobTxs)+len(remoteBlobTxs))

// if no bundles, not necessary to fill transactions
if len(bundles) == 0 {
return errors.New("no bundles in bundle pool")
}
}

{
txs, bundle, err := w.generateOrderedBundles(env, bundles)
if err != nil {
log.Error("fail to generate ordered bundles", "err", err)
return err
}

if err = w.commitBundles(env, txs, interruptCh, stopTimer); err != nil {
log.Error("fail to commit bundles", "err", err)
return err
}

env.profit.Add(env.profit, bundle.EthSentToSystem)
}

env.state.StopPrefetcher() // no need to prefetch txs for a builder

// Fill the block with all available pending transactions.
// we will abort when:
// 1.new block was imported
Expand All @@ -107,6 +108,7 @@ func (w *worker) fillTransactionsAndBundles(interruptCh chan int32, env *environ
// 4.interrupted resubmit timer, which is by default 10s.
// resubmit is for PoW only, can be deleted for PoS consensus later
if len(localPlainTxs) > 0 || len(localBlobTxs) > 0 {
log.Info("fill local transactions", "plain", len(localPlainTxs), "blob", len(localBlobTxs))
plainTxs := newTransactionsByPriceAndNonce(env.signer, localPlainTxs, env.header.BaseFee)
blobTxs := newTransactionsByPriceAndNonce(env.signer, localBlobTxs, env.header.BaseFee)

Expand All @@ -115,6 +117,7 @@ func (w *worker) fillTransactionsAndBundles(interruptCh chan int32, env *environ
}
}
if len(remotePlainTxs) > 0 || len(remoteBlobTxs) > 0 {
log.Info("fill remote transactions", "plain", len(remotePlainTxs), "blob", len(remoteBlobTxs))
plainTxs := newTransactionsByPriceAndNonce(env.signer, remotePlainTxs, env.header.BaseFee)
blobTxs := newTransactionsByPriceAndNonce(env.signer, remoteBlobTxs, env.header.BaseFee)

Expand Down

0 comments on commit 9fdda1f

Please sign in to comment.