Skip to content

Commit b90de6b

Browse files
arcoravenfarhanW3joaquim-vergesdependabot[bot]
authored
feat: Redis Workers POC (#467)
* Added beta packages & db * updated ingest layer to write to bullMQ (ioredis) * removed extra logs * committed graceful shutdown. Need to revist * updated webhooks to work based on worker. updated req ingestion * updates * updated to use queueTx() and allow all write end-points to work * updated webhook flow * Added beta GH workflow + minor updates * updates for idempotencyKey * updates for txenum * wip * simpify workers * reuse thirdweb client * brought back webhook pg listener. updated setex * updates to get things stable * wip * wip * Packages updates (#473) * Introduce strict Transaction types * clean up webhook code * "fix" signature before encoding relayer execute call (#474) * fix: add errorMessage to query to get queued txs (#475) * fix: add errorMessage to query to get queued txs * remove unused files * update thirdweb package * getWalletBalance fix * chore(deps): bump express from 4.18.2 to 4.19.2 (#470) Bumps [express](https://github.com/expressjs/express) from 4.18.2 to 4.19.2. - [Release notes](https://github.com/expressjs/express/releases) - [Changelog](https://github.com/expressjs/express/blob/master/History.md) - [Commits](expressjs/express@4.18.2...4.19.2) --- updated-dependencies: - dependency-name: express dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Updated Mined Tx flow (#476) * Bump follow-redirects from 1.15.2 to 1.15.6 (#448) Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.2 to 1.15.6. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](follow-redirects/follow-redirects@v1.15.2...v1.15.6) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Cache webhooks * fix webhooks * remove debug lines * serialize worker data * naming conflict --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: farhanW3 <farhan@thirdweb.com> Co-authored-by: farhanW3 <132962163+farhanW3@users.noreply.github.com> Co-authored-by: Joaquim Verges <joaquim.verges@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 86305f3 commit b90de6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1850
-1252
lines changed

.github/workflows/beta.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build on beta branch
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v2
13+
with:
14+
ref: beta # checkout the main branch to build nightly
15+
16+
- name: Check Disk Space Before Build
17+
run: df -h
18+
19+
- name: Docker Prune
20+
run: docker system prune -af
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v1
24+
25+
- name: Login to DockerHub
26+
uses: docker/login-action@v1
27+
with:
28+
username: ${{ secrets.DOCKER_USERNAME }}
29+
password: ${{ secrets.DOCKER_PASSWORD }}
30+
31+
- name: Build and Push Docker Image
32+
uses: docker/build-push-action@v2
33+
with:
34+
context: .
35+
target: prod
36+
platforms: linux/amd64,linux/arm64
37+
push: true
38+
tags: thirdweb/engine:beta-nightly
39+
build-args: |
40+
ENGINE_VERSION=beta-nightly
41+
42+
- name: Check Disk Space After Build
43+
run: df -h

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"editor.formatOnSave": true,
88
"eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }],
99
"typescript.tsdk": "node_modules/typescript/lib",
10-
"typescript.enablePromptUseWorkspaceTsdk": true
10+
"typescript.enablePromptUseWorkspaceTsdk": true,
11+
"cSpell.words": ["idempotency"]
1112
}

docker-compose-infra.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,29 @@ services:
2020
cpus: "2"
2121
memory: 2G
2222

23+
redis:
24+
container_name: redis
25+
image: redis:latest
26+
restart: always
27+
ports:
28+
- 6379:6379
29+
volumes:
30+
- redis_data:/data
31+
32+
bullboard:
33+
container_name: bullboard
34+
image: deadly0/bull-board:latest
35+
restart: always
36+
ports:
37+
- 3000:3000
38+
environment:
39+
REDIS_HOST: redis
40+
REDIS_PORT: 6379
41+
REDIS_USE_TLS: "false"
42+
BULL_PREFIX: bull
43+
depends_on:
44+
- redis
45+
2346
volumes:
2447
psql_db:
48+
redis_data:

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ services:
1515
reservations:
1616
cpus: "2"
1717
memory: 2G
18+
redis:
19+
image: redis:latest
20+
container_name: redis_container
21+
ports:
22+
- "6379:6379"
23+
volumes:
24+
- redis_data:/data
1825

1926
engine:
2027
build:
@@ -38,3 +45,4 @@ services:
3845

3946
volumes:
4047
db_data:
48+
redis_data:

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"docker": "docker compose --env-file ./.env up --remove-orphans",
1111
"docker:build": "docker compose build --no-cache",
12-
"dev": "yarn dev:infra && yarn dev:db && yarn dev:run",
12+
"dev": "yarn dev:infra && yarn dev:run",
1313
"dev:infra": "docker compose -f ./docker-compose-infra.yml up -d",
1414
"dev:db": "yarn prisma:setup:dev",
1515
"dev:run": "nodemon --watch 'src/**/*.ts' --exec 'npx tsx ./src/index.ts' --files src/index.ts",
@@ -47,24 +47,29 @@
4747
"@types/base-64": "^1.0.2",
4848
"base-64": "^1.0.0",
4949
"body-parser": "^1.20.2",
50+
"bullmq": "^5.4.2",
5051
"cookie": "^0.5.0",
5152
"cookie-parser": "^1.4.6",
5253
"copyfiles": "^2.4.1",
5354
"cron-parser": "^4.9.0",
5455
"crypto-js": "^4.2.0",
5556
"dotenv": "^16.0.3",
5657
"ethers": "5",
58+
"ethers-aws-kms-signer": "^1.3.2",
59+
"ethers-gcp-kms-signer": "^1.1.6",
5760
"fastify": "^4.15.0",
5861
"fastify-plugin": "^4.5.0",
5962
"http-status-codes": "^2.2.0",
63+
"ioredis": "^5.3.2",
6064
"knex": "^3.1.0",
6165
"mnemonist": "^0.39.8",
6266
"node-cron": "^3.0.2",
6367
"pg": "^8.11.3",
6468
"pino": "^8.15.1",
6569
"pino-pretty": "^10.0.0",
6670
"prisma": "^5.2.0",
67-
"thirdweb": "^5.0.0-beta-ca68bc77e74f594360b4da1e9e77793b66cfb12a-20240323045412",
71+
"superjson": "^2.2.1",
72+
"thirdweb": "^5.1.0",
6873
"uuid": "^9.0.1",
6974
"viem": "^1.14.0",
7075
"zod": "^3.21.4"

src/db/transactions/cleanTxs.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/db/transactions/getAllTxs.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import { Transactions } from "@prisma/client";
2-
import { Static } from "@sinclair/typebox";
32
import { ContractExtension } from "../../schema/extension";
43
import { PrismaTransaction } from "../../schema/prisma";
5-
import {
6-
TransactionStatus,
7-
transactionResponseSchema,
8-
} from "../../server/schemas/transaction";
4+
import { TransactionStatus } from "../../server/schemas/transaction";
95
import { getPrismaWithPostgresTx } from "../client";
10-
import { cleanTxs } from "./cleanTxs";
116

127
interface GetAllTxsParams {
138
pgtx?: PrismaTransaction;
@@ -18,7 +13,7 @@ interface GetAllTxsParams {
1813
}
1914

2015
interface GetAllTxsResponse {
21-
transactions: Static<typeof transactionResponseSchema>[];
16+
transactions: Transactions[];
2217
totalCount: number;
2318
}
2419

@@ -99,7 +94,7 @@ export const getAllTxs = async ({
9994
const [totalCount, txs] = await Promise.all([totalCountPromise, txsPromise]);
10095

10196
return {
102-
transactions: cleanTxs(txs),
97+
transactions: txs,
10398
totalCount: totalCount,
10499
};
105100
};

src/db/transactions/getAllTxsByWallet.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { PrismaTransaction } from "../../schema/prisma";
22
import { getPrismaWithPostgresTx } from "../client";
3-
import { cleanTxs } from "./cleanTxs";
43

54
interface GetAllTxsByWalletParams {
65
pgtx?: PrismaTransaction;
@@ -14,7 +13,7 @@ export const getAllTxsByWallet = async ({
1413
}: GetAllTxsByWalletParams) => {
1514
const prisma = getPrismaWithPostgresTx(pgtx);
1615

17-
const txs = await prisma.transactions.findMany({
16+
return await prisma.transactions.findMany({
1817
where: {
1918
fromAddress: walletAddress.toLowerCase(),
2019
},
@@ -24,6 +23,4 @@ export const getAllTxsByWallet = async ({
2423
},
2524
],
2625
});
27-
28-
return cleanTxs(txs);
2926
};

src/db/transactions/getQueuedTxs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const getQueuedTxs = async ({ pgtx }: GetQueuedTxsParams = {}): Promise<
2323
"sentAt" IS NULL
2424
AND "minedAt" IS NULL
2525
AND "cancelledAt" IS NULL
26+
AND "errorMessage" IS NULL
2627
ORDER BY
2728
"queuedAt"
2829
ASC

src/db/transactions/getTxById.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Static } from "@sinclair/typebox";
22
import { PrismaTransaction } from "../../schema/prisma";
3-
import { transactionResponseSchema } from "../../server/schemas/transaction";
3+
import {
4+
toTransactionResponse,
5+
transactionResponseSchema,
6+
} from "../../server/schemas/transaction";
47
import { getPrismaWithPostgresTx } from "../client";
5-
import { cleanTxs } from "./cleanTxs";
68

79
interface GetTxByIdParams {
810
queueId: string;
@@ -24,11 +26,5 @@ export const getTxById = async ({
2426
id: queueId,
2527
},
2628
});
27-
28-
if (!tx) {
29-
return null;
30-
}
31-
32-
const [cleanedTx] = cleanTxs([tx]);
33-
return cleanedTx;
29+
return tx ? toTransactionResponse(tx) : null;
3430
};

src/db/transactions/getTxByIds.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { Transactions } from "@prisma/client";
12
import { PrismaTransaction } from "../../schema/prisma";
23
import { getPrismaWithPostgresTx } from "../client";
3-
import { cleanTxs } from "./cleanTxs";
44

55
interface GetTxsByGroupIdParams {
66
pgtx?: PrismaTransaction;
@@ -10,17 +10,12 @@ interface GetTxsByGroupIdParams {
1010
export const getTxsByGroupId = async ({
1111
pgtx,
1212
groupId,
13-
}: GetTxsByGroupIdParams) => {
13+
}: GetTxsByGroupIdParams): Promise<Transactions[]> => {
1414
const prisma = getPrismaWithPostgresTx(pgtx);
1515
const txs = await prisma.transactions.findMany({
1616
where: {
1717
groupId,
1818
},
1919
});
20-
21-
if (!txs) {
22-
return [];
23-
}
24-
25-
return cleanTxs(txs);
20+
return txs;
2621
};

0 commit comments

Comments
 (0)