-
Notifications
You must be signed in to change notification settings - Fork 90
feat: forester dashboard + compression improvements #2310
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
Open
sergeytimoshin
wants to merge
15
commits into
main
Choose a base branch
from
sergey/forester-compressible
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
479bb4a
fix: update account data handling to strip discriminator prefix and i…
sergeytimoshin 9d0d2b3
chore: update photon subproject and refactor account data handling to…
sergeytimoshin a91aaf9
chore: update photon subproject to latest commit
sergeytimoshin f4c1c10
chore: update photon subproject to latest commit
sergeytimoshin 0183b9d
chore: update photon subproject to latest commit
sergeytimoshin 57247cd
feat: add --helius-rpc cli flag
sergeytimoshin 263e930
feat: enhance compressible data tracking
sergeytimoshin 93c98c4
fix: improve transaction handling in compressors
sergeytimoshin 4f2aa34
fix: improve error handling and method consistency in compressors and…
sergeytimoshin 7fe15c1
feat: add transaction verification to compressors and refactor MintAc…
sergeytimoshin 6120ced
fix: improve transaction confirmation handling and error reporting in…
sergeytimoshin 858960a
fix: remove unnecessary pubkey collection before marking accounts as …
sergeytimoshin 5cd2da6
chore: update subproject commit for photon dependency
sergeytimoshin 2e9f0db
fix: implement retry logic for transaction status verification
sergeytimoshin e724265
refactor transaction handling
sergeytimoshin 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
Submodule photon
updated
32 files
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
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,83 @@ | ||
| import { NextResponse } from "next/server"; | ||
|
|
||
| export const dynamic = "force-dynamic"; | ||
|
|
||
| const BACKEND_URL = | ||
| process.env.FORESTER_API_URL || "http://127.0.0.1:8080"; | ||
|
|
||
| const BACKEND_TIMEOUT_MS = Number( | ||
| process.env.FORESTER_API_TIMEOUT_MS ?? 8000 | ||
| ); | ||
|
|
||
| function isAbortError(error: unknown): boolean { | ||
| return ( | ||
| typeof error === "object" && | ||
| error !== null && | ||
| "name" in error && | ||
| (error as { name?: string }).name === "AbortError" | ||
| ); | ||
| } | ||
|
|
||
| function joinBackendUrl(path: string): string { | ||
| const base = BACKEND_URL.replace(/\/+$/, ""); | ||
| return `${base}/${path}`; | ||
| } | ||
|
|
||
| export async function GET( | ||
| _request: Request, | ||
| { params }: { params: Promise<{ path: string[] }> } | ||
| ) { | ||
| const { path } = await params; | ||
| const backendPath = path.join("/"); | ||
| const upstream = joinBackendUrl(backendPath); | ||
|
|
||
| const timeoutMs = | ||
| Number.isFinite(BACKEND_TIMEOUT_MS) && BACKEND_TIMEOUT_MS > 0 | ||
| ? BACKEND_TIMEOUT_MS | ||
| : 8000; | ||
|
|
||
| const controller = new AbortController(); | ||
| const timer = setTimeout(() => controller.abort(), timeoutMs); | ||
|
|
||
| try { | ||
| const response = await fetch(upstream, { | ||
| cache: "no-store", | ||
| signal: controller.signal, | ||
| }); | ||
|
|
||
| const contentType = response.headers.get("content-type") ?? ""; | ||
| const payload = contentType.includes("application/json") | ||
| ? await response.json() | ||
| : { message: await response.text() }; | ||
|
|
||
| if (!response.ok) { | ||
| return NextResponse.json( | ||
| { | ||
| error: `Forester backend returned ${response.status}`, | ||
| upstream, | ||
| details: payload, | ||
| }, | ||
| { status: response.status } | ||
| ); | ||
| } | ||
|
|
||
| return NextResponse.json(payload, { status: response.status }); | ||
| } catch (error) { | ||
| if (isAbortError(error)) { | ||
| return NextResponse.json( | ||
| { | ||
| error: `Backend request timed out after ${timeoutMs}ms`, | ||
| upstream, | ||
| }, | ||
| { status: 504 } | ||
| ); | ||
| } | ||
|
|
||
| return NextResponse.json( | ||
| { error: "Backend unavailable", upstream }, | ||
| { status: 502 } | ||
| ); | ||
| } finally { | ||
| clearTimeout(timer); | ||
| } | ||
| } |
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,91 @@ | ||
| import { NextResponse } from "next/server"; | ||
| import { Pool } from "pg"; | ||
|
|
||
| export const dynamic = "force-dynamic"; | ||
|
|
||
| let pool: Pool | null = null; | ||
|
|
||
| function getPool(): Pool | null { | ||
| const url = process.env.PHOTON_DATABASE_URL; | ||
| if (!url) return null; | ||
| if (!pool) { | ||
| pool = new Pool({ connectionString: url, max: 2, idleTimeoutMillis: 30_000 }); | ||
| } | ||
| return pool; | ||
| } | ||
|
|
||
| export async function GET() { | ||
| const db = getPool(); | ||
| if (!db) { | ||
| return NextResponse.json( | ||
| { error: "PHOTON_DATABASE_URL not configured" }, | ||
| { status: 503 } | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| const client = await db.connect(); | ||
| try { | ||
| const [accounts, tokens, compressed] = await Promise.all([ | ||
| client.query(` | ||
| SELECT | ||
| COUNT(*) AS total, | ||
| COUNT(*) FILTER (WHERE NOT spent) AS active | ||
| FROM accounts | ||
| `), | ||
| client.query(` | ||
| SELECT | ||
| COUNT(*) AS total, | ||
| COUNT(*) FILTER (WHERE NOT spent) AS active | ||
| FROM token_accounts | ||
| `), | ||
| client.query(` | ||
| SELECT | ||
| encode(a.owner, 'base64') AS owner_b64, | ||
| COUNT(*) AS total, | ||
| COUNT(*) FILTER (WHERE NOT a.spent) AS active | ||
| FROM accounts a | ||
| WHERE a.onchain_pubkey IS NOT NULL | ||
| GROUP BY a.owner | ||
| ORDER BY COUNT(*) DESC | ||
| `), | ||
| ]); | ||
|
|
||
| const totalAccounts = Number(accounts.rows[0].total); | ||
| const activeAccounts = Number(accounts.rows[0].active); | ||
| const totalTokens = Number(tokens.rows[0].total); | ||
| const activeTokens = Number(tokens.rows[0].active); | ||
|
|
||
| const compressedFromOnchain = compressed.rows.map((r: { owner_b64: string; total: string; active: string }) => ({ | ||
| owner: Buffer.from(r.owner_b64, "base64").toString("hex"), | ||
| total: Number(r.total), | ||
| active: Number(r.active), | ||
| })); | ||
|
|
||
| const totalCompressedFromOnchain = compressedFromOnchain.reduce( | ||
| (sum: number, r: { total: number }) => sum + r.total, | ||
| 0 | ||
| ); | ||
| const activeCompressedFromOnchain = compressedFromOnchain.reduce( | ||
| (sum: number, r: { active: number }) => sum + r.active, | ||
| 0 | ||
| ); | ||
|
|
||
| return NextResponse.json({ | ||
| accounts: { total: totalAccounts, active: activeAccounts }, | ||
| token_accounts: { total: totalTokens, active: activeTokens }, | ||
| compressed_from_onchain: { | ||
| total: totalCompressedFromOnchain, | ||
| active: activeCompressedFromOnchain, | ||
| by_owner: compressedFromOnchain, | ||
| }, | ||
| timestamp: Math.floor(Date.now() / 1000), | ||
| }); | ||
| } finally { | ||
| client.release(); | ||
| } | ||
| } catch (err) { | ||
| const message = err instanceof Error ? err.message : String(err); | ||
| return NextResponse.json({ error: message }, { status: 500 }); | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
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.
Uh oh!
There was an error while loading. Please reload this page.