Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .agents/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ This document serves as an architectural, operational, and development guide for

| File | Type | Description |
| :--- | :--- | :--- |
| `fee_adjuster.py` | Systemd Timer / Cronjob | **Dynamic Liquidity Fee Controller**: Adjusts outbound and inbound channel fees using Amboss Space statistics, 5-band liquidity curves, and stuck-channel decay, with `charge-lnd` export and inbound discount protection. Documented in `Other/fee_adjuster.md`; systemd installer in `Other/install_fee_adjuster_service.sh`. |
| `fee_adjuster.py` | Systemd Timer / Cronjob | **Dynamic Liquidity Fee Controller**: Adjusts outbound and inbound channel fees using Amboss Space statistics, 5-band liquidity curves, and stuck-channel decay, with `charge-lnd` export and inbound discount protection. Documented in `Other/fee_adjuster.md`; managed via `./install.sh` (`lpt_installer`). |
| `rebalance_guard.py` | Cronjob / CLI | **Standalone Rebalance Guard**: Audits all open LNDg channels across native Auto-Fees and `fee_adjuster.py`. Locks `ar_out_target = 100%` when an inbound discount is active and restores baseline targets (`data/rebalance_targets_baseline.json`) via dynamic hysteresis once liquidity recovers. |
| `swap_out-loop.py` | CLI Tool | **Economically Optimized Loop Out**: Ranks channels by net effective PPM, runs live fake-hash prepay route probes (with 2-hop direct Loop fallback), supports multi-channel MPP selection (`litloop` / `loopd`), interactive TTY multi-select, and native `loop_sqlite.db` history/CSV accounting. Documented in `Other/swap_out-loop.md`. |
| `boltz_swap-out.py` | CLI Tool | Executes reverse submarine swaps (Lightning to Liquid L-BTC) via `boltzd` / `boltzcli` using LNDg candidate channels, multi-batch payment retries, and `--debug` dry-run mode. |
Expand All @@ -78,7 +78,7 @@ This document serves as an architectural, operational, and development guide for

| File | Type | Description |
| :--- | :--- | :--- |
| `pocketmoney.py` | Systemd Timer / Daemon | Distributes scheduled fiat-denominated satoshi allowances from a parent LNbits wallet to child wallets defined in `wallets.json` (`--run-once` supported). Systemd timer installer in `LNBits/install_pocketmoney_service.sh`. |
| `pocketmoney.py` | Systemd Timer / Daemon | Distributes scheduled fiat-denominated satoshi allowances from a parent LNbits wallet to child wallets defined in `wallets.json` (`--run-once` supported). Managed via `./install.sh` (`lpt_installer`). |

---

Expand Down
65 changes: 59 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ jobs:
shell: bash
run: |
set -o pipefail
pytest tests/ -v --cov=LNDg --cov=Magma --cov=Other --cov=Peerswap --cov=LNBits --cov-report=term --cov-fail-under=35 | tee pytest_cov.txt
pytest tests/ -v --cov=LNDg --cov=Magma --cov=Other --cov=Peerswap --cov=LNBits --cov=lpt_installer --cov-report=term --cov-fail-under=35 | tee pytest_cov.txt
pytest tests/test_lpt_installer.py tests/test_ca_trust_hardening.py --cov=lpt_installer --cov-report=term --cov-fail-under=85
{
echo "### Pytest Coverage (Python ${{ matrix.python-version }})"
echo '```text'
tail -n 30 pytest_cov.txt
tail -n 35 pytest_cov.txt
echo '```'
} >> "$GITHUB_STEP_SUMMARY"

Expand All @@ -74,13 +75,65 @@ jobs:
- name: Install ruff
run: pip install -r requirements-dev.txt

- name: Run ruff check on modern/updated tests
run: ruff check tests/test_p0_runtime_safety.py tests/test_ca_trust_hardening.py tests/test_repo_hygiene.py
- name: Run ruff check on installer and updated tests
run: ruff check lpt_installer tests/test_lpt_installer.py tests/test_p0_runtime_safety.py tests/test_ca_trust_hardening.py tests/test_repo_hygiene.py

- name: Validate shell scripts
run: |
bash -n LNBits/install_pocketmoney_service.sh Other/install_fee_adjuster_service.sh
shellcheck -S error LNBits/install_pocketmoney_service.sh Other/install_fee_adjuster_service.sh
bash -n install.sh
shellcheck -S warning install.sh

- name: Verify rendered systemd units with systemd-analyze
shell: bash
run: |
UNIT_DIR="$RUNNER_TEMP/lpt-units"
mkdir -p "$UNIT_DIR"
python3 - "$UNIT_DIR" <<'PY'
import grp, os, sys
from pathlib import Path
from lpt_installer.registry import get_tool
from lpt_installer.scheduler import render_systemd_service, render_systemd_timer

