-
Notifications
You must be signed in to change notification settings - Fork 15
Added retry logic to minaTransactionSender #360
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
Open
Raunaque97
wants to merge
19
commits into
develop
Choose a base branch
from
raun/retryMinaTransactions
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
af11f38
added PendingL1TransactionStorage for persisting mina transactions in…
Raunaque97 183520d
implementing PendingL1TransactionStorage
Raunaque97 f3be038
implementing L1TransactionRetryStrategy
Raunaque97 f67aaee
added MinaSigner interface
Raunaque97 a1cd533
updated MinaTransactionSender to use L1TransactionRetryStrategy and P…
Raunaque97 40abbfd
fixing tests
Raunaque97 cdb5e7c
refactoring, removed feeStrategy dependencies from bridgingModule, se…
Raunaque97 c856dfb
using SettlementSigner, and removing LocalMinaSigner
Raunaque97 226be1f
storing transaction obj in PendingL1TransactionRecord instead of json…
Raunaque97 2b18a0d
making MinaTransactionSender closeable
Raunaque97 2fe0464
Refactor PendingL1Transaction and Settlement models to use transactio…
Raunaque97 5a02ce0
added a queued wait status in MinaTransactionSender
Raunaque97 843d91b
adding foreign key relation between Settlement and PendingL1Transaction
Raunaque97 e4ec80b
fixing lint errors
Raunaque97 aa5c082
created the migration file
Raunaque97 d06f252
refactoring, renaming mappers
Raunaque97 c2a69b4
lint fix
Raunaque97 a213a7f
Add hash field to PendingL1Transaction model and added txn status pol…
Raunaque97 84bc772
added minaTransactionSender tests
Raunaque97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| import console from "console"; | ||
| import "reflect-metadata"; | ||
|
|
||
| global.console = console; | ||
| globalThis.console = console; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/persistance/prisma/migrations/20251222105633_pending_l1_transactions/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| Warnings: | ||
|
|
||
| - You are about to drop the column `settlementTransactionHash` on the `Batch` table. All the data in the column will be lost. | ||
| - The primary key for the `Settlement` table will be changed. If it partially fails, the table could be left without primary key constraint. | ||
| - You are about to drop the column `transactionHash` on the `Settlement` table. All the data in the column will be lost. | ||
| - Added the required column `transactionId` to the `Settlement` table without a default value. This is not possible if the table is not empty. | ||
|
|
||
| */ | ||
| -- DropForeignKey | ||
| ALTER TABLE "Batch" DROP CONSTRAINT "Batch_settlementTransactionHash_fkey"; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "Batch" DROP COLUMN "settlementTransactionHash", | ||
| ADD COLUMN "settlementTransactionId" TEXT; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "Settlement" DROP CONSTRAINT "Settlement_pkey", | ||
| DROP COLUMN "transactionHash", | ||
| ADD COLUMN "transactionId" TEXT NOT NULL, | ||
| ADD CONSTRAINT "Settlement_pkey" PRIMARY KEY ("transactionId"); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "PendingL1Transaction" ( | ||
| "id" TEXT NOT NULL, | ||
| "sender" TEXT NOT NULL, | ||
| "nonce" INTEGER NOT NULL, | ||
| "attempts" INTEGER NOT NULL, | ||
| "status" VARCHAR(32) NOT NULL, | ||
| "transaction" JSON NOT NULL, | ||
| "lastError" TEXT, | ||
| "sentAt" TIMESTAMP(3), | ||
|
|
||
| CONSTRAINT "PendingL1Transaction_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "PendingL1Transaction_sender_nonce_key" ON "PendingL1Transaction"("sender", "nonce"); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "Batch" ADD CONSTRAINT "Batch_settlementTransactionId_fkey" FOREIGN KEY ("settlementTransactionId") REFERENCES "Settlement"("transactionId") ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "Settlement" ADD CONSTRAINT "Settlement_transactionId_fkey" FOREIGN KEY ("transactionId") REFERENCES "PendingL1Transaction"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/persistance/src/services/prisma/PrismaPendingL1TransactionStorage.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { inject, injectable } from "tsyringe"; | ||
| import { | ||
| PendingL1TransactionRecord, | ||
| PendingL1TransactionStatus, | ||
| PendingL1TransactionStorage, | ||
| } from "@proto-kit/sequencer"; | ||
|
|
||
| import type { PrismaConnection } from "../../PrismaDatabaseConnection"; | ||
|
|
||
| import { PendingL1TransactionMapper } from "./mappers/PendingL1TransactionMapper"; | ||
|
|
||
| @injectable() | ||
| export class PrismaPendingL1TransactionStorage | ||
| implements PendingL1TransactionStorage | ||
| { | ||
| private readonly mapper = new PendingL1TransactionMapper(); | ||
|
|
||
| public constructor( | ||
| @inject("Database") private readonly connection: PrismaConnection | ||
| ) {} | ||
|
|
||
| public async queue( | ||
| record: Omit<PendingL1TransactionRecord, "status"> | ||
| ): Promise<string> { | ||
| const { prismaClient } = this.connection; | ||
| const status: PendingL1TransactionStatus = "queued"; | ||
| const txnRecord = await prismaClient.pendingL1Transaction.create({ | ||
| data: this.mapper.mapOut({ ...record, status }), | ||
| }); | ||
| return txnRecord.id; | ||
| } | ||
|
|
||
| public async update( | ||
| id: string, | ||
| updates: Partial<Omit<PendingL1TransactionRecord, "id">> | ||
| ): Promise<void> { | ||
| const { prismaClient } = this.connection; | ||
| await prismaClient.pendingL1Transaction.update({ | ||
| where: { id }, | ||
| data: { | ||
| ...(updates.attempts !== undefined && { attempts: updates.attempts }), | ||
Raunaque97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ...(updates.status !== undefined && { status: updates.status }), | ||
| ...(updates.transaction !== undefined && { | ||
| transaction: updates.transaction.toJSON(), | ||
| }), | ||
| ...(updates.hash !== undefined && { hash: updates.hash }), | ||
| ...(updates.lastError !== undefined && { | ||
| lastError: updates.lastError, | ||
| }), | ||
| ...(updates.sentAt !== undefined && { sentAt: updates.sentAt }), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| public async delete(id: string): Promise<void> { | ||
| const { prismaClient } = this.connection; | ||
| await prismaClient.pendingL1Transaction.delete({ | ||
| where: { | ||
| id, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| public async findById( | ||
| id: string | ||
| ): Promise<PendingL1TransactionRecord | undefined> { | ||
| const { prismaClient } = this.connection; | ||
| const record = await prismaClient.pendingL1Transaction.findUnique({ | ||
| where: { | ||
| id, | ||
| }, | ||
| }); | ||
| if (!record) { | ||
| return undefined; | ||
| } | ||
| return this.mapper.mapIn(record); | ||
| } | ||
|
|
||
| public async findByStatuses( | ||
| statuses: PendingL1TransactionStatus[] | ||
| ): Promise<PendingL1TransactionRecord[]> { | ||
| const { prismaClient } = this.connection; | ||
| const rows = await prismaClient.pendingL1Transaction.findMany({ | ||
| where: { | ||
| status: { | ||
| in: statuses, | ||
| }, | ||
| }, | ||
| }); | ||
| return rows.map((record) => this.mapper.mapIn(record)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/persistance/src/services/prisma/mappers/PendingL1TransactionMapper.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { PendingL1Transaction, Prisma } from "@prisma/client"; | ||
| import { | ||
| PendingL1TransactionRecord, | ||
| PendingL1TransactionStatus, | ||
| } from "@proto-kit/sequencer"; | ||
| import { Mina } from "o1js"; | ||
|
|
||
| export class PendingL1TransactionMapper { | ||
| public mapIn(input: PendingL1Transaction): PendingL1TransactionRecord { | ||
| return { | ||
| id: input.id, | ||
| sender: input.sender, | ||
| nonce: input.nonce, | ||
| attempts: input.attempts, | ||
| status: input.status as PendingL1TransactionStatus, | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
| transaction: Mina.Transaction.fromJSON(input.transaction as any), | ||
| hash: input.hash ?? undefined, | ||
| lastError: input.lastError ?? undefined, | ||
| sentAt: input.sentAt ? new Date(input.sentAt) : undefined, | ||
| }; | ||
| } | ||
|
|
||
| public mapOut( | ||
| input: PendingL1TransactionRecord | ||
| ): Prisma.PendingL1TransactionCreateInput { | ||
| return { | ||
| id: input.id, | ||
| sender: input.sender, | ||
| nonce: input.nonce, | ||
| attempts: input.attempts, | ||
| status: input.status, | ||
| transaction: input.transaction.toJSON(), | ||
| hash: input.hash ?? null, | ||
| lastError: input.lastError ?? null, | ||
| sentAt: input.sentAt ? input.sentAt.toJSON() : null, | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You forgot to create a migration for this new schema change - do this by cd-ing into the persistence pkg, then run
prisma migrate devand it'll you for a name and migrate