bisq/docs/dev-setup.md

94 lines
5.9 KiB
Markdown
Raw Normal View History

# Bisq dev setup guide
This guide describes how to set up a complete Bisq development environment running against a local Bitcoin regtest network. You'll run your own Bisq seed node, arbitration and trading instances in order to allow for end-to-end development and testing.
## Prerequisites
Follow the instructions in [build.md](build.md) to build Bisq from source, and it is also recommended to follow the instructions in [idea-import.md](idea-import.md) to be able to run everything from within IntelliJ IDEA. Please also read and follow the instructions in [CONTRIBUTING.md](../CONTRIBUTING.md) prior to submitting any pull requests.
## Overview
When developing Bisq, you usually want to use Bitcoin in **regtest** mode and do all networking on **localhost** instead of using the Tor network. Typically, you'll want an environment set up with the following components:
- Bitcoin Core or bitcoind in regtest mode
- A local Bisq seed node
2019-09-19 15:28:49 +02:00
- A local Bisq arbitrator & mediator instance
- 2 local Bisq trading instances (BTC buyer and BTC seller for executing a trade)
You'll set up each of these in the steps that follow.
## Run Bitcoin Core (or bitcoind) in regtest mode
The regtest mode operates a local Bitcoin network on your computer. This environment is ideally suited for testing because you are able to create blocks on demand (no need to wait for confirmations) and you don't need to download the blockchain. By creating blocks you act like a miner and you can generate new Bitcoin.
You can find more information about the Bitcoin regtest mode [here](https://bitcoin.org/en/developer-examples#regtest-mode).
Navigate to the [bitcoin.conf](https://en.bitcoin.it/wiki/Running_Bitcoin#Bitcoin.conf_Configuration_File) file and set `regtest=1`, or add `-regtest` as a program argument when starting Bitcoin Core.
At first startup you need to create 101 blocks using the command `generate 101`* from the terminal inside Bitcoin Core. 101 blocks are required because of the coin maturity (100 blocks) so you need one more to have at least 50 BTC available for spending.
Later you can create new blocks with `generate 1`*.
*This method is deprecated in Bitcoin Core's v.0.18 and will be fully removed in v.0.19. Use instead `generatetoaddress amount address`.
## Understand Bisq P2P network options
2018-11-01 03:59:10 +01:00
For the local P2P network we prefer to use `localhost`, not the Tor network as it is much faster. But if needed you can combine any of the following combinations of Bitcoin network mode and P2P network mode:
- localhost + regtest
- localhost + testnet
- localhost + mainnet
- Tor + regtest
- Tor + testnet
- Tor + mainnet
## Understand Bisq program arguments
There are several program arguments required to run in development mode.
Here is an overview:
- `--baseCurrencyNetwork`: The BTC network to use. Possible values are: `BTC_REGTEST`, `BTC_TESTNET`, `BTC_MAINNET` (default)
- `--useLocalhostForP2P`: Uses localhost instead of Tor for Bisq P2P network
- `--nodePort`: Port number for localhost mode. For seed nodes there is a convention with the last digit is marking the network type and there is a list of hard coded seed nodes addresses (see: `DefaultSeedNodeAddresses.java`). For regtest: 2002 and 3002. For testnet 2001, 3001 and 4001 and for mainnet: 2000, 3000 and 4000. For normal nodes the port can be chosen freely.
- `--useDevPrivilegeKeys`: Important for dev testing to allow the developer key for arbitration registration
- `--appName`: Custom application name which is used for the data directory. It is important to separate your nodes to not interfere. If not set, it uses the default `Bisq` directory.
## Run Bisq seednode
Generate scripts for Bisq executables in root dir This change configures the Gradle build to generate "start scripts" for each Bisq executable (e.g. Bisq Desktop, Bisq Seednode, etc) in the root project directory, such that after invoking `./gradle build`, the following executable scripts become available: ~/Work/bisq-network/bisq $ ls -1 | egrep '(bisq*|lib)' bisq-desktop bisq-desktop.bat bisq-monitor bisq-monitor.bat bisq-relay bisq-relay.bat bisq-seednode bisq-seednode.bat bisq-statsnode bisq-statsnode.bat lib This makes it possible for users (developers) to easily discover and use these scripts in an idiomatic and platform-agnostic way as opposed to the previous situation where we would advise users to run e.g. java -jar desktop/build/libs/desktop-0.8.0-SNAPSHOT-all.jar This approach works, but is cumbersome and focuses unnecessarily on the Java-based nature of the project. Now, with the changes in this commit, the user would simply run: ./bisq-desktop The 'lib' directory shown above contains all the jar files necessary to construct classpaths for these various scripts. The 'cleanInstallDist' task deletes the 'bisq-*' files and the 'lib' directory, and the default 'clean' task has been configured to depend on the 'cleanInstallDist' task to ensure this cleanup happens automatically when most users would expect it. In the future, these same scripts can be used when installing Bisq executables properly on users' systems via package managers like Brew and Apt. The goal is to have the user experience around running `bisq-desktop` (and more importantly, the forthcoming `bisqd`) be similar in every way to installing and using `bitcoind`, `lnd` and other idiomatic *nix-style utilities, be they Bitcoin-related or not. See the changes in docs/build.md and docs/dev-setup.md for a further sense of the how this change impacts the developer experience.
2018-11-23 14:33:44 +01:00
For localhost/regtest mode run the `SeedNodeMain` class or `./bisq-seednode` script in the root project dir with following program arguments:
--baseCurrencyNetwork=BTC_REGTEST --useLocalhostForP2P=true --useDevPrivilegeKeys=true --nodePort=2002 --appName=bisq-BTC_REGTEST_Seed_2002
2019-09-19 15:28:49 +02:00
### Run Bisq arbitrator/mediator instance
Generate scripts for Bisq executables in root dir This change configures the Gradle build to generate "start scripts" for each Bisq executable (e.g. Bisq Desktop, Bisq Seednode, etc) in the root project directory, such that after invoking `./gradle build`, the following executable scripts become available: ~/Work/bisq-network/bisq $ ls -1 | egrep '(bisq*|lib)' bisq-desktop bisq-desktop.bat bisq-monitor bisq-monitor.bat bisq-relay bisq-relay.bat bisq-seednode bisq-seednode.bat bisq-statsnode bisq-statsnode.bat lib This makes it possible for users (developers) to easily discover and use these scripts in an idiomatic and platform-agnostic way as opposed to the previous situation where we would advise users to run e.g. java -jar desktop/build/libs/desktop-0.8.0-SNAPSHOT-all.jar This approach works, but is cumbersome and focuses unnecessarily on the Java-based nature of the project. Now, with the changes in this commit, the user would simply run: ./bisq-desktop The 'lib' directory shown above contains all the jar files necessary to construct classpaths for these various scripts. The 'cleanInstallDist' task deletes the 'bisq-*' files and the 'lib' directory, and the default 'clean' task has been configured to depend on the 'cleanInstallDist' task to ensure this cleanup happens automatically when most users would expect it. In the future, these same scripts can be used when installing Bisq executables properly on users' systems via package managers like Brew and Apt. The goal is to have the user experience around running `bisq-desktop` (and more importantly, the forthcoming `bisqd`) be similar in every way to installing and using `bitcoind`, `lnd` and other idiomatic *nix-style utilities, be they Bitcoin-related or not. See the changes in docs/build.md and docs/dev-setup.md for a further sense of the how this change impacts the developer experience.
2018-11-23 14:33:44 +01:00
For localhost/regtest mode run the `BisqAppMain` class or `./bisq-desktop` script in the root project dir with following program arguments:
--baseCurrencyNetwork=BTC_REGTEST --useLocalhostForP2P=true --useDevPrivilegeKeys=true --nodePort=4444 --appName=bisq-BTC_REGTEST_arbitrator
2019-09-19 15:28:49 +02:00
Once it has started up go to `Account` and click `CMD +r`. This will open a new tab for `Arbitration registration`. Select the tab and you will see a popup with a pre-filled private key. That is the developer private key (which is only valid if `--useDevPrivilegeKeys` is set) which allows you to register a new arbitrator. Follow the next screen and complete registration.
Next you have to register a mediator as well. Click `CMD + d`. This will open a new tab for `Mediator registration`. Follow the same steps as for the arbitrator registration before.
_Note: You need only register once but if you have shut down all nodes (including seed node) you need to start up the arbitrator again after you start the seed node so the arbitrator re-publishes his data to the P2P network. After it has started up you can close it again. You cannot trade without having an arbitrator available._
### Run two Bisq trade instances
Generate scripts for Bisq executables in root dir This change configures the Gradle build to generate "start scripts" for each Bisq executable (e.g. Bisq Desktop, Bisq Seednode, etc) in the root project directory, such that after invoking `./gradle build`, the following executable scripts become available: ~/Work/bisq-network/bisq $ ls -1 | egrep '(bisq*|lib)' bisq-desktop bisq-desktop.bat bisq-monitor bisq-monitor.bat bisq-relay bisq-relay.bat bisq-seednode bisq-seednode.bat bisq-statsnode bisq-statsnode.bat lib This makes it possible for users (developers) to easily discover and use these scripts in an idiomatic and platform-agnostic way as opposed to the previous situation where we would advise users to run e.g. java -jar desktop/build/libs/desktop-0.8.0-SNAPSHOT-all.jar This approach works, but is cumbersome and focuses unnecessarily on the Java-based nature of the project. Now, with the changes in this commit, the user would simply run: ./bisq-desktop The 'lib' directory shown above contains all the jar files necessary to construct classpaths for these various scripts. The 'cleanInstallDist' task deletes the 'bisq-*' files and the 'lib' directory, and the default 'clean' task has been configured to depend on the 'cleanInstallDist' task to ensure this cleanup happens automatically when most users would expect it. In the future, these same scripts can be used when installing Bisq executables properly on users' systems via package managers like Brew and Apt. The goal is to have the user experience around running `bisq-desktop` (and more importantly, the forthcoming `bisqd`) be similar in every way to installing and using `bitcoind`, `lnd` and other idiomatic *nix-style utilities, be they Bitcoin-related or not. See the changes in docs/build.md and docs/dev-setup.md for a further sense of the how this change impacts the developer experience.
2018-11-23 14:33:44 +01:00
For localhost/regtest mode run the `BisqAppMain` class or `./bisq-desktop` script in the root project dir with following program arguments:
--baseCurrencyNetwork=BTC_REGTEST --useLocalhostForP2P=true --useDevPrivilegeKeys=true --nodePort=5555 --appName=bisq-BTC_REGTEST_Alice
and
--baseCurrencyNetwork=BTC_REGTEST --useLocalhostForP2P=true --useDevPrivilegeKeys=true --nodePort=6666 --appName=bisq-BTC_REGTEST_Bob
At this point you can now perform trades between Alice and Bob using your local regtest environment and test from both the buyer's and seller's perspective. You can also open disputes with `cmd+o` and see how the arbitration system works (run the arbitrator in that case as well).
2018-11-01 04:08:48 +01:00
_Remember to generate a new block in the Bitcoin Core console after taking an offer using the command `generate 1` to trigger a block confirmation._