Skip to content
Open
Show file tree
Hide file tree
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 Nov 24, 2025
183520d
implementing PendingL1TransactionStorage
Raunaque97 Nov 24, 2025
f3be038
implementing L1TransactionRetryStrategy
Raunaque97 Nov 24, 2025
f67aaee
added MinaSigner interface
Raunaque97 Nov 24, 2025
a1cd533
updated MinaTransactionSender to use L1TransactionRetryStrategy and P…
Raunaque97 Nov 24, 2025
40abbfd
fixing tests
Raunaque97 Nov 24, 2025
cdb5e7c
refactoring, removed feeStrategy dependencies from bridgingModule, se…
Raunaque97 Nov 25, 2025
c856dfb
using SettlementSigner, and removing LocalMinaSigner
Raunaque97 Dec 16, 2025
226be1f
storing transaction obj in PendingL1TransactionRecord instead of json…
Raunaque97 Dec 16, 2025
2b18a0d
making MinaTransactionSender closeable
Raunaque97 Dec 18, 2025
2fe0464
Refactor PendingL1Transaction and Settlement models to use transactio…
Raunaque97 Dec 18, 2025
5a02ce0
added a queued wait status in MinaTransactionSender
Raunaque97 Dec 19, 2025
843d91b
adding foreign key relation between Settlement and PendingL1Transaction
Raunaque97 Dec 19, 2025
e4ec80b
fixing lint errors
Raunaque97 Dec 19, 2025
aa5c082
created the migration file
Raunaque97 Dec 22, 2025
d06f252
refactoring, renaming mappers
Raunaque97 Dec 22, 2025
c2a69b4
lint fix
Raunaque97 Dec 22, 2025
a213a7f
Add hash field to PendingL1Transaction model and added txn status pol…
Raunaque97 Jan 6, 2026
84bc772
added minaTransactionSender tests
Raunaque97 Jan 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions console-jest.config.js
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;
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"ts-jest": "^29.0.5",
"typedoc": "^0.26.11",
"typedoc-plugin-frontmatter": "1.0.0",
"typedoc-plugin-inline-sources": "1.2.0",
"typedoc-plugin-inline-sources": "^1.2.0",
"typedoc-plugin-markdown": "4.2.10",
"typescript": "5.1",
"istanbul-merge": "^2.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class GeneratedResolverFactoryGraphqlModule extends ResolverFactoryGraphq
public async initializePrismaClient() {
// setup the prisma client and feed it to the server,
// since this is necessary for the returned resolvers to work

const prismaClient = new PrismaClient({
// datasourceUrl: 'postgresql://admin:password@localhost:5433/protokit-indexer?schema=public'
});
Expand Down
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;
26 changes: 21 additions & 5 deletions packages/persistance/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ model Batch {

blocks Block[]

settlementTransactionHash String?
settlement Settlement? @relation(fields: [settlementTransactionHash], references: [transactionHash])
settlementTransactionId String?
settlement Settlement? @relation(fields: [settlementTransactionId], references: [transactionId])
}

model BlockResult {
Expand All @@ -123,11 +123,11 @@ model BlockResult {
}

model Settlement {
// transaction String
transactionHash String @id
transactionId String @id
promisedMessagesHash String

batches Batch[]
batches Batch[]
pendingL1Transaction PendingL1Transaction? @relation(fields: [transactionId], references: [id])
}

model IncomingMessageBatchTransaction {
Expand All @@ -148,3 +148,19 @@ model IncomingMessageBatch {

messages IncomingMessageBatchTransaction[]
}

model PendingL1Transaction {
Copy link
Member

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 dev and it'll you for a name and migrate

id String @id @default(cuid())
sender String
nonce Int
attempts Int
status String @db.VarChar(32)
transaction Json @db.Json
hash String?
lastError String?
sentAt DateTime?

settlement Settlement?

@@unique([sender, nonce])
}
5 changes: 5 additions & 0 deletions packages/persistance/src/PrismaDatabaseConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { PrismaBlockStorage } from "./services/prisma/PrismaBlockStorage";
import { PrismaSettlementStorage } from "./services/prisma/PrismaSettlementStorage";
import { PrismaMessageStorage } from "./services/prisma/PrismaMessageStorage";
import { PrismaTransactionStorage } from "./services/prisma/PrismaTransactionStorage";
import { PrismaPendingL1TransactionStorage } from "./services/prisma/PrismaPendingL1TransactionStorage";

export interface PrismaDatabaseConfig {
// Either object-based config or connection string
Expand Down Expand Up @@ -82,6 +83,9 @@ export class PrismaDatabaseConnection
transactionStorage: {
useClass: PrismaTransactionStorage,
},
pendingL1TransactionStorage: {
useClass: PrismaPendingL1TransactionStorage,
},
};
}

Expand All @@ -97,6 +101,7 @@ export class PrismaDatabaseConnection
"IncomingMessageBatch",
"IncomingMessageBatchTransaction",
"LinkedLeaf",
"PendingL1Transaction",
];

await this.prismaClient.$transaction(
Expand Down
1 change: 1 addition & 0 deletions packages/persistance/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from "./services/prisma/PrismaBatchStore";
export * from "./services/prisma/PrismaSettlementStorage";
export * from "./services/prisma/PrismaMessageStorage";
export * from "./services/prisma/PrismaTransactionStorage";
export * from "./services/prisma/PrismaPendingL1TransactionStorage";
export * from "./services/prisma/mappers/BatchMapper";
export * from "./services/prisma/mappers/BlockMapper";
export * from "./services/prisma/mappers/FieldMapper";
Expand Down
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 }),
...(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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class PrismaSettlementStorage implements SettlementStorage {

const batch = await prismaClient.batch.findFirst({
where: {
settlementTransactionHash: {
settlementTransactionId: {
not: null,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class BatchMapper
const batch: PrismaBatch = {
proof: input.proof,
height: input.height,
settlementTransactionHash: null,
settlementTransactionId: null,
};
return [batch, []];
}
Expand Down
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,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class SettlementMapper
const [settlement, batches] = input;
return {
batches,
transactionHash: settlement.transactionHash,
transactionId: settlement.transactionId,
promisedMessagesHash: settlement.promisedMessagesHash,
};
}
Expand All @@ -21,7 +21,7 @@ export class SettlementMapper
return [
{
promisedMessagesHash: input.promisedMessagesHash,
transactionHash: input.transactionHash,
transactionId: input.transactionId,
},
input.batches,
];
Expand Down
5 changes: 4 additions & 1 deletion packages/sequencer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export * from "./sequencer/builder/Closeable";
export * from "./worker/flow/Flow";
export * from "./worker/flow/Task";
export * from "./worker/flow/JSONTaskSerializer";
// export * from "./worker/queue/BullQueue";
export * from "./worker/queue/TaskQueue";
export * from "./worker/queue/LocalTaskQueue";
export * from "./worker/queue/ListenerList";
Expand Down Expand Up @@ -71,13 +70,15 @@ export * from "./storage/repositories/BlockStorage";
export * from "./storage/repositories/SettlementStorage";
export * from "./storage/repositories/MessageStorage";
export * from "./storage/repositories/TransactionStorage";
export * from "./storage/repositories/PendingL1TransactionStorage";
export * from "./storage/inmemory/InMemoryDatabase";
export * from "./storage/inmemory/InMemoryAsyncMerkleTreeStore";
export * from "./storage/inmemory/InMemoryBlockStorage";
export * from "./storage/inmemory/InMemoryBatchStorage";
export * from "./storage/inmemory/InMemorySettlementStorage";
export * from "./storage/inmemory/InMemoryMessageStorage";
export * from "./storage/inmemory/InMemoryTransactionStorage";
export * from "./storage/inmemory/InMemoryPendingL1TransactionStorage";
export * from "./storage/StorageDependencyFactory";
export * from "./storage/Database";
export * from "./storage/DatabasePruneModule";
Expand Down Expand Up @@ -107,6 +108,8 @@ export * from "./settlement/permissions/BaseLayerContractPermissions";
export * from "./settlement/permissions/ProvenSettlementPermissions";
export * from "./settlement/permissions/SignedSettlementPermissions";
export * from "./settlement/tasks/SettlementProvingTask";
export * from "./settlement/transactions/L1TransactionRetryStrategy";
export * from "./settlement/transactions/DefaultL1TransactionRetryStrategy";
export * from "./settlement/transactions/MinaTransactionSender";
export * from "./settlement/transactions/MinaTransactionSimulator";
export * from "./settlement/transactions/MinaSimulationService";
Expand Down
5 changes: 0 additions & 5 deletions packages/sequencer/src/settlement/BridgingModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { FungibleToken } from "mina-fungible-token";
// eslint-disable-next-line import/no-extraneous-dependencies
import groupBy from "lodash/groupBy";

import { FeeStrategy } from "../protocol/baselayer/fees/FeeStrategy";
import type { MinaBaseLayer } from "../protocol/baselayer/MinaBaseLayer";
import { AsyncLinkedLeafStore } from "../state/async/AsyncLinkedLeafStore";
import { CachedLinkedLeafStore } from "../state/lmt/CachedLinkedLeafStore";
Expand Down Expand Up @@ -94,8 +93,6 @@ export class BridgingModule {
private readonly outgoingMessageCollector: OutgoingMessageCollector,
@inject("AsyncLinkedLeafStore")
private readonly linkedLeafStore: AsyncLinkedLeafStore,
@inject("FeeStrategy")
private readonly feeStrategy: FeeStrategy,
@inject("BaseLayer") private readonly baseLayer: MinaBaseLayer,
@inject("SettlementSigner") private readonly signer: MinaSigner,
@inject("TransactionSender")
Expand Down Expand Up @@ -386,7 +383,6 @@ export class BridgingModule {
sender: feepayer,
// eslint-disable-next-line no-plusplus
nonce: nonce++,
fee: this.feeStrategy.getFee(),
memo: "pull state root",
},
async () => {
Expand Down Expand Up @@ -504,7 +500,6 @@ export class BridgingModule {
sender: feepayer,
// eslint-disable-next-line no-plusplus
nonce: nonce++,
fee: this.feeStrategy.getFee(),
memo: "roll up actions",
},
async () => {
Expand Down
Loading
Loading