Compare commits

...

5 Commits

Author SHA1 Message Date
natsoni
4fded37cda
Use decimal recommended fee in websocket and on dashboard 2024-08-23 16:08:05 +02:00
natsoni
e3c06eb93b
Add V2 API endpoint for decimal recommended fees 2024-08-23 16:06:36 +02:00
natsoni
2664f52a23
Proxy /api/v2/ on dev and prod environments 2024-08-23 15:42:25 +02:00
natsoni
37030356dd
Add API V2 URL prefix to production backend 2024-08-23 14:14:42 +02:00
natsoni
cfe4228a4c
Add API V2 URL prefix to backend config 2024-08-23 14:12:38 +02:00
24 changed files with 162 additions and 18 deletions

View File

@ -7,6 +7,7 @@
"HTTP_PORT": 8999,
"SPAWN_CLUSTER_PROCS": 0,
"API_URL_PREFIX": "/api/v1/",
"API_V2_URL_PREFIX": "/api/v2/",
"POLL_RATE_MS": 2000,
"CACHE_DIR": "./cache",
"CACHE_ENABLED": true,

View File

@ -10,6 +10,7 @@
"UNIX_SOCKET_PATH": "/mempool/socket/mempool-bitcoin-mainnet",
"SPAWN_CLUSTER_PROCS": 2,
"API_URL_PREFIX": "__MEMPOOL_API_URL_PREFIX__",
"API_V2_URL_PREFIX": "__MEMPOOL_API_V2_URL_PREFIX__",
"AUTOMATIC_POOLS_UPDATE": false,
"POLL_RATE_MS": 3,
"CACHE_DIR": "__MEMPOOL_CACHE_DIR__",

View File

