-
Notifications
You must be signed in to change notification settings - Fork 15
Solution to Failed TX Hooks #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d667476
96f483d
734d4ca
632b11e
288165d
087ca11
ccd776c
c38b83f
11ac9fc
80f0df4
1df5f56
5fff36d
df3b129
adb0bd3
0c83274
0419fcc
8b7f183
6ad9401
b29ac0c
2fe29f0
0297371
a4ac17b
4037f65
2221445
e210ef7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /* | ||
| Warnings: | ||
|
|
||
| - Added the required column `hooksStatus` to the `TransactionExecutionResult` table without a default value. This is not possible if the table is not empty. | ||
|
|
||
| */ | ||
| -- AlterTable | ||
| ALTER TABLE "TransactionExecutionResult" ADD COLUMN "hooksStatus" BOOLEAN NOT NULL; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,16 +110,22 @@ export class PrivateMempool | |
| return result?.result.afterNetworkState; | ||
| } | ||
|
|
||
| public async removeTxs(included: string[], dropped: string[]) { | ||
| await this.transactionStorage.removeTx(included, "included"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
| await this.transactionStorage.removeTx(dropped, "dropped"); | ||
| } | ||
|
|
||
| @trace("mempool.get_txs") | ||
| public async getTxs(limit?: number): Promise<PendingTransaction[]> { | ||
| // TODO Add limit to the storage (or do something smarter entirely) | ||
| const txs = await this.transactionStorage.getPendingUserTransactions(); | ||
|
|
||
| const baseCachedStateService = new CachedStateService(this.stateService); | ||
|
|
||
| const networkState = | ||
| (await this.getStagedNetworkState()) ?? NetworkState.empty(); | ||
|
|
||
| const validationEnabled = this.config.validationEnabled ?? true; | ||
| const validationEnabled = this.config.validationEnabled ?? false; | ||
| const sortedTxs = validationEnabled | ||
| ? await this.checkTxValid( | ||
| txs, | ||
|
|
@@ -128,7 +134,7 @@ export class PrivateMempool | |
| networkState, | ||
| limit | ||
| ) | ||
| : txs; | ||
| : txs.slice(0, limit); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely - that's covered in #330 |
||
|
|
||
| this.protocol.stateServiceProvider.popCurrentStateService(); | ||
| return sortedTxs; | ||
|
|
@@ -188,6 +194,7 @@ export class PrivateMempool | |
| executionContext.setup(contextInputs); | ||
|
|
||
| const signedTransaction = tx.toProtocolTransaction(); | ||
|
|
||
rpanic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // eslint-disable-next-line no-await-in-loop | ||
| await this.accountStateHook.beforeTransaction({ | ||
| networkState: networkState, | ||
|
|
@@ -218,6 +225,26 @@ export class PrivateMempool | |
| queue = queue.filter(distinctByPredicate((a, b) => a === b)); | ||
| } | ||
| } else { | ||
| // eslint-disable-next-line no-await-in-loop | ||
| const removeTxWhen = await this.accountStateHook.removeTransactionWhen({ | ||
| networkState: networkState, | ||
| transaction: signedTransaction.transaction, | ||
| signature: signedTransaction.signature, | ||
| prover: proverState, | ||
| }); | ||
| if (removeTxWhen) { | ||
| // eslint-disable-next-line no-await-in-loop | ||
| await this.transactionStorage.removeTx( | ||
| [tx.hash().toString()], | ||
| "dropped" | ||
| ); | ||
| log.trace( | ||
| `Deleting tx ${tx.hash().toString()} from mempool because removeTransactionWhen condition is satisfied` | ||
| ); | ||
| // eslint-disable-next-line no-continue | ||
| continue; | ||
| } | ||
|
|
||
| log.trace( | ||
| `Skipped tx ${tx.hash().toString()} because ${statusMessage}` | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!