From b456419de7fcca317e25c11247b5351fddb10152 Mon Sep 17 00:00:00 2001 From: Naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Fri, 11 Mar 2022 15:12:49 -0500 Subject: [PATCH 01/94] Create dependabot.yml Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- .github/dependabot.yml | 20 ++++++++++++++++++++ contributors/naveensrinivasan.txt | 3 +++ 2 files changed, 23 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 contributors/naveensrinivasan.txt diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..001ea3cb3 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,20 @@ +version: 2 +updates: +- package-ecosystem: npm + directory: "/backend" + schedule: + interval: daily + open-pull-requests-limit: 10 +- package-ecosystem: npm + directory: "/frontend" + schedule: + interval: daily + open-pull-requests-limit: 10 +- package-ecosystem: docker + directory: "/docker/backend" + schedule: + interval: weekly +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/contributors/naveensrinivasan.txt b/contributors/naveensrinivasan.txt new file mode 100644 index 000000000..84cdbdcdd --- /dev/null +++ b/contributors/naveensrinivasan.txt @@ -0,0 +1,3 @@ +I hereby accept the terms of the Contributor License Agreement in the CONTRIBUTING.md file of the mempool/mempool git repository as of March 11, 2022. + +Signed: naveensrinivasan From 8f8c22b8295538e7b15d0b62b5b571be4ced9033 Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Fri, 11 Mar 2022 22:48:15 +0000 Subject: [PATCH 02/94] Pin actions by SHA and set permissions for workflow - Pinned dependencies https://github.com/ossf/scorecard/blob/main/docs/checks.md#pinned-dependencies - Restricting permissions for github actions https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions --- .github/workflows/on-tag.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/on-tag.yml b/.github/workflows/on-tag.yml index a7a9929d9..da30f0641 100644 --- a/.github/workflows/on-tag.yml +++ b/.github/workflows/on-tag.yml @@ -11,6 +11,9 @@ on: - v[0-9]+.[0-9]+.[0-9]+ - v[0-9]+.[0-9]+.[0-9]+-* +permissions: + contents: read + jobs: build: strategy: @@ -35,24 +38,24 @@ jobs: run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin - name: Checkout project - uses: actions/checkout@v2 + uses: actions/checkout@629c2de402a417ea7690ca6ce3f33229e27606a5 # v2 - name: Init repo for Dockerization run: docker/init.sh "$TAG" - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@27d0a4f181a40b142cce983c5393082c365d1480 # v1 id: qemu - name: Setup Docker buildx action - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25 # v1 id: buildx - name: Available platforms run: echo ${{ steps.buildx.outputs.platforms }} - name: Cache Docker layers - uses: actions/cache@v2 + uses: actions/cache@661fd3eb7f2f20d8c7c84bc2b0509efd7a826628 # v2 id: cache with: path: /tmp/.buildx-cache From 74f4a6fcb443f87ae22bde7f341ea428b76296d5 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Mon, 21 Mar 2022 21:19:12 +0900 Subject: [PATCH 03/94] Work using native javascript milliseconds timestamp --- backend/src/api/mining.ts | 58 +++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/backend/src/api/mining.ts b/backend/src/api/mining.ts index b16a406cb..0946db15c 100644 --- a/backend/src/api/mining.ts +++ b/backend/src/api/mining.ts @@ -79,9 +79,9 @@ class Mining { } // We only run this once a week - const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_weekly_hashrates_indexing'); + const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_weekly_hashrates_indexing') * 1000; const now = new Date(); - if ((now.getTime() / 1000) - latestTimestamp < 604800) { + if (now.getTime() - latestTimestamp < 604800000) { return; } @@ -96,19 +96,19 @@ class Mining { const lastMonday = new Date(now.setDate(now.getDate() - (now.getDay() + 6) % 7)); const lastMondayMidnight = this.getDateMidnight(lastMonday); - let toTimestamp = Math.round((lastMondayMidnight.getTime() - 604800) / 1000); + let toTimestamp = Math.round((lastMondayMidnight.getTime() - 604800000)); const totalWeekIndexed = (await BlocksRepository.$blockCount(null, null)) / 1008; let indexedThisRun = 0; let totalIndexed = 0; - let startedAt = new Date().getTime() / 1000; + let startedAt = new Date().getTime(); while (toTimestamp > genesisTimestamp) { - const fromTimestamp = toTimestamp - 604800; + const fromTimestamp = toTimestamp - 604800000; // Skip already indexed weeks - if (indexedTimestamp.includes(toTimestamp)) { - toTimestamp -= 604800; + if (indexedTimestamp.includes(toTimestamp / 1000)) { + toTimestamp -= 604800000; ++totalIndexed; continue; } @@ -116,17 +116,17 @@ class Mining { // Check if we have blocks for the previous week (which mean that the week // we are currently indexing has complete data) const blockStatsPreviousWeek: any = await BlocksRepository.$blockCountBetweenTimestamp( - null, fromTimestamp - 604800, toTimestamp - 604800); + null, fromTimestamp - 604800000, toTimestamp - 604800000); if (blockStatsPreviousWeek.blockCount === 0) { // We are done indexing break; } const blockStats: any = await BlocksRepository.$blockCountBetweenTimestamp( - null, fromTimestamp, toTimestamp); + null, fromTimestamp / 1000, toTimestamp / 1000); const lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount, blockStats.lastBlockHeight); - let pools = await PoolsRepository.$getPoolsInfoBetween(fromTimestamp, toTimestamp); + let pools = await PoolsRepository.$getPoolsInfoBetween(fromTimestamp / 1000, toTimestamp / 1000); const totalBlocks = pools.reduce((acc, pool) => acc + pool.blockCount, 0); pools = pools.map((pool: any) => { pool.hashrate = (pool.blockCount / totalBlocks) * lastBlockHashrate; @@ -136,7 +136,7 @@ class Mining { for (const pool of pools) { hashrates.push({ - hashrateTimestamp: toTimestamp, + hashrateTimestamp: toTimestamp / 1000, avgHashrate: pool['hashrate'], poolId: pool.poolId, share: pool['share'], @@ -147,17 +147,17 @@ class Mining { await HashratesRepository.$saveHashrates(hashrates); hashrates.length = 0; - const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt)); + const elapsedSeconds = Math.max(1, Math.round((new Date().getTime()) - startedAt)); if (elapsedSeconds > 1) { const weeksPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2); - const formattedDate = new Date(fromTimestamp * 1000).toUTCString(); + const formattedDate = new Date(fromTimestamp).toUTCString(); const weeksLeft = Math.round(totalWeekIndexed - totalIndexed); logger.debug(`Getting weekly pool hashrate for ${formattedDate} | ~${weeksPerSeconds} weeks/sec | ~${weeksLeft} weeks left to index`); - startedAt = new Date().getTime() / 1000; + startedAt = new Date().getTime(); indexedThisRun = 0; } - toTimestamp -= 604800; + toTimestamp -= 604800000; ++indexedThisRun; ++totalIndexed; } @@ -180,8 +180,8 @@ class Mining { // We only run this once a day const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_hashrates_indexing'); - const now = new Date().getTime() / 1000; - if (now - latestTimestamp < 86400) { + const now = new Date().getTime(); + if (now - latestTimestamp < 86400000) { return; } @@ -193,20 +193,20 @@ class Mining { const indexedTimestamp = (await HashratesRepository.$getNetworkDailyHashrate(null)).map(hashrate => hashrate.timestamp); const genesisTimestamp = 1231006505; // bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f const lastMidnight = this.getDateMidnight(new Date()); - let toTimestamp = Math.round(lastMidnight.getTime() / 1000); + let toTimestamp = Math.round(lastMidnight.getTime()); const hashrates: any[] = []; const totalDayIndexed = (await BlocksRepository.$blockCount(null, null)) / 144; let indexedThisRun = 0; let totalIndexed = 0; - let startedAt = new Date().getTime() / 1000; + let startedAt = new Date().getTime(); while (toTimestamp > genesisTimestamp) { - const fromTimestamp = toTimestamp - 86400; + const fromTimestamp = toTimestamp - 86400000; // Skip already indexed weeks - if (indexedTimestamp.includes(toTimestamp)) { - toTimestamp -= 86400; + if (indexedTimestamp.includes(toTimestamp / 1000)) { + toTimestamp -= 86400000; ++totalIndexed; continue; } @@ -214,18 +214,18 @@ class Mining { // Check if we have blocks for the previous day (which mean that the day // we are currently indexing has complete data) const blockStatsPreviousDay: any = await BlocksRepository.$blockCountBetweenTimestamp( - null, fromTimestamp - 86400, toTimestamp - 86400); + null, fromTimestamp - 86400000, toTimestamp - 86400000); if (blockStatsPreviousDay.blockCount === 0) { // We are done indexing break; } const blockStats: any = await BlocksRepository.$blockCountBetweenTimestamp( - null, fromTimestamp, toTimestamp); + null, fromTimestamp / 1000, toTimestamp / 1000); const lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount, blockStats.lastBlockHeight); hashrates.push({ - hashrateTimestamp: toTimestamp, + hashrateTimestamp: toTimestamp / 1000, avgHashrate: lastBlockHashrate, poolId: 0, share: 1, @@ -237,17 +237,17 @@ class Mining { hashrates.length = 0; } - const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt)); + const elapsedSeconds = Math.max(1, Math.round(new Date().getTime() - startedAt)); if (elapsedSeconds > 1) { const daysPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2); - const formattedDate = new Date(fromTimestamp * 1000).toUTCString(); + const formattedDate = new Date(fromTimestamp).toUTCString(); const daysLeft = Math.round(totalDayIndexed - totalIndexed); logger.debug(`Getting network daily hashrate for ${formattedDate} | ~${daysPerSeconds} days/sec | ~${daysLeft} days left to index`); - startedAt = new Date().getTime() / 1000; + startedAt = new Date().getTime(); indexedThisRun = 0; } - toTimestamp -= 86400; + toTimestamp -= 86400000; ++indexedThisRun; ++totalIndexed; } From e5fd92b734adc6c05dc0d841e90a72cd3956bde6 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Tue, 22 Mar 2022 09:20:16 +0900 Subject: [PATCH 04/94] Most recent week was missing from indexing - Post merge fixes --- backend/src/api/mining.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/api/mining.ts b/backend/src/api/mining.ts index 0946db15c..480060afe 100644 --- a/backend/src/api/mining.ts +++ b/backend/src/api/mining.ts @@ -92,11 +92,11 @@ class Mining { const indexedTimestamp = await HashratesRepository.$getWeeklyHashrateTimestamps(); const hashrates: any[] = []; - const genesisTimestamp = 1231006505; // bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f + const genesisTimestamp = 1231006505000; // bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f const lastMonday = new Date(now.setDate(now.getDate() - (now.getDay() + 6) % 7)); const lastMondayMidnight = this.getDateMidnight(lastMonday); - let toTimestamp = Math.round((lastMondayMidnight.getTime() - 604800000)); + let toTimestamp = lastMondayMidnight.getTime(); const totalWeekIndexed = (await BlocksRepository.$blockCount(null, null)) / 1008; let indexedThisRun = 0; @@ -116,7 +116,7 @@ class Mining { // Check if we have blocks for the previous week (which mean that the week // we are currently indexing has complete data) const blockStatsPreviousWeek: any = await BlocksRepository.$blockCountBetweenTimestamp( - null, fromTimestamp - 604800000, toTimestamp - 604800000); + null, (fromTimestamp - 604800000) / 1000, (toTimestamp - 604800000) / 1000); if (blockStatsPreviousWeek.blockCount === 0) { // We are done indexing break; } @@ -191,7 +191,7 @@ class Mining { logger.info(`Indexing network daily hashrate`); const indexedTimestamp = (await HashratesRepository.$getNetworkDailyHashrate(null)).map(hashrate => hashrate.timestamp); - const genesisTimestamp = 1231006505; // bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f + const genesisTimestamp = 1231006505000; // bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f const lastMidnight = this.getDateMidnight(new Date()); let toTimestamp = Math.round(lastMidnight.getTime()); const hashrates: any[] = []; @@ -214,7 +214,7 @@ class Mining { // Check if we have blocks for the previous day (which mean that the day // we are currently indexing has complete data) const blockStatsPreviousDay: any = await BlocksRepository.$blockCountBetweenTimestamp( - null, fromTimestamp - 86400000, toTimestamp - 86400000); + null, (fromTimestamp - 86400000) / 1000, (toTimestamp - 86400000) / 1000); if (blockStatsPreviousDay.blockCount === 0) { // We are done indexing break; } From e1623b92341a4b1b74784271757808d1766467f6 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Tue, 22 Mar 2022 15:16:15 +0900 Subject: [PATCH 05/94] Fix blocks list pagination on mobile --- .../src/app/components/blocks-list/blocks-list.component.html | 2 +- .../src/app/components/blocks-list/blocks-list.component.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/components/blocks-list/blocks-list.component.html b/frontend/src/app/components/blocks-list/blocks-list.component.html index d0eaa25ea..d582b32fe 100644 --- a/frontend/src/app/components/blocks-list/blocks-list.component.html +++ b/frontend/src/app/components/blocks-list/blocks-list.component.html @@ -91,7 +91,7 @@ diff --git a/frontend/src/app/components/blocks-list/blocks-list.component.ts b/frontend/src/app/components/blocks-list/blocks-list.component.ts index c04403446..9da92f158 100644 --- a/frontend/src/app/components/blocks-list/blocks-list.component.ts +++ b/frontend/src/app/components/blocks-list/blocks-list.component.ts @@ -22,6 +22,7 @@ export class BlocksList implements OnInit { paginationMaxSize: number; page = 1; lastPage = 1; + maxSize = window.innerWidth <= 767.98 ? 3 : 5; blocksCount: number; fromHeightSubject: BehaviorSubject = new BehaviorSubject(this.fromBlockHeight); skeletonLines: number[] = []; From 7c1155ec93b3b28f6d9e8d8a56b21cbd9ce3b178 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Tue, 22 Mar 2022 15:43:04 +0900 Subject: [PATCH 06/94] Make sure blocks list container is at least 100vh on mobile --- .../app/components/blocks-list/blocks-list.component.html | 2 +- frontend/src/styles.scss | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/components/blocks-list/blocks-list.component.html b/frontend/src/app/components/blocks-list/blocks-list.component.html index d582b32fe..23cf9899c 100644 --- a/frontend/src/app/components/blocks-list/blocks-list.component.html +++ b/frontend/src/app/components/blocks-list/blocks-list.component.html @@ -1,4 +1,4 @@ -
+

