Skip to content

Commit f16477c

Browse files
authored
Merge pull request #214 from proto-kit/fix/mempool-context-clear
Fixed execution context not cleared after getTxs invocation
2 parents 242490e + 44823c9 commit f16477c

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

packages/sequencer/src/mempool/private/PrivateMempool.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ export class PrivateMempool extends SequencerModule implements Mempool {
9595

9696
public async getTxs(limit?: number): Promise<PendingTransaction[]> {
9797
const txs = await this.transactionStorage.getPendingUserTransactions();
98-
const executionContext = container.resolve<RuntimeMethodExecutionContext>(
99-
RuntimeMethodExecutionContext
100-
);
98+
10199
const baseCachedStateService = new CachedStateService(this.stateService);
102100

103101
const networkState =
@@ -108,17 +106,12 @@ export class PrivateMempool extends SequencerModule implements Mempool {
108106
baseCachedStateService,
109107
this.protocol.stateServiceProvider,
110108
networkState,
111-
executionContext,
112109
limit
113110
);
114111
this.protocol.stateServiceProvider.popCurrentStateService();
115112
return sortedTxs;
116113
}
117114

118-
public async start(): Promise<void> {
119-
noop();
120-
}
121-
122115
// We iterate through the transactions. For each tx we run the account state hook.
123116
// If the txs succeeds then it can be returned. If it fails then we keep track of it
124117
// 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 {
129122
baseService: CachedStateService,
130123
stateServiceProvider: StateServiceProvider,
131124
networkState: NetworkState,
132-
executionContext: RuntimeMethodExecutionContext,
133125
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
136133
const sortedTransactions: PendingTransaction[] = [];
134+
const skippedTransactions: Record<string, MempoolTransactionPaths> = {};
135+
137136
let queue: PendingTransaction[] = [...transactions];
138137

139138
while (
140139
queue.length > 0 &&
141-
(limit !== undefined ? sortedTransactions.length < limit : true)
140+
sortedTransactions.length < (limit ?? Number.MAX_VALUE)
142141
) {
143142
const [tx] = queue.splice(0, 1);
144143
const txStateService = new CachedStateService(baseService);
@@ -147,7 +146,6 @@ export class PrivateMempool extends SequencerModule implements Mempool {
147146
networkState: networkState,
148147
transaction: tx.toProtocolTransaction().transaction,
149148
};
150-
executionContext.clear();
151149
executionContext.setup(contextInputs);
152150

153151
const signedTransaction = tx.toProtocolTransaction();
@@ -193,7 +191,13 @@ export class PrivateMempool extends SequencerModule implements Mempool {
193191
}
194192
stateServiceProvider.popCurrentStateService();
195193
}
194+
195+
executionContext.clear();
196196
}
197197
return sortedTransactions;
198198
}
199+
200+
public async start(): Promise<void> {
201+
noop();
202+
}
199203
}

0 commit comments

Comments
 (0)