@ -23,6 +23,7 @@ describe('Mempool Backend Config', () => {
UNIX_SOCKET_PATH: '',
SPAWN_CLUSTER_PROCS: 0,
API_URL_PREFIX: '/api/v1/',
API_V2_URL_PREFIX: '/api/v2/',
AUTOMATIC_POOLS_UPDATE: false,
POLL_RATE_MS: 2000,
CACHE_DIR: './cache',

View File

@ -47,6 +47,9 @@ class BitcoinRoutes {
.post(config.MEMPOOL.API_URL_PREFIX + 'psbt/addparents', this.postPsbtCompletion)
.get(config.MEMPOOL.API_URL_PREFIX + 'blocks-bulk/:from', this.getBlocksByBulk.bind(this))
.get(config.MEMPOOL.API_URL_PREFIX + 'blocks-bulk/:from/:to', this.getBlocksByBulk.bind(this))
// V2 API
.get(config.MEMPOOL.API_V2_URL_PREFIX + 'fees/recommended', this.getRecommendedFeesDecimal)
;
if (config.MEMPOOL.BACKEND !== 'esplora') {
@ -100,6 +103,16 @@ class BitcoinRoutes {
res.json(result);
}
private getRecommendedFeesDecimal(req: Request, res: Response) {
if (!mempool.isInSync()) {
res.statusCode = 503;
res.send('Service Unavailable');
return;
}
const result = feeApi.getRecommendedFee(true);
res.json(result);
}
private getMempoolBlocks(req: Request, res: Response) {
try {
const result = mempoolBlocks.getMempoolBlocks();

View File

@ -19,10 +19,12 @@ class FeeApi {
defaultFee = isLiquid ? 0.1 : 1;
minimumIncrement = isLiquid ? 0.1 : 1;
public getRecommendedFee(): RecommendedFees {
public getRecommendedFee(decimal: boolean = false): RecommendedFees {
const pBlocks = projectedBlocks.getMempoolBlocks();
const mPool = mempool.getMempoolInfo();
const minimumFee = this.roundUpToNearest(mPool.mempoolminfee * 100000, this.minimumIncrement);
const minimumFee = decimal ?
this.roundUpToNearestDecimal(mPool.mempoolminfee * 100000) :
this.roundUpToNearest(mPool.mempoolminfee * 100000, this.minimumIncrement);
const defaultMinFee = Math.max(minimumFee, this.defaultFee);
if (!pBlocks.length) {
@ -35,9 +37,9 @@ class FeeApi {
};
}
const firstMedianFee = this.optimizeMedianFee(pBlocks[0], pBlocks[1]);
const secondMedianFee = pBlocks[1] ? this.optimizeMedianFee(pBlocks[1], pBlocks[2], firstMedianFee) : this.defaultFee;
const thirdMedianFee = pBlocks[2] ? this.optimizeMedianFee(pBlocks[2], pBlocks[3], secondMedianFee) : this.defaultFee;
const firstMedianFee = this.optimizeMedianFee(pBlocks[0], pBlocks[1], undefined, decimal);
const secondMedianFee = pBlocks[1] ? this.optimizeMedianFee(pBlocks[1], pBlocks[2], firstMedianFee, decimal) : this.defaultFee;
const thirdMedianFee = pBlocks[2] ? this.optimizeMedianFee(pBlocks[2], pBlocks[3], secondMedianFee, decimal) : this.defaultFee;
let fastestFee = Math.max(minimumFee, firstMedianFee);
let halfHourFee = Math.max(minimumFee, secondMedianFee);
@ -62,7 +64,7 @@ class FeeApi {
};
}
private optimizeMedianFee(pBlock: MempoolBlock, nextBlock: MempoolBlock | undefined, previousFee?: number): number {
private optimizeMedianFee(pBlock: MempoolBlock, nextBlock: MempoolBlock | undefined, previousFee?: number, decimal: boolean = false): number {
const useFee = previousFee ? (pBlock.medianFee + previousFee) / 2 : pBlock.medianFee;
if (pBlock.blockVSize <= 500000) {
return this.defaultFee;
@ -71,12 +73,18 @@ class FeeApi {
const multiplier = (pBlock.blockVSize - 500000) / 500000;
return Math.max(Math.round(useFee * multiplier), this.defaultFee);
}
return this.roundUpToNearest(useFee, this.minimumIncrement);
return decimal ?
this.roundUpToNearestDecimal(useFee) :
this.roundUpToNearest(useFee, this.minimumIncrement);
}
private roundUpToNearest(value: number, nearest: number): number {
return Math.ceil(value / nearest) * nearest;
}
private roundUpToNearestDecimal(value: number): number {
return Number(this.roundUpToNearest(value, 0.1).toFixed(1)); // avoid floating point errors
}
}
export default new FeeApi();

View File

@ -95,7 +95,7 @@ class WebsocketHandler {
'backendInfo': backendInfo.getBackendInfo(),
'loadingIndicators': loadingIndicators.getLoadingIndicators(),
'da': da?.previousTime ? da : undefined,
'fees': feeApi.getRecommendedFee(),
'fees': feeApi.getRecommendedFee(true),
});
}
@ -567,7 +567,7 @@ class WebsocketHandler {
}
memPool.removeFromSpendMap(deletedTransactions);
memPool.addToSpendMap(newTransactions);
const recommendedFees = feeApi.getRecommendedFee();
const recommendedFees = feeApi.getRecommendedFee(true);
const latestTransactions = memPool.getLatestTransactions();
@ -1048,7 +1048,7 @@ class WebsocketHandler {
const mBlockDeltas = mempoolBlocks.getMempoolBlockDeltas();
const da = difficultyAdjustment.getDifficultyAdjustment();
const fees = feeApi.getRecommendedFee();
const fees = feeApi.getRecommendedFee(true);
const mempoolInfo = memPool.getMempoolInfo();
// pre-compute address transactions

View File

@ -12,6 +12,7 @@ interface IConfig {
UNIX_SOCKET_PATH: string;
SPAWN_CLUSTER_PROCS: number;
API_URL_PREFIX: string;
API_V2_URL_PREFIX: string;
POLL_RATE_MS: number;
CACHE_DIR: string;
CACHE_ENABLED: boolean;
@ -172,6 +173,7 @@ const defaults: IConfig = {
'UNIX_SOCKET_PATH': '',
'SPAWN_CLUSTER_PROCS': 0,
'API_URL_PREFIX': '/api/v1/',
'API_V2_URL_PREFIX': '/api/v2/',
'POLL_RATE_MS': 2000,
'CACHE_DIR': './cache',
'CACHE_ENABLED': true,

View File

@ -8,6 +8,7 @@
"SPAWN_CLUSTER_PROCS": __MEMPOOL_SPAWN_CLUSTER_PROCS__,
"UNIX_SOCKET_PATH": "__MEMPOOL_UNIX_SOCKET_PATH__",
"API_URL_PREFIX": "__MEMPOOL_API_URL_PREFIX__",
"API_V2_URL_PREFIX": "__MEMPOOL_API_V2_URL_PREFIX__",
"POLL_RATE_MS": __MEMPOOL_POLL_RATE_MS__,
"CACHE_DIR": "__MEMPOOL_CACHE_DIR__",
"CACHE_ENABLED": __MEMPOOL_CACHE_ENABLED__,

View File

@ -9,6 +9,7 @@ __MEMPOOL_HTTP_PORT__=${BACKEND_HTTP_PORT:=8999}
__MEMPOOL_SPAWN_CLUSTER_PROCS__=${MEMPOOL_SPAWN_CLUSTER_PROCS:=0}
__MEMPOOL_UNIX_SOCKET_PATH__=${MEMPOOL_UNIX_SOCKET_PATH:=""}
__MEMPOOL_API_URL_PREFIX__=${MEMPOOL_API_URL_PREFIX:=/api/v1/}
__MEMPOOL_API_V2_URL_PREFIX__=${MEMPOOL_API_V2_URL_PREFIX:=/api/v2/}
__MEMPOOL_POLL_RATE_MS__=${MEMPOOL_POLL_RATE_MS:=2000}
__MEMPOOL_CACHE_DIR__=${MEMPOOL_CACHE_DIR:=./cache}
__MEMPOOL_CACHE_ENABLED__=${MEMPOOL_CACHE_ENABLED:=true}
@ -167,6 +168,7 @@ sed -i "s!__MEMPOOL_HTTP_PORT__!${__MEMPOOL_HTTP_PORT__}!g" mempool-config.json
sed -i "s!__MEMPOOL_SPAWN_CLUSTER_PROCS__!${__MEMPOOL_SPAWN_CLUSTER_PROCS__}!g" mempool-config.json
sed -i "s!__MEMPOOL_UNIX_SOCKET_PATH__!${__MEMPOOL_UNIX_SOCKET_PATH__}!g" mempool-config.json
sed -i "s!__MEMPOOL_API_URL_PREFIX__!${__MEMPOOL_API_URL_PREFIX__}!g" mempool-config.json
sed -i "s!__MEMPOOL_API_V2_URL_PREFIX__!${__MEMPOOL_API_V2_URL_PREFIX__}!g" mempool-config.json
sed -i "s!__MEMPOOL_POLL_RATE_MS__!${__MEMPOOL_POLL_RATE_MS__}!g" mempool-config.json
sed -i "s!__MEMPOOL_CACHE_DIR__!${__MEMPOOL_CACHE_DIR__}!g" mempool-config.json
sed -i "s!__MEMPOOL_CACHE_ENABLED__!${__MEMPOOL_CACHE_ENABLED__}!g" mempool-config.json

View File

@ -33,6 +33,17 @@ if (configContent && configContent.BASE_MODULE === 'liquid') {
"^/liquid": ""
},
},
{
context: ['/liquid/api/v2/**'],
target: `http://127.0.0.1:8999`,
secure: false,
ws: true,
changeOrigin: true,
proxyTimeout: 30000,
pathRewrite: {
"^/liquid": ""
},
},
{
context: ['/liquid/api/**'],
target: `http://127.0.0.1:3000`,
@ -54,6 +65,17 @@ if (configContent && configContent.BASE_MODULE === 'liquid') {
"^/liquidtestnet": ""
},
},
{
context: ['/liquidtestnet/api/v2/**'],
target: `http://127.0.0.1:8999`,
secure: false,
ws: true,
changeOrigin: true,
proxyTimeout: 30000,
pathRewrite: {
"^/liquidtestnet": ""
},
},
{
context: ['/liquidtestnet/api/**'],
target: `http://127.0.0.1:3000`,
@ -106,6 +128,14 @@ PROXY_CONFIG.push(...[
changeOrigin: true,
proxyTimeout: 30000,
},
{
context: ['/api/v2/**'],
target: `http://127.0.0.1:8999`,
secure: false,
ws: true,
changeOrigin: true,
proxyTimeout: 30000,
},
{
context: ['/api/**'],
target: `http://127.0.0.1:3000`,

View File

@ -33,6 +33,17 @@ if (configContent && configContent.BASE_MODULE === 'liquid') {
"^/liquid": ""
},
},
{
context: ['/liquid/api/v2/**'],
target: `http://localhost:8999`,
secure: false,
ws: true,
changeOrigin: true,
proxyTimeout: 30000,
pathRewrite: {
"^/liquid": ""
},
},
{
context: ['/liquid/api/**'],
target: `http://localhost:8999`,
@ -54,6 +65,17 @@ if (configContent && configContent.BASE_MODULE === 'liquid') {
"^/liquidtestnet": ""
},
},
{
context: ['/liquidtestnet/api/v2/**'],
target: `http://localhost:8999`,
secure: false,
ws: true,
changeOrigin: true,
proxyTimeout: 30000,
pathRewrite: {
"^/liquidtestnet": ""
},
},
{
context: ['/liquidtestnet/api/**'],
target: `http://localhost:8999`,
@ -94,6 +116,14 @@ PROXY_CONFIG.push(...[
changeOrigin: true,
proxyTimeout: 30000,
},
{
context: ['/api/v2/**'],
target: `http://localhost:8999`,
secure: false,
ws: true,
changeOrigin: true,
proxyTimeout: 30000,
},
{
context: ['/api/**'],
target: `http://localhost:8999`,

View File

@ -33,6 +33,17 @@ if (configContent && configContent.BASE_MODULE === 'liquid') {
"^/liquid": ""
},
},
{
context: ['/liquid/api/v2/**'],
target: `http://localhost:8999`,
secure: false,
ws: true,
changeOrigin: true,
proxyTimeout: 30000,
pathRewrite: {
"^/liquid": ""
},
},
{
context: ['/liquid/api/**'],
target: `https://liquid.network`,
@ -51,6 +62,17 @@ if (configContent && configContent.BASE_MODULE === 'liquid') {
"^/liquidtestnet": ""
},
},
{
context: ['/liquidtestnet/api/v2/**'],
target: `http://localhost:8999`,
secure: false,
ws: true,
changeOrigin: true,
proxyTimeout: 30000,
pathRewrite: {
"^/liquidtestnet": ""
},
},
{
context: ['/liquidtestnet/api/**'],
target: `https://liquid.network`,
@ -78,6 +100,14 @@ PROXY_CONFIG.push(...[
changeOrigin: true,
proxyTimeout: 30000,
},
{
context: ['/api/v2/**'],
target: `http://localhost:8999`,
secure: false,
ws: true,
changeOrigin: true,
proxyTimeout: 30000,
},
{
context: ['/api/**'],
target: `https://mempool.space`,

View File

@ -13,23 +13,23 @@
<div class="fee-estimation-container">
<div class="item">
<div class="card-text">
<div class="fee-text"><app-fee-rate [fee]="recommendedFees.economyFee" rounding="1.0-0"></app-fee-rate></div> <span class="fiat"><app-fiat i18n-ngbTooltip="Transaction fee tooltip" ngbTooltip="Based on average native segwit transaction of 140 vBytes" placement="bottom" [value]="recommendedFees.economyFee * 140" ></app-fiat></span>
<div class="fee-text"><app-fee-rate [fee]="recommendedFees.economyFee" rounding="1.0-1"></app-fee-rate></div> <span class="fiat"><app-fiat i18n-ngbTooltip="Transaction fee tooltip" ngbTooltip="Based on average native segwit transaction of 140 vBytes" placement="bottom" [value]="recommendedFees.economyFee * 140" ></app-fiat></span>
</div>
</div>
<div class="band-separator"></div>
<div class="item">
<div class="card-text">
<div class="fee-text"><app-fee-rate [fee]="recommendedFees.hourFee" rounding="1.0-0"></app-fee-rate></div> <span class="fiat"><app-fiat i18n-ngbTooltip="Transaction fee tooltip" ngbTooltip="Based on average native segwit transaction of 140 vBytes" placement="bottom" [value]="recommendedFees.hourFee * 140" ></app-fiat></span>
<div class="fee-text"><app-fee-rate [fee]="recommendedFees.hourFee" rounding="1.0-1"></app-fee-rate></div> <span class="fiat"><app-fiat i18n-ngbTooltip="Transaction fee tooltip" ngbTooltip="Based on average native segwit transaction of 140 vBytes" placement="bottom" [value]="recommendedFees.hourFee * 140" ></app-fiat></span>
</div>
</div>
<div class="item">
<div class="card-text">
<div class="fee-text"><app-fee-rate [fee]="recommendedFees.halfHourFee" rounding="1.0-0"></app-fee-rate></div> <span class="fiat"><app-fiat i18n-ngbTooltip="Transaction fee tooltip" ngbTooltip="Based on average native segwit transaction of 140 vBytes" placement="bottom" [value]="recommendedFees.halfHourFee * 140" ></app-fiat></span>
<div class="fee-text"><app-fee-rate [fee]="recommendedFees.halfHourFee" rounding="1.0-1"></app-fee-rate></div> <span class="fiat"><app-fiat i18n-ngbTooltip="Transaction fee tooltip" ngbTooltip="Based on average native segwit transaction of 140 vBytes" placement="bottom" [value]="recommendedFees.halfHourFee * 140" ></app-fiat></span>
</div>
</div>
<div class="item">
<div class="card-text">
<div class="fee-text"><app-fee-rate [fee]="recommendedFees.fastestFee" rounding="1.0-0"></app-fee-rate></div> <span class="fiat"><app-fiat i18n-ngbTooltip="Transaction fee tooltip" ngbTooltip="Based on average native segwit transaction of 140 vBytes" placement="bottom" [value]="recommendedFees.fastestFee * 140" ></app-fiat></span>
<div class="fee-text"><app-fee-rate [fee]="recommendedFees.fastestFee" rounding="1.0-1"></app-fee-rate></div> <span class="fiat"><app-fiat i18n-ngbTooltip="Transaction fee tooltip" ngbTooltip="Based on average native segwit transaction of 140 vBytes" placement="bottom" [value]="recommendedFees.fastestFee * 140" ></app-fiat></span>
</div>
</div>
</div>

View File

@ -36,7 +36,7 @@ export class FeesBoxComponent implements OnInit, OnDestroy {
this.recommendedFees$ = this.stateService.recommendedFees$
.pipe(
tap((fees) => {
this.fees = fees;
this.fees = this.roundFees(fees);
this.setFeeGradient();
}
)
@ -61,6 +61,19 @@ export class FeesBoxComponent implements OnInit, OnDestroy {
this.cd.markForCheck();
}
roundFees(fees: Recommendedfees): Recommendedfees {
fees.fastestFee = this.roundFeeValue(fees.fastestFee);
fees.halfHourFee = this.roundFeeValue(fees.halfHourFee);
fees.hourFee = this.roundFeeValue(fees.hourFee);
fees.economyFee = this.roundFeeValue(fees.economyFee);
fees.minimumFee = this.roundFeeValue(fees.minimumFee);
return fees;
}
roundFeeValue(fee: number): number {
return fee >= 10.0 ? Math.ceil(fee) : fee;
}
ngOnDestroy(): void {
this.themeSubscription.unsubscribe();
}

View File

@ -64,6 +64,9 @@
location /api/ {
proxy_pass http://127.0.0.1:8999/api/v1/;
}
location /api/v2 {
proxy_pass http://127.0.0.1:8999/api/v2;
}
# mainnet API
location /ws {

View File

@ -7,6 +7,7 @@
"MINED_BLOCKS_CACHE": 144,
"SPAWN_CLUSTER_PROCS": 0,
"API_URL_PREFIX": "/api/v1/",
"API_V2_URL_PREFIX": "/api/v2/",
"POLL_RATE_MS": 1000,
"DISK_CACHE_BLOCK_INTERVAL": 1
},

View File

@ -7,6 +7,7 @@
"MINED_BLOCKS_CACHE": 144,
"SPAWN_CLUSTER_PROCS": 0,
"API_URL_PREFIX": "/api/v1/",
"API_V2_URL_PREFIX": "/api/v2/",
"POLL_RATE_MS": 1000,
"DISK_CACHE_BLOCK_INTERVAL": 1
},

View File

@ -6,7 +6,8 @@
"BACKEND": "esplora",
"HTTP_PORT": 8993,
"INDEXING_BLOCKS_AMOUNT": 0,
"API_URL_PREFIX": "/api/v1/"
"API_URL_PREFIX": "/api/v1/",
"API_V2_URL_PREFIX": "/api/v2/"
},
"SYSLOG": {
"MIN_PRIORITY": "debug"

View File

@ -8,6 +8,7 @@
"MINED_BLOCKS_CACHE": 144,
"SPAWN_CLUSTER_PROCS": 0,
"API_URL_PREFIX": "/api/v1/",
"API_V2_URL_PREFIX": "/api/v2/",
"CLEAR_PROTECTION_MINUTES": 5,
"POLL_RATE_MS": 1000,
"INDEXING_BLOCKS_AMOUNT": -1,

View File

@ -6,7 +6,8 @@
"BACKEND": "esplora",
"HTTP_PORT": 8991,
"INDEXING_BLOCKS_AMOUNT": 0,
"API_URL_PREFIX": "/api/v1/"
"API_URL_PREFIX": "/api/v1/",
"API_V2_URL_PREFIX": "/api/v2/"
},
"SYSLOG": {
"MIN_PRIORITY": "debug"

View File

@ -7,6 +7,7 @@
"MINED_BLOCKS_CACHE": 144,
"SPAWN_CLUSTER_PROCS": 0,
"API_URL_PREFIX": "/api/v1/",
"API_V2_URL_PREFIX": "/api/v2/",
"INDEXING_BLOCKS_AMOUNT": -1,
"AUTOMATIC_POOLS_UPDATE": true,
"AUDIT": true,

View File

@ -6,7 +6,8 @@
"BACKEND": "esplora",
"HTTP_PORT": 8992,
"INDEXING_BLOCKS_AMOUNT": 0,
"API_URL_PREFIX": "/api/v1/"
"API_URL_PREFIX": "/api/v1/",
"API_V2_URL_PREFIX": "/api/v2/"
},
"SYSLOG": {
"MIN_PRIORITY": "debug"

View File

@ -7,6 +7,7 @@
"MINED_BLOCKS_CACHE": 144,
"SPAWN_CLUSTER_PROCS": 0,
"API_URL_PREFIX": "/api/v1/",
"API_V2_URL_PREFIX": "/api/v2/",
"INDEXING_BLOCKS_AMOUNT": -1,
"AUTOMATIC_POOLS_UPDATE": true,
"AUDIT": true,

View File

@ -7,6 +7,7 @@
"MINED_BLOCKS_CACHE": 144,
"SPAWN_CLUSTER_PROCS": 0,
"API_URL_PREFIX": "/api/v1/",
"API_V2_URL_PREFIX": "/api/v2/",
"INDEXING_BLOCKS_AMOUNT": -1,
"AUTOMATIC_POOLS_UPDATE": true,
"AUDIT": true,