Skip to content

Commit

Permalink
Merge pull request #6 from LN-Zap/recommendations
Browse files Browse the repository at this point in the history
Rename project and prep for deployment
  • Loading branch information
mrfelton authored Jan 3, 2024
2 parents 67752a7 + 944f683 commit bcdc16a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/latest.yml → .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Latest
name: Dev

on:
push:
Expand All @@ -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
Expand All @@ -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
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
17 changes: 15 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,21 @@ 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(`
<head>
<meta name="color-scheme" content="light dark">
</head>
<body>
<pre>${JSON.stringify(data, null, 2)}</pre>
</body>
`);
} else {
// Return a JSON response
res.json(data);
}
} catch (error) {
console.error(error);
res.status(500).send('Error fetching fee estimates');
Expand Down

0 comments on commit bcdc16a

Please sign in to comment.