From 7ea2d3b8080607a61cfa3ceace0f70b5273a3dfd Mon Sep 17 00:00:00 2001 From: nymkappa <1612910616@pm.me> Date: Fri, 3 Mar 2023 13:59:17 +0900 Subject: [PATCH 1/5] Use core to fetch block because esplora/electrs still return integer difficulty --- backend/src/api/bitcoin/bitcoin.routes.ts | 4 ++-- backend/src/api/blocks.ts | 14 +++++++------- backend/src/api/database-migration.ts | 1 + backend/src/api/mining/mining.ts | 8 ++++---- .../DifficultyAdjustmentsRepository.ts | 1 - 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/src/api/bitcoin/bitcoin.routes.ts b/backend/src/api/bitcoin/bitcoin.routes.ts index 2fc497650..2d5077bc4 100644 --- a/backend/src/api/bitcoin/bitcoin.routes.ts +++ b/backend/src/api/bitcoin/bitcoin.routes.ts @@ -6,7 +6,7 @@ import websocketHandler from '../websocket-handler'; import mempool from '../mempool'; import feeApi from '../fee-api'; import mempoolBlocks from '../mempool-blocks'; -import bitcoinApi from './bitcoin-api-factory'; +import bitcoinApi, { bitcoinCoreApi } from './bitcoin-api-factory'; import { Common } from '../common'; import backendInfo from '../backend-info'; import transactionUtils from '../transaction-utils'; @@ -469,7 +469,7 @@ class BitcoinRoutes { returnBlocks.push(localBlock); nextHash = localBlock.previousblockhash; } else { - const block = await bitcoinApi.$getBlock(nextHash); + const block = await bitcoinCoreApi.$getBlock(nextHash); returnBlocks.push(block); nextHash = block.previousblockhash; } diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index aa33f1ff7..ea2985b4f 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -1,5 +1,5 @@ import config from '../config'; -import bitcoinApi from './bitcoin/bitcoin-api-factory'; +import bitcoinApi, { bitcoinCoreApi } from './bitcoin/bitcoin-api-factory'; import logger from '../logger'; import memPool from './mempool'; import { BlockExtended, BlockExtension, BlockSummary, PoolTag, TransactionExtended, TransactionStripped, TransactionMinerInfo } from '../mempool.interfaces'; @@ -484,7 +484,7 @@ class Blocks { loadingIndicators.setProgress('block-indexing', progress, false); } const blockHash = await bitcoinApi.$getBlockHash(blockHeight); - const block: IEsploraApi.Block = await bitcoinApi.$getBlock(blockHash); + const block: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(blockHash); const transactions = await this.$getTransactionsExtended(blockHash, block.height, true, true); const blockExtended = await this.$getBlockExtended(block, transactions); @@ -532,13 +532,13 @@ class Blocks { if (blockchainInfo.blocks === blockchainInfo.headers) { const heightDiff = blockHeightTip % 2016; const blockHash = await bitcoinApi.$getBlockHash(blockHeightTip - heightDiff); - const block: IEsploraApi.Block = await bitcoinApi.$getBlock(blockHash); + const block: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(blockHash); this.lastDifficultyAdjustmentTime = block.timestamp; this.currentDifficulty = block.difficulty; if (blockHeightTip >= 2016) { const previousPeriodBlockHash = await bitcoinApi.$getBlockHash(blockHeightTip - heightDiff - 2016); - const previousPeriodBlock: IEsploraApi.Block = await bitcoinApi.$getBlock(previousPeriodBlockHash); + const previousPeriodBlock: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(previousPeriodBlockHash); this.previousDifficultyRetarget = (block.difficulty - previousPeriodBlock.difficulty) / previousPeriodBlock.difficulty * 100; logger.debug(`Initial difficulty adjustment data set.`); } @@ -662,7 +662,7 @@ class Blocks { } const blockHash = await bitcoinApi.$getBlockHash(height); - const block: IEsploraApi.Block = await bitcoinApi.$getBlock(blockHash); + const block: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(blockHash); const transactions = await this.$getTransactionsExtended(blockHash, block.height, true); const blockExtended = await this.$getBlockExtended(block, transactions); @@ -685,11 +685,11 @@ class Blocks { // Not Bitcoin network, return the block as it from the bitcoin backend if (['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) === false) { - return await bitcoinApi.$getBlock(hash); + return await bitcoinCoreApi.$getBlock(hash); } // Bitcoin network, add our custom data on top - const block: IEsploraApi.Block = await bitcoinApi.$getBlock(hash); + const block: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(hash); return await this.$indexBlock(block.height); } diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index d40637e74..b9c50645d 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -1023,6 +1023,7 @@ class DatabaseMigration { await this.$executeQuery(`TRUNCATE blocks`); await this.$executeQuery(`TRUNCATE hashrates`); + await this.$executeQuery(`TRUNCATE difficulty_adjustments`); await this.$executeQuery('DELETE FROM `pools`'); await this.$executeQuery('ALTER TABLE pools AUTO_INCREMENT = 1'); await this.$executeQuery(`UPDATE state SET string = NULL WHERE name = 'pools_json_sha'`); diff --git a/backend/src/api/mining/mining.ts b/backend/src/api/mining/mining.ts index e9b569485..eca29a609 100644 --- a/backend/src/api/mining/mining.ts +++ b/backend/src/api/mining/mining.ts @@ -11,7 +11,7 @@ import DifficultyAdjustmentsRepository from '../../repositories/DifficultyAdjust import config from '../../config'; import BlocksAuditsRepository from '../../repositories/BlocksAuditsRepository'; import PricesRepository from '../../repositories/PricesRepository'; -import bitcoinApiFactory from '../bitcoin/bitcoin-api-factory'; +import { bitcoinCoreApi } from '../bitcoin/bitcoin-api-factory'; import { IEsploraApi } from '../bitcoin/esplora-api.interface'; class Mining { @@ -191,7 +191,7 @@ class Mining { try { const oldestConsecutiveBlockTimestamp = 1000 * (await BlocksRepository.$getOldestConsecutiveBlock()).timestamp; - const genesisBlock: IEsploraApi.Block = await bitcoinApiFactory.$getBlock(await bitcoinClient.getBlockHash(0)); + const genesisBlock: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(await bitcoinClient.getBlockHash(0)); const genesisTimestamp = genesisBlock.timestamp * 1000; const indexedTimestamp = await HashratesRepository.$getWeeklyHashrateTimestamps(); @@ -294,7 +294,7 @@ class Mining { const oldestConsecutiveBlockTimestamp = 1000 * (await BlocksRepository.$getOldestConsecutiveBlock()).timestamp; try { - const genesisBlock: IEsploraApi.Block = await bitcoinApiFactory.$getBlock(await bitcoinClient.getBlockHash(0)); + const genesisBlock: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(await bitcoinClient.getBlockHash(0)); const genesisTimestamp = genesisBlock.timestamp * 1000; const indexedTimestamp = (await HashratesRepository.$getRawNetworkDailyHashrate(null)).map(hashrate => hashrate.timestamp); const lastMidnight = this.getDateMidnight(new Date()); @@ -396,7 +396,7 @@ class Mining { } const blocks: any = await BlocksRepository.$getBlocksDifficulty(); - const genesisBlock: IEsploraApi.Block = await bitcoinApiFactory.$getBlock(await bitcoinClient.getBlockHash(0)); + const genesisBlock: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(await bitcoinClient.getBlockHash(0)); let currentDifficulty = genesisBlock.difficulty; let totalIndexed = 0; diff --git a/backend/src/repositories/DifficultyAdjustmentsRepository.ts b/backend/src/repositories/DifficultyAdjustmentsRepository.ts index 910c65c10..1c101bcf2 100644 --- a/backend/src/repositories/DifficultyAdjustmentsRepository.ts +++ b/backend/src/repositories/DifficultyAdjustmentsRepository.ts @@ -1,5 +1,4 @@ import { Common } from '../api/common'; -import config from '../config'; import DB from '../database'; import logger from '../logger'; import { IndexedDifficultyAdjustment } from '../mempool.interfaces'; From 4e684989791bd2d5719ab4b3e71dbcab1697af48 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Fri, 3 Mar 2023 22:45:11 -0600 Subject: [PATCH 2/5] blockchain momentum scrolling --- .../app/components/start/start.component.ts | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/components/start/start.component.ts b/frontend/src/app/components/start/start.component.ts index 22507303e..d83ae2dec 100644 --- a/frontend/src/app/components/start/start.component.ts +++ b/frontend/src/app/components/start/start.component.ts @@ -38,6 +38,9 @@ export class StartComponent implements OnInit, OnDestroy { pageIndex: number = 0; pages: any[] = []; pendingMark: number | void = null; + lastUpdate: number = 0; + lastMouseX: number; + velocity: number = 0; constructor( private stateService: StateService, @@ -136,6 +139,7 @@ export class StartComponent implements OnInit, OnDestroy { onMouseDown(event: MouseEvent) { this.mouseDragStartX = event.clientX; + this.resetMomentum(event.clientX); this.blockchainScrollLeftInit = this.blockchainContainer.nativeElement.scrollLeft; } onPointerDown(event: PointerEvent) { @@ -159,6 +163,7 @@ export class StartComponent implements OnInit, OnDestroy { @HostListener('document:mousemove', ['$event']) onMouseMove(event: MouseEvent): void { if (this.mouseDragStartX != null) { + this.updateVelocity(event.clientX); this.stateService.setBlockScrollingInProgress(true); this.blockchainContainer.nativeElement.scrollLeft = this.blockchainScrollLeftInit + this.mouseDragStartX - event.clientX; @@ -167,7 +172,7 @@ export class StartComponent implements OnInit, OnDestroy { @HostListener('document:mouseup', []) onMouseUp() { this.mouseDragStartX = null; - this.stateService.setBlockScrollingInProgress(false); + this.animateMomentum(); } @HostListener('document:pointermove', ['$event']) onPointerMove(event: PointerEvent): void { @@ -183,6 +188,43 @@ export class StartComponent implements OnInit, OnDestroy { } } + resetMomentum(x: number) { + this.lastUpdate = performance.now(); + this.lastMouseX = x; + this.velocity = 0; + } + + updateVelocity(x: number) { + const now = performance.now(); + const dt = now - this.lastUpdate; + this.lastUpdate = now; + const velocity = (x - this.lastMouseX) / dt; + this.velocity = (0.8 * this.velocity) + (0.2 * velocity); + this.lastMouseX = x; + } + + animateMomentum() { + this.lastUpdate = performance.now(); + requestAnimationFrame(() => { + const now = performance.now(); + const dt = now - this.lastUpdate; + this.lastUpdate = now; + if (Math.abs(this.velocity) < 0.005) { + this.stateService.setBlockScrollingInProgress(false); + } else { + const deceleration = Math.max(0.0025, 0.001 * this.velocity * this.velocity) * (this.velocity > 0 ? -1 : 1); + const displacement = (this.velocity * dt) - (0.5 * (deceleration * dt * dt)); + const dv = (deceleration * dt); + if ((this.velocity < 0 && dv + this.velocity > 0) || (this.velocity > 0 && dv + this.velocity < 0)) { + this.velocity = 0; + } else { + this.velocity += dv; + } + this.blockchainContainer.nativeElement.scrollLeft -= displacement; + this.animateMomentum(); + } + }); + } onScroll(e) { const middlePage = this.pageIndex === 0 ? this.pages[0] : this.pages[1]; From 059139689d05e408772a155f2f0d2390d889b3d0 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Fri, 3 Mar 2023 23:39:01 -0600 Subject: [PATCH 3/5] Fix blockchain scrolling on high refresh-rate devices --- frontend/src/app/components/start/start.component.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/components/start/start.component.ts b/frontend/src/app/components/start/start.component.ts index d83ae2dec..77c8fd7f2 100644 --- a/frontend/src/app/components/start/start.component.ts +++ b/frontend/src/app/components/start/start.component.ts @@ -196,11 +196,13 @@ export class StartComponent implements OnInit, OnDestroy { updateVelocity(x: number) { const now = performance.now(); - const dt = now - this.lastUpdate; - this.lastUpdate = now; - const velocity = (x - this.lastMouseX) / dt; - this.velocity = (0.8 * this.velocity) + (0.2 * velocity); - this.lastMouseX = x; + let dt = now - this.lastUpdate; + if (dt > 0) { + this.lastUpdate = now; + const velocity = (x - this.lastMouseX) / dt; + this.velocity = (0.8 * this.velocity) + (0.2 * velocity); + this.lastMouseX = x; + } } animateMomentum() { From f8624020e8504d9da98a9b7b5e7f7b4bfef00ac3 Mon Sep 17 00:00:00 2001 From: softsimon Date: Sun, 29 Jan 2023 21:18:44 +0400 Subject: [PATCH 4/5] Bisq markets search bar fix fixes #2986 --- .../search-form/search-form.component.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/components/search-form/search-form.component.ts b/frontend/src/app/components/search-form/search-form.component.ts index a4dbf5985..af5ccc654 100644 --- a/frontend/src/app/components/search-form/search-form.component.ts +++ b/frontend/src/app/components/search-form/search-form.component.ts @@ -107,7 +107,13 @@ export class SearchFormComponent implements OnInit { }))), ); }), - tap((result: any[]) => { + map((result: any[]) => { + if (this.network === 'bisq') { + result[0] = result[0].map((address: string) => 'B' + address); + } + return result; + }), + tap(() => { this.isTypeaheading$.next(false); }) ); @@ -126,7 +132,7 @@ export class SearchFormComponent implements OnInit { ] ).pipe( map((latestData) => { - const searchText = latestData[0]; + let searchText = latestData[0]; if (!searchText.length) { return { searchText: '', @@ -144,15 +150,15 @@ export class SearchFormComponent implements OnInit { const addressPrefixSearchResults = result[0]; const lightningResults = result[1]; - if (this.network === 'bisq') { - return searchText.map((address: string) => 'B' + address); - } - const matchesBlockHeight = this.regexBlockheight.test(searchText); const matchesTxId = this.regexTransaction.test(searchText) && !this.regexBlockhash.test(searchText); const matchesBlockHash = this.regexBlockhash.test(searchText); const matchesAddress = this.regexAddress.test(searchText); + if (matchesAddress && this.network === 'bisq') { + searchText = 'B' + searchText; + } + return { searchText: searchText, hashQuickMatch: +(matchesBlockHeight || matchesBlockHash || matchesTxId || matchesAddress), From 5fb4eac4b754c4f9f8b265b5ccb2b7299c378910 Mon Sep 17 00:00:00 2001 From: wiz Date: Sat, 4 Mar 2023 15:53:49 +0900 Subject: [PATCH 5/5] ops: Add missing /api/address-prefix nginx route for bisq --- production/nginx/server-bisq.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/production/nginx/server-bisq.conf b/production/nginx/server-bisq.conf index 2ea99843b..76b0d304c 100644 --- a/production/nginx/server-bisq.conf +++ b/production/nginx/server-bisq.conf @@ -9,6 +9,10 @@ location /api/tx/ { rewrite ^/api/(.*) /$1 break; try_files /dev/null @esplora-api-cache-disabled; } +location /api/address-prefix/ { + rewrite ^/api/(.*) /$1 break; + try_files /dev/null @esplora-api-cache-disabled; +} # rewrite APIs to match what backend expects location /api/currencies {