-
Notifications
You must be signed in to change notification settings - Fork 153
Run the monitor via a Vercel cron task #1745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
017bc4c
Vercel build
yrong d1c674c
Add .vercelignore
yrong 6032bac
Relocate foundry
yrong d946afc
Fix build
yrong 097549c
Fix script
yrong 4192f92
Fix the deploy issue
yrong 0c05e30
Add dependencies
yrong ffa522e
Merge branch 'main' into ron/monitor-by-vercel
yrong e4cf4e7
Move to dependencies
yrong bd9c976
Potential fix for pull request finding
yrong 701c7db
Potential fix for pull request finding
yrong 44ba019
Potential fix for pull request finding
yrong e5d827a
Potential fix for pull request finding
yrong e2063d8
Potential fix for pull request finding
yrong 3276ee0
Use stable version
yrong c7559a1
Apply suggestion from @claravanstaden
yrong 462670d
Cleanup
yrong bb9c084
Merge branch 'ron/monitor-by-vercel' of https://github.com/snowfork/s…
yrong e94c4e8
Enforce cronSecret auth check
yrong 0fe8613
Hide error detail in response
yrong 7fcd4e2
Cleanup
yrong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,3 +42,4 @@ db.sqlite* | |
| .pnpm-store | ||
| /deploy | ||
| .envs/ | ||
| .vercel | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Reduce deployment size (Vercel 10MB request limit) | ||
| # Dependencies and build outputs | ||
| **/node_modules/ | ||
| **/.pnpm-store/ | ||
| **/dist/ | ||
| **/.turbo/ | ||
| **/out/ | ||
| **/cache/ | ||
| **/artifacts/ | ||
|
|
||
| # Foundry / contracts (lib is recreated by install-foundry.sh on Vercel) | ||
| contracts/lib/ | ||
| contracts/out/ | ||
| contracts/cache/ | ||
| contracts/broadcast/ | ||
| contracts/report/ | ||
| contracts/coverage/ | ||
| contracts/docs/ | ||
|
|
||
| # Other large dirs | ||
| lodestar/ | ||
| polkadot-sdk/ | ||
| relaychain/ | ||
| go/ | ||
| control/target/ | ||
| gas-estimator/target/ | ||
| **/.git/ | ||
| **/.cargo/ | ||
| **/.rustup/ | ||
| **/states/ | ||
| **/deploy/ | ||
| **/.vercel/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| .deps | ||
| .pnpm-store | ||
| .turbo | ||
| .vercel | ||
| scripts/.foundry |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Keep deployment under Vercel 10MB limit | ||
| node_modules/ | ||
| .turbo/ | ||
| **/dist/ | ||
| **/.next/ | ||
| .foundry/ | ||
| scripts/.foundry/ | ||
| *.log | ||
| .env*.local | ||
| .vercel/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Vercel serverless API | ||
|
|
||
| ## `/api/monitor` | ||
|
|
||
| Runs the Snowbridge monitor (bridge status, channel status, relayer/sovereign balances, indexer status) and sends metrics to CloudWatch. Used by Vercel Cron for periodic runs. | ||
|
|
||
| - **Cron**: Every 15 minutes (`*/15 * * * *`). Configure in `vercel.json`; change `schedule` to adjust. | ||
| - **Auth**: Set `CRON_SECRET` in Vercel (Project → Settings → Environment Variables). Vercel sends it as `Authorization: Bearer <CRON_SECRET>` when invoking the cron. | ||
| - **Env**: Same as the CLI monitor: `NODE_ENV`, RPC URLs (`BEACON_RPC_URL`, `ETHEREUM_RPC_URL_*`, `PARACHAIN_RPC_URL_*`, `RELAY_CHAIN_RPC_URL`), and AWS/CloudWatch vars used by `sendMetrics` in `packages/operations`. | ||
|
|
||
| Build must produce `packages/operations/dist/` (e.g. run `pnpm build` from repo root or `web` so that `@snowbridge/operations` is built). | ||
|
|
||
| ### Build (contract-types + Foundry) | ||
|
|
||
| The build depends on `@snowbridge/contract-types`, which runs `forge build` in `contracts/` then typechain. So Foundry must be available in the Vercel build. | ||
|
|
||
| - **Root Directory**: Keep as **`web`**. The full repo is cloned, so from `web/packages/contract-types`, `../../../contracts` correctly points at the repo’s `contracts/` folder. | ||
| - **Node**: Use **Node 20.x** (set in Project → Settings → General). Needed for GLIBC compatibility with Foundry binaries. | ||
| - **Install / Build**: `vercel.json` uses `installCommand: pnpm install && bash scripts/install-foundry.sh` and `buildCommand: pnpm run build:vercel`. The install script downloads the official Foundry nightly tarball from GitHub (`foundry_nightly_linux_amd64.tar.gz`) into `web/scripts/.foundry/bin` (on CI/Vercel), installs forge deps in `contracts/`, and runs `forge build`. The build script adds `scripts/.foundry/bin`, `.foundry/bin`, and `~/.foundry/bin` to PATH so `forge` is found, then runs `forge build` in `../contracts` and the full turbo build. | ||
| - If Foundry install fails (e.g. network), the install script exits non‑zero (due to `set -e`) and the Vercel build fails. `@snowbridge/contract-types` will only run `tsc` without invoking `forge` if pre-generated `src/` already exists and the build reaches that step. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import "dotenv/config"; | ||
| import type { VercelRequest, VercelResponse } from "@vercel/node"; | ||
| import { monitor } from "../packages/operations/dist/src/monitor"; | ||
|
|
||
| export const config = { | ||
| maxDuration: 60, | ||
| }; | ||
|
|
||
| export default async function handler(req: VercelRequest, res: VercelResponse) { | ||
| if (req.method !== "GET") { | ||
| res.setHeader("Allow", "GET"); | ||
| return res.status(405).json({ error: "Method not allowed" }); | ||
| } | ||
|
|
||
| const cronSecret = process.env.CRON_SECRET; | ||
| if (!cronSecret) { | ||
| return res.status(503).json({ | ||
| error: "Service unavailable", | ||
| message: "CRON_SECRET is not configured", | ||
| }); | ||
| } | ||
| const authHeader = req.headers.authorization; | ||
| if (authHeader !== `Bearer ${cronSecret}`) { | ||
| return res.status(401).json({ error: "Unauthorized" }); | ||
| } | ||
|
|
||
| try { | ||
| const metrics = await monitor(); | ||
| return res.status(200).json({ ok: true, name: metrics.name }); | ||
| } catch (error) { | ||
| console.error("Monitor error:", error); | ||
| return res.status(500).json({ | ||
| error: "Monitor failed", | ||
| message: "Monitor failed", | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is
--no-cacheremoved?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, the Vercel build process will fail. I can't find the detailed error messages right now, but there are also some warning messages in my local setup, which suggest that this option parameter may be deprecated.