Skip to content

Commit b390aaa

Browse files
committed
hotfix: avoid stale pendingTxs
1 parent 073f4ff commit b390aaa

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

k8s/local/skaffold.no_ui.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ requires:
99
- path: ./auth/image.yaml
1010
- path: ./event-cannon/image.yaml
1111
- path: ./aztec-listener/image.yaml
12+
- path: ./ethereum-listener/image.yaml
1213
deploy:
1314
kubectl:
1415
flags:
@@ -26,6 +27,7 @@ manifests:
2627
- k8s/local/auth/service.yaml
2728
- k8s/local/event-cannon/deployment.yaml
2829
- k8s/local/aztec-listener/deployment.yaml
30+
- k8s/local/ethereum-listener/deployment.yaml
2931
- k8s/local/aztec-sandbox-node/ingress.yaml
3032
- k8s/local/aztec-sandbox-node/deployment.yaml
3133
- k8s/local/aztec-sandbox-node/service.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ChicmozL2PendingTx } from "@chicmoz-pkg/types";
2+
import { eq } from "drizzle-orm";
3+
import { getDb as db } from "../../../database/index.js";
4+
import { l2Tx } from "../../schema/index.js";
5+
6+
export const deleteTx = async (
7+
hash: ChicmozL2PendingTx["hash"]
8+
): Promise<void> => {
9+
await db().delete(l2Tx).where(eq(l2Tx.hash, hash)).execute();
10+
};

services/explorer-api/src/event-handler/on-pending-txs.ts

+10
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@ import { chicmozL2PendingTxSchema } from "@chicmoz-pkg/types";
33
import { logger } from "../logger.js";
44
import { storeL2Tx } from "../database/controllers/l2Tx/store.js";
55
import { handleDuplicateError } from "./utils.js";
6+
import { getTxs } from "../database/controllers/l2Tx/get-tx.js";
7+
import { deleteTx } from "../database/controllers/l2Tx/delete.js";
68

79
export const onPendingTxs = async ({ txs }: PendingTxsEvent) => {
10+
const dbTxs = await getTxs();
11+
const staleTxs = dbTxs.filter(
12+
(dbTx) => !txs.some((tx) => tx.hash === dbTx.hash)
13+
);
814
for (const tx of txs) {
915
logger.info(`🕐 Pending tx: ${tx.hash}`);
1016
const res = chicmozL2PendingTxSchema.parse(tx);
1117
await storeL2Tx(res).catch((e) => {
1218
handleDuplicateError(e as Error, `tx ${res.hash}`);
1319
});
1420
}
21+
if (staleTxs.length > 0) {
22+
logger.info(`🕐🕐🕐 Stale txs: ${staleTxs.length}. Deleting...`);
23+
for (const tx of staleTxs) await deleteTx(tx.hash);
24+
}
1525
};

services/explorer-api/src/start.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as cache from "./cache/index.js";
2+
import {deleteAllTxs} from "./database/controllers/l2Tx/delete-all-txs.js";
23
import * as db from "./database/index.js";
34
import { subscribeHandlers } from "./event-handler/index.js";
45
import { setComponentInitializing, setComponentUp } from "./health.js";
@@ -39,7 +40,7 @@ export const start = async () => {
3940
ID: mb.ID,
4041
init: mb.init,
4142
});
42-
// TODO: clear pending txs DB
43+
await deleteAllTxs(); // TODO: perhaps a more specific deleteAllTxs should be created, also some logs could be good.
4344
setComponentInitializing("SUBSCRIPTIONS");
4445
await subscribeHandlers();
4546
setComponentUp("SUBSCRIPTIONS");

0 commit comments

Comments
 (0)