Skip to content
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

sndev cleanup #1563

Merged
merged 5 commits into from
Nov 9, 2024
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 .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ LND_PUBKEY=02cb2e2d5a6c5b17fa67b1a883e2973c82e328fb9bd08b2b156a9e23820c87a490
# stacker lnd container stuff
STACKER_LND_REST_PORT=8081
STACKER_LND_GRPC_PORT=10010
# docker exec -u lnd stacker_lnd lncli newaddress p2wkh --unused
# docker exec -u lnd lnd lncli newaddress p2wkh --unused
STACKER_LND_ADDR=bcrt1qfqau4ug9e6rtrvxrgclg58e0r93wshucumm9vu
STACKER_LND_PUBKEY=028093ae52e011d45b3e67f2e0f2cb6c3a1d7f88d2920d408f3ac6db3a56dc4b35

# stacker cln container stuff
STACKER_CLN_REST_PORT=9092
# docker exec -u clightning stacker_cln lightning-cli newaddr bech32
# docker exec -u clightning cln lightning-cli newaddr bech32
STACKER_CLN_ADDR=bcrt1q02sqd74l4pxedy24fg0qtjz4y2jq7x4lxlgzrx
STACKER_CLN_PUBKEY=03ca7acec181dbf5e427c682c4261a46a0dd9ea5f35d97acb094e399f727835b90

Expand Down
55 changes: 26 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,39 @@ USAGE
$ sndev help [COMMAND]

COMMANDS
help show help
help show help

env:
start start env
stop stop env
restart restart env
status status of env
logs logs from env
delete delete env
start start env
stop stop env
restart restart env
status status of env
logs logs from env
delete delete env

sn:
login login as a nym
fund_user fund a nym without using an LN invoice
login login as a nym
set_balance set the balance of a nym

lnd:
fund pay a bolt11 for funding
withdraw create a bolt11 for withdrawal

cln:
cln_fund pay a bolt11 for funding with CLN
cln_withdraw create a bolt11 for withdrawal with CLN
lightning:
fund pay a bolt11 for funding
withdraw create a bolt11 for withdrawal

db:
psql open psql on db
prisma run prisma commands
psql open psql on db
prisma run prisma commands

dev:
pr fetch and checkout a pr
lint run linters
open open container url in browser
pr fetch and checkout a pr
lint run linters
test run tests

other:
compose docker compose passthrough
sn_lndcli lncli passthrough on sn_lnd
stacker_lndcli lncli passthrough on stacker_lnd
stacker_clncli lightning-cli passthrough on stacker_cln
stacker_litcli litcli passthrough on litd

