-
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
22
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
22 commits
Select commit
Hold shift + click to select a range
fe09020
added PendingL1TransactionStorage for persisting mina transactions in…
Raunaque97 8f8f768
implementing PendingL1TransactionStorage
Raunaque97 b129ea7
implementing L1TransactionRetryStrategy
Raunaque97 1dd9d5e
added MinaSigner interface
Raunaque97 def1b44
updated MinaTransactionSender to use L1TransactionRetryStrategy and P…
Raunaque97 3e90a3a
fixing tests
Raunaque97 dd86edc
refactoring, removed feeStrategy dependencies from bridgingModule, se…
Raunaque97 e5d8922
using SettlementSigner, and removing LocalMinaSigner
Raunaque97 1f2f51a
storing transaction obj in PendingL1TransactionRecord instead of json…
Raunaque97 2068f62
making MinaTransactionSender closeable
Raunaque97 235e41e
Refactor PendingL1Transaction and Settlement models to use transactio…
Raunaque97 919fdf9
added a queued wait status in MinaTransactionSender
Raunaque97 2617552
adding foreign key relation between Settlement and PendingL1Transaction
Raunaque97 14f8827
fixing lint errors
Raunaque97 dfe29e7
created the migration file
Raunaque97 0bac257
refactoring, renaming mappers
Raunaque97 197fbeb
lint fix
Raunaque97 b81ca92
Add hash field to PendingL1Transaction model and added txn status pol…
Raunaque97 debc765
added minaTransactionSender tests
Raunaque97 9c6b506
updating PendingL1Transaction schema to include nextActionAt and queu…
Raunaque97 f3f2085
refactoring MinaTransactionSender.
Raunaque97 0ceb431
fixing build errors after rebase
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
96 changes: 96 additions & 0 deletions
96
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,96 @@ | ||
| 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" | "id"> | ||
| ): 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 }), | ||
| ...(updates.queuedAt !== undefined && { queuedAt: updates.queuedAt }), | ||
| ...(updates.nextActionAt !== undefined && { | ||
| nextActionAt: updates.nextActionAt, | ||
| }), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| 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
43 changes: 43 additions & 0 deletions
43
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,43 @@ | ||
| 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 ?? undefined, | ||
| queuedAt: input.queuedAt ?? undefined, | ||
| nextActionAt: input.nextActionAt ?? undefined, | ||
| }; | ||
| } | ||
|
|
||
| public mapOut( | ||
| input: Omit<PendingL1TransactionRecord, "id"> & { id?: string } | ||
| ): Prisma.PendingL1TransactionCreateInput { | ||
| return { | ||
| id: input.id ?? undefined, | ||
| 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 ?? null, | ||
| queuedAt: input.queuedAt ?? null, | ||
| nextActionAt: input.nextActionAt ?? 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
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