From 708d72524b0694726d253fef0b50618609504c1e Mon Sep 17 00:00:00 2001 From: Chen Yu Date: Thu, 14 Sep 2023 14:54:20 +0900 Subject: [PATCH 1/2] ci: remove actions of deployments (#100) The deployment has been migrated to vercel --- .github/workflows/_build_deploy.yml | 63 ----------------------------- .github/workflows/mainnet.yml | 15 ------- .github/workflows/testnet.yml | 15 ------- 3 files changed, 93 deletions(-) delete mode 100644 .github/workflows/_build_deploy.yml delete mode 100644 .github/workflows/mainnet.yml delete mode 100644 .github/workflows/testnet.yml diff --git a/.github/workflows/_build_deploy.yml b/.github/workflows/_build_deploy.yml deleted file mode 100644 index d0f5588a6..000000000 --- a/.github/workflows/_build_deploy.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: Pull, build, push and deploy -on: - workflow_call: - inputs: - ckb-mode: - required: true - type: string - k8s-namespace: - required: true - type: string - k8s-workload: - required: true - type: string - environment: - required: false - type: string - default: staging - secrets: - GHCR_USERNAME: - required: true - GHCR_TOKEN: - required: true - KUBOARD_USERNAME: - required: true - KUBOARD_ACCESS_KEY: - required: true - KUBOARD_API_URL: - required: true -jobs: - deploy: - runs-on: ubuntu-latest - environment: ${{ inputs.environment }} - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Build and push - id: docker_build - uses: mr-smithers-excellent/docker-build-push@v5 - with: - image: ckb-explorer-frontend - registry: ghcr.io - githubOrg: magickbase # optional - buildArgs: "API_URL=${{ secrets.API_URL }},CHAIN_TYPE=${{ inputs.ckb-mode }}" - enableBuildKit: true - username: ${{ secrets.GHCR_USERNAME }} - password: ${{ secrets.GHCR_TOKEN }} - - name: Update image on K8S - uses: fjogeleit/http-request-action@v1 - with: - url: ${{ secrets.KUBOARD_API_URL }}/cluster/ckb/kind/CICDApi/ops/resource/updateImageTag - method: 'PUT' - customHeaders: '{"Content-Type": "application/json", "Cookie": "KuboardUsername=${{ secrets.KUBOARD_USERNAME }}; KuboardAccessKey=${{ secrets.KUBOARD_ACCESS_KEY }}"}' - data: '{"kind":"deployments","namespace":"${{ inputs.k8s-namespace }}","name":"${{ inputs.k8s-workload }}","images":{"ckb-explorer-frontend":"${{ steps.docker_build.outputs.imageFullName }}:${{ steps.docker_build.outputs.tags }}"}}' - - name: Restart container - uses: fjogeleit/http-request-action@v1 - with: - url: ${{ secrets.KUBOARD_API_URL }}/cluster/ckb/kind/CICDApi/ops/resource/restartWorkload - method: 'PUT' - customHeaders: '{"Content-Type": "application/json", "Cookie": "KuboardUsername=${{ secrets.KUBOARD_USERNAME }}; KuboardAccessKey=${{ secrets.KUBOARD_ACCESS_KEY }}"}' - data: '{"kind":"deployments","namespace":"${{ inputs.k8s-namespace }}","name":"${{ inputs.k8s-workload }}"}' - - diff --git a/.github/workflows/mainnet.yml b/.github/workflows/mainnet.yml deleted file mode 100644 index 42c9dee55..000000000 --- a/.github/workflows/mainnet.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Deploy to mainnet - -on: - push: - branches: - - master -jobs: - deploy: - uses: ./.github/workflows/_build_deploy.yml - with: - ckb-mode: mainnet - k8s-namespace: mainnet - k8s-workload: ckb-explorer-front - environment: mainnet - secrets: inherit diff --git a/.github/workflows/testnet.yml b/.github/workflows/testnet.yml deleted file mode 100644 index cf20ae316..000000000 --- a/.github/workflows/testnet.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Deploy to testnet - -on: - push: - branches: - - testnet -jobs: - deploy: - uses: ./.github/workflows/_build_deploy.yml - with: - ckb-mode: testnet - k8s-namespace: testnet - k8s-workload: ckb-explorer-front - environment: testnet - secrets: inherit From 672233cc359113068bd7bb4a3af8211b87ca533c Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 14 Sep 2023 18:23:34 +0900 Subject: [PATCH 2/2] feat: add sample function for fee rate estimation --- .../FeeRateTracker/FeeRateTrackerComp.tsx | 3 +-- src/pages/FeeRateTracker/index.tsx | 11 +++++++- src/utils/chart.ts | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/pages/FeeRateTracker/FeeRateTrackerComp.tsx b/src/pages/FeeRateTracker/FeeRateTrackerComp.tsx index b2a2c801d..4170a8df6 100644 --- a/src/pages/FeeRateTracker/FeeRateTrackerComp.tsx +++ b/src/pages/FeeRateTracker/FeeRateTrackerComp.tsx @@ -41,8 +41,7 @@ const calcFeeRate = (tfrs: FeeRateTracker.TransactionFeeRate[]): string => const colors = ChartColor.moreColors export const FeeRateCards = ({ transactionFeeRates }: { transactionFeeRates: FeeRateTracker.TransactionFeeRate[] }) => { - const validFeeRateList = transactionFeeRates.filter(feeRate => feeRate.confirmationTime) - const allFrs = validFeeRateList.sort((a, b) => a.confirmationTime - b.confirmationTime) + const allFrs = transactionFeeRates.sort((a, b) => a.confirmationTime - b.confirmationTime) const avgConfirmationTime = getWeightedMedian(allFrs) const lowFrs = allFrs.filter(r => r.confirmationTime >= avgConfirmationTime) diff --git a/src/pages/FeeRateTracker/index.tsx b/src/pages/FeeRateTracker/index.tsx index 9b94874f0..25d78a6f0 100644 --- a/src/pages/FeeRateTracker/index.tsx +++ b/src/pages/FeeRateTracker/index.tsx @@ -12,8 +12,10 @@ import { LastNDaysTransactionFeeRateChart, } from './FeeRateTrackerComp' import Loading from '../../components/Loading' +import { useAppState } from '../../contexts/providers' import i18n from '../../utils/i18n' import { localeNumberString } from '../../utils/number' +import { getFeeRateSamples } from '../../utils/chart' const FeeRateTracker = () => { const lastFetchedTime = useRef(Number.MAX_SAFE_INTEGER) @@ -21,6 +23,8 @@ const FeeRateTracker = () => { const [secondAfterUpdate, setSecondAfterUpdate] = useState(0) const isMobile = useIsMobile() + const { statistics } = useAppState() + const { data: transactionFeesStatistic } = useQuery( ['statistics-transaction_fees'], () => @@ -62,7 +66,12 @@ const FeeRateTracker = () => {
{transactionFeesStatistic ? ( - + ) : ( )} diff --git a/src/utils/chart.ts b/src/utils/chart.ts index 1fe05fb1c..e76435b05 100644 --- a/src/utils/chart.ts +++ b/src/utils/chart.ts @@ -99,3 +99,29 @@ export const parseInterval = (max: number, min: number) => { const factor = 10 ** (length > 2 ? length - 2 : 0) return (Math.ceil(interval / factor) + 1) * factor } + +// This is a hotfix to avoid outliers in production environment, final algorithm will be decided later at +// https://github.com/Magickbase/ckb-explorer-public-issues/issues/394 +// TODO: add tests for the sample function +export const getFeeRateSamples = (feeRates: Array, TPM: number) => { + if (feeRates.length === 0) return feeRates + + const SAMPLES_MIN_COUNT = 100 + + const sampleCount = Math.max(SAMPLES_MIN_COUNT, Number.isNaN(TPM) ? 0 : Math.floor(TPM) * 10) + + const samples = feeRates + .filter(i => i.confirmationTime) + .sort((a, b) => a.confirmationTime - b.confirmationTime) + .reduce>((acc, cur) => { + const last = acc[acc.length - 1] + if (!last || last.feeRate >= cur.feeRate) { + return [...acc, cur] + } + return acc + }, []) + .sort((a, b) => b.timestamp - a.timestamp) + .slice(0, sampleCount) + + return samples +}