From d1d796d7534720c53c4d56494b006f6afa11b93c Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Wed, 3 Jan 2024 13:30:40 +0700 Subject: [PATCH 1/4] Prety print the result when accessed as text/html --- src/server.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/server.js b/src/server.js index cdbf3ce..13e5541 100644 --- a/src/server.js +++ b/src/server.js @@ -133,8 +133,14 @@ app.get('/v1/fee-estimates.json', async (req, res) => { // Set cache headers res.set('Cache-Control', `public, max-age=${stdTTL}`); - // Send the response. - res.json(data); + // Check the Accept header and return the appropriate response + if (req.headers.accept.includes('text/html')) { + // Return a pretty HTML response + res.send('
' + JSON.stringify(data, null, 2) + '
'); + } else { + // Return a JSON response + res.json(data); + } } catch (error) { console.error(error); res.status(500).send('Error fetching fee estimates'); From c62155f585a1e28e8c25a9af4c81c07197d7079f Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Wed, 3 Jan 2024 13:34:11 +0700 Subject: [PATCH 2/4] Use strike colour scheme --- src/server.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/server.js b/src/server.js index 13e5541..1a1fadf 100644 --- a/src/server.js +++ b/src/server.js @@ -136,7 +136,14 @@ app.get('/v1/fee-estimates.json', async (req, res) => { // Check the Accept header and return the appropriate response if (req.headers.accept.includes('text/html')) { // Return a pretty HTML response - res.send('
' + JSON.stringify(data, null, 2) + '
'); + res.send(` + + + + +
${JSON.stringify(data, null, 2)}
+ + `); } else { // Return a JSON response res.json(data); From d2208cc7c662726bed4eadf62799f3081db42532 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Wed, 3 Jan 2024 13:47:39 +0700 Subject: [PATCH 3/4] Rename project to bitcoin-blended-fee-estimator --- .github/workflows/latest.yml | 2 +- .github/workflows/release.yml | 4 ++-- README.md | 16 ++++++++-------- package-lock.json | 4 ++-- package.json | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/latest.yml b/.github/workflows/latest.yml index a79ebcf..307b585 100644 --- a/.github/workflows/latest.yml +++ b/.github/workflows/latest.yml @@ -13,7 +13,7 @@ jobs: env: GAR_REGISTRY: us-east1-docker.pkg.dev - GAR_IMAGE: zap-strike-infrastructure/zap-container-registry/lnd-mempoolspace + GAR_IMAGE: zap-strike-infrastructure/zap-container-registry/bitcoin-blended-fee-estimator steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4b71860..9d9cee5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,8 +10,8 @@ jobs: env: GAR_REGISTRY: us-east1-docker.pkg.dev - GAR_IMAGE: zap-strike-infrastructure/zap-container-registry/lnd-mempoolspace - DOCKERHUB_IMAGE: lnzap/lnd-mempoolspace + GAR_IMAGE: zap-strike-infrastructure/zap-container-registry/bitcoin-blended-fee-estimator + DOCKERHUB_IMAGE: lnzap/bitcoin-blended-fee-estimator steps: - name: Checkout Code diff --git a/README.md b/README.md index e4ce73c..4148bc8 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ -# Lnd Mempool.Space Integration +# Bitcoin Blended Fee Estimator -This project aims to integrate the [Lightning Network Daemon (lnd)](https://github.com/lightningnetwork/lnd) with [mempool.space](https://mempool.space/), a Bitcoin blockchain explorer. The primary feature of this integration is to provide fee estimates to lnd based on a combination of mempool-based estimates (from the mempool.space API) and history-based estimates (from the Blockstream API). +This project provides bitcoin fee estimates using a blend of mempool-based and history-based estimations. The initial use case is to provide onchain fee estimates to [lnd](https://github.com/lightningnetwork/lnd), however it could easily be adapted/extended to be used by other applications. ## Fee Estimates This application uses two APIs to get fee estimates for Bitcoin transactions: -- [**mempool.space API**](https://mempool.space/docs/api/rest): This API is used to get mempool-based fee estimates for upcoming blocks. The application fetches the fastestFee, halfHourFee, hourFee, economyFee, and minimumFee from the mempool.space API and uses these estimates to calculate the fee for upcoming blocks. The application also multiplies these estimates by a configurable multiplier to ensure that can be used to ensure that the fee estimates are always slightly higher or lower than the mempool.space estimates. +- [**mempool.space API**](https://mempool.space/docs/api/rest): This API is used to get mempool-based fee estimates for upcoming blocks. The application fetches the fastestFee, halfHourFee, hourFee, economyFee, and minimumFee from the mempool.space API and uses these estimates to calculate the fee for upcoming blocks. - [**Blockstream API**](https://github.com/Blockstream/esplora/blob/master/API.md): This API is used to get history-based fee estimates for further future blocks. The application fetches the fee estimates from the Blockstream API (which gets its data from bitcoind) and adds them to the fee estimates if they are lower than the lowest fee estimate from the mempool.space API. -Fee estimates are cached for a configurable amount of time (15 seconds by default) to reduce the number of API calls. The cache is automatically cleared after the configured time has elapsed. +Fee estimates are multipled by a configurable multiplier (1.05 by default) to provide estimates are always slightly higher or lower than the raw estimates (allows a more conservative or aggressive approach), and cached for a configurable amount of time (15 seconds by default). ## API -This application exposes a single API endpoint at `/v1/fee-estimates.json`. This endpoint returns a JSON object with the following structure, which is compatible with the LND's `feeurl` setting: +This application exposes a single API endpoint at `/v1/fee-estimates.json`. This endpoint returns a JSON object with the following structure, which is compatible with the lnd's `feeurl` setting: ```json { @@ -94,10 +94,10 @@ PORT=4000 MEMPOOL_HOSTNAME=localhost npm start This project includes Docker support and an official Docker image is available. You can run the Docker image with the following command: ```bash -docker run -p 3000:3000 lnzap/lnd-mempoolspace:latest +docker run -p 3000:3000 lnzap/bitcoin-blended-fee-estimator:latest ``` -This command will pull the latest `lnzap/lnd-mempoolspace` image from Docker Hub and run it. By default, the Docker image runs the server on port 3000. +This command will pull the latest `lnzap/bitcoin-blended-fee-estimator` image from Docker Hub and run it. By default, the Docker image runs the server on port 3000. Please ensure that Docker is installed and running on your machine before running these commands. @@ -134,7 +134,7 @@ Once the release is published, the Docker build and push process will start auto Please note that you need to have the necessary permissions to create a release and push to Docker Hub. ## Contributing -We welcome contributions to this project. Please feel free to open an [issue](https://github.com/LN-Zap/lnd-mempoolspace/issues) or submit a [pull request](https://github.com/LN-Zap/lnd-mempoolspace/pulls). +We welcome contributions to this project. Please feel free to open an [issue](https://github.com/LN-Zap/bitcoin-blended-fee-estimator/issues) or submit a [pull request](https://github.com/LN-Zap/bitcoin-blended-fee-estimator/pulls). ## License This project is licensed under the MIT License. See the [LICENSE](./LICENSE.md) file for more details. diff --git a/package-lock.json b/package-lock.json index b103aae..6ac7bdf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "lnd-mempoolspace", + "name": "bitcoin-blended-fee-estimator", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "lnd-mempoolspace", + "name": "bitcoin-blended-fee-estimator", "version": "1.0.0", "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 86dfd44..5cc33e3 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { - "name": "lnd-mempoolspace", + "name": "bitcoin-blended-fee-estimator", "version": "1.0.0", "description": "Integration between Lightning Network Daemon (lnd) and mempool.space for Bitcoin fee estimates", "main": "src/server.js", "scripts": { "start": "node src/server.js", - "docker:build": "docker build -t lnd-mempoolspace .", - "docker:run": "docker run --init -p 3000:3000 lnd-mempoolspace" + "docker:build": "docker build -t bitcoin-blended-fee-estimator .", + "docker:run": "docker run --init -p 3000:3000 bitcoin-blended-fee-estimator" }, "keywords": [ "lnd", From 944f683e4ee665b62cbcf6bed404a47988f985d5 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Wed, 3 Jan 2024 13:55:16 +0700 Subject: [PATCH 4/4] Use dev tag for dev builds --- .github/workflows/{latest.yml => dev.yml} | 4 ++-- .github/workflows/release.yml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) rename .github/workflows/{latest.yml => dev.yml} (93%) diff --git a/.github/workflows/latest.yml b/.github/workflows/dev.yml similarity index 93% rename from .github/workflows/latest.yml rename to .github/workflows/dev.yml index 307b585..5997a24 100644 --- a/.github/workflows/latest.yml +++ b/.github/workflows/dev.yml @@ -1,4 +1,4 @@ -name: Latest +name: Dev on: push: @@ -33,6 +33,6 @@ jobs: with: context: . push: true - tags: ${{ env.GAR_REGISTRY }}/${{ env.GAR_IMAGE }}:latest + tags: ${{ env.GAR_REGISTRY }}/${{ env.GAR_IMAGE }}:dev cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9d9cee5..01c616f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,6 +36,7 @@ jobs: push: true tags: | ${{ env.GAR_REGISTRY }}/${{ env.GAR_IMAGE }}:${{ env.VERSION }} + ${{ env.GAR_REGISTRY }}/${{ env.GAR_IMAGE }}:latest ${{ env.DOCKERHUB_IMAGE }}:latest ${{ env.DOCKERHUB_IMAGE }}:${{ env.VERSION }} platforms: linux/amd64,linux/arm64