Skip to content

Commit

Permalink
hotfix: avoid stale pendingTxs
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipHarald committed Jan 13, 2025
1 parent 073f4ff commit b390aaa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions k8s/local/skaffold.no_ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ requires:
- path: ./auth/image.yaml
- path: ./event-cannon/image.yaml
- path: ./aztec-listener/image.yaml
- path: ./ethereum-listener/image.yaml
deploy:
kubectl:
flags:
Expand All @@ -26,6 +27,7 @@ manifests:
- k8s/local/auth/service.yaml
- k8s/local/event-cannon/deployment.yaml
- k8s/local/aztec-listener/deployment.yaml
- k8s/local/ethereum-listener/deployment.yaml
- k8s/local/aztec-sandbox-node/ingress.yaml
- k8s/local/aztec-sandbox-node/deployment.yaml
- k8s/local/aztec-sandbox-node/service.yaml
Expand Down
10 changes: 10 additions & 0 deletions services/explorer-api/src/database/controllers/l2Tx/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ChicmozL2PendingTx } from "@chicmoz-pkg/types";
import { eq } from "drizzle-orm";
import { getDb as db } from "../../../database/index.js";
import { l2Tx } from "../../schema/index.js";

export const deleteTx = async (
hash: ChicmozL2PendingTx["hash"]
): Promise<void> => {
await db().delete(l2Tx).where(eq(l2Tx.hash, hash)).execute();
};
10 changes: 10 additions & 0 deletions services/explorer-api/src/event-handler/on-pending-txs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ import { chicmozL2PendingTxSchema } from "@chicmoz-pkg/types";
import { logger } from "../logger.js";
import { storeL2Tx } from "../database/controllers/l2Tx/store.js";
import { handleDuplicateError } from "./utils.js";
import { getTxs } from "../database/controllers/l2Tx/get-tx.js";
import { deleteTx } from "../database/controllers/l2Tx/delete.js";

export const onPendingTxs = async ({ txs }: PendingTxsEvent) => {
const dbTxs = await getTxs();
const staleTxs = dbTxs.filter(
(dbTx) => !txs.some((tx) => tx.hash === dbTx.hash)
);
for (const tx of txs) {
logger.info(`🕐 Pending tx: ${tx.hash}`);
const res = chicmozL2PendingTxSchema.parse(tx);
await storeL2Tx(res).catch((e) => {
handleDuplicateError(e as Error, `tx ${res.hash}`);
});
}
if (staleTxs.length > 0) {
logger.info(`🕐🕐🕐 Stale txs: ${staleTxs.length}. Deleting...`);
for (const tx of staleTxs) await deleteTx(tx.hash);
}
};
3 changes: 2 additions & 1 deletion services/explorer-api/src/start.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as cache from "./cache/index.js";
import {deleteAllTxs} from "./database/controllers/l2Tx/delete-all-txs.js";
import * as db from "./database/index.js";
import { subscribeHandlers } from "./event-handler/index.js";
import { setComponentInitializing, setComponentUp } from "./health.js";
Expand Down Expand Up @@ -39,7 +40,7 @@ export const start = async () => {
ID: mb.ID,
init: mb.init,
});
// TODO: clear pending txs DB
await deleteAllTxs(); // TODO: perhaps a more specific deleteAllTxs should be created, also some logs could be good.
setComponentInitializing("SUBSCRIPTIONS");
await subscribeHandlers();
setComponentUp("SUBSCRIPTIONS");
Expand Down

0 comments on commit b390aaa

Please sign in to comment.