@ -205,6 +205,7 @@ type worker struct {
mu sync . RWMutex // The lock used to protect the coinbase and extra fields
mu sync . RWMutex // The lock used to protect the coinbase and extra fields
coinbase common . Address
coinbase common . Address
extra [ ] byte
extra [ ] byte
tip * big . Int // Minimum tip needed for non-local transaction to include them
pendingMu sync . RWMutex
pendingMu sync . RWMutex
pendingTasks map [ common . Hash ] * task
pendingTasks map [ common . Hash ] * task
@ -251,6 +252,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
isLocalBlock : isLocalBlock ,
isLocalBlock : isLocalBlock ,
coinbase : config . Etherbase ,
coinbase : config . Etherbase ,
extra : config . ExtraData ,
extra : config . ExtraData ,
tip : config . GasPrice ,
pendingTasks : make ( map [ common . Hash ] * task ) ,
pendingTasks : make ( map [ common . Hash ] * task ) ,
txsCh : make ( chan core . NewTxsEvent , txChanSize ) ,
txsCh : make ( chan core . NewTxsEvent , txChanSize ) ,
chainHeadCh : make ( chan core . ChainHeadEvent , chainHeadChanSize ) ,
chainHeadCh : make ( chan core . ChainHeadEvent , chainHeadChanSize ) ,
@ -327,6 +329,13 @@ func (w *worker) setExtra(extra []byte) {
w . extra = extra
w . extra = extra
}
}
// setGasTip sets the minimum miner tip needed to include a non-local transaction.
func ( w * worker ) setGasTip ( tip * big . Int ) {
w . mu . Lock ( )
defer w . mu . Unlock ( )
w . tip = tip
}
// setRecommitInterval updates the interval for miner sealing work recommitting.
// setRecommitInterval updates the interval for miner sealing work recommitting.
func ( w * worker ) setRecommitInterval ( interval time . Duration ) {
func ( w * worker ) setRecommitInterval ( interval time . Duration ) {
select {
select {
@ -554,7 +563,7 @@ func (w *worker) mainLoop() {
}
}
txset := newTransactionsByPriceAndNonce ( w . current . signer , txs , w . current . header . BaseFee )
txset := newTransactionsByPriceAndNonce ( w . current . signer , txs , w . current . header . BaseFee )
tcount := w . current . tcount
tcount := w . current . tcount
w . commitTransactions ( w . current , txset , nil )
w . commitTransactions ( w . current , txset , nil , new ( big . Int ) )
// Only update the snapshot if any new transactions were added
// Only update the snapshot if any new transactions were added
// to the pending block
// to the pending block
@ -792,7 +801,7 @@ func (w *worker) applyTransaction(env *environment, tx *types.Transaction) (*typ
return receipt , err
return receipt , err
}
}
func ( w * worker ) commitTransactions ( env * environment , txs * transactionsByPriceAndNonce , interrupt * atomic . Int32 ) error {
func ( w * worker ) commitTransactions ( env * environment , txs * transactionsByPriceAndNonce , interrupt * atomic . Int32 , minTip * big . Int ) error {
gasLimit := env . header . GasLimit
gasLimit := env . header . GasLimit
if env . gasPool == nil {
if env . gasPool == nil {
env . gasPool = new ( core . GasPool ) . AddGas ( gasLimit )
env . gasPool = new ( core . GasPool ) . AddGas ( gasLimit )
@ -812,7 +821,7 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn
break
break
}
}
// Retrieve the next transaction and abort if all done.
// Retrieve the next transaction and abort if all done.
ltx := txs . Peek ( )
ltx , tip := txs . Peek ( )
if ltx == nil {
if ltx == nil {
break
break
}
}
@ -827,6 +836,11 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn
txs . Pop ( )
txs . Pop ( )
continue
continue
}
}
// If we don't receive enough tip for the next transaction, skip the account
if tip . Cmp ( minTip ) < 0 {
log . Trace ( "Not enough tip for transaction" , "hash" , ltx . Hash , "tip" , tip , "needed" , minTip )
break // If the next-best is too low, surely no better will be available
}
// Transaction seems to fit, pull it up from the pool
// Transaction seems to fit, pull it up from the pool
tx := ltx . Resolve ( )
tx := ltx . Resolve ( )
if tx == nil {
if tx == nil {
@ -997,15 +1011,19 @@ func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) err
}
}
// Fill the block with all available pending transactions.
// Fill the block with all available pending transactions.
w . mu . RLock ( )
tip := w . tip
w . mu . RUnlock ( )
if len ( localTxs ) > 0 {
if len ( localTxs ) > 0 {
txs := newTransactionsByPriceAndNonce ( env . signer , localTxs , env . header . BaseFee )
txs := newTransactionsByPriceAndNonce ( env . signer , localTxs , env . header . BaseFee )
if err := w . commitTransactions ( env , txs , interrupt ) ; err != nil {
if err := w . commitTransactions ( env , txs , interrupt , new ( big . Int ) ) ; err != nil {
return err
return err
}
}
}
}
if len ( remoteTxs ) > 0 {
if len ( remoteTxs ) > 0 {
txs := newTransactionsByPriceAndNonce ( env . signer , remoteTxs , env . header . BaseFee )
txs := newTransactionsByPriceAndNonce ( env . signer , remoteTxs , env . header . BaseFee )
if err := w . commitTransactions ( env , txs , interrupt ) ; err != nil {
if err := w . commitTransactions ( env , txs , interrupt , tip ) ; err != nil {
return err
return err
}
}
}
}