@@ -95,9 +95,7 @@ export class PrivateMempool extends SequencerModule implements Mempool {
95
95
96
96
public async getTxs ( limit ?: number ) : Promise < PendingTransaction [ ] > {
97
97
const txs = await this . transactionStorage . getPendingUserTransactions ( ) ;
98
- const executionContext = container . resolve < RuntimeMethodExecutionContext > (
99
- RuntimeMethodExecutionContext
100
- ) ;
98
+
101
99
const baseCachedStateService = new CachedStateService ( this . stateService ) ;
102
100
103
101
const networkState =
@@ -108,17 +106,12 @@ export class PrivateMempool extends SequencerModule implements Mempool {
108
106
baseCachedStateService ,
109
107
this . protocol . stateServiceProvider ,
110
108
networkState ,
111
- executionContext ,
112
109
limit
113
110
) ;
114
111
this . protocol . stateServiceProvider . popCurrentStateService ( ) ;
115
112
return sortedTxs ;
116
113
}
117
114
118
- public async start ( ) : Promise < void > {
119
- noop ( ) ;
120
- }
121
-
122
115
// We iterate through the transactions. For each tx we run the account state hook.
123
116
// If the txs succeeds then it can be returned. If it fails then we keep track of it
124
117
// in the skipped txs list and when later txs succeed we check to see if any state transition
@@ -129,16 +122,22 @@ export class PrivateMempool extends SequencerModule implements Mempool {
129
122
baseService : CachedStateService ,
130
123
stateServiceProvider : StateServiceProvider ,
131
124
networkState : NetworkState ,
132
- executionContext : RuntimeMethodExecutionContext ,
133
125
limit ?: number
134
- ) : Promise < PendingTransaction [ ] > {
135
- const skippedTransactions : Record < string , MempoolTransactionPaths > = { } ;
126
+ ) {
127
+ const executionContext = container . resolve < RuntimeMethodExecutionContext > (
128
+ RuntimeMethodExecutionContext
129
+ ) ;
130
+ executionContext . clear ( ) ;
131
+
132
+ // Initialize starting state
136
133
const sortedTransactions : PendingTransaction [ ] = [ ] ;
134
+ const skippedTransactions : Record < string , MempoolTransactionPaths > = { } ;
135
+
137
136
let queue : PendingTransaction [ ] = [ ...transactions ] ;
138
137
139
138
while (
140
139
queue . length > 0 &&
141
- ( limit !== undefined ? sortedTransactions . length < limit : true )
140
+ sortedTransactions . length < ( limit ?? Number . MAX_VALUE )
142
141
) {
143
142
const [ tx ] = queue . splice ( 0 , 1 ) ;
144
143
const txStateService = new CachedStateService ( baseService ) ;
@@ -147,7 +146,6 @@ export class PrivateMempool extends SequencerModule implements Mempool {
147
146
networkState : networkState ,
148
147
transaction : tx . toProtocolTransaction ( ) . transaction ,
149
148
} ;
150
- executionContext . clear ( ) ;
151
149
executionContext . setup ( contextInputs ) ;
152
150
153
151
const signedTransaction = tx . toProtocolTransaction ( ) ;
@@ -193,7 +191,13 @@ export class PrivateMempool extends SequencerModule implements Mempool {
193
191
}
194
192
stateServiceProvider . popCurrentStateService ( ) ;
195
193
}
194
+
195
+ executionContext . clear ( ) ;
196
196
}
197
197
return sortedTransactions ;
198
198
}
199
+
200
+ public async start ( ) : Promise < void > {
201
+ noop ( ) ;
202
+ }
199
203
}
0 commit comments