out_dir = Path(sys.argv[1])
repo = Path.cwd()
user = os.environ["USER"]
group = grp.getgrgid(os.getgid()).gr_name
py_bin = Path(sys.executable)

for tid, cal in (("pocketmoney", "Fri *-*-* 09:00:00"), ("fee-adjuster", "*:0/20:00")):
tool = get_tool(tid)
(out_dir / f"lpt-{tid}.service").write_text(
render_systemd_service(
tool,
repo,
user=user,
group=group,
mode="systemd-timer",
python_bin=py_bin,
unit_exists=lambda _: False,
),
encoding="utf-8",
)
(out_dir / f"lpt-{tid}.timer").write_text(
render_systemd_timer(tool, cal),
encoding="utf-8",
)

magma = get_tool("magma-sale")
(out_dir / "lpt-magma-sale.service").write_text(
render_systemd_service(
magma,
repo,
user=user,
group=group,
mode="systemd-service",
python_bin=py_bin,
unit_exists=lambda _: False,
),
encoding="utf-8",
)
PY
SYSTEMD_UNIT_PATH="$UNIT_DIR:" systemd-analyze verify --man=no "$UNIT_DIR"/*.service "$UNIT_DIR"/*.timer

security:
runs-on: ubuntu-latest
Expand Down
119 changes: 0 additions & 119 deletions LNBits/install_pocketmoney_service.sh

This file was deleted.

5 changes: 2 additions & 3 deletions Other/fee_adjuster.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ config_file = file:///home/admin/.chargelnd/.config/fee_adjuster.txt

## Installation (systemd Timer or Crontab)

Use the included installer script to set up `fee_adjuster.service` and an hourly `fee_adjuster.timer`:
Use the unified installer (`./install.sh`) to configure `lpt-fee-adjuster.service` + `lpt-fee-adjuster.timer` (or a managed cron entry):
```bash
chmod +x Other/install_fee_adjuster_service.sh
sudo ./Other/install_fee_adjuster_service.sh
./install.sh install fee-adjuster --scheduler systemd
```

Or schedule via `crontab -e`:
Expand Down
94 changes: 0 additions & 94 deletions Other/install_fee_adjuster_service.sh

This file was deleted.

14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,15 @@ chmod 600 config.ini Magma/magma_config.ini feeConfig.json wallets.json

## Running as Background Services

### Automated Systemd Service Installers
Helper scripts are included to generate and enable `systemd` oneshot services and timers (pre-configured with OS CA trust bundle environment variables):
### Unified Service & Scheduler Installer
Use the interactive CLI manager (`./install.sh`) to set up `.venv`, copy/harden configs (`chmod 600`), and generate `systemd` services/timers or `cron` jobs (pre-configured with OS CA trust bundle environment variables):

```bash
# Install hourly fee_adjuster.service + fee_adjuster.timer
chmod +x Other/install_fee_adjuster_service.sh
sudo ./Other/install_fee_adjuster_service.sh
chmod +x install.sh
./install.sh

# Install scheduled pocketmoney.service + pocketmoney.timer (reads [Schedule] from config.ini)
chmod +x LNBits/install_pocketmoney_service.sh
sudo ./LNBits/install_pocketmoney_service.sh
# Or install non-interactively via CLI:
./install.sh install fee-adjuster pocketmoney --scheduler systemd --accept-disclaimer
```

### Systemd Daemon Example
Expand Down
32 changes: 32 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail

if [ "${EUID:-$(id -u)}" -eq 0 ]; then
echo "Error: Do not run ./install.sh as root or via sudo." >&2
echo "Run as your regular node operator user (e.g. admin)." >&2
echo "The installer elevates via sudo only when writing system-wide systemd units." >&2
exit 1
fi

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"

PYTHON_BIN=""
for candidate in python3 python3.13 python3.12 python3.11; do
if command -v "$candidate" >/dev/null 2>&1; then
if "$candidate" -c 'import sys; sys.exit(0 if (3, 11) <= sys.version_info < (3, 14) else 1)' 2>/dev/null; then
PYTHON_BIN="$candidate"
break
fi
fi
done

if [ -z "$PYTHON_BIN" ]; then
echo "Error: Python 3.11, 3.12, or 3.13 is required to run Lightning-Python-Tools." >&2
echo "On Debian/Ubuntu, install it with: sudo apt-get update && sudo apt-get install -y python3 python3-venv" >&2
exit 1
fi

export LPT_REPO_ROOT="$SCRIPT_DIR"
export PYTHONPATH="$SCRIPT_DIR${PYTHONPATH:+:$PYTHONPATH}"

exec "$PYTHON_BIN" -m lpt_installer "$@"
Loading