@@ -562,9 +562,11 @@ func (w *worker) mainLoop() {
562
562
BlobGas : tx .BlobGas (),
563
563
})
564
564
}
565
- txset := newTransactionsByPriceAndNonce (w .current .signer , txs , w .current .header .BaseFee )
565
+ plainTxs := newTransactionsByPriceAndNonce (w .current .signer , txs , w .current .header .BaseFee ) // Mixed bag of everrything, yolo
566
+ blobTxs := newTransactionsByPriceAndNonce (w .current .signer , nil , w .current .header .BaseFee ) // Empty bag, don't bother optimising
567
+
566
568
tcount := w .current .tcount
567
- w .commitTransactions (w .current , txset , nil , new (uint256. Int ) )
569
+ w .commitTransactions (w .current , plainTxs , blobTxs , nil )
568
570
569
571
// Only update the snapshot if any new transactions were added
570
572
// to the pending block
@@ -802,7 +804,7 @@ func (w *worker) applyTransaction(env *environment, tx *types.Transaction) (*typ
802
804
return receipt , err
803
805
}
804
806
805
- func (w * worker ) commitTransactions (env * environment , txs * transactionsByPriceAndNonce , interrupt * atomic.Int32 , minTip * uint256. Int ) error {
807
+ func (w * worker ) commitTransactions (env * environment , plainTxs , blobTxs * transactionsByPriceAndNonce , interrupt * atomic.Int32 ) error {
806
808
gasLimit := env .header .GasLimit
807
809
if env .gasPool == nil {
808
810
env .gasPool = new (core.GasPool ).AddGas (gasLimit )
@@ -821,8 +823,33 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn
821
823
log .Trace ("Not enough gas for further transactions" , "have" , env .gasPool , "want" , params .TxGas )
822
824
break
823
825
}
826
+ // If we don't have enough blob space for any further blob transactions,
827
+ // skip that list altogether
828
+ if ! blobTxs .Empty () && env .blobs * params .BlobTxBlobGasPerBlob >= params .MaxBlobGasPerBlock {
829
+ log .Trace ("Not enough blob space for further blob transactions" )
830
+ blobTxs .Clear ()
831
+ // Fall though to pick up any plain txs
832
+ }
824
833
// Retrieve the next transaction and abort if all done.
825
- ltx , tip := txs .Peek ()
834
+ var (
835
+ ltx * txpool.LazyTransaction
836
+ txs * transactionsByPriceAndNonce
837
+ )
838
+ pltx , ptip := plainTxs .Peek ()
839
+ bltx , btip := blobTxs .Peek ()
840
+
841
+ switch {
842
+ case pltx == nil :
843
+ txs , ltx = blobTxs , bltx
844
+ case bltx == nil :
845
+ txs , ltx = plainTxs , pltx
846
+ default :
847
+ if ptip .Lt (btip ) {
848
+ txs , ltx = blobTxs , bltx
849
+ } else {
850
+ txs , ltx = plainTxs , pltx
851
+ }
852
+ }
826
853
if ltx == nil {
827
854
break
828
855
}
@@ -837,11 +864,6 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn
837
864
txs .Pop ()
838
865
continue
839
866
}
840
- // If we don't receive enough tip for the next transaction, skip the account
841
- if tip .Cmp (minTip ) < 0 {
842
- log .Trace ("Not enough tip for transaction" , "hash" , ltx .Hash , "tip" , tip , "needed" , minTip )
843
- break // If the next-best is too low, surely no better will be available
844
- }
845
867
// Transaction seems to fit, pull it up from the pool
846
868
tx := ltx .Resolve ()
847
869
if tx == nil {
@@ -1005,35 +1027,49 @@ func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) err
1005
1027
w .mu .RUnlock ()
1006
1028
1007
1029
// Retrieve the pending transactions pre-filtered by the 1559/4844 dynamic fees
1008
- var baseFee * uint256.Int
1030
+ filter := txpool.PendingFilter {
1031
+ MinTip : tip ,
1032
+ }
1009
1033
if env .header .BaseFee != nil {
1010
- baseFee = uint256 .MustFromBig (env .header .BaseFee )
1034
+ filter . BaseFee = uint256 .MustFromBig (env .header .BaseFee )
1011
1035
}
1012
- var blobFee * uint256.Int
1013
1036
if env .header .ExcessBlobGas != nil {
1014
- blobFee = uint256 .MustFromBig (eip4844 .CalcBlobFee (* env .header .ExcessBlobGas ))
1037
+ filter . BlobFee = uint256 .MustFromBig (eip4844 .CalcBlobFee (* env .header .ExcessBlobGas ))
1015
1038
}
1016
- pending := w .eth .TxPool ().Pending (tip , baseFee , blobFee )
1039
+ filter .OnlyPlainTxs , filter .OnlyBlobTxs = true , false
1040
+ pendingPlainTxs := w .eth .TxPool ().Pending (filter )
1041
+
1042
+ filter .OnlyPlainTxs , filter .OnlyBlobTxs = false , true
1043
+ pendingBlobTxs := w .eth .TxPool ().Pending (filter )
1017
1044
1018
1045
// Split the pending transactions into locals and remotes.
1019
- localTxs , remoteTxs := make (map [common.Address ][]* txpool.LazyTransaction ), pending
1046
+ localPlainTxs , remotePlainTxs := make (map [common.Address ][]* txpool.LazyTransaction ), pendingPlainTxs
1047
+ localBlobTxs , remoteBlobTxs := make (map [common.Address ][]* txpool.LazyTransaction ), pendingBlobTxs
1048
+
1020
1049
for _ , account := range w .eth .TxPool ().Locals () {
1021
- if txs := remoteTxs [account ]; len (txs ) > 0 {
1022
- delete (remoteTxs , account )
1023
- localTxs [account ] = txs
1050
+ if txs := remotePlainTxs [account ]; len (txs ) > 0 {
1051
+ delete (remotePlainTxs , account )
1052
+ localPlainTxs [account ] = txs
1053
+ }
1054
+ if txs := remoteBlobTxs [account ]; len (txs ) > 0 {
1055
+ delete (remoteBlobTxs , account )
1056
+ localBlobTxs [account ] = txs
1024
1057
}
1025
1058
}
1026
-
1027
1059
// Fill the block with all available pending transactions.
1028
- if len (localTxs ) > 0 {
1029
- txs := newTransactionsByPriceAndNonce (env .signer , localTxs , env .header .BaseFee )
1030
- if err := w .commitTransactions (env , txs , interrupt , new (uint256.Int )); err != nil {
1060
+ if len (localPlainTxs ) > 0 || len (localBlobTxs ) > 0 {
1061
+ plainTxs := newTransactionsByPriceAndNonce (env .signer , localPlainTxs , env .header .BaseFee )
1062
+ blobTxs := newTransactionsByPriceAndNonce (env .signer , localBlobTxs , env .header .BaseFee )
1063
+
1064
+ if err := w .commitTransactions (env , plainTxs , blobTxs , interrupt ); err != nil {
1031
1065
return err
1032
1066
}
1033
1067
}
1034
- if len (remoteTxs ) > 0 {
1035
- txs := newTransactionsByPriceAndNonce (env .signer , remoteTxs , env .header .BaseFee )
1036
- if err := w .commitTransactions (env , txs , interrupt , tip ); err != nil {
1068
+ if len (remotePlainTxs ) > 0 || len (remoteBlobTxs ) > 0 {
1069
+ plainTxs := newTransactionsByPriceAndNonce (env .signer , remotePlainTxs , env .header .BaseFee )
1070
+ blobTxs := newTransactionsByPriceAndNonce (env .signer , remoteBlobTxs , env .header .BaseFee )
1071
+
1072
+ if err := w .commitTransactions (env , plainTxs , blobTxs , interrupt ); err != nil {
1037
1073
return err
1038
1074
}
1039
1075
}
0 commit comments