diff --git a/backend/src/api/explorer/nodes.api.ts b/backend/src/api/explorer/nodes.api.ts index b21544e4b..f9677c193 100644 --- a/backend/src/api/explorer/nodes.api.ts +++ b/backend/src/api/explorer/nodes.api.ts @@ -524,7 +524,37 @@ class NodesApi { public async $getNodesPerISP(ISPId: string) { try { - const query = ` + let query = ` + SELECT channels.node1_public_key AS node1PublicKey, isp1.id as isp1ID, + channels.node2_public_key AS node2PublicKey, isp2.id as isp2ID + FROM channels + JOIN nodes node1 ON node1.public_key = channels.node1_public_key + JOIN nodes node2 ON node2.public_key = channels.node2_public_key + JOIN geo_names isp1 ON isp1.id = node1.as_number + JOIN geo_names isp2 ON isp2.id = node2.as_number + WHERE channels.status = 1 AND (node1.as_number IN (?) OR node2.as_number IN (?)) + ORDER BY short_id DESC + `; + + const IPSIds = ISPId.split(','); + const [rows]: any = await DB.query(query, [IPSIds, IPSIds]); + const nodes = {}; + + const intISPIds: number[] = []; + for (const ispId of IPSIds) { + intISPIds.push(parseInt(ispId, 10)); + } + + for (const channel of rows) { + if (intISPIds.includes(channel.isp1ID)) { + nodes[channel.node1PublicKey] = true; + } + if (intISPIds.includes(channel.isp2ID)) { + nodes[channel.node2PublicKey] = true; + } + } + + query = ` SELECT nodes.public_key, CAST(COALESCE(nodes.capacity, 0) as INT) as capacity, CAST(COALESCE(nodes.channels, 0) as INT) as channels, nodes.alias, UNIX_TIMESTAMP(nodes.first_seen) as first_seen, UNIX_TIMESTAMP(nodes.updated_at) as updated_at, geo_names_city.names as city, geo_names_country.names as country, @@ -535,17 +565,18 @@ class NodesApi { LEFT JOIN geo_names geo_names_city ON geo_names_city.id = nodes.city_id AND geo_names_city.type = 'city' LEFT JOIN geo_names geo_names_iso ON geo_names_iso.id = nodes.country_id AND geo_names_iso.type = 'country_iso_code' LEFT JOIN geo_names geo_names_subdivision on geo_names_subdivision.id = nodes.subdivision_id AND geo_names_subdivision.type = 'division' - WHERE nodes.as_number IN (?) + WHERE nodes.public_key IN (?) ORDER BY capacity DESC `; - const [rows]: any = await DB.query(query, [ISPId.split(',')]); - for (let i = 0; i < rows.length; ++i) { - rows[i].country = JSON.parse(rows[i].country); - rows[i].city = JSON.parse(rows[i].city); - rows[i].subdivision = JSON.parse(rows[i].subdivision); + const [rows2]: any = await DB.query(query, [Object.keys(nodes)]); + for (let i = 0; i < rows2.length; ++i) { + rows2[i].country = JSON.parse(rows2[i].country); + rows2[i].city = JSON.parse(rows2[i].city); + rows2[i].subdivision = JSON.parse(rows2[i].subdivision); } - return rows; + return rows2; + } catch (e) { logger.err(`Cannot get nodes for ISP id ${ISPId}. Reason: ${e instanceof Error ? e.message : e}`); throw e; diff --git a/backend/src/tasks/lightning/sync-tasks/node-locations.ts b/backend/src/tasks/lightning/sync-tasks/node-locations.ts index ba59e9e48..afd280ec7 100644 --- a/backend/src/tasks/lightning/sync-tasks/node-locations.ts +++ b/backend/src/tasks/lightning/sync-tasks/node-locations.ts @@ -6,6 +6,7 @@ import DB from '../../../database'; import logger from '../../../logger'; import { ResultSetHeader } from 'mysql2'; import * as IPCheck from '../../../utils/ipcheck.js'; +import { Reader } from 'mmdb-lib'; export async function $lookupNodeLocation(): Promise { let loggerTimer = new Date().getTime() / 1000; @@ -18,7 +19,10 @@ export async function $lookupNodeLocation(): Promise { const nodes = await nodesApi.$getAllNodes(); const lookupCity = await maxmind.open(config.MAXMIND.GEOLITE2_CITY); const lookupAsn = await maxmind.open(config.MAXMIND.GEOLITE2_ASN); - const lookupIsp = await maxmind.open(config.MAXMIND.GEOIP2_ISP); + let lookupIsp: Reader | null = null; + try { + lookupIsp = await maxmind.open(config.MAXMIND.GEOIP2_ISP); + } catch (e) { } for (const node of nodes) { const sockets: string[] = node.sockets.split(','); @@ -29,7 +33,10 @@ export async function $lookupNodeLocation(): Promise { if (hasClearnet && ip !== '127.0.1.1' && ip !== '127.0.0.1') { const city = lookupCity.get(ip); const asn = lookupAsn.get(ip); - const isp = lookupIsp.get(ip); + let isp: IspResponse | null = null; + if (lookupIsp) { + isp = lookupIsp.get(ip); + } let asOverwrite: any | undefined; if (asn && (IPCheck.match(ip, '170.75.160.0/20') || IPCheck.match(ip, '172.81.176.0/21'))) { diff --git a/backend/src/tasks/price-feeds/ftx-api.ts b/backend/src/tasks/price-feeds/ftx-api.ts deleted file mode 100644 index 193d3e881..000000000 --- a/backend/src/tasks/price-feeds/ftx-api.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { query } from '../../utils/axios-query'; -import priceUpdater, { PriceFeed, PriceHistory } from '../price-updater'; - -class FtxApi implements PriceFeed { - public name: string = 'FTX'; - public currencies: string[] = ['USD', 'BRZ', 'EUR', 'JPY', 'AUD']; - - public url: string = 'https://ftx.com/api/markets/BTC/'; - public urlHist: string = 'https://ftx.com/api/markets/BTC/{CURRENCY}/candles?resolution={GRANULARITY}'; - - constructor() { - } - - public async $fetchPrice(currency): Promise { - const response = await query(this.url + currency); - return response ? parseInt(response['result']['last'], 10) : -1; - } - - public async $fetchRecentPrice(currencies: string[], type: 'hour' | 'day'): Promise { - const priceHistory: PriceHistory = {}; - - for (const currency of currencies) { - if (this.currencies.includes(currency) === false) { - continue; - } - - const response = await query(this.urlHist.replace('{GRANULARITY}', type === 'hour' ? '3600' : '86400').replace('{CURRENCY}', currency)); - const pricesRaw = response ? response['result'] : []; - - for (const price of pricesRaw as any[]) { - const time = Math.round(price['time'] / 1000); - if (priceHistory[time] === undefined) { - priceHistory[time] = priceUpdater.getEmptyPricesObj(); - } - priceHistory[time][currency] = price['close']; - } - } - - return priceHistory; - } -} - -export default FtxApi; diff --git a/backend/src/tasks/price-updater.ts b/backend/src/tasks/price-updater.ts index 891e2bce3..e069e4db4 100644 --- a/backend/src/tasks/price-updater.ts +++ b/backend/src/tasks/price-updater.ts @@ -1,13 +1,11 @@ import * as fs from 'fs'; import path from "path"; -import { Common } from '../api/common'; import config from '../config'; import logger from '../logger'; import PricesRepository from '../repositories/PricesRepository'; import BitfinexApi from './price-feeds/bitfinex-api'; import BitflyerApi from './price-feeds/bitflyer-api'; import CoinbaseApi from './price-feeds/coinbase-api'; -import FtxApi from './price-feeds/ftx-api'; import GeminiApi from './price-feeds/gemini-api'; import KrakenApi from './price-feeds/kraken-api'; @@ -48,7 +46,6 @@ class PriceUpdater { this.latestPrices = this.getEmptyPricesObj(); this.feeds.push(new BitflyerApi()); // Does not have historical endpoint - this.feeds.push(new FtxApi()); this.feeds.push(new KrakenApi()); this.feeds.push(new CoinbaseApi()); this.feeds.push(new BitfinexApi()); diff --git a/frontend/src/app/components/transactions-list/transactions-list.component.html b/frontend/src/app/components/transactions-list/transactions-list.component.html index 96f792f82..8368a62c4 100644 --- a/frontend/src/app/components/transactions-list/transactions-list.component.html +++ b/frontend/src/app/components/transactions-list/transactions-list.component.html @@ -20,7 +20,7 @@
- + inputRowLimit && tx['@vinLimit']"> + @@ -158,7 +164,7 @@
- +
- + outputRowLimit && tx['@voutLimit']"> + @@ -271,7 +283,7 @@
{{ tx.fee / (tx.weight / 4) | feeRounding }} sat/vB  – {{ tx.fee | number }} sat
-
Show all inputs to reveal fee data
+
Show more inputs to reveal fee data
diff --git a/frontend/src/app/components/transactions-list/transactions-list.component.ts b/frontend/src/app/components/transactions-list/transactions-list.component.ts index 9f1245532..b09226f33 100644 --- a/frontend/src/app/components/transactions-list/transactions-list.component.ts +++ b/frontend/src/app/components/transactions-list/transactions-list.component.ts @@ -18,6 +18,7 @@ import { ApiService } from '../../services/api.service'; export class TransactionsListComponent implements OnInit, OnChanges { network = ''; nativeAssetId = this.stateService.network === 'liquidtestnet' ? environment.nativeTestAssetId : environment.nativeAssetId; + showMoreIncrement = 1000; @Input() transactions: Transaction[]; @Input() showConfirmations = false; @@ -208,14 +209,50 @@ export class TransactionsListComponent implements OnInit, OnChanges { } loadMoreInputs(tx: Transaction): void { - tx['@vinLimit'] = false; + if (!tx['@vinLoaded']) { + this.electrsApiService.getTransaction$(tx.txid) + .subscribe((newTx) => { + tx['@vinLoaded'] = true; + tx.vin = newTx.vin; + tx.fee = newTx.fee; + this.ref.markForCheck(); + }); + } + } - this.electrsApiService.getTransaction$(tx.txid) - .subscribe((newTx) => { - tx.vin = newTx.vin; - tx.fee = newTx.fee; - this.ref.markForCheck(); - }); + showMoreInputs(tx: Transaction): void { + this.loadMoreInputs(tx); + tx['@vinLimit'] = this.getVinLimit(tx, true); + } + + showMoreOutputs(tx: Transaction): void { + tx['@voutLimit'] = this.getVoutLimit(tx, true); + } + + getVinLimit(tx: Transaction, next = false): number { + let limit; + if ((tx['@vinLimit'] || 0) > this.inputRowLimit) { + limit = Math.min(tx['@vinLimit'] + (next ? this.showMoreIncrement : 0), tx.vin.length); + } else { + limit = Math.min((next ? this.showMoreIncrement : this.inputRowLimit), tx.vin.length); + } + if (tx.vin.length - limit <= 5) { + limit = tx.vin.length; + } + return limit; + } + + getVoutLimit(tx: Transaction, next = false): number { + let limit; + if ((tx['@voutLimit'] || 0) > this.outputRowLimit) { + limit = Math.min(tx['@voutLimit'] + (next ? this.showMoreIncrement : 0), tx.vout.length); + } else { + limit = Math.min((next ? this.showMoreIncrement : this.outputRowLimit), tx.vout.length); + } + if (tx.vout.length - limit <= 5) { + limit = tx.vout.length; + } + return limit; } ngOnDestroy(): void { diff --git a/frontend/src/app/docs/api-docs/api-docs-data.ts b/frontend/src/app/docs/api-docs/api-docs-data.ts index 0b2f4b2ff..8cbf03dfb 100644 --- a/frontend/src/app/docs/api-docs/api-docs-data.ts +++ b/frontend/src/app/docs/api-docs/api-docs-data.ts @@ -8562,20 +8562,6 @@ export const faqData = [ fragment: "what-is-svb", title: "What is sat/vB?", }, - { - type: "endpoint", - category: "basics", - showConditions: bitcoinNetworks, - fragment: "what-is-full-mempool", - title: "What does it mean for the mempool to be \"full\"?", - }, - { - type: "endpoint", - category: "basics", - showConditions: bitcoinNetworks, - fragment: "why-empty-blocks", - title: "Why are there empty blocks?", - }, { type: "category", category: "help", @@ -8657,33 +8643,68 @@ export const faqData = [ type: "endpoint", category: "advanced", showConditions: bitcoinNetworks, + fragment: "what-is-full-mempool", + title: "What does it mean for the mempool to be \"full\"?", + }, + { + type: "endpoint", + category: "advanced", + showConditions: bitcoinNetworks, + fragment: "why-empty-blocks", + title: "Why are there empty blocks?", + }, + { + type: "endpoint", + category: "advanced", + showConditions: bitcoinNetworks, + fragment: "why-block-timestamps-dont-always-increase", + title: "Why don't block timestamps always increase?", + }, + { + type: "endpoint", + category: "advanced", + showConditions: bitcoinNetworks, + fragment: "why-dont-fee-ranges-match", + title: "Why doesn't the fee range shown for a block match the feerates of transactions within the block?", + }, + { + type: "category", + category: "self-hosting", + fragment: "self-hosting", + title: "Self-Hosting", + showConditions: bitcoinNetworks + }, + { + type: "endpoint", + category: "self-hosting", + showConditions: bitcoinNetworks, fragment: "who-runs-this-website", title: "Who runs this website?", }, { type: "endpoint", - category: "advanced", + category: "self-hosting", showConditions: bitcoinNetworks, fragment: "host-my-own-instance-raspberry-pi", title: "How can I host my own instance on a Raspberry Pi?", }, { type: "endpoint", - category: "advanced", + category: "self-hosting", showConditions: bitcoinNetworks, fragment: "host-my-own-instance-linux-server", title: "How can I host my own instance on a Linux server?", }, { type: "endpoint", - category: "advanced", + category: "self-hosting", showConditions: bitcoinNetworks, fragment: "install-mempool-with-docker", title: "Can I install Mempool using Docker?", }, { type: "endpoint", - category: "advanced", + category: "self-hosting", showConditions: bitcoinNetworks, fragment: "address-lookup-issues", title: "Why do I get an error for certain address lookups on my Mempool instance?", diff --git a/frontend/src/app/docs/api-docs/api-docs.component.html b/frontend/src/app/docs/api-docs/api-docs.component.html index 4f7cdd9ad..c343d24c8 100644 --- a/frontend/src/app/docs/api-docs/api-docs.component.html +++ b/frontend/src/app/docs/api-docs/api-docs.component.html @@ -168,14 +168,6 @@

There are feerate estimates on the top of the main dashboard you can use as a guide. See this FAQ for more on picking the right feerate.

- -

When a Bitcoin transaction is made, it is stored in a Bitcoin node's mempool before it is confirmed into a block. When the rate of incoming transactions exceeds the rate transactions are confirmed, the mempool grows in size.

The default maximum size of a Bitcoin node's mempool is 300MB, so when there are 300MB of transactions in the mempool, we say it's "full".

-
- - -

When a new block is found, mining pools send miners a block template with no transactions so they can start searching for the next block as soon as possible. They send a block template full of transactions right afterward, but a full block template is a bigger data transfer and takes slightly longer to reach miners.

In this intervening time, which is usually no more than 1-2 seconds, miners sometimes get lucky and find a new block using the empty block template.

-
-

If it's been a while and your transaction hasn't confirmed, your transaction is probably using a lower feerate relative to other transactions currently in the mempool. Depending on how you made your transaction, there may be ways to accelerate the process.

There's no need to panic—a Bitcoin transaction will always either confirm completely (or not at all) at some point. As long as you have your transaction's ID, you can always see where your funds are.

This site only provides data about the Bitcoin network—it cannot help you get your transaction confirmed quicker.

@@ -208,6 +200,24 @@ See the graphs page for aggregate trends over time: mempool size over time and incoming transaction velocity over time. + +

When a Bitcoin transaction is made, it is stored in a Bitcoin node's mempool before it is confirmed into a block. When the rate of incoming transactions exceeds the rate transactions are confirmed, the mempool grows in size.

By default, Bitcoin Core allocates 300MB of memory for its mempool, so when a node's mempool grows big enough to use all 300MB of allocated memory, we say it's "full".

Once a node's mempool is using all of its allocated memory, it will start rejecting new transactions below a certain feerate threshold—so when this is the case, be extra sure to set a feerate that (at a minimum) exceeds that threshold. The current threshold feerate (and memory usage) are displayed right on Mempool's front page.

+
+ + +

When a new block is found, mining pools send miners a block template with no transactions so they can start searching for the next block as soon as possible. They send a block template full of transactions right afterward, but a full block template is a bigger data transfer and takes slightly longer to reach miners.

In this intervening time, which is usually no more than 1-2 seconds, miners sometimes get lucky and find a new block using the empty block template.

+
+ + +

Block validation rules do not strictly require that a block's timestamp be more recent than the timestamp of the block preceding it. Without a central authority, it's impossible to know what the exact correct time is. Instead, the Bitcoin protocol requires that a block's timestamp meet certain requirements. One of those requirements is that a block's timestamp cannot be older than the median timestamp of the 12 blocks that came before it. See more details here.

As a result, timestamps are only accurate to within an hour or so, which sometimes results in blocks with timestamps that appear out of order.

+
+ + +

Mempool aims to show you the effective feerate range for blocks—how much would you actually need to pay to get a transaction included in a block.

+

A transaction's effective feerate is not always the same as the feerate explicitly set for it. For example, if you see a 1 s/vb transaction in a block with a displayed feerate range of 5 s/vb to 72 s/vb, chances are that 1 s/vb transaction had a high-feerate child transaction that boosted its effective feerate to 5 s/vb or higher (this is how CPFP fee-bumping works). In such a case, it would be misleading to use 1 s/vb as the lower bound of the block's feerate range because it actually required more than 1 s/vb to confirm that transaction in that block.

+

For unconfirmed CPFP transactions, Mempool will show the effective feerate (along with descendent & ancestor transaction information) on the transaction page. For confirmed transactions, CPFP relationships are not stored, so this additional information is not shown.

+
+ The official mempool.space website is operated by The Mempool Open Source Project. See more information on our About page. There are also many unofficial instances of this website operated by individual members of the Bitcoin community. diff --git a/frontend/src/app/docs/api-docs/api-docs.component.scss b/frontend/src/app/docs/api-docs/api-docs.component.scss index 0285e750c..7392d1f55 100644 --- a/frontend/src/app/docs/api-docs/api-docs.component.scss +++ b/frontend/src/app/docs/api-docs/api-docs.component.scss @@ -172,6 +172,7 @@ h3 { border-radius: 0.25rem; font-family: monospace; float: right; + white-space: nowrap; } .endpoint-container .section-header table { diff --git a/frontend/src/app/lightning/nodes-per-isp/nodes-per-isp.component.html b/frontend/src/app/lightning/nodes-per-isp/nodes-per-isp.component.html index a2f2a9b29..6e402e945 100644 --- a/frontend/src/app/lightning/nodes-per-isp/nodes-per-isp.component.html +++ b/frontend/src/app/lightning/nodes-per-isp/nodes-per-isp.component.html @@ -11,7 +11,7 @@
- +
- +
{{ isp?.id }}
NodesActive nodes {{ ispNodes.nodes.length }}