cli service cli passthrough
open open service GUI in browser
onion service onion address
cert service tls cert
compose docker compose passthrough
```

### Modifying services
Expand Down Expand Up @@ -368,9 +363,11 @@ You can connect to the local database via `./sndev psql`. [psql](https://www.pos

<br>

## Running lncli on the local lnd nodes
## Running cli on local lightning nodes

You can run `lncli` on the local lnd nodes via `./sndev cli lnd` and `./sndev cli sn_lnd`. The node for your local SN instance is `sn_lnd` and the node serving as any external node, like a stacker's node or external wallet, is `lnd`.

You can run `lncli` on the local lnd nodes via `./sndev sn_lncli` and `./sndev stacker_lncli`. The node for your local SN instance is `sn_lnd` and the node serving as any external node, like a stacker's node or external wallet, is `stacker_lnd`.
You can run `lightning-cli` on the local cln node via `./sndev cli cln` which serves as an external node or wallet.

<br>

Expand Down
77 changes: 45 additions & 32 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ services:
echo "Creating wallet and address..."
bitcoin-cli createwallet ""
nodes+=($$(bitcoin-cli getnewaddress))
echo "Mining 100 blocks to sn_lnd, stacker_lnd, stacker_cln..."
echo "Mining 100 blocks to sn_lnd, lnd, cln..."
for addr in "$${nodes[@]}"; do
bitcoin-cli generatetoaddress 100 $$addr
echo "Mining 100 blocks to a random address..."
Expand Down Expand Up @@ -349,24 +349,26 @@ services:
volumes:
- sn_lnd:/home/lnd/.lnd
labels:
CLI: "lncli"
CLI_USER: "lnd"
ofelia.enabled: "true"
ofelia.job-exec.sn_channel_cron.schedule: "@every 1m"
ofelia.job-exec.sn_channel_cron.command: >
su lnd -c bash -c "
if [ $$(lncli getinfo | jq '.num_active_channels + .num_pending_channels') -ge 3 ]; then
exit 0
else
lncli openchannel --node_key=$STACKER_LND_PUBKEY --connect stacker_lnd:9735 --sat_per_vbyte 1 \\
lncli openchannel --node_key=$STACKER_LND_PUBKEY --connect lnd:9735 --sat_per_vbyte 1 \\
--min_confs 0 --local_amt=1000000000 --push_amt=500000000
fi
"
cpu_shares: "${CPU_SHARES_MODERATE}"
stacker_lnd:
lnd:
build:
context: ./docker/lnd
args:
- LN_NODE_FOR=stacker
container_name: stacker_lnd
container_name: lnd
restart: unless-stopped
profiles:
- payments
Expand All @@ -384,9 +386,9 @@ services:
- 'lnd'
- '--noseedbackup'
- '--trickledelay=5000'
- '--alias=stacker_lnd'
- '--externalip=stacker_lnd'
- '--tlsextradomain=stacker_lnd'
- '--alias=lnd'
- '--externalip=lnd'
- '--tlsextradomain=lnd'
- '--tlsextradomain=host.docker.internal'
- '--tlsextradomain=$${ONION_DOMAIN}'
- '--listen=0.0.0.0:9735'
Expand All @@ -413,12 +415,16 @@ services:
- "${STACKER_LND_REST_PORT}:8080"
- "${STACKER_LND_GRPC_PORT}:10009"
volumes:
- stacker_lnd:/home/lnd/.lnd
- lnd:/home/lnd/.lnd
- tordata:/home/lnd/.tor
labels:
TORDIR: "/home/lnd/.tor"
CERTDIR: "/home/lnd/.lnd"
CLI: "lncli"
CLI_USER: "lnd"
ofelia.enabled: "true"
ofelia.job-exec.stacker_lnd_channel_cron.schedule: "@every 1m"
ofelia.job-exec.stacker_lnd_channel_cron.command: >
ofelia.job-exec.lnd_channel_cron.schedule: "@every 1m"
ofelia.job-exec.lnd_channel_cron.command: >
su lnd -c bash -c "
if [ $$(lncli getinfo | jq '.num_active_channels + .num_pending_channels') -ge 3 ]; then
exit 0
Expand All @@ -439,11 +445,11 @@ services:
<<: *healthcheck
test: ["CMD", "curl", "-f", "http://localhost:8443"]
depends_on:
stacker_lnd:
lnd:
condition: service_healthy
restart: true
volumes:
- stacker_lnd:/lnd
- lnd:/lnd
ports:
- "8443:8443"
command:
Expand All @@ -454,19 +460,21 @@ services:
- '--lnd-mode=remote'
- '--network=regtest'
- '--remote.lit-debuglevel=debug'
- '--remote.lnd.rpcserver=stacker_lnd:10009'
- '--remote.lnd.rpcserver=lnd:10009'
- '--remote.lnd.macaroonpath=/lnd/data/chain/bitcoin/regtest/admin.macaroon'
- '--remote.lnd.tlscertpath=/lnd/tls.cert'
- '--autopilot.disable'
- '--pool.auctionserver=test.pool.lightning.finance:12010'
- '--loop.server.host=test.swap.lightning.today:11010'
labels:
CONNECT: "localhost:8443"
CLI: "litcli"
CLI_ARGS: "-n regtest --rpcserver localhost:8444"
cpu_shares: "${CPU_SHARES_MODERATE}"
stacker_cln:
cln:
build:
context: ./docker/cln
container_name: stacker_cln
container_name: cln
restart: unless-stopped
profiles:
- payments
Expand All @@ -482,7 +490,7 @@ services:
command:
- 'lightningd'
- '--network=regtest'
- '--alias=stacker_cln'
- '--alias=cln'
- '--bitcoin-rpcconnect=bitcoin'
- '--bitcoin-rpcuser=${RPC_USER}'
- '--bitcoin-rpcpassword=${RPC_PASS}'
Expand All @@ -495,12 +503,16 @@ services:
ports:
- "${STACKER_CLN_REST_PORT}:3010"
volumes:
- stacker_cln:/home/clightning/.lightning
- cln:/home/clightning/.lightning
- tordata:/home/clightning/.tor
labels:
TORDIR: "/home/clightning/.tor"
CLI: "lightning-cli"
CLI_USER: "clightning"
CLI_ARGS: "--regtest"
ofelia.enabled: "true"
ofelia.job-exec.stacker_cln_channel_cron.schedule: "@every 1m"
ofelia.job-exec.stacker_cln_channel_cron.command: >
ofelia.job-exec.cln_channel_cron.schedule: "@every 1m"
ofelia.job-exec.cln_channel_cron.command: >
su clightning -c bash -c "
if [ $$(lightning-cli --regtest getinfo | jq '.num_active_channels + .num_pending_channels') -ge 3 ]; then
exit 0
Expand All @@ -519,8 +531,8 @@ services:
depends_on:
- bitcoin
- sn_lnd
- stacker_lnd
- stacker_cln
- lnd
- cln
restart: unless-stopped
command: daemon --docker -f label=com.docker.compose.project=${COMPOSE_PROJECT_NAME}
volumes:
Expand Down Expand Up @@ -550,12 +562,12 @@ services:
- wallets
restart: unless-stopped
depends_on:
stacker_lnd:
lnd:
condition: service_healthy
restart: true
volumes:
- nwc_send:/app
- stacker_lnd:/app/.lnd
- lnd:/app/.lnd
environment:
- RUST_LOG=info
entrypoint:
Expand All @@ -567,7 +579,7 @@ services:
- '--cert-file'
- '/app/.lnd/tls.cert'
- '--lnd-host'
- 'stacker_lnd'
- 'lnd'
- '--lnd-port'
- '10009'
- '--max-amount'
Expand All @@ -584,12 +596,12 @@ services:
- wallets
restart: unless-stopped
depends_on:
stacker_lnd:
lnd:
condition: service_healthy
restart: true
volumes:
- nwc_recv:/app
- stacker_lnd:/app/.lnd
- lnd:/app/.lnd
environment:
- RUST_LOG=info
entrypoint:
Expand All @@ -601,7 +613,7 @@ services:
- '--cert-file'
- '/app/.lnd/tls.cert'
- '--lnd-host'
- 'stacker_lnd'
- 'lnd'
- '--lnd-port'
- '10009'
- '--max-amount'
Expand All @@ -624,29 +636,30 @@ services:
tor:
condition: service_healthy
restart: true
stacker_lnd:
lnd:
condition: service_healthy
restart: true
environment:
- LNBITS_ADMIN_UI=true
- LNBITS_BACKEND_WALLET_CLASS=LndWallet
- LND_GRPC_ENDPOINT=stacker_lnd
- LND_GRPC_ENDPOINT=lnd
- LND_GRPC_PORT=10009
- LND_GRPC_CERT=/app/.lnd/tls.cert
- LND_GRPC_MACAROON=/app/.lnd/data/chain/bitcoin/regtest/admin.macaroon
volumes:
- stacker_lnd:/app/.lnd
- lnd:/app/.lnd
- tordata:/app/.tor
labels:
CONNECT: "localhost:${LNBITS_WEB_PORT}"
TORDIR: "/app/.tor"
cpu_shares: "${CPU_SHARES_LOW}"
volumes:
db:
os:
bitcoin:
sn_lnd:
stacker_lnd:
stacker_cln:
lnd:
cln:
s3:
nwc_send:
nwc_recv:
Expand Down
4 changes: 2 additions & 2 deletions docker/tor/services.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
HiddenServicePort 10009 stacker_lnd:10009
HiddenServicePort 3010 stacker_cln:3010
HiddenServicePort 10009 lnd:10009
HiddenServicePort 3010 cln:3010
HiddenServicePort 5000 lnbits:5000
12 changes: 6 additions & 6 deletions docker/tor/tor.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

function initialize {
function initialize {
####################### generate and save control password ########################
cp -f /etc/tor/torrc.template /tordata/torrc
TOR_PASSWORD=""
Expand All @@ -21,9 +21,9 @@ function mergeServices {
cat /services.conf >> /tordata/torrc
}

# There is a circular dependency between tor and stacker_lnd:
# <-> tor needs stacker_lnd to be running to resolve the hidden service target
# <-> stacker_lnd needs to wait for tor to start and generate the hidden service address
# There is a circular dependency between tor and lnd:
# <-> tor needs lnd to be running to resolve the hidden service target
# <-> lnd needs to wait for tor to start and generate the hidden service address
# Afaik there isn't an "official" solution for this issue.
#
# This workaround starts tor the first time without the lnd hidden service
Expand All @@ -47,7 +47,7 @@ then
exit 0
fi
else
# Step 1: we start tor with a fake hidden service that points to port 8080,
# Step 1: we start tor with a fake hidden service that points to port 8080,
# just to get it to generate the hidden service data, then we kill it immediately after
echo "Initializing..."
initialize
Expand All @@ -58,7 +58,7 @@ else

# debug
ls /tordata/hidden_service/

# Step 2: we merge the service configuration and start tor again
echo "Starting tor..."
initialize
Expand Down
Loading
Loading