diff --git a/packages/api/src/graphql/modules/MempoolResolver.ts b/packages/api/src/graphql/modules/MempoolResolver.ts index 04ab160ef..a1554c529 100644 --- a/packages/api/src/graphql/modules/MempoolResolver.ts +++ b/packages/api/src/graphql/modules/MempoolResolver.ts @@ -137,6 +137,7 @@ export class MempoolResolver extends GraphqlModule { return decoded.hash().toString(); } + // TODO Add retrieval of pending messages somewhere as well @Query(() => InclusionStatus, { description: "Returns the state of a given transaction", }) @@ -146,13 +147,6 @@ export class MempoolResolver extends GraphqlModule { }) hash: string ): Promise { - const txs = await this.mempool.getTxs(); - const tx = txs.find((x) => x.hash().toString() === hash); - - if (tx) { - return InclusionStatus.PENDING; - } - const dbTx = await this.transactionStorage.findTransaction(hash); if (dbTx !== undefined) { @@ -162,6 +156,7 @@ export class MempoolResolver extends GraphqlModule { if (dbTx.block !== undefined) { return InclusionStatus.INCLUDED; } + return InclusionStatus.PENDING; } return InclusionStatus.UNKNOWN; @@ -172,7 +167,7 @@ export class MempoolResolver extends GraphqlModule { "Returns the hashes of all transactions that are currently inside the mempool", }) public async transactions() { - const txs = await this.mempool.getTxs(); + const txs = await this.transactionStorage.getPendingUserTransactions(); return txs.map((x) => x.hash().toString()); } } diff --git a/packages/sequencer/src/storage/inmemory/InMemoryTransactionStorage.ts b/packages/sequencer/src/storage/inmemory/InMemoryTransactionStorage.ts index 01be9451b..c50b06b1b 100644 --- a/packages/sequencer/src/storage/inmemory/InMemoryTransactionStorage.ts +++ b/packages/sequencer/src/storage/inmemory/InMemoryTransactionStorage.ts @@ -78,6 +78,14 @@ export class InMemoryTransactionStorage implements TransactionStorage { } | undefined > { + const pending = await this.getPendingUserTransactions(); + const pendingResult = pending.find((tx) => tx.hash().toString() === hash); + if (pendingResult !== undefined) { + return { + transaction: pendingResult, + }; + } + const tipHeight = await this.blockStorage.getCurrentBlockHeight(); const hashField = Field(hash); diff --git a/packages/sequencer/src/storage/repositories/TransactionStorage.ts b/packages/sequencer/src/storage/repositories/TransactionStorage.ts index 858d82ad6..c739f68b4 100644 --- a/packages/sequencer/src/storage/repositories/TransactionStorage.ts +++ b/packages/sequencer/src/storage/repositories/TransactionStorage.ts @@ -5,6 +5,13 @@ export interface TransactionStorage { getPendingUserTransactions: () => Promise; + /** + * Finds a transaction by its hash. + * It returns both pending transaction and already included transactions + * In case the transaction has been included, it also returns the block hash + * and batch number where applicable. + * @param hash + */ findTransaction: (hash: string) => Promise< | { transaction: PendingTransaction;