diff --git a/backend/src/api/bitcoin/bitcoin-api-abstract-factory.ts b/backend/src/api/bitcoin/bitcoin-api-abstract-factory.ts index 358bd29e4..aa9fe5d15 100644 --- a/backend/src/api/bitcoin/bitcoin-api-abstract-factory.ts +++ b/backend/src/api/bitcoin/bitcoin-api-abstract-factory.ts @@ -3,6 +3,7 @@ import { IEsploraApi } from './esplora-api.interface'; export interface AbstractBitcoinApi { $getRawMempool(): Promise; $getRawTransaction(txId: string, skipConversion?: boolean, addPrevout?: boolean, lazyPrevouts?: boolean): Promise; + $getTransactionHex(txId: string): Promise; $getBlockHeightTip(): Promise; $getBlockHashTip(): Promise; $getTxIdsForBlock(hash: string): Promise; diff --git a/backend/src/api/bitcoin/bitcoin-api.ts b/backend/src/api/bitcoin/bitcoin-api.ts index ebde5cc07..0a3d674ec 100644 --- a/backend/src/api/bitcoin/bitcoin-api.ts +++ b/backend/src/api/bitcoin/bitcoin-api.ts @@ -57,6 +57,11 @@ class BitcoinApi implements AbstractBitcoinApi { }); } + $getTransactionHex(txId: string): Promise { + return this.$getRawTransaction(txId, true) + .then((tx) => tx.hex || ''); + } + $getBlockHeightTip(): Promise { return this.bitcoindClient.getChainTips() .then((result: IBitcoinApi.ChainTips[]) => { diff --git a/backend/src/api/bitcoin/bitcoin.routes.ts b/backend/src/api/bitcoin/bitcoin.routes.ts index 2c3fd9467..3740cccd4 100644 --- a/backend/src/api/bitcoin/bitcoin.routes.ts +++ b/backend/src/api/bitcoin/bitcoin.routes.ts @@ -1,5 +1,6 @@ import { Application, Request, Response } from 'express'; import axios from 'axios'; +import * as bitcoinjs from 'bitcoinjs-lib'; import config from '../../config'; import websocketHandler from '../websocket-handler'; import mempool from '../mempool'; @@ -87,7 +88,8 @@ class BitcoinRoutes { .get(config.MEMPOOL.API_URL_PREFIX + 'blocks', this.getBlocks.bind(this)) .get(config.MEMPOOL.API_URL_PREFIX + 'blocks/:height', this.getBlocks.bind(this)) .get(config.MEMPOOL.API_URL_PREFIX + 'block/:hash', this.getBlock) - .get(config.MEMPOOL.API_URL_PREFIX + 'block/:hash/summary', this.getStrippedBlockTransactions); + .get(config.MEMPOOL.API_URL_PREFIX + 'block/:hash/summary', this.getStrippedBlockTransactions) + .post(config.MEMPOOL.API_URL_PREFIX + 'psbt/addparents', this.postPsbtCompletion) ; if (config.MEMPOOL.BACKEND !== 'esplora') { @@ -241,6 +243,74 @@ class BitcoinRoutes { } } + /** + * Takes the PSBT as text/plain body, parses it, and adds the full + * parent transaction to each input that doesn't already have it. + * This is used for BTCPayServer / Trezor users which need access to + * the full parent transaction even with segwit inputs. + * It will respond with a text/plain PSBT in the same format (hex|base64). + */ + private async postPsbtCompletion(req: Request, res: Response): Promise { + res.setHeader('content-type', 'text/plain'); + const notFoundError = `Couldn't get transaction hex for parent of input`; + try { + let psbt: bitcoinjs.Psbt; + let format: 'hex' | 'base64'; + let isModified = false; + try { + psbt = bitcoinjs.Psbt.fromBase64(req.body); + format = 'base64'; + } catch (e1) { + try { + psbt = bitcoinjs.Psbt.fromHex(req.body); + format = 'hex'; + } catch (e2) { + throw new Error(`Unable to parse PSBT`); + } + } + for (const [index, input] of psbt.data.inputs.entries()) { + if (!input.nonWitnessUtxo) { + // Buffer.from ensures it won't be modified in place by reverse() + const txid = Buffer.from(psbt.txInputs[index].hash) + .reverse() + .toString('hex'); + + let transactionHex: string; + // If missing transaction, return 404 status error + try { + transactionHex = await bitcoinApi.$getTransactionHex(txid); + if (!transactionHex) { + throw new Error(''); + } + } catch (err) { + throw new Error(`${notFoundError} #${index} @ ${txid}`); + } + + psbt.updateInput(index, { + nonWitnessUtxo: Buffer.from(transactionHex, 'hex'), + }); + if (!isModified) { + isModified = true; + } + } + } + if (isModified) { + res.send(format === 'hex' ? psbt.toHex() : psbt.toBase64()); + } else { + // Not modified + // 422 Unprocessable Entity + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422 + res.status(422).send(`Psbt had no missing nonWitnessUtxos.`); + } + } catch (e: any) { + if (e instanceof Error && new RegExp(notFoundError).test(e.message)) { + res.status(404).send(e.message); + } else { + res.status(500).send(e instanceof Error ? e.message : e); + } + } + } + private async getTransactionStatus(req: Request, res: Response) { try { const transaction = await transactionUtils.$getTransactionExtended(req.params.txId, true); diff --git a/backend/src/api/bitcoin/esplora-api.ts b/backend/src/api/bitcoin/esplora-api.ts index ebaf2f6a0..3662347d6 100644 --- a/backend/src/api/bitcoin/esplora-api.ts +++ b/backend/src/api/bitcoin/esplora-api.ts @@ -20,6 +20,11 @@ class ElectrsApi implements AbstractBitcoinApi { .then((response) => response.data); } + $getTransactionHex(txId: string): Promise { + return axios.get(config.ESPLORA.REST_API_URL + '/tx/' + txId + '/hex', this.axiosConfig) + .then((response) => response.data); + } + $getBlockHeightTip(): Promise { return axios.get(config.ESPLORA.REST_API_URL + '/blocks/tip/height', this.axiosConfig) .then((response) => response.data); diff --git a/backend/src/index.ts b/backend/src/index.ts index 00afad8bf..8371e927f 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -84,7 +84,7 @@ class Server { next(); }) .use(express.urlencoded({ extended: true })) - .use(express.text()) + .use(express.text({ type: ['text/plain', 'application/base64'] })) ; this.server = http.createServer(this.app); 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/transaction/transaction.component.html b/frontend/src/app/components/transaction/transaction.component.html index cd0cd716d..d478da053 100644 --- a/frontend/src/app/components/transaction/transaction.component.html +++ b/frontend/src/app/components/transaction/transaction.component.html @@ -204,7 +204,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/components/tx-bowtie-graph/tx-bowtie-graph.component.ts b/frontend/src/app/components/tx-bowtie-graph/tx-bowtie-graph.component.ts index 3e4c87678..74eb4c67b 100644 --- a/frontend/src/app/components/tx-bowtie-graph/tx-bowtie-graph.component.ts +++ b/frontend/src/app/components/tx-bowtie-graph/tx-bowtie-graph.component.ts @@ -298,7 +298,7 @@ export class TxBowtieGraphComponent implements OnInit, OnChanges { // required to prevent this line overlapping its neighbor if (this.tooltip || !xputs[i].rest) { - const w = (this.width - Math.max(lastWeight, line.weight) - (2 * this.connectorWidth)) / 2; // approximate horizontal width of the curved section of the line + const w = (this.txWidth - Math.max(lastWeight, line.weight) - (this.connectorWidth * 2)) / 2; // approximate horizontal width of the curved section of the line const y1 = line.outerY; const y2 = line.innerY; const t = (lastWeight + line.weight) / 2; // distance between center of this line and center of previous line @@ -356,7 +356,7 @@ export class TxBowtieGraphComponent implements OnInit, OnChanges { makePath(side: 'in' | 'out', outer: number, inner: number, weight: number, offset: number, pad: number): string { const start = (weight * 0.5) + this.connectorWidth; - const curveStart = Math.max(start + 5, pad - offset); + const curveStart = Math.max(start + 5, pad + this.connectorWidth - offset); const end = this.width / 2 - (this.midWidth * 0.9) + 1; const curveEnd = end - offset - 10; const midpoint = (curveStart + curveEnd) / 2; 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/production/nginx/location-redirects.conf b/production/nginx/location-redirects.conf index c6f20e7ad..d330b9deb 100644 --- a/production/nginx/location-redirects.conf +++ b/production/nginx/location-redirects.conf @@ -1,12 +1,12 @@ # redirect mempool.space/liquid to liquid.network -location /liquid { +location = /liquid { rewrite /liquid/(.*) https://liquid.network/$1; rewrite /liquid https://liquid.network/; return 308; } # redirect mempool.space/liquidtestnet to liquid.network/testnet -location /liquidtestnet { +location = /liquidtestnet { rewrite /liquidtestnet/(.*) https://liquid.network/testnet/$1; rewrite /liquidtestnet/ https://liquid.network/testnet/; rewrite /liquidtestnet https://liquid.network/testnet; @@ -14,7 +14,7 @@ location /liquidtestnet { } # redirect mempool.space/bisq to bisq.markets -location /bisq { +location = /bisq { rewrite /bisq/(.*) https://bisq.markets/$1; rewrite /bisq https://bisq.markets/; return 308;
- +