|
| 1 | +# Robosats traditional environment |
| 2 | + |
| 3 | +Robosats backend development and testing without docker and containers. |
| 4 | + |
| 5 | +Binaries needed: |
| 6 | +* postgresql (`postgres`, `initdb`, `psql`) |
| 7 | +* redis (`redis-server`) |
| 8 | +* bitcoin (`bitcoind`, `bitcoin-cli`) |
| 9 | +* cln (`lightningd`, `lightning-cli`, `holdinvoice`) |
| 10 | +* lnd (`lnd`, `lncli`) |
| 11 | + |
| 12 | +## Preparation |
| 13 | + |
| 14 | +Postgresql and redis can be found in all linux distros and bsds. |
| 15 | + |
| 16 | +Some distros do not put postgresql binaries in `PATH`, if this is the |
| 17 | +case simply link them somewhere in your `PATH`. |
| 18 | + |
| 19 | +Example on debian: |
| 20 | +``` |
| 21 | +ln -sf /usr/lib/postgresql/16/bin/postgres ~/.local/bin/ |
| 22 | +ln -sf /usr/lib/postgresql/16/bin/initdb ~/.local/bin/ |
| 23 | +ln -sf /usr/lib/postgresql/16/bin/psql ~/.local/bin/ |
| 24 | +``` |
| 25 | + |
| 26 | +Bitcoin nodes if not already installed need to be manually downloaded. |
| 27 | +* bitcoin core binaries can be found here: https://bitcoincore.org/en/download |
| 28 | +* cln binaries can be found here: https://github.com/ElementsProject/lightning/releases |
| 29 | +* holdinvoice binary can be found here: https://github.com/daywalker90/holdinvoice/releases |
| 30 | +* lnd binaries can be found here: https://github.com/lightningnetwork/lnd/releases |
| 31 | + |
| 32 | +Example preparation: |
| 33 | +``` |
| 34 | +$ python3 -m venv venv |
| 35 | +$ . venv/bin/activate |
| 36 | +$ pip install -r requirements_dev.txt |
| 37 | +$ pip install -r requirements.txt |
| 38 | +
|
| 39 | +$ mkdir regtest |
| 40 | +$ mkdir regtest/programs |
| 41 | +$ cd regtest/programs |
| 42 | +$ mkdir bitcoin cln lnd |
| 43 | +# download bitcoin, cln (and holdinvoice) and lnd binaries |
| 44 | +
|
| 45 | +# if you want to use roboauto |
| 46 | +# still in regtest/programs |
| 47 | +$ git clone https://github.com/jerryfletcher21/roboauto |
| 48 | +$ cd roboauto |
| 49 | +$ pip install -r requirements.txt |
| 50 | +$ pip install . |
| 51 | +``` |
| 52 | + |
| 53 | +## env file |
| 54 | + |
| 55 | +``` |
| 56 | +$ cp .env-sample .env |
| 57 | +``` |
| 58 | +Edit `.env`, both robosats and regtest scripts will read from there. |
| 59 | + |
| 60 | +Variables to change: |
| 61 | +``` |
| 62 | +LNVENDOR = "CLN" |
| 63 | +# LNVENDOR = "LND" |
| 64 | +
|
| 65 | +LND_DIR = "regtest/nodes/lnd-coord/" |
| 66 | +MACAROON_PATH = "data/chain/bitcoin/regtest/admin.macaroon" |
| 67 | +CLN_DIR = "regtest/nodes/cln-coord/regtest/" |
| 68 | +BITCOIND_RPCPORT = "18443" |
| 69 | +POSTGRES_DB = "robosats" |
| 70 | +POSTGRES_USER = "robosats" |
| 71 | +POSTGRES_PASSWORD = "robosats" |
| 72 | +USE_TOR = False |
| 73 | +LOG_TO_CONSOLE = True |
| 74 | +LOGGER_LEVEL = "INFO" |
| 75 | +``` |
| 76 | + |
| 77 | +Variables to add: |
| 78 | +``` |
| 79 | +DEVELOPMENT = True |
| 80 | +TESTING = True |
| 81 | +
|
| 82 | +LNVENDOR_ROBOT = "LND" |
| 83 | +# LNVENDOR_ROBOT = "CLN" |
| 84 | +
|
| 85 | +BITCOIND_BIN = "regtest/programs/bitcoin/bitcoin-27.1/bin/bitcoind" |
| 86 | +BITCOIN_CLI_BIN = "regtest/programs/bitcoin/bitcoin-27.1/bin/bitcoin-cli" |
| 87 | +LIGHTNINGD_BIN = "regtest/programs/cln/usr/bin/lightningd" |
| 88 | +LIGHTNING_CLI_BIN = "regtest/programs/cln/usr/bin/lightning-cli" |
| 89 | +HOLDINVOICE_PLUGIN_BIN = "regtest/programs/cln/holdinvoice" |
| 90 | +LND_BIN = "regtest/programs/lnd/lnd-linux-amd64-v0.18.1-beta/lnd" |
| 91 | +LNCLI_BIN = "regtest/programs/lnd/lnd-linux-amd64-v0.18.1-beta/lncli" |
| 92 | +ROBOAUTO_GIT_DIR = "regtest/programs/roboauto" |
| 93 | +
|
| 94 | +REGTEST_NODES_DIR = "regtest/nodes" |
| 95 | +REGTEST_SERVICES_DIR = "regtest/services" |
| 96 | +REGTEST_LOGS_DIR = "regtest/logs" |
| 97 | +GNUPG_DIR = "regtest/services/gnupg" |
| 98 | +
|
| 99 | +BITCOIND_TEST_RPCUSER = "robodev" |
| 100 | +BITCOIND_TEST_RPCPASSWORD = "robodev" |
| 101 | +CLN_TEST_COORD_LISTEN_PORT = 9785 |
| 102 | +LND_TEST_COORD_LISTEN_PORT = 9885 |
| 103 | +LND_TEST_COORD_MACAROON_PATH = "regtest/nodes/lnd-coord/data/chain/bitcoin/regtest/admin.macaroon" |
| 104 | +LND_TEST_ROBOT_MACAROON_PATH = "regtest/nodes/lnd-user/data/chain/bitcoin/regtest/admin.macaroon" |
| 105 | +LND_TEST_ROBOT_REST_PORT = 8180 |
| 106 | +LND_TEST_COORD_REST_PORT = 8181 |
| 107 | +``` |
| 108 | + |
| 109 | +Paths can be relative or absolute. Binaries should be paths, they are |
| 110 | +not resolved with `PATH`. |
| 111 | + |
| 112 | +Roboauto can be disabled by not setting `ROBOAUTO_GIT_DIR` or setting it |
| 113 | +to `false`. |
| 114 | + |
| 115 | +If some ports are already in use, change their value. |
| 116 | + |
| 117 | +To check which port are already in use, `netstat -tulnp` with root |
| 118 | +privileges can be used. |
| 119 | + |
| 120 | +For example if there is alread an instance of postgresql running on the |
| 121 | +default port, change `POSTGRES_PORT = "5433"`. |
| 122 | + |
| 123 | +## Usage |
| 124 | + |
| 125 | +For development and testing two scripts are provided: |
| 126 | +* `regtest-services` for non bitcoin related services |
| 127 | +* `regtest-nodes` for bitcoin and lightning nodes |
| 128 | + |
| 129 | +`regtest-services` sets up the database and manages the services. |
| 130 | + |
| 131 | +Everything is done locally, so no root privileges/service managers are |
| 132 | +needed. |
| 133 | + |
| 134 | +`regtest-nodes` is a script that should be sourced, it sets up a regtest |
| 135 | +environment, with bitcoin core, cln, lnd and roboauto, connecting them |
| 136 | +and creating channels. It then exposes the functions `btc_reg`, |
| 137 | +`cln_coord`, `cln_user`, `lnd_coord`, `lnd_user`, `ra_reg` to interact |
| 138 | +with the nodes and roboauto. |
| 139 | + |
| 140 | +If the script is sourced in a `bash` shell, it will also source |
| 141 | +completions for all the functions. |
| 142 | + |
| 143 | +`regtest-nodes` can also be run without arguments to simply expose the |
| 144 | +functions to start and remove the nodes and to create the channels |
| 145 | +between them, without setting up a specific environment. |
| 146 | + |
| 147 | +Setup: |
| 148 | +``` |
| 149 | +# after having changed .env file |
| 150 | +
|
| 151 | +$ . venv/bin/activate |
| 152 | +
|
| 153 | +# generate cln and lnd grpc |
| 154 | +$ scripts/generate_grpc.sh |
| 155 | +
|
| 156 | +$ scripts/traditional/regtest-services postgres-setup |
| 157 | +
|
| 158 | +$ scripts/traditional/regtest-services postgres-database |
| 159 | +
|
| 160 | +# postgres-database will create the database specified by |
| 161 | +# POSTGRES_DB in .env, it can be run multiple times with |
| 162 | +# different values of POSTGRES_DB for different databases |
| 163 | +``` |
| 164 | + |
| 165 | +Testing: |
| 166 | +``` |
| 167 | +# edit .env setting LNVENDOR to either "CLN" or "LND" |
| 168 | +# LNVENDOR_ROBOT while running tests should be set to "LND" |
| 169 | +
|
| 170 | +# in the main window |
| 171 | +$ . venv/bin/activate |
| 172 | +$ . scripts/traditional/regtest-nodes test |
| 173 | +
|
| 174 | +# in a secondary window |
| 175 | +$ . venv/bin/activate |
| 176 | +# can be stopped with Control-C |
| 177 | +$ scripts/traditional/regtest-services test |
| 178 | +
|
| 179 | +# back in the main window |
| 180 | +$ python3 manage.py test |
| 181 | +
|
| 182 | +# after having run the tests run |
| 183 | +$ robosats_regtest_stop_and_remove_all |
| 184 | +# to remove the nodes, they will be recreated when |
| 185 | +# running the tests again |
| 186 | +
|
| 187 | +# the tests should be run with a clean database so if you have already run |
| 188 | +# the server and want to keep the database, either use a different value |
| 189 | +# of POSTGRES_DB or use a different directory by moving |
| 190 | +# regtest/services/postgres somewhere and the moving it back when you want |
| 191 | +# to run the server again |
| 192 | +``` |
| 193 | + |
| 194 | +Development: |
| 195 | +``` |
| 196 | +# edit .env setting LNVENDOR to either "CLN" or "LND" |
| 197 | +# and LNVENDOR_ROBOT to either "CLN" or "LND" |
| 198 | +
|
| 199 | +# in the main window |
| 200 | +$ . venv/bin/activate |
| 201 | +$ . scripts/traditional/regtest-nodes server |
| 202 | +
|
| 203 | +# in a secondary window |
| 204 | +$ . venv/bin/activate |
| 205 | +# can be stopped with Control-C |
| 206 | +$ scripts/traditional/regtest-services server |
| 207 | +
|
| 208 | +# to see the output of the django runserver command |
| 209 | +# in a third window |
| 210 | +$ tail -f regtest/logs/runserver |
| 211 | +
|
| 212 | +# if roboauto is active, use it to test the backend |
| 213 | +# back in the main window |
| 214 | +$ ra_reg --help |
| 215 | +... |
| 216 | +$ ra_reg create-order "$(ra_reg generate-robot --loc)" type=buy currency=btc min_amount=0.01 max_amount=0.02 payment_method="On-Chain BTC" premium=-1.5 |
| 217 | +... |
| 218 | +$ ra_reg take-order $(ra_reg generate-robot --loc) order-id |
| 219 | +... |
| 220 | +$ ra_reg escrow-pay RobotName |
| 221 | +... |
| 222 | +``` |
0 commit comments