Blocks

diff --git a/frontend/src/styles.scss b/frontend/src/styles.scss index 54476206c..b56d7848d 100644 --- a/frontend/src/styles.scss +++ b/frontend/src/styles.scss @@ -66,6 +66,11 @@ body { .container-xl { padding-bottom: 60px; } +.full-height { + @media (max-width: 767.98px) { + min-height: 100vh; + } +} :focus { outline: none !important; From f88af9c3f94ed1de49b87e70b623963030717d3a Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Wed, 23 Mar 2022 12:16:21 -0700 Subject: [PATCH 07/94] Add the DOCKER_COMMIT_HASH env var to the backend Dockerfile --- docker/backend/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/backend/Dockerfile b/docker/backend/Dockerfile index ceddc9000..c013fc23a 100644 --- a/docker/backend/Dockerfile +++ b/docker/backend/Dockerfile @@ -1,5 +1,8 @@ FROM node:16.10.0-buster-slim AS builder +ARG commitHash +ENV DOCKER_COMMIT_HASH=${commitHash} + WORKDIR /build COPY . . From 4bb6f499504f160079ff64e7c15e3075262b1b7d Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Wed, 23 Mar 2022 12:17:23 -0700 Subject: [PATCH 08/94] Copy the git commit hash logic to the backend --- backend/src/api/backend-info.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/backend/src/api/backend-info.ts b/backend/src/api/backend-info.ts index 5a556ef18..3dde6ea47 100644 --- a/backend/src/api/backend-info.ts +++ b/backend/src/api/backend-info.ts @@ -2,6 +2,7 @@ import * as fs from 'fs'; import * as os from 'os'; import logger from '../logger'; import { IBackendInfo } from '../mempool.interfaces'; +const { spawnSync } = require('child_process'); class BackendInfo { private gitCommitHash = ''; @@ -27,10 +28,24 @@ class BackendInfo { } private setLatestCommitHash(): void { - try { - this.gitCommitHash = fs.readFileSync('../.git/refs/heads/master').toString().trim(); - } catch (e) { - logger.err('Could not load git commit info: ' + (e instanceof Error ? e.message : e)); + //TODO: share this logic with `generate-config.js` + if (process.env.DOCKER_COMMIT_HASH) { + this.gitCommitHash = process.env.DOCKER_COMMIT_HASH; + } else { + try { + const gitRevParse = spawnSync('git', ['rev-parse', '--short', 'HEAD']); + + if (!gitRevParse.error) { + this.gitCommitHash = gitRevParse.stdout.toString('utf-8').replace(/[\n\r\s]+$/, ''); + console.log(`mempool revision ${this.gitCommitHash}`); + } else if (gitRevParse.error.code === 'ENOENT') { + console.log('git not found, cannot parse git hash'); + this.gitCommitHash = '?'; + } + } catch (e: any) { + console.log('Could not load git commit info: ' + e.message); + this.gitCommitHash = '?'; + } } } From 230fbdbc8ea739f5ca26c430a47ca014b919917c Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Wed, 23 Mar 2022 12:33:15 -0700 Subject: [PATCH 09/94] Fix empty revision case --- backend/src/api/backend-info.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/backend/src/api/backend-info.ts b/backend/src/api/backend-info.ts index 3dde6ea47..d98675671 100644 --- a/backend/src/api/backend-info.ts +++ b/backend/src/api/backend-info.ts @@ -34,10 +34,9 @@ class BackendInfo { } else { try { const gitRevParse = spawnSync('git', ['rev-parse', '--short', 'HEAD']); - if (!gitRevParse.error) { - this.gitCommitHash = gitRevParse.stdout.toString('utf-8').replace(/[\n\r\s]+$/, ''); - console.log(`mempool revision ${this.gitCommitHash}`); + const output = gitRevParse.stdout.toString('utf-8').replace(/[\n\r\s]+$/, ''); + this.gitCommitHash = output ? output : '?'; } else if (gitRevParse.error.code === 'ENOENT') { console.log('git not found, cannot parse git hash'); this.gitCommitHash = '?'; From 9c3fc9f75a23ca99fdee2f632ec8718e702640b3 Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Wed, 23 Mar 2022 12:33:47 -0700 Subject: [PATCH 10/94] Update frontend git commit hash logic --- frontend/generate-config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/generate-config.js b/frontend/generate-config.js index 617ab3c0e..1f37953b7 100644 --- a/frontend/generate-config.js +++ b/frontend/generate-config.js @@ -51,9 +51,9 @@ if (process.env.DOCKER_COMMIT_HASH) { } else { try { const gitRevParse = spawnSync('git', ['rev-parse', '--short', 'HEAD']); - if (!gitRevParse.error) { - gitCommitHash = gitRevParse.stdout.toString('utf-8').replace(/[\n\r\s]+$/, ''); + const output = gitRevParse.stdout.toString('utf-8').replace(/[\n\r\s]+$/, ''); + gitCommitHash = output ? output : '?'; console.log(`mempool revision ${gitCommitHash}`); } else if (gitRevParse.error.code === 'ENOENT') { console.log('git not found, cannot parse git hash'); From dcaa7fc4e8293effbbbb60c2d6f417b40997267b Mon Sep 17 00:00:00 2001 From: softsimon Date: Thu, 24 Mar 2022 00:24:17 +0400 Subject: [PATCH 11/94] Last hashrate indexing check needs to be in milliseconds --- backend/src/api/mining.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/api/mining.ts b/backend/src/api/mining.ts index 76d497cb5..75fea9768 100644 --- a/backend/src/api/mining.ts +++ b/backend/src/api/mining.ts @@ -186,7 +186,7 @@ class Mining { } // We only run this once a day - const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_hashrates_indexing'); + const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_hashrates_indexing') * 1000; const now = new Date().getTime(); if (now - latestTimestamp < 86400000) { return; From 185dddd8c747f33d8c5f2e10f348015dcd655d16 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Thu, 24 Mar 2022 07:40:03 +0900 Subject: [PATCH 12/94] Truncate hashrates after #1435 - Fix hashrate indexing logs --- backend/src/api/database-migration.ts | 7 ++++++- backend/src/api/mining.ts | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index ffa9041e3..20519cbf2 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -6,7 +6,7 @@ import logger from '../logger'; const sleep = (ms: number) => new Promise(res => setTimeout(res, ms)); class DatabaseMigration { - private static currentVersion = 15; + private static currentVersion = 16; private queryTimeout = 120000; private statisticsAddedIndexed = false; @@ -175,6 +175,11 @@ class DatabaseMigration { await this.$executeQuery(connection, 'ALTER TABLE `hashrates` MODIFY `pool_id` SMALLINT UNSIGNED NOT NULL DEFAULT "0"'); } + if (databaseSchemaVersion < 16 && isBitcoin === true) { + logger.warn(`'hashrates' table has been truncated. Re-indexing from scratch.`); + await this.$executeQuery(connection, 'TRUNCATE hashrates;'); // Need to re-index because we changed timestamps + } + connection.release(); } catch (e) { connection.release(); diff --git a/backend/src/api/mining.ts b/backend/src/api/mining.ts index 75fea9768..35884efb3 100644 --- a/backend/src/api/mining.ts +++ b/backend/src/api/mining.ts @@ -154,7 +154,7 @@ class Mining { await HashratesRepository.$saveHashrates(hashrates); hashrates.length = 0; - const elapsedSeconds = Math.max(1, Math.round((new Date().getTime()) - startedAt)); + const elapsedSeconds = Math.max(1, Math.round((new Date().getTime()) - startedAt)) / 1000; if (elapsedSeconds > 1) { const weeksPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2); const formattedDate = new Date(fromTimestamp).toUTCString(); @@ -244,7 +244,7 @@ class Mining { hashrates.length = 0; } - const elapsedSeconds = Math.max(1, Math.round(new Date().getTime() - startedAt)); + const elapsedSeconds = Math.max(1, Math.round(new Date().getTime() - startedAt)) / 1000; if (elapsedSeconds > 1) { const daysPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2); const formattedDate = new Date(fromTimestamp).toUTCString(); From f1bb742341508fcadb92bcd4278be9fee822a188 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Thu, 24 Mar 2022 18:03:12 +0900 Subject: [PATCH 13/94] Fix rounding issue in reward stats --- .../app/components/reward-stats/reward-stats.component.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/components/reward-stats/reward-stats.component.ts b/frontend/src/app/components/reward-stats/reward-stats.component.ts index dd466985e..8116f2db7 100644 --- a/frontend/src/app/components/reward-stats/reward-stats.component.ts +++ b/frontend/src/app/components/reward-stats/reward-stats.component.ts @@ -24,10 +24,11 @@ export class RewardStatsComponent implements OnInit { return this.apiService.getRewardStats$() .pipe( map((stats) => { + const precision = 100; return { totalReward: stats.totalReward, - rewardPerTx: stats.totalReward / stats.totalTx, - feePerTx: stats.totalFee / stats.totalTx, + rewardPerTx: Math.round((stats.totalReward / stats.totalTx) * precision) / precision, + feePerTx: Math.round((stats.totalFee / stats.totalTx) * precision) / precision, }; }) ); From bb0fd78f2857e0568cfafa7fe3f9d292f4b05e68 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Thu, 24 Mar 2022 19:44:22 +0900 Subject: [PATCH 14/94] Added slug into `pools` table --- backend/src/api/database-migration.ts | 6 +++++- backend/src/api/pools-parser.ts | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index 20519cbf2..3978a7d85 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -6,7 +6,7 @@ import logger from '../logger'; const sleep = (ms: number) => new Promise(res => setTimeout(res, ms)); class DatabaseMigration { - private static currentVersion = 16; + private static currentVersion = 17; private queryTimeout = 120000; private statisticsAddedIndexed = false; @@ -180,6 +180,10 @@ class DatabaseMigration { await this.$executeQuery(connection, 'TRUNCATE hashrates;'); // Need to re-index because we changed timestamps } + if (databaseSchemaVersion < 17 && isBitcoin === true) { + await this.$executeQuery(connection, 'ALTER TABLE `pools` ADD `slug` CHAR(50) NULL'); + } + connection.release(); } catch (e) { connection.release(); diff --git a/backend/src/api/pools-parser.ts b/backend/src/api/pools-parser.ts index ff70c3cb9..5428f931d 100644 --- a/backend/src/api/pools-parser.ts +++ b/backend/src/api/pools-parser.ts @@ -8,6 +8,7 @@ interface Pool { link: string; regexes: string[]; addresses: string[]; + slug: string; } class PoolsParser { @@ -42,6 +43,7 @@ class PoolsParser { 'link': (coinbaseTags[i][1]).link, 'regexes': [coinbaseTags[i][0]], 'addresses': [], + 'slug': '' }); } logger.debug('Parse payout_addresses'); @@ -52,6 +54,7 @@ class PoolsParser { 'link': (addressesTags[i][1]).link, 'regexes': [], 'addresses': [addressesTags[i][0]], + 'slug': '' }); } @@ -90,14 +93,15 @@ class PoolsParser { } const finalPoolName = poolNames[i].replace(`'`, `''`); // To support single quote in names when doing db queries + const slug = poolsJson['slugs'][poolNames[i]]; if (existingPools.find((pool) => pool.name === poolNames[i]) !== undefined) { - logger.debug(`Update '${finalPoolName}' mining pool`); finalPoolDataUpdate.push({ 'name': finalPoolName, 'link': match[0].link, 'regexes': allRegexes, 'addresses': allAddresses, + 'slug': slug }); } else { logger.debug(`Add '${finalPoolName}' mining pool`); @@ -106,6 +110,7 @@ class PoolsParser { 'link': match[0].link, 'regexes': allRegexes, 'addresses': allAddresses, + 'slug': slug }); } } @@ -126,7 +131,8 @@ class PoolsParser { updateQueries.push(` UPDATE pools SET name='${finalPoolDataUpdate[i].name}', link='${finalPoolDataUpdate[i].link}', - regexes='${JSON.stringify(finalPoolDataUpdate[i].regexes)}', addresses='${JSON.stringify(finalPoolDataUpdate[i].addresses)}' + regexes='${JSON.stringify(finalPoolDataUpdate[i].regexes)}', addresses='${JSON.stringify(finalPoolDataUpdate[i].addresses)}', + slug='${finalPoolDataUpdate[i].slug}' WHERE name='${finalPoolDataUpdate[i].name}' ;`); } @@ -156,11 +162,17 @@ class PoolsParser { try { const [rows]: any[] = await connection.query({ sql: 'SELECT name from pools where name="Unknown"', timeout: 120000 }); if (rows.length === 0) { - logger.debug('Manually inserting "Unknown" mining pool into the databse'); await connection.query({ sql: `INSERT INTO pools(name, link, regexes, addresses) - VALUES("Unknown", "https://learnmeabitcoin.com/technical/coinbase-transaction", "[]", "[]"); + VALUES("Unknown", "https://learnmeabitcoin.com/technical/coinbase-transaction", "[]", "[]", "unknown"); `}); + } else { + await connection.query(`UPDATE pools + SET name='Unknown', link='https://learnmeabitcoin.com/technical/coinbase-transaction', + regexes='[]', addresses='[]', + slug='unknown' + WHERE name='Unknown' + `) } } catch (e) { logger.err('Unable to insert "Unknown" mining pool'); From 37e2786c5e55595e56e07d2bcd6e8514d0c5899d Mon Sep 17 00:00:00 2001 From: hunicus <93150691+hunicus@users.noreply.github.com> Date: Thu, 24 Mar 2022 08:55:20 -0400 Subject: [PATCH 15/94] Add faq tab placeholder --- frontend/src/app/app-routing.module.ts | 4 ++++ .../src/app/components/docs/docs.component.html | 17 +++++++++++++---- .../src/app/components/docs/docs.component.ts | 11 ++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index 003bbcf0d..37fb1d62d 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -127,6 +127,10 @@ let routes: Routes = [ path: 'docs/api/:type', component: DocsComponent }, + { + path: 'docs/faq', + component: DocsComponent + }, { path: 'docs/api', redirectTo: 'docs/api/rest' diff --git a/frontend/src/app/components/docs/docs.component.html b/frontend/src/app/components/docs/docs.component.html index 8dc4a9e72..d6b43f064 100644 --- a/frontend/src/app/components/docs/docs.component.html +++ b/frontend/src/app/components/docs/docs.component.html @@ -4,9 +4,18 @@

Documentation