From 1314dc7cbe0b35d846f9cf279e842b662c4ad64c Mon Sep 17 00:00:00 2001 From: Izumi Hoshino Date: Tue, 8 Aug 2023 00:48:10 +0900 Subject: [PATCH] Plot filter value now is the function of height (#1979) --- .../components/harvest/HarvesterOverview.tsx | 16 +++++---- packages/gui/src/util/plot.ts | 34 ++++++++++++++++++- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/packages/gui/src/components/harvest/HarvesterOverview.tsx b/packages/gui/src/components/harvest/HarvesterOverview.tsx index 8361107772..c5e80392d5 100644 --- a/packages/gui/src/components/harvest/HarvesterOverview.tsx +++ b/packages/gui/src/components/harvest/HarvesterOverview.tsx @@ -1,16 +1,18 @@ -import { useGetHarvestersQuery, useGetNewFarmingInfoQuery } from '@chia-network/api-react'; -import { Flex, FormatBytes, FormatLargeNumber, CardSimple } from '@chia-network/core'; +import { useGetBlockchainStateQuery, useGetHarvestersQuery, useGetNewFarmingInfoQuery } from '@chia-network/api-react'; +import { Flex, FormatBytes, FormatLargeNumber, CardSimple, useCurrencyCode } from '@chia-network/core'; import { Trans } from '@lingui/macro'; import { Grid, Typography } from '@mui/material'; import BigNumber from 'bignumber.js'; import React from 'react'; -import { PLOT_FILTER } from '../../util/plot'; +import { getPlotFilter } from '../../util/plot'; import HarvesterDetail from './HarvesterDetail'; export default function HarvesterOverview() { + const { isLoading: isLoadingBlockchainState, data: blockChainState } = useGetBlockchainStateQuery(); const { isLoading: isLoadingHarvesters, data: harvesters } = useGetHarvestersQuery(); const { isLoading: isLoadingFarmingInfo, data } = useGetNewFarmingInfoQuery(); + const isTestnet = (useCurrencyCode() ?? 'XCH').toUpperCase() === 'TXCH'; const newFarmingInfo = data?.newFarmingInfo; const latencyData = data?.latencyData; @@ -88,18 +90,20 @@ export default function HarvesterOverview() { sumPassedFilter += passedFilter; } - const expectedAvgPassedFilter = Math.round((latestTotalPlots / PLOT_FILTER) * 1000) / 1000; + const peak = !isLoadingBlockchainState && blockChainState ? blockChainState.peak.height : 0; + const plotFilter = getPlotFilter(peak, isTestnet); + const expectedAvgPassedFilter = Math.round((latestTotalPlots / plotFilter) * 1000) / 1000; const avgPassedFilter = sps.length > 0 ? Math.round((sumPassedFilter / sps.length) * 1000) / 1000 : 0; return { tooltip: ( The average number of plots which passed filter over the last 64 signage points. It is expected to be{' '} - {expectedAvgPassedFilter} for total {latestTotalPlots} plots + {expectedAvgPassedFilter} for total {latestTotalPlots} plots. (Current plot filter: 1 / {plotFilter}) ), value: avgPassedFilter, }; - }, [newFarmingInfo]); + }, [newFarmingInfo, isTestnet, blockChainState, isLoadingBlockchainState]); const duplicatePlots = React.useMemo(() => { if (!harvesters) { diff --git a/packages/gui/src/util/plot.ts b/packages/gui/src/util/plot.ts index 1e84e7b784..0bda5a199a 100644 --- a/packages/gui/src/util/plot.ts +++ b/packages/gui/src/util/plot.ts @@ -1 +1,33 @@ -export const PLOT_FILTER = 512; +const PLOT_FILTER_CONSTANTS = { + mainnet: { + HARD_FORK_HEIGHT: 5_496_000, + PLOT_FILTER_128_HEIGHT: 10_542_000, + PLOT_FILTER_64_HEIGHT: 15_592_000, + PLOT_FILTER_32_HEIGHT: 20_643_000, + }, + testnet10: { + HARD_FORK_HEIGHT: 2_997_292, + PLOT_FILTER_128_HEIGHT: 3_061_804, + PLOT_FILTER_64_HEIGHT: 8_010_796, + PLOT_FILTER_32_HEIGHT: 13_056_556, + }, +}; + +export function getPlotFilter(height: number = 0, isTestnet: boolean = false) { + const constants = isTestnet ? PLOT_FILTER_CONSTANTS.testnet10 : PLOT_FILTER_CONSTANTS.mainnet; + let prefixBits = 9; + + if (height >= constants.PLOT_FILTER_32_HEIGHT) { + prefixBits -= 4; + } else if (height >= constants.PLOT_FILTER_64_HEIGHT) { + prefixBits -= 3; + } else if (height >= constants.PLOT_FILTER_128_HEIGHT) { + prefixBits -= 2; + } else if (height >= constants.HARD_FORK_HEIGHT) { + prefixBits -= 1; + } + + prefixBits = Math.max(0, prefixBits); + + return 2 ** prefixBits; +}