@@ -94,55 +94,49 @@ export class PrivateMempool extends SequencerModule implements Mempool {
94
94
95
95
public async getTxs ( ) : Promise < PendingTransaction [ ] > {
96
96
const txs = await this . transactionStorage . getPendingUserTransactions ( ) ;
97
- const sortedTxs : PendingTransaction [ ] = [ ] ;
98
- const skippedTxs : Record < string , MempoolTransactionPaths > = { } ;
99
- const executionContext = container . resolve < RuntimeMethodExecutionContext > (
100
- RuntimeMethodExecutionContext
101
- ) ;
97
+
102
98
const baseCachedStateService = new CachedStateService ( this . stateService ) ;
103
99
104
100
const networkState =
105
101
( await this . getStagedNetworkState ( ) ) ?? NetworkState . empty ( ) ;
106
102
107
- await this . checkTxValid (
103
+ const sortedTxs = await this . checkTxValid (
108
104
txs ,
109
- sortedTxs ,
110
- skippedTxs ,
111
105
baseCachedStateService ,
112
106
this . protocol . stateServiceProvider ,
113
- networkState ,
114
- executionContext
107
+ networkState
115
108
) ;
116
109
this . protocol . stateServiceProvider . popCurrentStateService ( ) ;
117
110
return sortedTxs ;
118
111
}
119
112
120
- public async start ( ) : Promise < void > {
121
- noop ( ) ;
122
- }
123
-
124
113
// We iterate through the transactions. For each tx we run the account state hook.
125
114
// If the txs succeeds then it can be returned. If it fails then we keep track of it
126
115
// in the skipped txs list and when later txs succeed we check to see if any state transition
127
116
// paths are shared between the just succeeded tx and any of the skipped txs. This is
128
117
// because a failed tx may succeed now if the failure was to do with a nonce issue, say.
129
118
private async checkTxValid (
130
119
transactions : PendingTransaction [ ] ,
131
- sortedTransactions : PendingTransaction [ ] ,
132
- skippedTransactions : Record < string , MempoolTransactionPaths > ,
133
120
baseService : CachedStateService ,
134
121
stateServiceProvider : StateServiceProvider ,
135
- networkState : NetworkState ,
136
- executionContext : RuntimeMethodExecutionContext
122
+ networkState : NetworkState
137
123
) {
124
+ const executionContext = container . resolve < RuntimeMethodExecutionContext > (
125
+ RuntimeMethodExecutionContext
126
+ ) ;
127
+ executionContext . clear ( ) ;
128
+
129
+ // Initialize starting state
130
+ const sortedTransactions : PendingTransaction [ ] = [ ] ;
131
+ const skippedTransactions : Record < string , MempoolTransactionPaths > = { } ;
132
+
138
133
for ( const [ index , tx ] of transactions . entries ( ) ) {
139
134
const txStateService = new CachedStateService ( baseService ) ;
140
135
stateServiceProvider . setCurrentStateService ( txStateService ) ;
141
136
const contextInputs : RuntimeMethodExecutionData = {
142
137
networkState : networkState ,
143
138
transaction : tx . toProtocolTransaction ( ) . transaction ,
144
139
} ;
145
- executionContext . clear ( ) ;
146
140
executionContext . setup ( contextInputs ) ;
147
141
148
142
const signedTransaction = tx . toProtocolTransaction ( ) ;
@@ -155,6 +149,7 @@ export class PrivateMempool extends SequencerModule implements Mempool {
155
149
delete transactions [ index ] ;
156
150
const { status, statusMessage, stateTransitions } =
157
151
executionContext . current ( ) . result ;
152
+
158
153
if ( status . toBoolean ( ) ) {
159
154
log . info ( `Accepted tx ${ tx . hash ( ) . toString ( ) } ` ) ;
160
155
sortedTransactions . push ( tx ) ;
@@ -191,6 +186,13 @@ export class PrivateMempool extends SequencerModule implements Mempool {
191
186
} ;
192
187
}
193
188
}
189
+
190
+ executionContext . clear ( ) ;
194
191
}
192
+ return sortedTransactions ;
193
+ }
194
+
195
+ public async start ( ) : Promise < void > {
196
+ noop ( ) ;
195
197
}
196
198
}
0 commit comments