diff --git a/constants/manualPolls.ts b/constants/manualPolls.ts deleted file mode 100644 index 5585421b..00000000 --- a/constants/manualPolls.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { PollsQuery } from "apollo"; - -/** - * TEMPORARY stopgap: manually surface governance polls that were created while - * the subgraph was behind on indexing, so voting stays functional during the - * outage. Entries are shaped like subgraph poll results and merged into the - * voting list/detail pages, deduped by poll address — once the subgraph - * reindexes a poll, its real (tallied) copy wins and the manual entry drops out. - * - * These carry no vote tally (the subgraph computes the stake-weighted counts), - * so the UI shows a "counts not loaded" note for them; voting itself is on-chain - * and works regardless. - * - * Remove entries (or delete this file and its imports) once indexing recovers. - */ -type SubgraphPoll = PollsQuery["polls"][number]; - -export const MANUAL_POLLS: SubgraphPoll[] = [ - { - // LIP-118 "Delegated Reward Calling" — created during the subgraph indexing halt. - // tx: 0xb8ab2a824b4a5b16b76be99f1313a8238f35acc2259b139562277e1df8ba02e4 - __typename: "Poll", - id: "0x74479927117d4158b32c03d5400c14bdd7e6a46a", - proposal: "QmcYGZp3SipMEz699bpeZqocdouYWTE2zHG8TMdaSYqowF", - endBlock: "25622119", - quorum: "333300", - quota: "500000", - tally: null, - votes: [], - }, -]; - -const norm = (id: string) => id.toLowerCase(); - -/** The manually-listed poll for `id`, if any. */ -export const getManualPoll = ( - id: string | undefined | null -): SubgraphPoll | undefined => - id ? MANUAL_POLLS.find((p) => norm(p.id) === norm(id)) : undefined; - -/** Whether `id` is a manually-listed poll (i.e. not sourced from the subgraph). */ -export const isManualPoll = (id: string | undefined | null): boolean => - Boolean(getManualPoll(id)); - -/** - * Merge manual polls into a subgraph poll list, deduped by address. The subgraph - * copy takes precedence, so a poll that has since been indexed is not duplicated. - */ -export const mergeManualPolls = ( - polls: SubgraphPoll[] | undefined -): SubgraphPoll[] => { - const list = polls ? [...polls] : []; - const seen = new Set(list.map((p) => norm(p.id))); - for (const poll of MANUAL_POLLS) { - if (!seen.has(norm(poll.id))) list.push(poll); - } - return list; -}; diff --git a/layouts/main.tsx b/layouts/main.tsx index f1700b5e..68a9627c 100644 --- a/layouts/main.tsx +++ b/layouts/main.tsx @@ -40,7 +40,6 @@ import { useTreasuryProposalsQuery, } from "apollo"; import { BRIDGE_LPT_URL, GET_LPT_URL } from "constants/links"; -import { mergeManualPolls } from "constants/manualPolls"; import { BigNumber } from "ethers"; import { CHAIN_INFO, DEFAULT_CHAIN_ID } from "lib/chains"; import dynamic from "next/dynamic"; @@ -179,7 +178,7 @@ const Layout = ({ children, title = "Livepeer Explorer" }) => { const totalActivePolls = useMemo( () => - mergeManualPolls(pollData?.polls).filter( + pollData?.polls.filter( (p) => (currentRound?.currentL1Block ?? Number.MAX_VALUE) <= parseInt(p.endBlock) diff --git a/lib/api/polls.ts b/lib/api/polls.ts index 12f6bb48..87192da4 100644 --- a/lib/api/polls.ts +++ b/lib/api/polls.ts @@ -170,33 +170,24 @@ const getEstimatedEndTimeByBlockNumber = async ( }; const getTotalStake = async (l2BlockNumber?: number | undefined) => { - try { - const client = getApollo(); - - const protocolResponse = await client.query< - ProtocolByBlockQuery, - ProtocolByBlockQueryVariables - >({ - query: ProtocolByBlockDocument, - variables: l2BlockNumber - ? { - block: { - number: l2BlockNumber, - }, - } - : undefined, - fetchPolicy: "network-only", - }); - - return protocolResponse?.data?.protocol?.totalActiveStake; - } catch (err) { - // The subgraph can be unavailable (e.g. an indexing halt). Total stake only - // feeds participation percentages, so degrade gracefully instead of failing - // the whole poll render — this keeps manually-listed polls viewable/votable. - const detail = err instanceof Error ? err.message : String(err); - console.warn(`Could not fetch total stake from subgraph (${detail})`); - return undefined; - } + const client = getApollo(); + + const protocolResponse = await client.query< + ProtocolByBlockQuery, + ProtocolByBlockQueryVariables + >({ + query: ProtocolByBlockDocument, + variables: l2BlockNumber + ? { + block: { + number: l2BlockNumber, + }, + } + : undefined, + fetchPolicy: "network-only", + }); + + return protocolResponse?.data?.protocol?.totalActiveStake; }; const getL2BlockRangeForL1 = async (l1BlockNumber: number) => { diff --git a/pages/voting/[poll].tsx b/pages/voting/[poll].tsx index ce06159a..5cc80eed 100644 --- a/pages/voting/[poll].tsx +++ b/pages/voting/[poll].tsx @@ -28,7 +28,6 @@ import { useVoteQuery, } from "apollo"; import { sentenceCase } from "change-case"; -import { getManualPoll, isManualPoll } from "constants/manualPolls"; import Head from "next/head"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; @@ -91,22 +90,18 @@ const Poll = () => { useEffect(() => { const init = async () => { - // Fall back to a manually-listed poll when the subgraph doesn't have it - // (e.g. created while indexing was down), so it stays viewable/votable. - const source = data?.poll ?? getManualPoll(pollId); - if (source && currentRound?.currentL1Block) { + if (data && currentRound?.currentL1Block) { const response = await getPollExtended( - source, + data.poll, currentRound.currentL1Block ); setPollData(response); } }; init(); - }, [data, pollId, currentRound?.currentL1Block]); + }, [data, currentRound?.currentL1Block]); - // Only 404 on a genuine subgraph error with no manual fallback for this poll. - if (pollError && !getManualPoll(pollId)) { + if (pollError) { return ; } @@ -217,23 +212,6 @@ const Poll = () => { - {isManualPoll(pollData.id) && ( - - - Live vote counts aren't available for this poll yet — - the subgraph is still indexing it. The totals below may read - 0 until indexing catches up. Voting works normally. - - - )} { const currentRound = useCurrentRoundData(); useEffect(() => { - // Render as soon as the (on-chain) current round is available, even if the - // subgraph query returned nothing, so manually-listed polls still show while - // indexing is down. mergeManualPolls tolerates `data` being undefined. - if (currentRound?.currentL1Block) { + if (data && currentRound?.currentL1Block) { const init = async () => { setPolls( await Promise.all( - mergeManualPolls(data?.polls).map((p) => + (data?.polls ?? []).map((p) => getPollExtended(p, currentRound.currentL1Block) ) )