Merge branch 'master' into nymkappa/bugfix/cleanup-mining-states
This commit is contained in:
commit
1192d4fbd4
@ -6,7 +6,7 @@ import websocketHandler from '../websocket-handler';
|
|||||||
import mempool from '../mempool';
|
import mempool from '../mempool';
|
||||||
import feeApi from '../fee-api';
|
import feeApi from '../fee-api';
|
||||||
import mempoolBlocks from '../mempool-blocks';
|
import mempoolBlocks from '../mempool-blocks';
|
||||||
import bitcoinApi from './bitcoin-api-factory';
|
import bitcoinApi, { bitcoinCoreApi } from './bitcoin-api-factory';
|
||||||
import { Common } from '../common';
|
import { Common } from '../common';
|
||||||
import backendInfo from '../backend-info';
|
import backendInfo from '../backend-info';
|
||||||
import transactionUtils from '../transaction-utils';
|
import transactionUtils from '../transaction-utils';
|
||||||
@ -469,7 +469,7 @@ class BitcoinRoutes {
|
|||||||
returnBlocks.push(localBlock);
|
returnBlocks.push(localBlock);
|
||||||
nextHash = localBlock.previousblockhash;
|
nextHash = localBlock.previousblockhash;
|
||||||
} else {
|
} else {
|
||||||
const block = await bitcoinApi.$getBlock(nextHash);
|
const block = await bitcoinCoreApi.$getBlock(nextHash);
|
||||||
returnBlocks.push(block);
|
returnBlocks.push(block);
|
||||||
nextHash = block.previousblockhash;
|
nextHash = block.previousblockhash;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import config from '../config';
|
import config from '../config';
|
||||||
import bitcoinApi from './bitcoin/bitcoin-api-factory';
|
import bitcoinApi, { bitcoinCoreApi } from './bitcoin/bitcoin-api-factory';
|
||||||
import logger from '../logger';
|
import logger from '../logger';
|
||||||
import memPool from './mempool';
|
import memPool from './mempool';
|
||||||
import { BlockExtended, BlockExtension, BlockSummary, PoolTag, TransactionExtended, TransactionStripped, TransactionMinerInfo } from '../mempool.interfaces';
|
import { BlockExtended, BlockExtension, BlockSummary, PoolTag, TransactionExtended, TransactionStripped, TransactionMinerInfo } from '../mempool.interfaces';
|
||||||
@ -484,7 +484,7 @@ class Blocks {
|
|||||||
loadingIndicators.setProgress('block-indexing', progress, false);
|
loadingIndicators.setProgress('block-indexing', progress, false);
|
||||||
}
|
}
|
||||||
const blockHash = await bitcoinApi.$getBlockHash(blockHeight);
|
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 transactions = await this.$getTransactionsExtended(blockHash, block.height, true, true);
|
||||||
const blockExtended = await this.$getBlockExtended(block, transactions);
|
const blockExtended = await this.$getBlockExtended(block, transactions);
|
||||||
|
|
||||||
@ -532,13 +532,13 @@ class Blocks {
|
|||||||
if (blockchainInfo.blocks === blockchainInfo.headers) {
|
if (blockchainInfo.blocks === blockchainInfo.headers) {
|
||||||
const heightDiff = blockHeightTip % 2016;
|
const heightDiff = blockHeightTip % 2016;
|
||||||
const blockHash = await bitcoinApi.$getBlockHash(blockHeightTip - heightDiff);
|
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.lastDifficultyAdjustmentTime = block.timestamp;
|
||||||
this.currentDifficulty = block.difficulty;
|
this.currentDifficulty = block.difficulty;
|
||||||
|
|
||||||
if (blockHeightTip >= 2016) {
|
if (blockHeightTip >= 2016) {
|
||||||
const previousPeriodBlockHash = await bitcoinApi.$getBlockHash(blockHeightTip - heightDiff - 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;
|
this.previousDifficultyRetarget = (block.difficulty - previousPeriodBlock.difficulty) / previousPeriodBlock.difficulty * 100;
|
||||||
logger.debug(`Initial difficulty adjustment data set.`);
|
logger.debug(`Initial difficulty adjustment data set.`);
|
||||||
}
|
}
|
||||||
@ -662,7 +662,7 @@ class Blocks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const blockHash = await bitcoinApi.$getBlockHash(height);
|
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 transactions = await this.$getTransactionsExtended(blockHash, block.height, true);
|
||||||
const blockExtended = await this.$getBlockExtended(block, transactions);
|
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
|
// Not Bitcoin network, return the block as it from the bitcoin backend
|
||||||
if (['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) === false) {
|
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
|
// 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);
|
return await this.$indexBlock(block.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1033,6 +1033,7 @@ class DatabaseMigration {
|
|||||||
|
|
||||||
await this.$executeQuery(`TRUNCATE blocks`);
|
await this.$executeQuery(`TRUNCATE blocks`);
|
||||||
await this.$executeQuery(`TRUNCATE hashrates`);
|
await this.$executeQuery(`TRUNCATE hashrates`);
|
||||||
|
await this.$executeQuery(`TRUNCATE difficulty_adjustments`);
|
||||||
await this.$executeQuery('DELETE FROM `pools`');
|
await this.$executeQuery('DELETE FROM `pools`');
|
||||||
await this.$executeQuery('ALTER TABLE pools AUTO_INCREMENT = 1');
|
await this.$executeQuery('ALTER TABLE pools AUTO_INCREMENT = 1');
|
||||||
await this.$executeQuery(`UPDATE state SET string = NULL WHERE name = 'pools_json_sha'`);
|
await this.$executeQuery(`UPDATE state SET string = NULL WHERE name = 'pools_json_sha'`);
|
||||||
|
@ -11,7 +11,7 @@ import DifficultyAdjustmentsRepository from '../../repositories/DifficultyAdjust
|
|||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import BlocksAuditsRepository from '../../repositories/BlocksAuditsRepository';
|
import BlocksAuditsRepository from '../../repositories/BlocksAuditsRepository';
|
||||||
import PricesRepository from '../../repositories/PricesRepository';
|
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';
|
import { IEsploraApi } from '../bitcoin/esplora-api.interface';
|
||||||
|
|
||||||
class Mining {
|
class Mining {
|
||||||
@ -191,7 +191,7 @@ class Mining {
|
|||||||
try {
|
try {
|
||||||
const oldestConsecutiveBlockTimestamp = 1000 * (await BlocksRepository.$getOldestConsecutiveBlock()).timestamp;
|
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 genesisTimestamp = genesisBlock.timestamp * 1000;
|
||||||
|
|
||||||
const indexedTimestamp = await HashratesRepository.$getWeeklyHashrateTimestamps();
|
const indexedTimestamp = await HashratesRepository.$getWeeklyHashrateTimestamps();
|
||||||
@ -294,7 +294,7 @@ class Mining {
|
|||||||
const oldestConsecutiveBlockTimestamp = 1000 * (await BlocksRepository.$getOldestConsecutiveBlock()).timestamp;
|
const oldestConsecutiveBlockTimestamp = 1000 * (await BlocksRepository.$getOldestConsecutiveBlock()).timestamp;
|
||||||
|
|
||||||
try {
|
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 genesisTimestamp = genesisBlock.timestamp * 1000;
|
||||||
const indexedTimestamp = (await HashratesRepository.$getRawNetworkDailyHashrate(null)).map(hashrate => hashrate.timestamp);
|
const indexedTimestamp = (await HashratesRepository.$getRawNetworkDailyHashrate(null)).map(hashrate => hashrate.timestamp);
|
||||||
const lastMidnight = this.getDateMidnight(new Date());
|
const lastMidnight = this.getDateMidnight(new Date());
|
||||||
@ -396,7 +396,7 @@ class Mining {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const blocks: any = await BlocksRepository.$getBlocksDifficulty();
|
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 currentDifficulty = genesisBlock.difficulty;
|
||||||
let totalIndexed = 0;
|
let totalIndexed = 0;
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { Common } from '../api/common';
|
import { Common } from '../api/common';
|
||||||
import config from '../config';
|
|
||||||
import DB from '../database';
|
import DB from '../database';
|
||||||
import logger from '../logger';
|
import logger from '../logger';
|
||||||
import { IndexedDifficultyAdjustment } from '../mempool.interfaces';
|
import { IndexedDifficultyAdjustment } from '../mempool.interfaces';
|
||||||
|
@ -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);
|
this.isTypeaheading$.next(false);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -126,7 +132,7 @@ export class SearchFormComponent implements OnInit {
|
|||||||
]
|
]
|
||||||
).pipe(
|
).pipe(
|
||||||
map((latestData) => {
|
map((latestData) => {
|
||||||
const searchText = latestData[0];
|
let searchText = latestData[0];
|
||||||
if (!searchText.length) {
|
if (!searchText.length) {
|
||||||
return {
|
return {
|
||||||
searchText: '',
|
searchText: '',
|
||||||
@ -144,15 +150,15 @@ export class SearchFormComponent implements OnInit {
|
|||||||
const addressPrefixSearchResults = result[0];
|
const addressPrefixSearchResults = result[0];
|
||||||
const lightningResults = result[1];
|
const lightningResults = result[1];
|
||||||
|
|
||||||
if (this.network === 'bisq') {
|
|
||||||
return searchText.map((address: string) => 'B' + address);
|
|
||||||
}
|
|
||||||
|
|
||||||
const matchesBlockHeight = this.regexBlockheight.test(searchText);
|
const matchesBlockHeight = this.regexBlockheight.test(searchText);
|
||||||
const matchesTxId = this.regexTransaction.test(searchText) && !this.regexBlockhash.test(searchText);
|
const matchesTxId = this.regexTransaction.test(searchText) && !this.regexBlockhash.test(searchText);
|
||||||
const matchesBlockHash = this.regexBlockhash.test(searchText);
|
const matchesBlockHash = this.regexBlockhash.test(searchText);
|
||||||
const matchesAddress = this.regexAddress.test(searchText);
|
const matchesAddress = this.regexAddress.test(searchText);
|
||||||
|
|
||||||
|
if (matchesAddress && this.network === 'bisq') {
|
||||||
|
searchText = 'B' + searchText;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
searchText: searchText,
|
searchText: searchText,
|
||||||
hashQuickMatch: +(matchesBlockHeight || matchesBlockHash || matchesTxId || matchesAddress),
|
hashQuickMatch: +(matchesBlockHeight || matchesBlockHash || matchesTxId || matchesAddress),
|
||||||
|
@ -38,6 +38,9 @@ export class StartComponent implements OnInit, OnDestroy {
|
|||||||
pageIndex: number = 0;
|
pageIndex: number = 0;
|
||||||
pages: any[] = [];
|
pages: any[] = [];
|
||||||
pendingMark: number | void = null;
|
pendingMark: number | void = null;
|
||||||
|
lastUpdate: number = 0;
|
||||||
|
lastMouseX: number;
|
||||||
|
velocity: number = 0;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private stateService: StateService,
|
private stateService: StateService,
|
||||||
@ -136,6 +139,7 @@ export class StartComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
onMouseDown(event: MouseEvent) {
|
onMouseDown(event: MouseEvent) {
|
||||||
this.mouseDragStartX = event.clientX;
|
this.mouseDragStartX = event.clientX;
|
||||||
|
this.resetMomentum(event.clientX);
|
||||||
this.blockchainScrollLeftInit = this.blockchainContainer.nativeElement.scrollLeft;
|
this.blockchainScrollLeftInit = this.blockchainContainer.nativeElement.scrollLeft;
|
||||||
}
|
}
|
||||||
onPointerDown(event: PointerEvent) {
|
onPointerDown(event: PointerEvent) {
|
||||||
@ -159,6 +163,7 @@ export class StartComponent implements OnInit, OnDestroy {
|
|||||||
@HostListener('document:mousemove', ['$event'])
|
@HostListener('document:mousemove', ['$event'])
|
||||||
onMouseMove(event: MouseEvent): void {
|
onMouseMove(event: MouseEvent): void {
|
||||||
if (this.mouseDragStartX != null) {
|
if (this.mouseDragStartX != null) {
|
||||||
|
this.updateVelocity(event.clientX);
|
||||||
this.stateService.setBlockScrollingInProgress(true);
|
this.stateService.setBlockScrollingInProgress(true);
|
||||||
this.blockchainContainer.nativeElement.scrollLeft =
|
this.blockchainContainer.nativeElement.scrollLeft =
|
||||||
this.blockchainScrollLeftInit + this.mouseDragStartX - event.clientX;
|
this.blockchainScrollLeftInit + this.mouseDragStartX - event.clientX;
|
||||||
@ -167,7 +172,7 @@ export class StartComponent implements OnInit, OnDestroy {
|
|||||||
@HostListener('document:mouseup', [])
|
@HostListener('document:mouseup', [])
|
||||||
onMouseUp() {
|
onMouseUp() {
|
||||||
this.mouseDragStartX = null;
|
this.mouseDragStartX = null;
|
||||||
this.stateService.setBlockScrollingInProgress(false);
|
this.animateMomentum();
|
||||||
}
|
}
|
||||||
@HostListener('document:pointermove', ['$event'])
|
@HostListener('document:pointermove', ['$event'])
|
||||||
onPointerMove(event: PointerEvent): void {
|
onPointerMove(event: PointerEvent): void {
|
||||||
@ -183,6 +188,45 @@ 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();
|
||||||
|
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() {
|
||||||
|
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) {
|
onScroll(e) {
|
||||||
const middlePage = this.pageIndex === 0 ? this.pages[0] : this.pages[1];
|
const middlePage = this.pageIndex === 0 ? this.pages[0] : this.pages[1];
|
||||||
|
@ -9,6 +9,10 @@ location /api/tx/ {
|
|||||||
rewrite ^/api/(.*) /$1 break;
|
rewrite ^/api/(.*) /$1 break;
|
||||||
try_files /dev/null @esplora-api-cache-disabled;
|
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
|
# rewrite APIs to match what backend expects
|
||||||
location /api/currencies {
|
location /api/currencies {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user