Skip to content

LMare/lightning-playground

Repository files navigation

Lightning Playground

CI codecov

Personnal projet as playground to discover and improve skill on :

Stack :

  • Golang
  • gRPC (use & extend gRPC API)
  • Lnd
  • HTMX
  • SSE
  • Makefile
  • dockerfile
  • docker compose / bake
  • CI
  • Kubernetes / HELM
  • monitoring : Prometheus + Grafana (dashboard/panel for metrics)

TODO :

  • Warehouse + ELT : Stack identified : DuckDB + dbt + Perfect (Airflow in a second time ?)
  • archi hexagonal to complete TI for test cover
  • monitoring (alerts)
  • monitoring (logs)
  • SSE with Deployement Backend broken -> need to put a broker (ex: Redis)
  • Wallet creation/unlock is handled by the backend via gRPC WalletUnlocker service).
  • Define NetworkPolicies to restrict communication paths (frontend ↔ backend ↔ LND ↔ btcd) ?
  • infra as code (Terraform + kubernetes with Kind) ?
  • LLM

Prupose

Be able to do a little web application to interract with and a lightning serveur running on simnet

Checking the prerequis

make check-deps

The application can be launch with docker compose or Kubernetes (kind)

Lauch the app

# Docker compose
docker buildx bake
docker compose up -d
# Kubernetes
make all

Go to : http://localhost:3000/ (docker compose)

Go to : http://lightning-playground.local/ (Kubernetes)

Grafana (Kubernetes) :

Clé Valeur
URL https://grafana.lightning-playground.local/d/admzlxj/lightning-playground-backend-dashboard?orgId=1&from=now-30m&to=now&timezone=browser&refresh=5s
Login admin
Password kubectl get secret -n monitoring monitoring-grafana -o jsonpath="{.data.admin-password}" | base64 --decode

First launch

To use the lnd fonctionalities, you will need at least 2 lnd nodes with a wallet :

# Docker compose
docker exec -it lightning-playground-lnd1-1 lncli --network=simnet create
docker exec -it lightning-playground-lnd2-1 lncli --network=simnet create
# Kubernetes
kubectl exec -it lnd-0 -n lightning-playground -- lncli --network=simnet create
kubectl exec -it lnd-1 -n lightning-playground -- lncli --network=simnet create
kubectl exec -it lnd-2 -n lightning-playground -- lncli --network=simnet create

To mine with one of these address do :

# Docker compose
docker exec -it lightning-playground-lnd1-1 lncli --network=simnet newaddress np2wkh
# Kubernetes
kubectl exec -it lnd-0 -n lightning-playground -- lncli --network=simnet newaddress np2wkh

Copy the address then replace the value of miningaddr in the service btcd of docker-compose.yml or kubernetes/manifests/btcd/btcd-statefulset.yaml. And reload the containers

# Docker compose
docker compose up -d
# Kubernetes
kubectl apply -f btcd-statefulset.yaml -n lightning-playground
kubectl delete pod btcd-0 -n lightning-playground

Mine enough block to activate taproot

# Docker compose
docker exec -it lightning-playground-btcd-1 btcctl --simnet generate 1500
# Kubernetes
kubectl exec -it btcd-0 -n lightning-playground -- btcctl --simnet generate 1500

Unlock the wallet

After each up of the lnd containers, the wallet must be unlock

# Docker compose
docker exec -it lightning-playground-lnd1-1 lncli --network=simnet unlock
docker exec -it lightning-playground-lnd2-1 lncli --network=simnet unlock
# Kubernetes
kubectl exec -it lnd-0 -n lightning-playground -- lncli --network=simnet unlock
kubectl exec -it lnd-1 -n lightning-playground -- lncli --network=simnet unlock
kubectl exec -it lnd-2 -n lightning-playground -- lncli --network=simnet unlock

Generate a new block

In the simnet network the news blocks must to be mine manually. Run this cmd (every 10 minutes) to keep the lnd node synchronised with the btcd node

# Docker compose
docker exec -it lightning-playground-btcd-1 btcctl --simnet generate 1
# Kubernetes
kubectl exec -it btcd-0 -n lightning-playground -- btcctl --simnet generate 1

Stop the app

# Docker compose
docker-compose down
# Kubernetes
docker stop lightning-playground-control-plane

Using the application

Lightning-Playground

Steps :

  1. Add new pair with the URI of other nodes
  2. Create channels between pairs. After creating the channel to pass it in active state, generate some blocs with :
# Docker compose
docker exec -it lightning-playground-btcd-1 btcctl --simnet generate 10
# Kubernetes
kubectl exec -it btcd-0 -n lightning-playground -- btcctl --simnet generate 1
  1. Generate an invoice
  2. Import the invoice on another node and pay-it

Adding lnd node (increase de replicas number)

kubectl scale statefulset lnd --replicas=5

Note :

The app works with a LND customised LMare/lnd. This version allow to modify the alias and the color of the node LND by gRPC call.

About

A playground evolving from a small Go/HTMX Lightning simnet app into a full Kubernetes sandbox with monitoring and a modern ELT pipeline.

Topics

Resources

License

Stars

Watchers

Forks

Contributors