From 1054e9a3b159f6767c5bc3c6e6821be789c6b424 Mon Sep 17 00:00:00 2001 From: elsirion Date: Fri, 20 May 2022 09:51:21 +0000 Subject: [PATCH] Add cln feeadjuster plugin --- modules/clightning-plugins/default.nix | 1 + modules/clightning-plugins/feeadjuster.nix | 78 ++++++++++++++++++++++ pkgs/clightning-plugins/default.nix | 3 + 3 files changed, 82 insertions(+) create mode 100644 modules/clightning-plugins/feeadjuster.nix diff --git a/modules/clightning-plugins/default.nix b/modules/clightning-plugins/default.nix index da30464..36f2937 100644 --- a/modules/clightning-plugins/default.nix +++ b/modules/clightning-plugins/default.nix @@ -14,6 +14,7 @@ in { imports = [ ./clboss.nix ./commando.nix + ./feeadjuster.nix ./prometheus.nix ./summary.nix ./zmq.nix diff --git a/modules/clightning-plugins/feeadjuster.nix b/modules/clightning-plugins/feeadjuster.nix new file mode 100644 index 0000000..2ec4859 --- /dev/null +++ b/modules/clightning-plugins/feeadjuster.nix @@ -0,0 +1,78 @@ +{ config, lib, ... }: + +with lib; +let + options.services.clightning.plugins.feeadjuster = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + Enable feeaduster (clightning plugin). + This plugin auto-updates channel fees to keep channels balanced. + + See here for for all available options: + https://github.com/lightningd/plugins/blob/master/feeadjuster/feeadjuster.py + Extra options can be set via `services.clightning.extraConfig`. + ''; + }; + fuzz = mkOption { + type = types.bool; + default = true; + description = "Enable update threshold randomization and hysteresis."; + }; + adjustOnForward = mkOption { + type = types.bool; + default = false; + description = "Automatically update fees on forward events."; + }; + method = mkOption { + type = types.enum [ "soft" "default" "hard" ]; + default = "default"; + description = '' + Adjustment method to calculate channel fees. + `soft`: less difference when adjusting fees. + `hard`: greater difference when adjusting fees. + ''; + }; + adjustDaily = mkOption { + type = types.bool; + default = true; + description = "Automatically update fees daily."; + }; + }; + + cfg = config.services.clightning.plugins.feeadjuster; + inherit (config.services) clightning; +in +{ + inherit options; + + config = mkIf (cfg.enable && clightning.enable) { + services.clightning.extraConfig = '' + plugin=${config.nix-bitcoin.pkgs.clightning-plugins.feeadjuster.path} + feeadjuster-adjustment-method="${cfg.method}" + '' + optionalString (!cfg.fuzz) '' + feeadjuster-deactivate-fuzz + '' + optionalString (!cfg.adjustOnForward) '' + feeadjuster-deactivate-fee-update + ''; + + systemd = mkIf cfg.adjustDaily { + services.clightning-feeadjuster = { + # Only run when clightning is running + requisite = [ "clightning.service" ]; + after = [ "clightning.service" ]; + serviceConfig = { + Type = "oneshot"; + User = "clightning"; + ExecStart = "${clightning.package}/bin/lightning-cli --lightning-dir ${clightning.dataDir} feeadjust"; + }; + unitConfig.JoinsNamespaceOf = [ "clightning.service" ]; + startAt = [ "daily" ]; + }; + timers.clightning-feeadjuster.timerConfig = { + RandomizedDelaySec = "6h"; + }; + }; + }; +} diff --git a/pkgs/clightning-plugins/default.nix b/pkgs/clightning-plugins/default.nix index 49f39c9..d8eb58e 100644 --- a/pkgs/clightning-plugins/default.nix +++ b/pkgs/clightning-plugins/default.nix @@ -39,6 +39,9 @@ let scriptName = "cl-zmq"; extraPkgs = [ twisted txzmq ]; }; + feeadjuster = { + description = "Dynamically changes channel fees to keep your channels more balanced"; + }; }; basePkgs = [ nbPython3Packages.pyln-client ];