Skip to content

Commit cfe7a24

Browse files
authored
Merge pull request #35 from Poly-pay/parallel-tx
feat: support parallel transactions instead of sequential
2 parents 409daa6 + 4469e5f commit cfe7a24

File tree

21 files changed

+455
-390
lines changed

21 files changed

+455
-390
lines changed

packages/backend/assets/vkey.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"vkHash":"0x104717314e0c94ef15d6992292b713aa2ffc48c74e0c41f7344a611caa606dde"}
1+
{"vkHash":"0x80aca2e84f244400a76040aa5c77f9d83ff8409a2bf0d0cde96daffcf0a50e1b"}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[walletAddress,nonce]` on the table `Transaction` will be added. If there are existing duplicate values, this will fail.
5+
6+
*/
7+
-- CreateTable
8+
CREATE TABLE "ReservedNonce" (
9+
"id" TEXT NOT NULL,
10+
"walletAddress" TEXT NOT NULL,
11+
"nonce" INTEGER NOT NULL,
12+
"expiresAt" TIMESTAMP(3) NOT NULL,
13+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
14+
15+
CONSTRAINT "ReservedNonce_pkey" PRIMARY KEY ("id")
16+
);
17+
18+
-- CreateIndex
19+
CREATE UNIQUE INDEX "ReservedNonce_walletAddress_nonce_key" ON "ReservedNonce"("walletAddress", "nonce");
20+
21+
-- CreateIndex
22+
CREATE UNIQUE INDEX "Transaction_walletAddress_nonce_key" ON "Transaction"("walletAddress", "nonce");

packages/backend/prisma/schema.prisma

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ model Transaction {
5757
txId Int @unique @default(autoincrement())
5858
type TxType
5959
status TxStatus @default(PENDING)
60-
nonce Int
60+
nonce Int // unique per wallet
6161
6262
// Transfer (ETH only)
6363
to String?
@@ -94,11 +94,22 @@ model Transaction {
9494
9595
votes Vote[]
9696
97+
@@unique([walletAddress, nonce])
9798
@@index([status])
9899
@@index([walletAddress])
99100
@@index([contactId])
100101
}
101102

103+
model ReservedNonce {
104+
id String @id @default(cuid())
105+
walletAddress String
106+
nonce Int
107+
expiresAt DateTime
108+
createdAt DateTime @default(now())
109+
110+
@@unique([walletAddress, nonce])
111+
}
112+
102113
model Vote {
103114
id String @id @default(cuid())
104115
txId Int
@@ -197,9 +208,9 @@ enum TxType {
197208

198209
enum TxStatus {
199210
PENDING
200-
EXECUTING
211+
EXECUTING // DEPRECATED: No longer needed. Check realtime on frontend instead
201212
EXECUTED
202-
OUTDATED
213+
OUTDATED // DEPRECATED: No longer needed with txId as nonce. Kept for backward compatibility.
203214
FAILED
204215
}
205216

packages/backend/src/common/contracts/MetaMultiSigWallet.ts

Lines changed: 31 additions & 28 deletions
Large diffs are not rendered by default.

packages/backend/src/relayer-wallet/relayer-wallet.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ export class RelayerService {
9393
*/
9494
async executeTransaction(
9595
walletAddress: string,
96+
nonce: number,
9697
to: string,
9798
value: string,
9899
data: string,
99100
zkProofs: {
101+
commitment: string;
100102
nullifier: string;
101103
aggregationId: string;
102104
domainId: number;
@@ -260,6 +262,7 @@ export class RelayerService {
260262

261263
// 2. Format proofs for contract
262264
const formattedProofs = zkProofs.map((proof) => ({
265+
commitment: BigInt(proof.commitment),
263266
nullifier: BigInt(proof.nullifier),
264267
aggregationId: BigInt(proof.aggregationId),
265268
domainId: BigInt(proof.domainId),
@@ -269,6 +272,7 @@ export class RelayerService {
269272
}));
270273

271274
const args = [
275+
BigInt(nonce),
272276
to as `0x${string}`,
273277
BigInt(value),
274278
data as `0x${string}`,

packages/backend/src/transaction/transaction.controller.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,9 @@ export class TransactionController {
9898
async executeOnChain(@Param('txId', ParseIntPipe) txId: number) {
9999
return this.transactionService.executeOnChain(txId);
100100
}
101+
102+
@Post('reserve-nonce')
103+
async reserveNonce(@Body('walletAddress') walletAddress: string) {
104+
return this.transactionService.reserveNonce(walletAddress);
105+
}
101106
}

0 commit comments

Comments
 (0)