Skip to content

Commit 0046b32

Browse files
committed
Fixed execution context not cleared after getTxs invocation
1 parent d13a304 commit 0046b32

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,55 +94,49 @@ export class PrivateMempool extends SequencerModule implements Mempool {
9494

9595
public async getTxs(): Promise<PendingTransaction[]> {
9696
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+
10298
const baseCachedStateService = new CachedStateService(this.stateService);
10399

104100
const networkState =
105101
(await this.getStagedNetworkState()) ?? NetworkState.empty();
106102

107-
await this.checkTxValid(
103+
const sortedTxs = await this.checkTxValid(
108104
txs,
109-
sortedTxs,
110-
skippedTxs,
111105
baseCachedStateService,
112106
this.protocol.stateServiceProvider,
113-
networkState,
114-
executionContext
107+
networkState
115108
);
116109
this.protocol.stateServiceProvider.popCurrentStateService();
117110
return sortedTxs;
118111
}
119112

120-
public async start(): Promise<void> {
121-
noop();
122-
}
123-
124113
// We iterate through the transactions. For each tx we run the account state hook.
125114
// If the txs succeeds then it can be returned. If it fails then we keep track of it
126115
// in the skipped txs list and when later txs succeed we check to see if any state transition
127116
// paths are shared between the just succeeded tx and any of the skipped txs. This is
128117
// because a failed tx may succeed now if the failure was to do with a nonce issue, say.
129118
private async checkTxValid(
130119
transactions: PendingTransaction[],
131-
sortedTransactions: PendingTransaction[],
132-
skippedTransactions: Record<string, MempoolTransactionPaths>,
133120
baseService: CachedStateService,
134121
stateServiceProvider: StateServiceProvider,
135-
networkState: NetworkState,
136-
executionContext: RuntimeMethodExecutionContext
122+
networkState: NetworkState
137123
) {
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+
138133
for (const [index, tx] of transactions.entries()) {
139134
const txStateService = new CachedStateService(baseService);
140135
stateServiceProvider.setCurrentStateService(txStateService);
141136
const contextInputs: RuntimeMethodExecutionData = {
142137
networkState: networkState,
143138
transaction: tx.toProtocolTransaction().transaction,
144139
};
145-
executionContext.clear();
146140
executionContext.setup(contextInputs);
147141

148142
const signedTransaction = tx.toProtocolTransaction();
@@ -155,6 +149,7 @@ export class PrivateMempool extends SequencerModule implements Mempool {
155149
delete transactions[index];
156150
const { status, statusMessage, stateTransitions } =
157151
executionContext.current().result;
152+
158153
if (status.toBoolean()) {
159154
log.info(`Accepted tx ${tx.hash().toString()}`);
160155
sortedTransactions.push(tx);
@@ -191,6 +186,13 @@ export class PrivateMempool extends SequencerModule implements Mempool {
191186
};
192187
}
193188
}
189+
190+
executionContext.clear();
194191
}
192+
return sortedTransactions;
193+
}
194+
195+
public async start(): Promise<void> {
196+
noop();
195197
}
196198
}

0 commit comments

Comments
 (0)