Last active
May 1, 2022 01:32
-
-
Save arcticmatt/c0d68d1b8a0e21e72a75651a78b4fb1f to your computer and use it in GitHub Desktop.
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
import { Connection } from "@solana/web3.js"; | |
import SolanaNetworkHealth from "types/enums/SolanaNetworkHealth"; | |
import getRecentAverageTps from "utils/solana/health/getRecentAverageTps"; | |
const SOLANA_SLOW_TPS_CUTOFF = 1_250; | |
const SOLANA_DOWN_TPS_CUTOFF = 500; | |
export default async function getSolanaNetworkHealth( | |
connection: Connection, | |
minutesLookback: number, | |
solanaDownTpsCutoff = SOLANA_DOWN_TPS_CUTOFF, | |
solanaSlowTpsCutoff = SOLANA_SLOW_TPS_CUTOFF | |
) { | |
const tps = await getRecentAverageTps(connection, minutesLookback); | |
if (tps == null) { | |
return { health: SolanaNetworkHealth.Down, tps: null }; | |
} | |
if (tps > solanaSlowTpsCutoff) { | |
return { health: SolanaNetworkHealth.Good, tps }; | |
} | |
if (tps > solanaDownTpsCutoff) { | |
return { health: SolanaNetworkHealth.Slow, tps }; | |
} | |
return { health: SolanaNetworkHealth.Down, tps }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment