@@ -18,6 +18,7 @@ import (
18
18
"github.com/ethereum/go-ethereum/params"
19
19
"github.com/ethereum/go-ethereum/rlp"
20
20
"github.com/holiman/uint256"
21
+ "golang.org/x/exp/maps"
21
22
)
22
23
23
24
// BuildTransactionsLists builds multiple transactions lists which satisfy all the given conditions
@@ -71,51 +72,35 @@ func (w *worker) BuildTransactionsLists(
71
72
localTxs , remoteTxs = w .getPendingTxs (localAccounts , baseFee )
72
73
)
73
74
74
- commitTxs := func (firstTransaction * types. Transaction ) (* types. Transaction , * PreBuiltTxList , error ) {
75
+ commitTxs := func () (* PreBuiltTxList , error ) {
75
76
env .tcount = 0
76
77
env .txs = []* types.Transaction {}
77
78
env .gasPool = new (core.GasPool ).AddGas (blockMaxGasLimit )
78
79
env .header .GasLimit = blockMaxGasLimit
79
80
80
- var (
81
- locals = make (map [common.Address ][]* txpool.LazyTransaction )
82
- remotes = make (map [common.Address ][]* txpool.LazyTransaction )
83
- )
84
-
85
- for address , txs := range localTxs {
86
- locals [address ] = txs
87
- }
88
- for address , txs := range remoteTxs {
89
- remotes [address ] = txs
90
- }
91
-
92
- lastTransaction := w .commitL2Transactions (
81
+ w .commitL2Transactions (
93
82
env ,
94
- firstTransaction ,
95
- newTransactionsByPriceAndNonce (signer , locals , baseFee ),
96
- newTransactionsByPriceAndNonce (signer , remotes , baseFee ),
83
+ newTransactionsByPriceAndNonce (signer , maps .Clone (localTxs ), baseFee ),
84
+ newTransactionsByPriceAndNonce (signer , maps .Clone (remoteTxs ), baseFee ),
97
85
maxBytesPerTxList ,
98
86
minTip ,
99
87
)
100
88
101
89
b , err := encodeAndCompressTxList (env .txs )
102
90
if err != nil {
103
- return nil , nil , err
91
+ return nil , err
104
92
}
105
93
106
- return lastTransaction , & PreBuiltTxList {
94
+ return & PreBuiltTxList {
107
95
TxList : env .txs ,
108
96
EstimatedGasUsed : env .header .GasLimit - env .gasPool .Gas (),
109
97
BytesLength : uint64 (len (b )),
110
98
}, nil
111
99
}
112
100
113
- var (
114
- lastTx * types.Transaction
115
- res * PreBuiltTxList
116
- )
117
101
for i := 0 ; i < int (maxTransactionsLists ); i ++ {
118
- if lastTx , res , err = commitTxs (lastTx ); err != nil {
102
+ res , err := commitTxs ()
103
+ if err != nil {
119
104
return nil , err
120
105
}
121
106
@@ -238,22 +223,16 @@ func (w *worker) getPendingTxs(localAccounts []string, baseFee *big.Int) (
238
223
// commitL2Transactions tries to commit the transactions into the given state.
239
224
func (w * worker ) commitL2Transactions (
240
225
env * environment ,
241
- firstTransaction * types.Transaction ,
242
226
txsLocal * transactionsByPriceAndNonce ,
243
227
txsRemote * transactionsByPriceAndNonce ,
244
228
maxBytesPerTxList uint64 ,
245
229
minTip uint64 ,
246
- ) * types. Transaction {
230
+ ) {
247
231
var (
248
- txs = txsLocal
249
- isLocal = true
250
- lastTransaction * types.Transaction
232
+ txs = txsLocal
233
+ isLocal = true
251
234
)
252
235
253
- if firstTransaction != nil {
254
- env .txs = append (env .txs , firstTransaction )
255
- }
256
-
257
236
loop:
258
237
for {
259
238
// If we don't have enough gas for any further transactions then we're done.
@@ -301,6 +280,8 @@ loop:
301
280
// Start executing the transaction
302
281
env .state .SetTxContext (tx .Hash (), env .tcount )
303
282
283
+ snap := env .state .RevisionId ()
284
+ gasPool := env .gasPool .Gas ()
304
285
_ , err := w .commitTransaction (env , tx )
305
286
switch {
306
287
case errors .Is (err , core .ErrNonceTooLow ):
@@ -321,8 +302,9 @@ loop:
321
302
continue
322
303
}
323
304
if len (b ) > int (maxBytesPerTxList ) {
324
- lastTransaction = env .txs [env .tcount - 1 ]
325
305
env .txs = env .txs [0 : env .tcount - 1 ]
306
+ env .state .RevertToSnapshot (snap )
307
+ env .gasPool .SetGas (gasPool )
326
308
break loop
327
309
}
328
310
default :
@@ -332,8 +314,6 @@ loop:
332
314
txs .Pop ()
333
315
}
334
316
}
335
-
336
- return lastTransaction
337
317
}
338
318
339
319
// encodeAndCompressTxList encodes and compresses the given transactions list.
0 commit comments