From 2de7768f411d0f217393769acb5a45ee2c0502e2 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Tue, 1 Sep 2020 12:46:19 +0800 Subject: [PATCH] Remove cached transactions from explorer and update copy (#11965) --- explorer/src/pages/TransactionDetailsPage.tsx | 11 +- explorer/src/providers/transactions/cached.ts | 290 ------------------ .../src/providers/transactions/details.tsx | 22 +- explorer/src/providers/transactions/index.tsx | 84 +++-- 4 files changed, 49 insertions(+), 358 deletions(-) delete mode 100644 explorer/src/providers/transactions/cached.ts diff --git a/explorer/src/pages/TransactionDetailsPage.tsx b/explorer/src/pages/TransactionDetailsPage.tsx index feaf39a84b..700ea4088b 100644 --- a/explorer/src/pages/TransactionDetailsPage.tsx +++ b/explorer/src/pages/TransactionDetailsPage.tsx @@ -22,7 +22,6 @@ import { LoadingCard } from "components/common/LoadingCard"; import { TableCardBody } from "components/common/TableCardBody"; import { displayTimestamp } from "utils/date"; import { InfoTooltip } from "components/common/InfoTooltip"; -import { isCached } from "providers/transactions/cached"; import { Address } from "components/common/Address"; import { Signature } from "components/common/Signature"; import { intoTransactionInstruction } from "utils/tx"; @@ -281,7 +280,6 @@ function AccountsCard({ signature, autoRefresh, }: SignatureProps & AutoRefreshProps) { - const { url } = useCluster(); const details = useTransactionDetails(signature); const fetchDetails = useFetchTransactionDetails(); const fetchStatus = useFetchTransactionStatus(); @@ -314,17 +312,14 @@ function AccountsCard({ } else if (!details || details.status === FetchStatus.Fetching) { return ; } else if (details.status === FetchStatus.FetchFailed) { - return ; + return ; } else if (!details.data?.transaction || !message) { - return ; + return ; } const { meta } = details.data.transaction; if (!meta) { - if (isCached(url, signature)) { - return null; - } - return ; + return ; } const accountRows = message.accountKeys.map((account, index) => { diff --git a/explorer/src/providers/transactions/cached.ts b/explorer/src/providers/transactions/cached.ts deleted file mode 100644 index 99f988c404..0000000000 --- a/explorer/src/providers/transactions/cached.ts +++ /dev/null @@ -1,290 +0,0 @@ -/** - * TEMPORARY - * - * Adds the ability cache select transactions from mainnet-beta and return them as - * if they came from the RPC node itself, until we have a longer transaction history - */ - -import { TransactionStatusInfo } from "./index"; -import { - Transaction, - ParsedConfirmedTransaction, - Message, - clusterApiUrl, -} from "@solana/web3.js"; -import { intoParsedTransaction } from "utils/tx"; - -export const isCached = (url: string, signature: string): boolean => { - return url === clusterApiUrl("mainnet-beta") && signature in CACHED_STATUSES; -}; - -export const CACHED_STATUSES: { [key: string]: TransactionStatusInfo } = { - uQf4pS38FjRF294QFEXizhYkZFjSR9ZSBvvV6MV5b4VpdfRnK3PY9TWZ2qHMQKtte3XwKVLcWqsTF6wL9NEZMty: { - slot: 10440804, - result: { err: null }, - timestamp: 1589212180, - confirmations: "max", - }, - DYrfStEEzbV5sftX8LgUa54Nwnc5m5E1731cqBtiiC66TeXgKpfqZEQTuFY3vhHZ2K1BsaFM3X9FqisR28EtZr8: { - slot: 10451288, - result: { err: null }, - timestamp: 1589216984, - confirmations: "max", - }, - "3bLx2PLpkxCxJA5P7HVe8asFdSWXVAh1DrxfkqWE9bWvPRxXE2hqwj1vuSC858fUw3XAGQcHbJknhtNdxY2sehab": { - slot: 10516588, - result: { err: null }, - timestamp: 1589247117, - confirmations: "max", - }, - "3fE8xNgyxbwbvA5MX3wM87ahDDgCVEaaMMSa8UCWWNxojaRYBgrQyiKXLSxcryMWb7sEyVLBWyqUaRWnQCroSqjY": { - slot: 10575124, - result: { err: null }, - timestamp: 1589274236, - confirmations: "max", - }, - "5PWymGjKV7T1oqeqGn139EHFyjNM2dnNhHCUcfD2bmdj8cfF95HpY1uJ84W89c4sJQnmyZxXcYrcjumx2jHUvxZQ": { - slot: 12447825, - result: { err: null }, - timestamp: 15901860565, - confirmations: "max", - }, - "5K4KuqTTRNtzfpxWiwnkePzGfsa3tBEmpMy7vQFR3KWFAZNVY9tvoSaz1Yt5dKxcgsZPio2EsASVDGbQB1HvirGD": { - slot: 12450728, - result: { err: null }, - timestamp: 15901874549, - confirmations: "max", - }, - "45pGoC4Rr3fJ1TKrsiRkhHRbdUeX7633XAGVec6XzVdpRbzQgHhe6ZC6Uq164MPWtiqMg7wCkC6Wy3jy2BqsDEKf": { - slot: 12972684, - result: { err: null }, - timestamp: 1590432412, - confirmations: "max", - }, -}; - -export const CACHED_DETAILS: { [key: string]: ParsedConfirmedTransaction } = { - uQf4pS38FjRF294QFEXizhYkZFjSR9ZSBvvV6MV5b4VpdfRnK3PY9TWZ2qHMQKtte3XwKVLcWqsTF6wL9NEZMty: { - meta: null, - slot: 10440804, - transaction: intoParsedTransaction( - Transaction.populate( - new Message({ - accountKeys: [ - "2ojv9BAiHUrvsm9gxDe7fJSzbNZSJcxZvf8dqmWGHG8S", - "4C6NCcLPUgGuBBkV2dJW96mrptMUCp3RG1ft9rqwjFi9", - "11111111111111111111111111111111", - ], - header: { - numReadonlySignedAccounts: 0, - numReadonlyUnsignedAccounts: 1, - numRequiredSignatures: 1, - }, - instructions: [ - { accounts: [0, 1], data: "3Bxs411UBrj8QXUb", programIdIndex: 2 }, - ], - recentBlockhash: "5Aw8MaMYdYtnfJyyrregWMWGgiMtWZ6GtRzeP6Ufo65Z", - }), - [ - "uQf4pS38FjRF294QFEXizhYkZFjSR9ZSBvvV6MV5b4VpdfRnK3PY9TWZ2qHMQKtte3XwKVLcWqsTF6wL9NEZMty", - ] - ) - ), - }, - - DYrfStEEzbV5sftX8LgUa54Nwnc5m5E1731cqBtiiC66TeXgKpfqZEQTuFY3vhHZ2K1BsaFM3X9FqisR28EtZr8: { - meta: null, - slot: 10451288, - transaction: intoParsedTransaction( - Transaction.populate( - new Message({ - accountKeys: [ - "2ojv9BAiHUrvsm9gxDe7fJSzbNZSJcxZvf8dqmWGHG8S", - "4C6NCcLPUgGuBBkV2dJW96mrptMUCp3RG1ft9rqwjFi9", - "11111111111111111111111111111111", - ], - header: { - numReadonlySignedAccounts: 0, - numReadonlyUnsignedAccounts: 1, - numRequiredSignatures: 1, - }, - instructions: [ - { - accounts: [0, 1], - data: "3Bxs3zwYHuDo723R", - programIdIndex: 2, - }, - ], - recentBlockhash: "4hXYcBdfcadcjfWV17ZwMa4MXe8kbZHYHwr3GzfyqunL", - }), - [ - "DYrfStEEzbV5sftX8LgUa54Nwnc5m5E1731cqBtiiC66TeXgKpfqZEQTuFY3vhHZ2K1BsaFM3X9FqisR28EtZr8", - ] - ) - ), - }, - - "3bLx2PLpkxCxJA5P7HVe8asFdSWXVAh1DrxfkqWE9bWvPRxXE2hqwj1vuSC858fUw3XAGQcHbJknhtNdxY2sehab": { - meta: null, - slot: 10516588, - transaction: intoParsedTransaction( - Transaction.populate( - new Message({ - accountKeys: [ - "2ojv9BAiHUrvsm9gxDe7fJSzbNZSJcxZvf8dqmWGHG8S", - "4C6NCcLPUgGuBBkV2dJW96mrptMUCp3RG1ft9rqwjFi9", - "11111111111111111111111111111111", - ], - header: { - numReadonlySignedAccounts: 0, - numReadonlyUnsignedAccounts: 1, - numRequiredSignatures: 1, - }, - instructions: [ - { - accounts: [0, 1], - data: "3Bxs3zwYHuDo723R", - programIdIndex: 2, - }, - ], - recentBlockhash: "HSzTGt3PJMeQtFr94gEdeZqTRaBxgS8Wf1zq3MDdNT3L", - }), - [ - "3bLx2PLpkxCxJA5P7HVe8asFdSWXVAh1DrxfkqWE9bWvPRxXE2hqwj1vuSC858fUw3XAGQcHbJknhtNdxY2sehab", - ] - ) - ), - }, - - "3fE8xNgyxbwbvA5MX3wM87ahDDgCVEaaMMSa8UCWWNxojaRYBgrQyiKXLSxcryMWb7sEyVLBWyqUaRWnQCroSqjY": { - meta: null, - slot: 10575124, - transaction: intoParsedTransaction( - Transaction.populate( - new Message({ - accountKeys: [ - "2ojv9BAiHUrvsm9gxDe7fJSzbNZSJcxZvf8dqmWGHG8S", - "4C6NCcLPUgGuBBkV2dJW96mrptMUCp3RG1ft9rqwjFi9", - "11111111111111111111111111111111", - ], - header: { - numReadonlySignedAccounts: 0, - numReadonlyUnsignedAccounts: 1, - numRequiredSignatures: 1, - }, - instructions: [ - { - accounts: [0, 1], - data: "3Bxs3zuKU6mRKSqD", - programIdIndex: 2, - }, - ], - recentBlockhash: "6f6TBMhUoypfR5HHnEqC6VoooKxEcNad5W3Sf63j9MSD", - }), - [ - "3fE8xNgyxbwbvA5MX3wM87ahDDgCVEaaMMSa8UCWWNxojaRYBgrQyiKXLSxcryMWb7sEyVLBWyqUaRWnQCroSqjY", - ] - ) - ), - }, - - "5PWymGjKV7T1oqeqGn139EHFyjNM2dnNhHCUcfD2bmdj8cfF95HpY1uJ84W89c4sJQnmyZxXcYrcjumx2jHUvxZQ": { - meta: null, - slot: 12447825, - transaction: intoParsedTransaction( - Transaction.populate( - new Message({ - accountKeys: [ - "HCV5dGFJXRrJ3jhDYA4DCeb9TEDTwGGYXtT3wHksu2Zr", - "4C6NCcLPUgGuBBkV2dJW96mrptMUCp3RG1ft9rqwjFi9", - "11111111111111111111111111111111", - ], - header: { - numReadonlySignedAccounts: 0, - numReadonlyUnsignedAccounts: 1, - numRequiredSignatures: 1, - }, - instructions: [ - { - accounts: [0, 1], - data: "3Bxs3zrfhSqZJTR1", - programIdIndex: 2, - }, - ], - recentBlockhash: "3HJNFraT7XGAqMrQs83EKwDGB6LpHVwUMQKGaYMNY49E", - }), - [ - "5PWymGjKV7T1oqeqGn139EHFyjNM2dnNhHCUcfD2bmdj8cfF95HpY1uJ84W89c4sJQnmyZxXcYrcjumx2jHUvxZQ", - ] - ) - ), - }, - - "5K4KuqTTRNtzfpxWiwnkePzGfsa3tBEmpMy7vQFR3KWFAZNVY9tvoSaz1Yt5dKxcgsZPio2EsASVDGbQB1HvirGD": { - meta: null, - slot: 12450728, - transaction: intoParsedTransaction( - Transaction.populate( - new Message({ - accountKeys: [ - "6yKHERk8rsbmJxvMpPuwPs1ct3hRiP7xaJF2tvnGU6nK", - "4C6NCcLPUgGuBBkV2dJW96mrptMUCp3RG1ft9rqwjFi9", - "3o6xgkJ9sTmDeQWyfj3sxwon18fXJB9PV5LDc8sfgR4a", - "11111111111111111111111111111111", - ], - header: { - numReadonlySignedAccounts: 0, - numReadonlyUnsignedAccounts: 1, - numRequiredSignatures: 2, - }, - instructions: [ - { - accounts: [1, 2], - data: "3Bxs3ztRCp3tH1yZ", - programIdIndex: 3, - }, - ], - recentBlockhash: "8eXVUNRxrDgpsEuoTWyLay1LUh2djc3Y8cw2owXRN8cU", - }), - [ - "5K4KuqTTRNtzfpxWiwnkePzGfsa3tBEmpMy7vQFR3KWFAZNVY9tvoSaz1Yt5dKxcgsZPio2EsASVDGbQB1HvirGD", - "37tvpG1eAeEBizJPhJvmpC2BY8npwy6K1wrZdNwdRAfWSbkerY3ZwYAPMHbrzoq7tthvWC2qFU28niqLPxbukeXF", - ] - ) - ), - }, - - "45pGoC4Rr3fJ1TKrsiRkhHRbdUeX7633XAGVec6XzVdpRbzQgHhe6ZC6Uq164MPWtiqMg7wCkC6Wy3jy2BqsDEKf": { - meta: null, - slot: 12972684, - transaction: intoParsedTransaction( - Transaction.populate( - new Message({ - accountKeys: [ - "6yKHERk8rsbmJxvMpPuwPs1ct3hRiP7xaJF2tvnGU6nK", - "3o6xgkJ9sTmDeQWyfj3sxwon18fXJB9PV5LDc8sfgR4a", - "1nc1nerator11111111111111111111111111111111", - "11111111111111111111111111111111", - ], - header: { - numReadonlySignedAccounts: 0, - numReadonlyUnsignedAccounts: 1, - numRequiredSignatures: 2, - }, - instructions: [ - { - accounts: [1, 2], - data: "3Bxs4NNAyLXRbuZZ", - programIdIndex: 3, - }, - ], - recentBlockhash: "2xnatNUtSbeMRwi3k4vxPwXxeKFQYVuCNRg2rAgydWVP", - }), - [ - "45pGoC4Rr3fJ1TKrsiRkhHRbdUeX7633XAGVec6XzVdpRbzQgHhe6ZC6Uq164MPWtiqMg7wCkC6Wy3jy2BqsDEKf", - "2E7CDMTssxTYkdetCKVWQv9X2KNDPiuZrT2Y7647PhFEXuAWWxmHJb3ryCmP29ocQ1SNc7VyJjjm4X3jE8xWDmGY", - ] - ) - ), - }, -}; diff --git a/explorer/src/providers/transactions/details.tsx b/explorer/src/providers/transactions/details.tsx index 594627d842..5fc1e66f83 100644 --- a/explorer/src/providers/transactions/details.tsx +++ b/explorer/src/providers/transactions/details.tsx @@ -6,7 +6,6 @@ import { ParsedConfirmedTransaction, } from "@solana/web3.js"; import { useCluster, Cluster } from "../cluster"; -import { CACHED_DETAILS, isCached } from "./cached"; import * as Cache from "providers/cache"; import { ActionType, FetchStatus } from "providers/cache"; @@ -55,21 +54,16 @@ async function fetchDetails( let fetchStatus; let transaction; - if (isCached(url, signature)) { - transaction = CACHED_DETAILS[signature]; + try { + transaction = await new Connection(url).getParsedConfirmedTransaction( + signature + ); fetchStatus = FetchStatus.Fetched; - } else { - try { - transaction = await new Connection(url).getParsedConfirmedTransaction( - signature - ); - fetchStatus = FetchStatus.Fetched; - } catch (error) { - if (cluster !== Cluster.Custom) { - Sentry.captureException(error, { tags: { url } }); - } - fetchStatus = FetchStatus.FetchFailed; + } catch (error) { + if (cluster !== Cluster.Custom) { + Sentry.captureException(error, { tags: { url } }); } + fetchStatus = FetchStatus.FetchFailed; } dispatch({ type: ActionType.Update, diff --git a/explorer/src/providers/transactions/index.tsx b/explorer/src/providers/transactions/index.tsx index 50eb029569..44975a5a4c 100644 --- a/explorer/src/providers/transactions/index.tsx +++ b/explorer/src/providers/transactions/index.tsx @@ -9,7 +9,6 @@ import { useCluster, Cluster } from "../cluster"; import { DetailsProvider } from "./details"; import * as Cache from "providers/cache"; import { ActionType, FetchStatus } from "providers/cache"; -import { CACHED_STATUSES, isCached } from "./cached"; export { useTransactionDetails } from "./details"; export type Confirmations = number | "max"; @@ -68,54 +67,47 @@ export async function fetchTransactionStatus( let fetchStatus; let data; - if (isCached(url, signature)) { - const info = CACHED_STATUSES[signature]; + try { + const connection = new Connection(url); + const { value } = await connection.getSignatureStatus(signature, { + searchTransactionHistory: true, + }); + + let info = null; + if (value !== null) { + let blockTime = null; + try { + blockTime = await connection.getBlockTime(value.slot); + } catch (error) { + if (cluster === Cluster.MainnetBeta) { + Sentry.captureException(error, { + tags: { slot: `${value.slot}` }, + }); + } + } + let timestamp: Timestamp = blockTime !== null ? blockTime : "unavailable"; + + let confirmations: Confirmations; + if (typeof value.confirmations === "number") { + confirmations = value.confirmations; + } else { + confirmations = "max"; + } + + info = { + slot: value.slot, + timestamp, + confirmations, + result: { err: value.err }, + }; + } data = { signature, info }; fetchStatus = FetchStatus.Fetched; - } else { - try { - const connection = new Connection(url); - const { value } = await connection.getSignatureStatus(signature, { - searchTransactionHistory: true, - }); - - let info = null; - if (value !== null) { - let blockTime = null; - try { - blockTime = await connection.getBlockTime(value.slot); - } catch (error) { - if (cluster === Cluster.MainnetBeta) { - Sentry.captureException(error, { - tags: { slot: `${value.slot}` }, - }); - } - } - let timestamp: Timestamp = - blockTime !== null ? blockTime : "unavailable"; - - let confirmations: Confirmations; - if (typeof value.confirmations === "number") { - confirmations = value.confirmations; - } else { - confirmations = "max"; - } - - info = { - slot: value.slot, - timestamp, - confirmations, - result: { err: value.err }, - }; - } - data = { signature, info }; - fetchStatus = FetchStatus.Fetched; - } catch (error) { - if (cluster !== Cluster.Custom) { - Sentry.captureException(error, { tags: { url } }); - } - fetchStatus = FetchStatus.FetchFailed; + } catch (error) { + if (cluster !== Cluster.Custom) { + Sentry.captureException(error, { tags: { url } }); } + fetchStatus = FetchStatus.FetchFailed; } dispatch({