@@ -205,6 +205,7 @@ type worker struct {
205205	mu        sync.RWMutex  // The lock used to protect the coinbase and extra fields 
206206	coinbase  common.Address 
207207	extra     []byte 
208+ 	tip       * big.Int  // Minimum tip needed for non-local transaction to include them 
208209
209210	pendingMu     sync.RWMutex 
210211	pendingTasks  map [common.Hash ]* task 
@@ -251,6 +252,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
251252		isLocalBlock :       isLocalBlock ,
252253		coinbase :           config .Etherbase ,
253254		extra :              config .ExtraData ,
255+ 		tip :                config .GasPrice ,
254256		pendingTasks :       make (map [common.Hash ]* task ),
255257		txsCh :              make (chan  core.NewTxsEvent , txChanSize ),
256258		chainHeadCh :        make (chan  core.ChainHeadEvent , chainHeadChanSize ),
@@ -327,6 +329,13 @@ func (w *worker) setExtra(extra []byte) {
327329	w .extra  =  extra 
328330}
329331
332+ // setGasTip sets the minimum miner tip needed to include a non-local transaction. 
333+ func  (w  * worker ) setGasTip (tip  * big.Int ) {
334+ 	w .mu .Lock ()
335+ 	defer  w .mu .Unlock ()
336+ 	w .tip  =  tip 
337+ }
338+ 
330339// setRecommitInterval updates the interval for miner sealing work recommitting. 
331340func  (w  * worker ) setRecommitInterval (interval  time.Duration ) {
332341	select  {
@@ -554,7 +563,7 @@ func (w *worker) mainLoop() {
554563				}
555564				txset  :=  newTransactionsByPriceAndNonce (w .current .signer , txs , w .current .header .BaseFee )
556565				tcount  :=  w .current .tcount 
557- 				w .commitTransactions (w .current , txset , nil )
566+ 				w .commitTransactions (w .current , txset , nil ,  new (big. Int ) )
558567
559568				// Only update the snapshot if any new transactions were added 
560569				// to the pending block 
@@ -792,7 +801,7 @@ func (w *worker) applyTransaction(env *environment, tx *types.Transaction) (*typ
792801	return  receipt , err 
793802}
794803
795- func  (w  * worker ) commitTransactions (env  * environment , txs  * transactionsByPriceAndNonce , interrupt  * atomic.Int32 ) error  {
804+ func  (w  * worker ) commitTransactions (env  * environment , txs  * transactionsByPriceAndNonce , interrupt  * atomic.Int32 ,  minTip   * big. Int ) error  {
796805	gasLimit  :=  env .header .GasLimit 
797806	if  env .gasPool  ==  nil  {
798807		env .gasPool  =  new (core.GasPool ).AddGas (gasLimit )
@@ -812,7 +821,7 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn
812821			break 
813822		}
814823		// Retrieve the next transaction and abort if all done. 
815- 		ltx  :=  txs .Peek ()
824+ 		ltx ,  tip  :=  txs .Peek ()
816825		if  ltx  ==  nil  {
817826			break 
818827		}
@@ -827,6 +836,11 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn
827836			txs .Pop ()
828837			continue 
829838		}
839+ 		// If we don't receive enough tip for the next transaction, skip the account 
840+ 		if  tip .Cmp (minTip ) <  0  {
841+ 			log .Trace ("Not enough tip for transaction" , "hash" , ltx .Hash , "tip" , tip , "needed" , minTip )
842+ 			break  // If the next-best is too low, surely no better will be available 
843+ 		}
830844		// Transaction seems to fit, pull it up from the pool 
831845		tx  :=  ltx .Resolve ()
832846		if  tx  ==  nil  {
@@ -997,15 +1011,19 @@ func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) err
9971011	}
9981012
9991013	// Fill the block with all available pending transactions. 
1014+ 	w .mu .RLock ()
1015+ 	tip  :=  w .tip 
1016+ 	w .mu .RUnlock ()
1017+ 
10001018	if  len (localTxs ) >  0  {
10011019		txs  :=  newTransactionsByPriceAndNonce (env .signer , localTxs , env .header .BaseFee )
1002- 		if  err  :=  w .commitTransactions (env , txs , interrupt ); err  !=  nil  {
1020+ 		if  err  :=  w .commitTransactions (env , txs , interrupt ,  new (big. Int ) ); err  !=  nil  {
10031021			return  err 
10041022		}
10051023	}
10061024	if  len (remoteTxs ) >  0  {
10071025		txs  :=  newTransactionsByPriceAndNonce (env .signer , remoteTxs , env .header .BaseFee )
1008- 		if  err  :=  w .commitTransactions (env , txs , interrupt ); err  !=  nil  {
1026+ 		if  err  :=  w .commitTransactions (env , txs , interrupt ,  tip ); err  !=  nil  {
10091027			return  err 
10101028		}
10111029	}
0 commit comments