Merge branch 'distro' into protocol

# Conflicts:
#	cmd/docker/release/builds.go
#	cmd/docker/release/packaging.go
#	go.sum
This commit is contained in:
херетик
2023-02-10 15:45:37 +00:00
12 changed files with 205 additions and 27 deletions

View File

@@ -1,7 +1,7 @@
package main
import (
"github.com/indra-labs/indra/pkg/docker"
"git-indra.lan/indra-labs/indra/pkg/docker"
)
var (

View File

@@ -1,7 +1,7 @@
package main
import (
"github.com/indra-labs/indra/pkg/docker"
"git-indra.lan/indra-labs/indra/pkg/docker"
)
var (

View File

@@ -0,0 +1,176 @@
# Running a dockerized BTCD/LND Simnet
This guide will show you how to setup a btcd with lnd simnet environment.
The environment consists of four nodes, one btcd node, and three lnd nodes (miner, alice and bob).
- The btcd instance will mine coins to the 'miner' lnd node.
- The 'alice' and 'bob' lnd nodes will be bootstrapped with 100 sBTC each, as part of the setup.
## Requirements
The following services are required in order to run this environment:
| Library | Download |
|----------------|-------------------------------------------------|
| docker | https://www.docker.com/products/docker-desktop/ |
| docker-compose | https://docs.docker.com/compose/install/ |
| jq | https://stedolan.github.io/jq/download/ |
Just to note:
- We will also assume that you've added your current user to the docker group. You can find a guide on how to do this at https://docs.docker.com/engine/install/linux-postinstall/.
- This will ensure that you can run docker under your current user.
## Setting up the environment
Bootstrapping is pretty straightforward, assuming that you have all of the requirements above installed. It can be done the following way:
### Running Setup
Navigate to your indra project root directory, and run the following:
- We will assume in the following example the directory is contained in `/opt/indra-labs/indra`.
- BEWARE: This script must be run from the project root directory!
```
docker/release/targets/lnd/scripts/setup.sh
```
When complete, it will produce an environment configuration file, located at `docker/release/targets/lnd/.env`. It will be in the following format:
```
MINER_PUBKEY=<lightning_public_key>
MINER_ADDRESS=<bitcoin_address>
ALICE_PUBKEY=<lightning_public_key>
ALICE_ADDRESS=<bitcoin_address>
BOB_PUBKEY=<lightning_public_key>
BOB_ADDRESS=<bitcoin_address>
```
### Using the environment config
The config file has two functions:
- The MINER_ADDRESS is passed to the docker-compose.yml file, on start. This will ensure that any block rewards will be send to the 'miner' node.
- The rest of the environment variables can be used by the user for constructing transactions. See the use-cases below.
```
export $(grep -vE "^(#.*|\s*)$" /opt/indra-labs/indra/docker/release/targets/lnd/.env)
```
This will take around 30 seconds to complete. Once complete, we can move on to using the simnet.
### Adding the bin folder to your $PATH (recommended)
For example: (this will not persist, and assumes your indra project root as at /opt/indra-labs/indra):
```
export PATH=$PATH:/opt/indra-labs/indra/docker/release/targets/lnd/bin
```
#### Adding $PATH persistence
If you would like to persist your path, check out this tutorial: https://linuxhint.com/add-path-permanently-linux/
## Starting / Stopping the network
The following section will show you how to start and stop the network.
### Starting
To start the environment, run the following from your indra project root directory:
```
docker-compose --file=docker/release/targets/lnd/docker-compose.yml up
```
#### Running in the background
To start the environment *as a background process*, run the following (from your indra project root directory):
```
docker-compose --file=docker/release/targets/lnd/docker-compose.yml up --detach
```
### Stopping
To stop the environment, run the following (from your indra project root directory):
```
docker-compose --file=docker/release/targets/lnd/docker-compose.yml down
```
## Running commands on the network
Assuming we've already started the environment, we can run commands for all nodes in the simnet.
### Generating blocks
To generate a new block, run the following:
```
lnsim-btcctl generate 1
```
If you would like to generate many blocks, you can use the second argument. Here's an example to generate 100 blocks:
```
lnsim-btcctl generate 100
```
#### A small rule of thumb
- In order for a lightning channel to be opened, there is a requirement that 6 blocks must be generated to confirm the open.
### Interacting with the LND nodes
The lncli interface for any of the nodes can be accessed with the following commands
#### Getting the wallet balance:
To check the balance of the 'miner' node
```
lnsim-lncli-miner walletbalance
```
To check alice's balance:
```
lnsim-lncli-alice walletbalance
```
To check bob's balance:
```
lnsim-lncli-bob walletbalance
```
## Some useful use-cases
### Sending alice and bob 1 sBTC from the miner
```
lnsim-lncli-miner sendcoins --addr $LNSIM_ALICE_ADDRESS --amt 100000000
lnsim-lncli-miner sendcoins --addr $LNSIM_BOB_ADDRESS --amt 100000000
lnsim-btcctl generate 1
```
### Opening a (0.01 sBTC) channel between alice and bob
```
lnsim-lncli-alice openchannel --node_key=$LNSIM_BOB_PUBKEY --connect=172.16.43.11:9735 --local_amt 1000000
lnsim-btcctl generate 6
lnsim-lncli-alice listchannels
lnsim-lncli-bob listchannels
```
You can optionally check the pending channel before generating blocks, with the following:
```
lnsim-lncli-alice pendingchannels
```
### Sending a (0.0005 sBTC) payment from alice to bob
```
lnsim-lncli-alice sendpayment --dest=$LNSIM_BOB_PUBKEY --amt=50000 --keysend
lnsim-lncli-alice channelbalance
```
# fin; happy simulating!

View File

@@ -13,7 +13,7 @@ services:
- "--rpcpass=simnet"
- "--simnet"
- "--txindex"
- "--miningaddr=${MINER_ADDRESS:-SSBjQ58PsRmBtGZQ8ckXFRxijZFCBdeMMT}"
- "--miningaddr=${LNSIM_MINER_ADDRESS:-SSBjQ58PsRmBtGZQ8ckXFRxijZFCBdeMMT}" # Using a random simnet address by default.
lnd-miner:
image: indralabs/lnd-multi-arch:linux-amd64-dev
volumes:

View File

@@ -1,59 +1,68 @@
#!/bin/bash
# Remove existing containers
echo "wiping the exising environment..."
docker stop lnd-btcd-1 lnd-lnd-miner-1 lnd-lnd-alice-1 lnd-lnd-bob-1 2>/dev/null 1>/dev/null
docker rm lnd-btcd-1 lnd-lnd-miner-1 lnd-lnd-alice-1 lnd-lnd-bob-1 2>/dev/null 1>/dev/null
# Remove existing volumes
docker volume rm lnd_btcd_config lnd_btcd_data lnd_lnd_miner_config lnd_lnd_miner_data lnd_lnd_alice_config lnd_lnd_alice_data lnd_lnd_bob_config lnd_lnd_bob_data 2>/dev/null 1>/dev/null
echo "running bootstrapping of wallets"
docker-compose -f docker/release/targets/lnd/docker-compose.yml up --quiet-pull --detach 1>/dev/null
rm docker/release/targets/lnd/.env 2>/dev/null
echo "waiting for the environment to start..."
sleep 10
sleep 5
echo "generating an lnd pubkey and address for miner, alice and bob."
docker/release/targets/lnd/bin/lncli-miner getinfo | jq -r .identity_pubkey | xargs -I {} echo "MINER_PUBKEY={}" \
docker/release/targets/lnd/bin/lnsim-lncli-miner getinfo | jq -r .identity_pubkey | xargs -I {} echo "LNSIM_MINER_PUBKEY={}" \
>> docker/release/targets/lnd/.env
docker/release/targets/lnd/bin/lncli-miner newaddress np2wkh | jq -r .address | xargs -I {} echo "MINER_ADDRESS={}" \
docker/release/targets/lnd/bin/lnsim-lncli-miner newaddress np2wkh | jq -r .address | xargs -I {} echo "LNSIM_MINER_ADDRESS={}" \
>> docker/release/targets/lnd/.env
docker/release/targets/lnd/bin/lncli-alice getinfo | jq -r .identity_pubkey | xargs -I {} echo "ALICE_PUBKEY={}" \
docker/release/targets/lnd/bin/lnsim-lncli-alice getinfo | jq -r .identity_pubkey | xargs -I {} echo "LNSIM_ALICE_PUBKEY={}" \
>> docker/release/targets/lnd/.env
docker/release/targets/lnd/bin/lncli-alice newaddress np2wkh | jq -r .address | xargs -I {} echo "ALICE_ADDRESS={}" \
docker/release/targets/lnd/bin/lnsim-lncli-alice newaddress np2wkh | jq -r .address | xargs -I {} echo "LNSIM_ALICE_ADDRESS={}" \
>> docker/release/targets/lnd/.env
docker/release/targets/lnd/bin/lncli-bob getinfo | jq -r .identity_pubkey | xargs -I {} echo "BOB_PUBKEY={}" \
docker/release/targets/lnd/bin/lnsim-lncli-bob getinfo | jq -r .identity_pubkey | xargs -I {} echo "LNSIM_BOB_PUBKEY={}" \
>> docker/release/targets/lnd/.env
docker/release/targets/lnd/bin/lncli-bob newaddress np2wkh | jq -r .address | xargs -I {} echo "BOB_ADDRESS={}" \
docker/release/targets/lnd/bin/lnsim-lncli-bob newaddress np2wkh | jq -r .address | xargs -I {} echo "LNSIM_BOB_ADDRESS={}" \
>> docker/release/targets/lnd/.env
echo "shutting down environment to enable btcd to mine to the miner address."
docker-compose -f docker/release/targets/lnd/docker-compose.yml down
echo "running coin sending to alice and bob"
docker-compose --env-file=docker/release/targets/lnd/.env -f docker/release/targets/lnd/docker-compose.yml up --quiet-pull --detach
echo "waiting for the environment to start...again..."
sleep 10
echo "waiting for the environment to start..."
sleep 5
docker/release/targets/lnd/bin/btcctl generate 500 1>/dev/null
echo "generating 500 blocks to enable segwit."
docker/release/targets/lnd/bin/lnsim-btcctl generate 500 1>/dev/null
echo "getting miners wallet balance"
docker/release/targets/lnd/bin/lncli-miner walletbalance
docker/release/targets/lnd/bin/lnsim-lncli-miner walletbalance
echo "sourcing environment variables"
source docker/release/targets/lnd/.env
echo "sending coins to alice and bob."
docker/release/targets/lnd/bin/lncli-miner sendcoins --addr $ALICE_ADDRESS --amt 100000000000
docker/release/targets/lnd/bin/lncli-miner sendcoins --addr $BOB_ADDRESS --amt 100000000000
docker/release/targets/lnd/bin/lnsim-lncli-miner sendcoins --addr $LNSIM_ALICE_ADDRESS --amt 100000000000
docker/release/targets/lnd/bin/lnsim-lncli-miner sendcoins --addr $LNSIM_BOB_ADDRESS --amt 100000000000
docker/release/targets/lnd/bin/btcctl generate 1 1>/dev/null
echo "generating 100 blocks to allow them to be spent"
docker/release/targets/lnd/bin/lnsim-btcctl generate 100 1>/dev/null
echo "getting alice's wallet balance:"
docker/release/targets/lnd/bin/lncli-alice walletbalance
docker/release/targets/lnd/bin/lnsim-lncli-alice walletbalance
echo "getting bob's wallet balance:"
docker/release/targets/lnd/bin/lncli-bob walletbalance
docker/release/targets/lnd/bin/lnsim-lncli-bob walletbalance
docker-compose -f docker/release/targets/lnd/docker-compose.yml down
echo "setup is complete!"

View File

@@ -3,7 +3,7 @@ services:
btcd:
sysctls:
- "net.ipv6.conf.all.disable_ipv6=0"
image: indralabs/btcd:latest
image: indralabs/btcd-multi-arch:linux-amd64-dev
container_name: indra-btcd
volumes:
- btcd_config:/etc/btcd:ro

1
go.mod
View File

@@ -74,7 +74,6 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/indra-labs/lnd v0.15.5-beta // indirect
github.com/ipfs/go-cid v0.3.2 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
github.com/ipfs/go-ipfs-util v0.0.2 // indirect

6
go.sum
View File

@@ -65,8 +65,6 @@ github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugX
github.com/Microsoft/go-winio v0.4.17-0.20210211115548-6eac466e5fa3/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Microsoft/go-winio v0.4.17-0.20210324224401-5516f17a5958/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Microsoft/go-winio v0.4.17/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg=
@@ -583,10 +581,6 @@ github.com/imdario/mergo v0.3.10/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/indra-labs/indra v0.1.9 h1:IgjDWVCiS4uSrWQe3LL8kCPMHx5kSPBqmJeTupxi2Pk=
github.com/indra-labs/indra v0.1.9/go.mod h1:tbAsGhLx2/RaFsGhhp7YSwBu6SuPxeeBKF8Lp+mnKtM=
github.com/indra-labs/lnd v0.15.5-beta h1:moLiD+/bBIDpkdZWGuDgm7+CoC8U0p8jrPbyQ9wlw3A=
github.com/indra-labs/lnd v0.15.5-beta/go.mod h1:iddXZqwzGmXtsq0h6bx/JMOuweedbphKjP3ZsUA8hyk=
github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj6+M=
github.com/ipfs/go-cid v0.3.2 h1:OGgOd+JCFM+y1DjWPmVH+2/4POtpDzwcr7VgnB7mZXc=
github.com/ipfs/go-cid v0.3.2/go.mod h1:gQ8pKqT/sUxGY+tIwy1RPpAojYu7jAyCp5Tz1svoupw=