Skip to content

Conversation

@ejMina226
Copy link
Contributor

@ejMina226 ejMina226 commented Mar 11, 2025

Closes #321

Currently, when a tx hook fails the tx is not removed from the mempool. In some cases this is what's needed. However, in others, like when a nonce is too small, this is a problem as the tx will persist in the memppool indefinitely, occupying resources. The solution is to incorporate a new check into the txHook abstract class, called removeTransactionWhen, which when satisfied causes the tx to be removed from the mempool.

@ejMina226 ejMina226 self-assigned this Mar 11, 2025
@ejMina226 ejMina226 linked an issue Mar 11, 2025 that may be closed by this pull request
@ejMina226 ejMina226 marked this pull request as draft March 11, 2025 11:43
@ejMina226 ejMina226 marked this pull request as ready for review March 11, 2025 12:33
@ejMina226 ejMina226 requested a review from rpanic March 11, 2025 16:36
Copy link
Member

@rpanic rpanic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above, and also let's get the CI working, then i'd say its gtg

@rpanic rpanic mentioned this pull request Apr 17, 2025
8 tasks
Copy link
Contributor

@kadirchan kadirchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed with my limited knowledge about codebase but looks good overall. Added couple things

}

public async removeTxs(included: string[], dropped: string[]) {
await this.transactionStorage.removeTx(included, "included");
Copy link
Contributor

@kadirchan kadirchan Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (type === "dropped") check in removeTx() method makes this call redundant, we can refactor removeTxs() if there is a need of dropping for included ones or remove that call.
Mentioned removeTx()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While what you're saying is true - its only the case for the PrismaTransactionStorage, not for the InMemoryTransactionStorage. This is because they are implemented differently, and for the inmemory version, we will need to remove them explicitely (while for prisma, the DB schema takes care of it via foreign key relationships)

limit
)
: txs;
: txs.slice(0, limit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better if we add limit parameter to getPendingUserTransactions method with db level limiting instead and slicing after getting all transactions. This could be a performance problem as txs grows

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely - that's covered in #330

Comment on lines 21 to 27

public async removeTx(hashes: string[]) {
this.queue = this.queue.filter((tx) => {
const hash = tx.hash().toString();
return !hashes.includes(hash);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can reduce lookup complexity in here

Suggested change
public async removeTx(hashes: string[]) {
this.queue = this.queue.filter((tx) => {
const hash = tx.hash().toString();
return !hashes.includes(hash);
});
}
public async removeTx(hashes: string[]) {
const hashSet = new Set(hashes)
this.queue = this.queue.filter((tx) => {
const hash = tx.hash().toString();
return !hashSet.has(hash);
});
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also would be better caching that set

}

// Under these conditions we want the tx removed from the mempool.
public async removeTransactionWhen({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a silly question, but in the current version I couldn't be sure whether the transaction gets removed from the mempool when there isn't enough gas fee. Also, an option could be added for after a certain timeout period.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it, thanks for spotting this!

@rpanic rpanic merged commit 324ba85 into develop Nov 14, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handling of failed tx hooks for incoming messages Figure out how to deal with transaction where the tx hooks fail

4 participants