Skip to content

feat: Knots support#1303

Open
kwsantiago wants to merge 5 commits intojamaljsr:masterfrom
privkeyio:knots-support
Open

feat: Knots support#1303
kwsantiago wants to merge 5 commits intojamaljsr:masterfrom
privkeyio:knots-support

Conversation

@kwsantiago
Copy link

@kwsantiago kwsantiago commented Oct 22, 2025

Closes #1302

Description

This PR adds full support for Bitcoin Knots v29 as a Bitcoin backend implementation in Polar, alongside the existing Bitcoin Core support.

What changed:

  • Added Bitcoin Knots (v29, v28, v27, v26) as a new managed node implementation
  • Created Docker configuration and build files for bitcoind-knots
  • Added Bitcoin Knots input field to the network creation form UI
  • Updated all type definitions and test files to support bitcoindKnotsNodes parameter
  • Bitcoin Knots nodes use the same Bitcoin RPC service as Bitcoin Core (they're API-compatible)

Technical details:

  • New implementation type: 'bitcoind-knots' added to BitcoinNode interface
  • Created createBitcoindKnotsNetworkNode() function for network node creation
  • Updated network store to handle bitcoindKnotsNodes in network creation flow
  • Updated test files to include the new parameter
  • Port configuration matches bitcoind (RPC, P2P, ZMQ Block, ZMQ Tx)

Steps to Test

  1. Start Polar with yarn dev
  2. Click "Create Lightning Network"
  3. In the form, set Bitcoin Core to 0 and Bitcoin Knots to 1
  4. Add 2 LND nodes
  5. Click "Create Network"
  6. Start the network
  7. Verify the backend node is using implementation "bitcoind-knots"
  8. Test mining blocks and sending funds - should work identically to Bitcoin Core

Screenshots

image image image

@Abdulkbk
Copy link
Contributor

Thanks for the PR. I want to review, but I'm curious, is there any reason to add knots to polar? Are there users who specifically want to use it in Polar? Consider adding a justification to the PR description. It's important to ensure that managing the implementation versions over time is truly worthwhile.

@kwsantiago
Copy link
Author

Hi @Abdulkbk , the justification is in the issue: #1302

Personally I am building software using Knots and it would be helpful to test with a local regtest environment that Polar provides.

@jamaljsr
Copy link
Owner

jamaljsr commented Nov 8, 2025

@kwsantiago Thanks for the contribution. I don't have any objections to adding Bitcoin Knots since the RPC is identical to Bitcoin Core, so there should be very little code changes required for it to work. But I do have some concerns about the ongoing maintenance burden this will add for maintainers (primarily myself) to ensure we add support for future versions of Knots in a timely manner. I'm already behind on this with the 6 implementations we currently support. Would you be willing to commit to helping in this regard for some time?

I've tried to review this but I'm facing a few hurdles getting this working:

  1. The Dockerfile doesn't build as-is using the latest version 29.0 listed in the README. There is no downloadable file for 29.0 on https://bitcoinknots.org/files/29.x/. I managed to get the image to build by using 29.2 but this breaks other things below.
  2. After updating the defaultRepoState in constants.ts to use 29.2, I was getting an error creating a network because the compatibility mapping for LND targets bitcoind versions. Since there is no 29.0 version of Knots, I had to change this to 29.2. Unfortunately, this breaks using Core nodes since we haven't added support for 29.2 yet. I suspect this will be a challenge going forward as we'll have to keep the versions of both in sync at all times for the compatibility check to work, or we'll have to do a refactoring of how compatibility is defined and validated to handle differing Bitcoin node versions.
  3. After fixing the above, I was able to create the network. When i tried to start it, I get the docker error below. It looks like the Knots nodes are incorrectly referencing the bitcoind image instead of bitcoind-knots.
    Error response from daemon: manifest for polarlightning/bitcoind:29.2 not found: manifest unknown: manifest unknown
    

After facing these issues so far, I'd like to hand this PR back to you to make improvements. Please confirm that you have this feature fully functional on your end, then I can take another pass on it. Thanks again for what you have done so far.

@kwsantiago
Copy link
Author

Thank you for the feedback @jamaljsr . Addressed in 3246d68

@jamaljsr
Copy link
Owner

@kwsantiago I'm not sure how you are successfully running this on your machine. I'm still facing issues:

  1. When trying to build the docker image:
$ docker build --build-arg BITCOIN_VERSION=29.2 --build-arg KNOTS_DATE=20251010 -t polarlightning/bitcoind-kn
ots:29.2 .
[+] Building 47.6s (9/12)                                                                                    docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                         0.0s
 => => transferring dockerfile: 1.21kB                                                                                       0.0s
 => [internal] load metadata for docker.io/library/debian:stable-slim                                                        1.1s
 => [auth] library/debian:pull token for registry-1.docker.io                                                                0.0s
 => [internal] load .dockerignore                                                                                            0.0s
 => => transferring context: 2B                                                                                              0.0s
 => [1/7] FROM docker.io/library/debian:stable-slim@sha256:7cb087f19bcc175b96fbe4c2aef42ed00733a659581a80f6ebccfd8fe3185a3d  0.0s
 => => resolve docker.io/library/debian:stable-slim@sha256:7cb087f19bcc175b96fbe4c2aef42ed00733a659581a80f6ebccfd8fe3185a3d  0.0s
 => => sha256:7cb087f19bcc175b96fbe4c2aef42ed00733a659581a80f6ebccfd8fe3185a3d 8.97kB / 8.97kB                               0.0s
 => => sha256:beecb6bc7f57ce868d4bc779278fff18f5695b2754044167ad3e0c141e2426da 1.04kB / 1.04kB                               0.0s
 => => sha256:898ab49d3e2bb1d49d32c0422a44593a94471289bcca1148e8ba8308cf803225 466B / 466B                                   0.0s
 => [internal] load build context                                                                                            0.0s
 => => transferring context: 1.08kB                                                                                          0.0s
 => [2/7] RUN apt-get update -y   && apt-get install -y curl gosu   && apt-get clean   && rm -rf /var/lib/apt/lists/* /tmp  43.4s
 => [3/7] RUN SYS_ARCH="$(uname -m)"   && MAJOR_VERSION="$(echo 29.2 | cut -d. -f1)"   && curl -SLO https://bitcoinknots.or  2.8s
 => ERROR [4/7] RUN curl -SLO https://raw.githubusercontent.com/bitcoin/bitcoin/master/contrib/completions/bash/bitcoin-cli  0.3s 
------                                                                                                                            
 > [4/7] RUN curl -SLO https://raw.githubusercontent.com/bitcoin/bitcoin/master/contrib/completions/bash/bitcoin-cli.bash   && mkdir /etc/bash_completion.d   && mv bitcoin-cli.bash /etc/bash_completion.d/bitcoin-cli.bash-completion   && curl -SLO https://raw.githubusercontent.com/scop/bash-completion/master/bash_completion   && mv bash_completion /usr/share/bash-completion/:             
0.108   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
0.108                                  Dload  Upload   Total   Spent    Left  Speed
100  4102  100  4102    0     0  33705      0 --:--:-- --:--:-- --:--:-- 33900
0.233 mkdir: cannot create directory '/etc/bash_completion.d': File exists
------
Dockerfile:19
--------------------
  18 |     
  19 | >>> RUN curl -SLO https://raw.githubusercontent.com/bitcoin/bitcoin/master/contrib/completions/bash/bitcoin-cli.bash \
  20 | >>>   && mkdir /etc/bash_completion.d \
  21 | >>>   && mv bitcoin-cli.bash /etc/bash_completion.d/bitcoin-cli.bash-completion \
  22 | >>>   && curl -SLO https://raw.githubusercontent.com/scop/bash-completion/master/bash_completion \
  23 | >>>   && mv bash_completion /usr/share/bash-completion/
  24 |     
--------------------
ERROR: failed to build: failed to solve: process "/bin/sh -c curl -SLO https://raw.githubusercontent.com/bitcoin/bitcoin/master/contrib/completions/bash/bitcoin-cli.bash   && mkdir /etc/bash_completion.d   && mv bitcoin-cli.bash /etc/bash_completion.d/bitcoin-cli.bash-completion   && curl -SLO https://raw.githubusercontent.com/scop/bash-completion/master/bash_completion   && mv bash_completion /usr/share/bash-completion/" did not complete successfully: exit code: 1

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/u2krscm2tun0zx45bi35mtfot
  1. When running yarn dev:
image

Please resolve these errors, provide proper testing instructions and be sure that they work without any issues before requesting another round of review.

@kwsantiago kwsantiago force-pushed the knots-support branch 3 times, most recently from bea93e2 to 279137f Compare November 30, 2025 10:22
@kwsantiago
Copy link
Author

@jamaljsr both issues are resolved in 279137f

Testing instructions below and in PR description.

Build docker image

cd docker/bitcoind-knots
docker build --build-arg BITCOIN_VERSION=29.2 --build-arg KNOTS_DATE=20251110 -t
polarlightning/bitcoind-knots:29.2 .

Run app

yarn dev

@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

❌ Patch coverage is 29.41176% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.58%. Comparing base (2d9881c) to head (279137f).
⚠️ Report is 18 commits behind head on master.

Files with missing lines Patch % Lines
src/utils/network.ts 9.09% 20 Missing ⚠️
src/store/models/network.ts 33.33% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##            master    #1303      +/-   ##
===========================================
- Coverage   100.00%   99.58%   -0.42%     
===========================================
  Files          156      156              
  Lines         5734     5764      +30     
  Branches      1104     1161      +57     
===========================================
+ Hits          5734     5740       +6     
- Misses           0       24      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kwsantiago
Copy link
Author

@jamaljsr any update on this? I left testing instructions on the last comment. Please let me know if anything else is needed.

@greptile-apps
Copy link

greptile-apps bot commented Mar 10, 2026

Greptile Summary

This PR adds Bitcoin Knots (v26–v29) as a fully supported Bitcoin backend implementation in Polar alongside Bitcoin Core. It introduces a new Docker image (polarlightning/bitcoind-knots), registers the implementation across the type system, factory, compose file, network creation utilities, and the UI form — reusing bitcoindService since Bitcoin Knots is RPC-compatible with Bitcoin Core.

Key changes:

  • New docker/bitcoind-knots/ directory with Dockerfile, bashrc, and docker-entrypoint.sh
  • 'bitcoind-knots' added to BitcoinNode['implementation'] union type and a new BitcoindKnotsNode interface in shared/types.ts
  • createBitcoindKnotsNetworkNode() added in network.ts; createNetwork extended with bitcoindKnotsNodes parameter
  • composeFile.ts updated to dynamically select image/command based on implementation (a clean generalisation)
  • NewNetwork.tsx validation updated: bitcoindNodes min changed from 1→0, with a new JS-level guard requiring at least one Bitcoin backend when Lightning nodes are configured
  • All test helpers updated with bitcoindKnotsNodes: 0 for backward compatibility

Critical issue found:

  • BasePorts['bitcoind-knots'].rest is set to 18443 in constants.ts — the same value as BasePorts.bitcoind.rest. However, the new tests in app.spec.ts and settingsService.spec.ts (also in this PR) assert the initial settings rest value as 18543. Because app.ts derives its default state directly from BasePorts['bitcoind-knots'].rest, these tests will fail. Setting the base port to 18543 (a +100 offset, consistent with how other implementations are spaced) would fix both the test failure and allow a bitcoind network and a bitcoind-knots network to run simultaneously without a port collision.

Confidence Score: 2/5

  • Not safe to merge — the port constant mismatch will cause test failures in CI.
  • The feature implementation is architecturally sound and well-integrated, but there is a definitive bug: BasePorts['bitcoind-knots'].rest = 18443 in constants.ts conflicts with the test expectations of 18543 added in this same PR. This will cause app.spec.ts and settingsService.spec.ts to fail. It also means a bitcoind and a bitcoind-knots node in separate networks would both bind to port 18443 and conflict if started concurrently.
  • src/utils/constants.ts requires the 'bitcoind-knots' base port correction before this PR can pass CI.

Important Files Changed

Filename Overview
src/utils/constants.ts Adds BasePorts['bitcoind-knots'] and dockerConfigs['bitcoind-knots'] — but BasePorts['bitcoind-knots'].rest is set to 18443 (same as bitcoind), which conflicts with test expectations of 18543 and would cause port collisions between two different-implementation networks running simultaneously.
src/utils/network.ts Adds createBitcoindKnotsNetworkNode and updates createNetwork to handle bitcoindKnotsNodes. Implementation closely mirrors createBitcoindNetworkNode. Minor inconsistency: p2p/zmqBlock/zmqTx always use global BasePorts constants regardless of the passed basePort argument (same as bitcoind's pattern).
src/store/models/network.ts Adds bitcoindKnotsNodes to AddNetworkArgs, forwards it in addNetwork, and adds a new case 'bitcoind-knots' in addNode. Uses defensive `
src/components/network/NewNetwork.tsx Adds bitcoindKnotsNodes input field, adjusts column widths from span={6} to span={4} to fit 5 columns, and replaces the hardcoded min={1} on bitcoindNodes with a JS-level validation requiring at least one Bitcoin backend when Lightning nodes are present.
docker/bitcoind-knots/Dockerfile New Dockerfile that downloads Bitcoin Knots binaries from bitcoinknots.org using build args for version and release date. No checksum verification on the downloaded tarball. Also fetches bash completion scripts from external GitHub URLs at build time.
src/shared/types.ts Adds 'bitcoind-knots' to BitcoinNode['implementation'] union type and introduces a new BitcoindKnotsNode interface. Clean, correct type extension.
src/lib/bitcoin/bitcoinFactory.ts Registers 'bitcoind-knots' in the factory using the existing bitcoindService — correct, since Bitcoin Knots is API-compatible with Bitcoin Core.
src/lib/docker/composeFile.ts Updates addBitcoind to dynamically select image name and default command based on implementation rather than hardcoding 'bitcoind'. This correctly supports both bitcoind and bitcoind-knots.
src/store/models/app.ts Adds 'bitcoind-knots' to newNodeCounts (default 0) and basePorts initial state using BasePorts['bitcoind-knots'].rest. Due to the port mismatch in constants.ts, this will emit 18443 rather than the 18543 expected by the tests.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[NewNetwork Form] -->|Submit| B{Validation}
    B -->|tapdNodes > lndNodes| E1[Error: tapdCountError]
    B -->|hasLightning && !hasBitcoinBackend| E2[Error: bitcoinBackendError]
    B -->|Valid| C[addNetwork action]

    C --> D[createNetwork]
    D --> D1[Create bitcoind nodes\ncreateBitcoindNetworkNode]
    D --> D2[Create bitcoind-knots nodes\ncreateBitcoindKnotsNetworkNode]
    D1 & D2 --> D3[Peer nodes together\nin bitcoin array]

    C --> F[Docker Compose]
    F --> G{node.implementation}
    G -->|bitcoind| H[polarlightning/bitcoind image]
    G -->|bitcoind-knots| I[polarlightning/bitcoind-knots image]
    H & I --> J[bitcoindService RPC\nsame API for both]

    K[addNode action] -->|type: bitcoind-knots| L[createBitcoindKnotsNetworkNode\nwith settings.basePorts]
    L --> D3
Loading

Last reviewed commit: 8b66208

Copy link
Contributor

@Abdulkbk Abdulkbk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kwsantiago, I looked into this feature, and I have a couple of initial feedback:

  1. There are a couple of linter issues with some files, for example, src/components/network/NetworkSetting.tsx and src/components/network/NewNetwork.tsx.
  2. Opening a terminal does not work currently.
  3. I think the logo for knots should be different from that of bitcoind.
  4. In some places, you use bitcoind-knots, while in others, you use bitcoindKnots, be consistent.
  5. After creating a network, adding a knot using the drag-and-drop feature does not work.
  6. Running yarn ci locally fails.

Generally, I think there's a bit more work needed to bring this to the finish line.

@kwsantiago
Copy link
Author

@Abdulkbk thank you for the feedback, it is greatly appreciated!

Addressed all feedback: fixed linter issues, terminal support, drag-and-drop, added distinct Knots logo, updated to v29.3, squashed commits, and yarn ci passes clean.

Note: Docker images need to be built and pushed to polarlightning/bitcoind-knots before end-to-end testing.

@Abdulkbk
Copy link
Contributor

Abdulkbk commented Mar 16, 2026

squashed commits

Oh no, this isn't what I was suggesting. Now I see only one commit, which makes it nearly impossible to review. You should break the commits, like you did earlier. My suggestion was to squash just the last commit into the first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Knots Support

3 participants