-
Notifications
You must be signed in to change notification settings - Fork 137
Add support for core lightning watchtower TEoS (The Eye of Satoshi) - server and client #543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seberm
wants to merge
20
commits into
fort-nix:master
Choose a base branch
from
seberm:feature/add-rust-teos
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b901f4e
rust-teos: init at 0.1.2
seberm c5356af
rust-teos: add module
seberm 1541cc8
clightning: add TEoS watchtower plugin
seberm 174124d
teos: add new options and defaults for teos v0.2.0
seberm fd7e178
teos: fix onion ports to be handled by the nix-bitcoin onion-services…
seberm e466074
teos: change btc network name to mainnet
seberm c47eab6
teos: improve the docs in example configuration
seberm be06246
teos: enable tor in teos conditionally
seberm d5ae5a4
teos: rename the teos-watchtower-plugin to just teos-watchtower
seberm e0c5afc
teos: fix the onionServices condition
seberm 9e95d94
teos: just enable onion service for teos, no need to set it public
seberm a90ced3
teos: fix the onion services port mapping
seberm aa51b19
teos: add documentation watchtower plugin usage in lightning-cli
seberm c2bbc7f
teos: tests: improve tests for teos service and teos-cli
seberm f56346c
teos: tests: add tests for cln watchtower plugin
seberm 2ec0b4f
teos: netns: add possibility of clightning to connect to local teos s…
seberm 25f4db3
teos: final code cleanup
seberm 92113dd
nodeinfo: add teos tower ID
seberm b1802c3
clightning: watchtower: do not hide the tower data directory
seberm bd3f0d9
backups: add teos and teos-watchtower to regular backups
seberm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ in { | |
| ./clboss.nix | ||
| ./feeadjuster.nix | ||
| ./trustedcoin.nix | ||
| ./teos-watchtower.nix | ||
| ./zmq.nix | ||
| ]; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| { config, lib, ... }: | ||
|
|
||
| with lib; | ||
| let cfg = config.services.clightning.plugins.teos-watchtower; in | ||
| { | ||
| # Ref.: https://github.com/talaia-labs/rust-teos/tree/master/watchtower-plugin | ||
| options.services.clightning.plugins.teos-watchtower = { | ||
| enable = mkEnableOption "TEoS watchtower (clightning plugin)"; | ||
| package = mkOption { | ||
| type = types.package; | ||
| default = config.nix-bitcoin.pkgs.teos-watchtower-plugin; | ||
| defaultText = "config.nix-bitcoin.pkgs.teos-watchtower-plugin"; | ||
| description = mdDoc "The package providing TEoS watchtower plugin binaries."; | ||
| }; | ||
| port = mkOption { | ||
| type = types.port; | ||
| default = config.services.teos.port; | ||
| description = mdDoc "Tower API port."; | ||
| }; | ||
| dataDir = mkOption { | ||
| type = types.path; | ||
| default = "${config.services.clightning.dataDir}/watchtower"; | ||
| description = mdDoc "The data directory for teos-watchtower."; | ||
| }; | ||
| maxRetryTime = mkOption { | ||
| type = types.int; | ||
| default = 3600; | ||
| description = mdDoc "For how long (in seconds) a retry strategy will try to reach a temporary unreachable tower before giving up."; | ||
| }; | ||
| autoRetryDelay = mkOption { | ||
| type = types.int; | ||
| default = 28800; | ||
| description = mdDoc "For how long (in seconds) the client will wait before auto-retrying a failed tower."; | ||
| }; | ||
| }; | ||
|
|
||
| config = mkIf cfg.enable { | ||
| services.clightning.extraConfig = '' | ||
| plugin=${cfg.package}/bin/watchtower-client | ||
| watchtower-port=${toString cfg.port} | ||
| watchtower-max-retry-time=${toString cfg.maxRetryTime} | ||
| watchtower-auto-retry-delay=${toString cfg.autoRetryDelay} | ||
| ''; | ||
|
|
||
| # The data directory of teos-watchtower must be specified and must | ||
| # be writeable. Otherwise the plugin fails to load. | ||
| systemd.services.clightning.environment = { | ||
| TOWERS_DATA_DIR = cfg.dataDir; | ||
| }; | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| ./rtl.nix | ||
| ./mempool.nix | ||
| ./electrs.nix | ||
| ./teos.nix | ||
| ./fulcrum.nix | ||
| ./liquid.nix | ||
| ./btcpayserver.nix | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| { config, lib, pkgs, ... }: | ||
|
|
||
| with lib; | ||
| let | ||
| options.services.teos = { | ||
| enable = mkEnableOption "Lightning watchtower compliant with BOLT13, written in Rust"; | ||
| address = mkOption { | ||
| type = types.str; | ||
| default = "127.0.0.1"; | ||
| description = mdDoc "Address to listen for API connections."; | ||
| }; | ||
| port = mkOption { | ||
| type = types.port; | ||
| default = 9814; | ||
| description = mdDoc "Port to listen for API connections."; | ||
| }; | ||
|
|
||
| rpc = { | ||
| address = mkOption { | ||
| type = types.str; | ||
| default = "127.0.0.1"; | ||
| description = mdDoc "Address to listen for RPC connections."; | ||
| }; | ||
| port = mkOption { | ||
| type = types.port; | ||
| default = 8814; | ||
| description = mdDoc "Port to listen for RPC connections."; | ||
| }; | ||
| }; | ||
|
|
||
| internalApi = { | ||
| address = mkOption { | ||
| type = types.str; | ||
| default = "127.0.0.1"; | ||
| description = mdDoc "Address to listen for internal API connections."; | ||
| }; | ||
| port = mkOption { | ||
| type = types.port; | ||
| default = 50051; | ||
| description = mdDoc "Port to listen for internal API connections."; | ||
| }; | ||
| }; | ||
|
|
||
| dataDir = mkOption { | ||
| type = types.path; | ||
| default = "/var/lib/teos"; | ||
| description = mdDoc "The data directory for teos."; | ||
| }; | ||
| extraArgs = mkOption { | ||
| type = types.separatedString " "; | ||
| default = ""; | ||
| description = mdDoc "Extra command line arguments passed to teosd."; | ||
| }; | ||
| user = mkOption { | ||
| type = types.str; | ||
| default = "teos"; | ||
| description = mdDoc "The user as which to run teos."; | ||
| }; | ||
| group = mkOption { | ||
| type = types.str; | ||
| default = cfg.user; | ||
| description = mdDoc "The group as which to run teos."; | ||
| }; | ||
| package = mkOption { | ||
| type = types.package; | ||
| default = nbPkgs.teos; | ||
| defaultText = "config.nix-bitcoin.pkgs.teos"; | ||
| description = mdDoc "The package providing teos binaries."; | ||
| }; | ||
| cli = mkOption { | ||
| readOnly = true; | ||
| default = pkgs.writeScriptBin "teos-cli" '' | ||
| ${cfg.package}/bin/teos-cli --datadir='${cfg.dataDir}' "$@" | ||
| ''; | ||
| defaultText = "(See source)"; | ||
| description = mdDoc "Binary to connect with the teos instance."; | ||
| }; | ||
| tor.enforce = nbLib.tor.enforce; | ||
| }; | ||
|
|
||
| cfg = config.services.teos; | ||
| nbLib = config.nix-bitcoin.lib; | ||
| nbPkgs = config.nix-bitcoin.pkgs; | ||
|
|
||
| secretsDir = config.nix-bitcoin.secretsDir; | ||
| bitcoind = config.services.bitcoind; | ||
| in { | ||
| inherit options; | ||
|
|
||
| config = mkIf cfg.enable { | ||
| services.bitcoind = { | ||
| enable = true; | ||
| listenWhitelisted = true; | ||
| }; | ||
|
|
||
| environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ]; | ||
|
|
||
| systemd.tmpfiles.rules = [ | ||
| "d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -" | ||
| ]; | ||
|
|
||
| systemd.services.teos = { | ||
| wantedBy = [ "multi-user.target" ]; | ||
| requires = [ "bitcoind.service" ]; | ||
| after = [ "bitcoind.service" ]; | ||
|
|
||
| # Example configuration file: | ||
| # Ref.: | ||
| # - https://github.com/talaia-labs/rust-teos/blob/master/teos/src/conf_template.toml | ||
| # | ||
| # Note about tor support: | ||
| # We don't want to enable TOR support in teos configuration file, because | ||
| # the `tor_support = true` option would create an additional endpoint to | ||
| # the clearnet HTTP API. The optional Tor support is configured by | ||
| # onionServices. | ||
| # Ref.: | ||
| # - https://github.com/talaia-labs/rust-teos/issues/174 | ||
| preStart = '' | ||
| install -m 640 /dev/null teos.toml | ||
|
|
||
| cat <<EOF > teos.toml | ||
| # API | ||
| api_bind = "${cfg.address}" | ||
| api_port = ${toString cfg.port} | ||
|
|
||
| # Tor | ||
| tor_support = false | ||
|
|
||
| # RPC | ||
| rpc_bind = "${cfg.rpc.address}" | ||
| rpc_port = ${toString cfg.rpc.port} | ||
|
|
||
| # bitcoind | ||
| btc_network = "${bitcoind.makeNetworkName "mainnet" "regtest"}" | ||
| btc_rpc_user = "${bitcoind.rpc.users.public.name}" | ||
| btc_rpc_password = "$(cat ${secretsDir}/bitcoin-rpcpassword-public)" | ||
| btc_rpc_connect = "${bitcoind.rpc.address}" | ||
| btc_rpc_port = ${toString bitcoind.rpc.port} | ||
|
|
||
| # Flags | ||
| debug = false | ||
| overwrite_key = false | ||
|
|
||
| # General | ||
| subscription_slots = 10000 | ||
| subscription_duration = 4320 | ||
| expiry_delta = 6 | ||
| min_to_self_delay = 20 | ||
| polling_delta = 60 | ||
|
|
||
| # Internal API | ||
| internal_api_bind = "${cfg.internalApi.address}" | ||
| internal_api_port = ${toString cfg.internalApi.port} | ||
| EOF | ||
| ''; | ||
|
|
||
| serviceConfig = nbLib.defaultHardening // { | ||
| WorkingDirectory = cfg.dataDir; | ||
| ExecStart = '' | ||
| ${cfg.package}/bin/teosd \ | ||
| --datadir='${cfg.dataDir}' \ | ||
| ${cfg.extraArgs} | ||
| ''; | ||
| User = cfg.user; | ||
| Group = cfg.group; | ||
| Restart = "on-failure"; | ||
| RestartSec = "10s"; | ||
| ReadWritePaths = [ cfg.dataDir ]; | ||
| } // nbLib.allowedIPAddresses cfg.tor.enforce; | ||
| }; | ||
|
|
||
| users.users.${cfg.user} = { | ||
| isSystemUser = true; | ||
| group = cfg.group; | ||
| extraGroups = [ "bitcoinrpc-public" ]; | ||
| }; | ||
| users.groups.${cfg.group} = {}; | ||
| nix-bitcoin.operator.groups = [ cfg.group ]; | ||
| }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.