From b56f110f28099e8e6f9c9d6ef4131c56141e08ba Mon Sep 17 00:00:00 2001 From: nymkappa Date: Sat, 30 Apr 2022 17:54:49 +0900 Subject: [PATCH 1/6] Run hashrate indexing after midnight --- backend/src/api/mining.ts | 22 ++++++++++--------- backend/src/index.ts | 4 ++-- .../src/repositories/HashratesRepository.ts | 18 +++++++-------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/backend/src/api/mining.ts b/backend/src/api/mining.ts index 94191a09f..2c7530643 100644 --- a/backend/src/api/mining.ts +++ b/backend/src/api/mining.ts @@ -139,10 +139,13 @@ class Mining { try { this.weeklyHashrateIndexingStarted = true; + const lastestRunDate = await HashratesRepository.$getLatestRun('last_weekly_hashrates_indexing'); - // We only run this once a week - const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_weekly_hashrates_indexing') * 1000; - if (now.getTime() - latestTimestamp < 604800000) { + // Run only if: + // * lastestRunDate is set to 0 (node backend restart, reorg) + // * we started a new week (around Monday midnight) + const runIndexing = lastestRunDate === 0 || now.getUTCDay() === 1 && lastestRunDate !== now.getUTCDate(); + if (!runIndexing) { this.weeklyHashrateIndexingStarted = false; return; } @@ -226,7 +229,7 @@ class Mining { ++totalIndexed; } this.weeklyHashrateIndexingStarted = false; - await HashratesRepository.$setLatestRunTimestamp('last_weekly_hashrates_indexing'); + await HashratesRepository.$setLatestRun('last_weekly_hashrates_indexing', new Date().getUTCDate()); if (newlyIndexed > 0) { logger.info(`Indexed ${newlyIndexed} pools weekly hashrate`); } @@ -244,14 +247,13 @@ class Mining { return; } - const now = new Date().getTime(); - try { this.hashrateIndexingStarted = true; - // We only run this once a day - const latestTimestamp = await HashratesRepository.$getLatestRunTimestamp('last_hashrates_indexing') * 1000; - if (now - latestTimestamp < 86400000) { + // We only run this once a day around midnight + const latestRunDate = await HashratesRepository.$getLatestRun('last_hashrates_indexing'); + const now = new Date().getUTCDate(); + if (now === latestRunDate) { this.hashrateIndexingStarted = false; return; } @@ -339,7 +341,7 @@ class Mining { newlyIndexed += hashrates.length; await HashratesRepository.$saveHashrates(hashrates); - await HashratesRepository.$setLatestRunTimestamp('last_hashrates_indexing'); + await HashratesRepository.$setLatestRun('last_hashrates_indexing', new Date().getUTCDate()); this.hashrateIndexingStarted = false; if (newlyIndexed > 0) { logger.info(`Indexed ${newlyIndexed} day of network hashrate`); diff --git a/backend/src/index.ts b/backend/src/index.ts index 7bf213a81..b44bc6369 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -174,8 +174,8 @@ class Server { async $resetHashratesIndexingState() { try { - await HashratesRepository.$setLatestRunTimestamp('last_hashrates_indexing', 0); - await HashratesRepository.$setLatestRunTimestamp('last_weekly_hashrates_indexing', 0); + await HashratesRepository.$setLatestRun('last_hashrates_indexing', 0); + await HashratesRepository.$setLatestRun('last_weekly_hashrates_indexing', 0); } catch (e) { logger.err(`Cannot reset hashrate indexing timestamps. Reason: ` + (e instanceof Error ? e.message : e)); } diff --git a/backend/src/repositories/HashratesRepository.ts b/backend/src/repositories/HashratesRepository.ts index 3ec1a8d28..661535aa3 100644 --- a/backend/src/repositories/HashratesRepository.ts +++ b/backend/src/repositories/HashratesRepository.ts @@ -147,13 +147,13 @@ class HashratesRepository { /** * Set latest run timestamp */ - public async $setLatestRunTimestamp(key: string, val: any = null) { + public async $setLatestRun(key: string, val: number) { const query = `UPDATE state SET number = ? WHERE name = ?`; try { - await DB.query(query, (val === null) ? [Math.round(new Date().getTime() / 1000), key] : [val, key]); + await DB.query(query, [val, key]); } catch (e) { - logger.err(`Cannot set last indexing timestamp for ${key}. Reason: ` + (e instanceof Error ? e.message : e)); + logger.err(`Cannot set last indexing run for ${key}. Reason: ` + (e instanceof Error ? e.message : e)); throw e; } } @@ -161,7 +161,7 @@ class HashratesRepository { /** * Get latest run timestamp */ - public async $getLatestRunTimestamp(key: string): Promise { + public async $getLatestRun(key: string): Promise { const query = `SELECT number FROM state WHERE name = ?`; try { @@ -172,7 +172,7 @@ class HashratesRepository { } return rows[0]['number']; } catch (e) { - logger.err(`Cannot retreive last indexing timestamp for ${key}. Reason: ` + (e instanceof Error ? e.message : e)); + logger.err(`Cannot retrieve last indexing run for ${key}. Reason: ` + (e instanceof Error ? e.message : e)); throw e; } } @@ -189,8 +189,8 @@ class HashratesRepository { await DB.query(`DELETE FROM hashrates WHERE hashrate_timestamp = ?`, [row.timestamp]); } // Re-run the hashrate indexing to fill up missing data - await this.$setLatestRunTimestamp('last_hashrates_indexing', 0); - await this.$setLatestRunTimestamp('last_weekly_hashrates_indexing', 0); + await this.$setLatestRun('last_hashrates_indexing', 0); + await this.$setLatestRun('last_weekly_hashrates_indexing', 0); } catch (e) { logger.err('Cannot delete latest hashrates data points. Reason: ' + (e instanceof Error ? e.message : e)); } @@ -205,8 +205,8 @@ class HashratesRepository { try { await DB.query(`DELETE FROM hashrates WHERE hashrate_timestamp >= FROM_UNIXTIME(?)`, [timestamp]); // Re-run the hashrate indexing to fill up missing data - await this.$setLatestRunTimestamp('last_hashrates_indexing', 0); - await this.$setLatestRunTimestamp('last_weekly_hashrates_indexing', 0); + await this.$setLatestRun('last_hashrates_indexing', 0); + await this.$setLatestRun('last_weekly_hashrates_indexing', 0); } catch (e) { logger.err('Cannot delete latest hashrates data points. Reason: ' + (e instanceof Error ? e.message : e)); } From 222696f85936372fb9a9e84203131eb2bf1b781f Mon Sep 17 00:00:00 2001 From: Antoni Spaanderman <56turtle56@gmail.com> Date: Tue, 3 May 2022 17:26:32 +0200 Subject: [PATCH 2/6] fix lightning force close label with CSV delay <= 16 --- .../app/components/address-labels/address-labels.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/components/address-labels/address-labels.component.ts b/frontend/src/app/components/address-labels/address-labels.component.ts index b22d66e42..36532b835 100644 --- a/frontend/src/app/components/address-labels/address-labels.component.ts +++ b/frontend/src/app/components/address-labels/address-labels.component.ts @@ -42,7 +42,7 @@ export class AddressLabelsComponent implements OnInit { } const topElement = this.vin.witness[this.vin.witness.length - 2]; - if (/^OP_IF OP_PUSHBYTES_33 \w{66} OP_ELSE OP_PUSHBYTES_(1 \w{2}|2 \w{4}) OP_CSV OP_DROP OP_PUSHBYTES_33 \w{66} OP_ENDIF OP_CHECKSIG$/.test(this.vin.inner_witnessscript_asm)) { + if (/^OP_IF OP_PUSHBYTES_33 \w{66} OP_ELSE OP_PUSH(NUM_\d+|BYTES_(1 \w{2}|2 \w{4})) OP_CSV OP_DROP OP_PUSHBYTES_33 \w{66} OP_ENDIF OP_CHECKSIG$/.test(this.vin.inner_witnessscript_asm)) { // https://github.com/lightning/bolts/blob/master/03-transactions.md#commitment-transaction-outputs if (topElement === '01') { // top element is '01' to get in the revocation path From 3baf6fdcdc3521ff25f400ace871fa3d168e6cfe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 6 May 2022 06:27:56 +0000 Subject: [PATCH 3/6] Bump express from 4.17.1 to 4.18.1 in /backend Bumps [express](https://github.com/expressjs/express) from 4.17.1 to 4.18.1. - [Release notes](https://github.com/expressjs/express/releases) - [Changelog](https://github.com/expressjs/express/blob/master/History.md) - [Commits](https://github.com/expressjs/express/compare/4.17.1...4.18.1) --- updated-dependencies: - dependency-name: express dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- backend/package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index f887af417..562aed483 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -572,9 +572,9 @@ } }, "node_modules/express": { - "version": "4.18.0", - "resolved": "https://registry.npmjs.org/express/-/express-4.18.0.tgz", - "integrity": "sha512-EJEXxiTQJS3lIPrU1AE2vRuT7X7E+0KBbpm5GSoK524yl0K8X+er8zS2P14E64eqsVNoWbMCT7MpmQ+ErAhgRg==", + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.18.1.tgz", + "integrity": "sha512-zZBcOX9TfehHQhtupq57OF8lFZ3UZi08Y97dwFCkD8p9d/d2Y3M+ykKcwaMDEL+4qyUolgBDX6AblpR3fL212Q==", "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", @@ -2019,9 +2019,9 @@ "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" }, "express": { - "version": "4.18.0", - "resolved": "https://registry.npmjs.org/express/-/express-4.18.0.tgz", - "integrity": "sha512-EJEXxiTQJS3lIPrU1AE2vRuT7X7E+0KBbpm5GSoK524yl0K8X+er8zS2P14E64eqsVNoWbMCT7MpmQ+ErAhgRg==", + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.18.1.tgz", + "integrity": "sha512-zZBcOX9TfehHQhtupq57OF8lFZ3UZi08Y97dwFCkD8p9d/d2Y3M+ykKcwaMDEL+4qyUolgBDX6AblpR3fL212Q==", "requires": { "accepts": "~1.3.8", "array-flatten": "1.1.1", From 074104e9736094a6db12b31ec3cd187ac591a8b7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 May 2022 02:39:48 +0000 Subject: [PATCH 4/6] Bump typescript from 4.4.4 to 4.6.4 in /backend Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.4.4 to 4.6.4. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/compare/v4.4.4...v4.6.4) --- updated-dependencies: - dependency-name: typescript dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- backend/package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index f887af417..e86b2335f 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -1469,9 +1469,9 @@ "integrity": "sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g==" }, "node_modules/typescript": { - "version": "4.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", - "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==", + "version": "4.6.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.4.tgz", + "integrity": "sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -2708,9 +2708,9 @@ "integrity": "sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g==" }, "typescript": { - "version": "4.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", - "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==" + "version": "4.6.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.4.tgz", + "integrity": "sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==" }, "unpipe": { "version": "1.0.0", From 06451f5342e6f30ce4f933bafecc64ec744c1d4e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 May 2022 02:40:04 +0000 Subject: [PATCH 5/6] Bump crypto-js from 4.0.0 to 4.1.1 in /backend Bumps [crypto-js](https://github.com/brix/crypto-js) from 4.0.0 to 4.1.1. - [Release notes](https://github.com/brix/crypto-js/releases) - [Commits](https://github.com/brix/crypto-js/compare/4.0.0...4.1.1) --- updated-dependencies: - dependency-name: crypto-js dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- backend/package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index f887af417..a70d2aafe 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -469,9 +469,9 @@ } }, "node_modules/crypto-js": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz", - "integrity": "sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg==" + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz", + "integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==" }, "node_modules/debug": { "version": "2.6.9", @@ -1948,9 +1948,9 @@ } }, "crypto-js": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz", - "integrity": "sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg==" + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz", + "integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==" }, "debug": { "version": "2.6.9", From 072c192d9a96007ac2cbda6182aacdf52b313b71 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 May 2022 02:42:41 +0000 Subject: [PATCH 6/6] Bump ws from 8.3.0 to 8.6.0 in /backend Bumps [ws](https://github.com/websockets/ws) from 8.3.0 to 8.6.0. - [Release notes](https://github.com/websockets/ws/releases) - [Commits](https://github.com/websockets/ws/compare/8.3.0...8.6.0) --- updated-dependencies: - dependency-name: ws dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- backend/package-lock.json | 14 +++++++------- backend/package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index f887af417..2e4dc2f17 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -18,7 +18,7 @@ "node-worker-threads-pool": "^1.5.1", "socks-proxy-agent": "^6.2.0", "typescript": "~4.6.3", - "ws": "~8.3.0" + "ws": "~8.6.0" }, "devDependencies": { "@types/compression": "^1.7.2", @@ -1532,9 +1532,9 @@ "dev": true }, "node_modules/ws": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.3.0.tgz", - "integrity": "sha512-Gs5EZtpqZzLvmIM59w4igITU57lrtYVFneaa434VROv4thzJyV6UjIL3D42lslWlI+D4KzLYnxSwtfuiO79sNw==", + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.6.0.tgz", + "integrity": "sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==", "engines": { "node": ">=10.0.0" }, @@ -2755,9 +2755,9 @@ "dev": true }, "ws": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.3.0.tgz", - "integrity": "sha512-Gs5EZtpqZzLvmIM59w4igITU57lrtYVFneaa434VROv4thzJyV6UjIL3D42lslWlI+D4KzLYnxSwtfuiO79sNw==", + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.6.0.tgz", + "integrity": "sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==", "requires": {} }, "yallist": { diff --git a/backend/package.json b/backend/package.json index 48a00d479..97ce387db 100644 --- a/backend/package.json +++ b/backend/package.json @@ -37,7 +37,7 @@ "node-worker-threads-pool": "^1.5.1", "socks-proxy-agent": "^6.2.0", "typescript": "~4.6.3", - "ws": "~8.3.0" + "ws": "~8.6.0" }, "devDependencies": { "@types/compression": "^1.7.2",