Skip to content

Commit

Permalink
Merge pull request #1983 from Chia-Network/checkpoint/main_from_relea…
Browse files Browse the repository at this point in the history
…se_2.0.0_1314dc7cbe0b35d846f9cf279e842b662c4ad64c
  • Loading branch information
paninaro authored Aug 7, 2023
2 parents c005ac1 + a4a8ac6 commit 8e920fe
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
16 changes: 10 additions & 6 deletions packages/gui/src/components/harvest/HarvesterOverview.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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: (
<Trans>
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})
</Trans>
),
value: avgPassedFilter,
};
}, [newFarmingInfo]);
}, [newFarmingInfo, isTestnet, blockChainState, isLoadingBlockchainState]);

const duplicatePlots = React.useMemo(() => {
if (!harvesters) {
Expand Down
34 changes: 33 additions & 1 deletion packages/gui/src/util/plot.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 8e920fe

Please sign in to comment.