Skip to content

Commit

Permalink
fix(core-transaction-pool): prioritized removeForgedTransaction (#4389)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainydio committed May 17, 2021
1 parent 56111ed commit ee8c5e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions __tests__/unit/core-transaction-pool/sender-mempool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe("SenderMempool.removeForgedTransaction", () => {
expect(remainingTransactions).toStrictEqual([transaction3]);
});

it("should return all added transactions when accepting unknown transaction", async () => {
it("should return no transactions when accepting unknown transaction", async () => {
configuration.getRequired.mockReturnValueOnce(10); // maxTransactionsPerSender

const senderMempool = container.resolve(SenderMempool);
Expand All @@ -217,7 +217,7 @@ describe("SenderMempool.removeForgedTransaction", () => {
const removedTransactions = await senderMempool.removeForgedTransaction(transaction3.id);
const remainingTransactions = senderMempool.getFromEarliest();

expect(removedTransactions).toStrictEqual([transaction1, transaction2]);
expect(remainingTransactions).toStrictEqual([]);
expect(removedTransactions).toStrictEqual([]);
expect(remainingTransactions).toStrictEqual([transaction1, transaction2]);
});
});
15 changes: 7 additions & 8 deletions packages/core-transaction-pool/src/sender-mempool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,13 @@ export class SenderMempool implements Contracts.TransactionPool.SenderMempool {
try {
this.concurrency++;

return await this.lock.runExclusive(async () => {
const index: number = this.transactions.findIndex((t) => t.id === id);
if (index === -1) {
return this.transactions.splice(0, this.transactions.length);
} else {
return this.transactions.splice(0, index + 1);
}
});
const index: number = this.transactions.findIndex((t) => t.id === id);

if (index !== -1) {
return this.transactions.splice(0, index + 1);
} else {
return []; // TODO: implement this.reboot();
}
} finally {
this.concurrency--;
}
Expand Down

0 comments on commit ee8c5e3

Please sign in to comment.