Skip to content

Commit 696fb2e

Browse files
committed
Code review changes.
1 parent 62733b2 commit 696fb2e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

packages/sequencer/src/mempool/Mempool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ export interface Mempool<Events extends MempoolEvents = MempoolEvents>
1717
/**
1818
* Retrieve all transactions that are currently in the mempool
1919
*/
20-
getTxs: () => Promise<PendingTransaction[]>;
20+
getTxs: (limit?: number) => Promise<PendingTransaction[]>;
2121
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class PrivateMempool extends SequencerModule implements Mempool {
9393
return result?.result.afterNetworkState;
9494
}
9595

96-
public async getTxs(): Promise<PendingTransaction[]> {
96+
public async getTxs(limit?: number): Promise<PendingTransaction[]> {
9797
const txs = await this.transactionStorage.getPendingUserTransactions();
9898
const executionContext = container.resolve<RuntimeMethodExecutionContext>(
9999
RuntimeMethodExecutionContext
@@ -108,7 +108,8 @@ export class PrivateMempool extends SequencerModule implements Mempool {
108108
baseCachedStateService,
109109
this.protocol.stateServiceProvider,
110110
networkState,
111-
executionContext
111+
executionContext,
112+
limit
112113
);
113114
this.protocol.stateServiceProvider.popCurrentStateService();
114115
return sortedTxs;
@@ -128,13 +129,17 @@ export class PrivateMempool extends SequencerModule implements Mempool {
128129
baseService: CachedStateService,
129130
stateServiceProvider: StateServiceProvider,
130131
networkState: NetworkState,
131-
executionContext: RuntimeMethodExecutionContext
132+
executionContext: RuntimeMethodExecutionContext,
133+
limit?: number
132134
): Promise<PendingTransaction[]> {
133135
const skippedTransactions: Record<string, MempoolTransactionPaths> = {};
134136
const sortedTransactions: PendingTransaction[] = [];
135137
let queue: PendingTransaction[] = [...transactions];
136138

137-
while (queue.length > 0) {
139+
while (
140+
queue.length > 0 &&
141+
(limit !== undefined ? sortedTransactions.length < limit : true)
142+
) {
138143
const [tx] = queue.splice(0, 1);
139144
const txStateService = new CachedStateService(baseService);
140145
stateServiceProvider.setCurrentStateService(txStateService);

0 commit comments

Comments
 (0)