Browse Source

Merge pull request #118 from Samourai-Wallet/feat_mydojo_local_indexer

add the support of local indexers as the data source of imports and rescans
feat-mydojo_upgrade_explorer
kenshin samourai 5 years ago
committed by GitHub
parent
commit
200c621af4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      README.md
  2. 99
      doc/DOCKER_advanced_setups.md
  3. 46
      doc/DOCKER_setup.md
  4. 10
      docker/my-dojo/.env
  5. 42
      docker/my-dojo/conf/docker-indexer.conf.tpl
  6. 2
      docker/my-dojo/conf/docker-node.conf.tpl
  7. 1
      docker/my-dojo/docker-compose.yaml
  8. 20
      docker/my-dojo/dojo.sh
  9. 5
      docker/my-dojo/explorer/Dockerfile
  10. 23
      docker/my-dojo/explorer/restart.sh
  11. 43
      docker/my-dojo/indexer/Dockerfile
  12. 22
      docker/my-dojo/indexer/restart.sh
  13. 178
      docker/my-dojo/indexer/wait-for-it.sh
  14. 5
      docker/my-dojo/install/install-scripts.sh
  15. 3
      docker/my-dojo/install/upgrade-scripts.sh
  16. 12
      docker/my-dojo/node/keys.index.js
  17. 2
      docker/my-dojo/overrides/explorer.install.yaml
  18. 27
      docker/my-dojo/overrides/indexer.install.yaml

15
README.md

@ -17,7 +17,8 @@ It provides in a single command the setup of a full Samourai backend composed of
* the backend database, * the backend database,
* the backend modules with an API accessible as a static Tor hidden service, * the backend modules with an API accessible as a static Tor hidden service,
* a maintenance tool accessible through a Tor web browser, * a maintenance tool accessible through a Tor web browser,
* a block explorer ([BTC RPC Explorer](https://github.com/janoside/btc-rpc-explorer)) accessible through a Tor web browser. * a block explorer ([BTC RPC Explorer](https://github.com/janoside/btc-rpc-explorer)) accessible through a Tor web browser,
* an optional indexer of Bitcoin addresses ([addrindexrs](https://github.com/Samourai-Wallet/addrindexrs)) providing fast and private rescans of HD accounts and loose addresses.
See [the documentation](./doc/DOCKER_setup.md) for detailed setup instructions. See [the documentation](./doc/DOCKER_setup.md) for detailed setup instructions.
@ -61,13 +62,16 @@ Authentication is enforced by an API key and Json Web Tokens.
**Import of HD Accounts and data sources** **Import of HD Accounts and data sources**
* First import of an unknown HD account relies on a data source (local bitcoind or OXT). After that, the tracker will keep everything current. * First import of an unknown HD account relies on a data source (local bitcoind, local indexer or OXT). After that, the tracker will keep everything current.
* Default option relies on the local bitcoind and makes you 100% independent of Samourai Wallet's infrastructure. This option is recommended for better privacy. * Using the local bitcoind (default option) or the local indexer makes you 100% independent of Samourai Wallet's infrastructure and is recommended for better privacy.
* Activation of bitcoind as the data source: * Activation of bitcoind as the data source:
* Edit /keys/index.js and set "indexer.active" to "local_bitcoind". OXT API will be ignored. * Edit /keys/index.js and set "indexer.active" to "local_bitcoind". OXT API will be ignored.
* Activation of the local indexer as the data source:
* Edit /keys/index.js and set "indexer.active" to "local_indexer". OXT API will be ignored.
* Activation of OXT as the data source (through socks5): * Activation of OXT as the data source (through socks5):
* Edit /keys/index.js and set "indexer.active" to "third_party_explorer". * Edit /keys/index.js and set "indexer.active" to "third_party_explorer".
@ -77,5 +81,8 @@ Authentication is enforced by an API key and Json Web Tokens.
* It's slightly slower than using the option relying on the OXT API. * It's slightly slower than using the option relying on the OXT API.
* It may fail to correctly import an existing wallet if this wallet had a large activity. * It may fail to correctly import an existing wallet if this wallet had a large activity.
* If you use bitcoind and if the import seems to return an invalid balance, you can use the "XPUB rescan" function provided by the maintenance tool. This function allows you to force the minimum number of addresses to be derived and the start index for the derivation. * If you use bitcoind and if the import seems to return an invalid balance, you can use the "XPUB rescan" function provided by the maintenance tool. This function allows you to force the minimum number of addresses to be derived and the start index for the derivation.
* As a rule of thumb, we recommend to use bitcoind as the source of imports and to setup your Dojo with a new clean wallet. It increases your privacy and it removes all potential issues with the import of a large wallet.
* Main drawbacks of using your local indexer for these imports:
* It requires 120GB of additional disk space during its initialization.
As a rule of thumb, we recommend to use the local indexer as the source of imports and to setup your Dojo with a new clean wallet. It increases your privacy and it removes all potential issues with the import of a large wallet.

99
doc/DOCKER_advanced_setups.md

@ -3,10 +3,12 @@
The configuration files of Dojo provide a few advanced options allowing to tune your setup. The configuration files of Dojo provide a few advanced options allowing to tune your setup.
A word of caution, though, the default values of these options try to maximize your privacy at a network level. Most of the advanced setups described in this document may damage your privacy. Use at your own risk! A word of caution, though, the default values of these options try to maximize your privacy at a network level. Some of the advanced setups described in this document may damage your privacy. Use at your own risk!
## Table of Content ## ## Table of Content ##
- [Local indexer of Bitcoin addresses](#local_indexer)
- [Local Electrum server used as data source for imports/rescans](#local_electrum)
- [External Bitcoin full node](#external_bitcoind) - [External Bitcoin full node](#external_bitcoind)
- [bitcoind RPC API ans ZMQ notifications exposed to external apps](#exposed_rpc_zmq) - [bitcoind RPC API ans ZMQ notifications exposed to external apps](#exposed_rpc_zmq)
- [Static onion address for bitcoind hidden service](#static_onion) - [Static onion address for bitcoind hidden service](#static_onion)
@ -14,6 +16,101 @@ A word of caution, though, the default values of these options try to maximize y
- [Support of testnet](#testnet) - [Support of testnet](#testnet)
<a name="local_indexer"/>
## Local indexer of Bitcoin addresses ##
By default, Dojo uses the local full node as its data source for imports and rescans of HD accounts and addresses. While private, this default option has many limitations. MyDojo allows to install a local indexer ([addrindexrs](https://github.com/Samourai-Wallet/addrindexrs)) providing the best of both worlds (no request sent to a third party, fast and real time rescans, complete transactional history is retrieved).
### Requirements ###
To date, the initial installation of the indexer requires 120GB of additionnal disk space.
### Main benefits ###
- Fast, private and exhaustive real time rescans,
- Allows the block explorer to display the detailed activity of Bitcoin addresses
### Known drawbacks ###
* Additionnal disk space consumed by the index,
* Increased duration of upgrades (from 5 to 20 minutes depending on the machine hosting your Dojo),
* Slight increase of startup duration,
* First indexation will require a few hours.
### Procedure ###
```
# Edit the indexer config template file
nano ./conf/docker-indexer.conf.tpl
#
# Set the value of INDEXER_INSTALL to "on"
# Save and exit nano
#
# Edit the nodejs config file (or the corresponding template file if it's your first installation of Dojo)
nano ./conf/docker-node.conf
#
# Set the value of NODE_ACTIVE_INDEXER to "local_indexer"
# Save and exit nano
#
#
# Launch the installation or the upgrade of your Dojo
# with the commands `dojo.sh install` or `dojo.sh upgrade`
#
#
# Be patient!
# First indexation of all Bitcoin addresses will require a few hours.
# Let the indexer complete all these operations before trying to use it for an import or a rescan.
# You can follow the progress made by the indexer with the commands:
# `dojo.sh logs`
# or
# `dojo.sh logs indexer`
#
```
<a name="local_electrum"/>
## Local Electrum server used as data source for imports/rescans ##
If you're running an instance of ElectrumX or Electrs on your local network, Dojo allows you to define this instance as the data source used for imports and rescans. This setup is an alternative to the local indexer provided by MyDojo.
Important: Do not use an Electrum server operated by a third party or hosted on a different local network.
### Procedure ###
```
# Edit the indexer config template file
nano ./conf/docker-indexer.conf.tpl
#
# Set the value of INDEXER_INSTALL to "off"
# Set the value of INDEXER_IP with the IP address of your Electrum server
# Set the value of INDEXER_RPC_PORT with the port used by the RPC API of your Electrum server (default= 50001)
# Set the value of INDEXER_BATCH_SUPPORT to "active" if your Electrum server is ElectrumX, otherwise set the value to "inactive"
# Save and exit nano
#
# Edit the nodejs config file (or the corresponding template file if it's your first installation of Dojo)
nano ./conf/docker-node.conf
#
# Set the value of NODE_ACTIVE_INDEXER to "local_indexer"
# Save and exit nano
#
```
<a name="external_bitcoind"/> <a name="external_bitcoind"/>
## External Bitcoin full node ## ## External Bitcoin full node ##

46
doc/DOCKER_setup.md

@ -6,6 +6,7 @@ MyDojo is a set of Docker containers providing a full Samourai backend composed
* backend modules with an API accessible as a static Tor hidden service, * backend modules with an API accessible as a static Tor hidden service,
* a maintenance tool accessible through a Tor web browser, * a maintenance tool accessible through a Tor web browser,
* a block explorer ([BTC RPC Explorer](https://github.com/janoside/btc-rpc-explorer)) accessible as a static Tor hidden service. * a block explorer ([BTC RPC Explorer](https://github.com/janoside/btc-rpc-explorer)) accessible as a static Tor hidden service.
* an optional indexer of Bitcoin addresses ([addrindexrs](https://github.com/Samourai-Wallet/addrindexrs)) providing fast and private rescans of HD accounts and loose addresses.
## Table of Content ## ## Table of Content ##
@ -40,33 +41,39 @@ MyDojo is a set of Docker containers providing a full Samourai backend composed
Host machine | (Tor hidden services) Host machine | (Tor hidden services)
______________________________ | _____________________________ ______________________________ | _____________________________
| | | | | |
| ------------------- dmznet | | --------- dmznet |
| | Tor Container | | | --------| Tor |------------ |
| ------------------- | | | --------- | |
| | | | | | | |
| ------------------- | | | --------- | |
| | Nginx Container | | | | --| Nginx |-------- | |
| ------------------- | | | | --------- | | |
|- - - - - - - - - - - | - - -|- - - - | - - - - - - - - - - - | |- - - - -|- - - - - - - - - - -|- - - - - - - - -|- - - - - - |
| -------------------- | -------------------- |
| | Nodejs Container | ------ | Bitcoind Container | |
| -------------------- | -------------------- |
| | | | | | | | | |
| -------------------- | -------------------- | | ---------- ---------- ---------- |
| | MySQL Container | ---- | BTC RPC Explorer | | | | Nodejs |----------| Explorer |------| Bitcoind | |
| -------------------- -------------------- | | ---------- ---------- ---------- |
| | | | | | | |
| | ------- | | |
| | | | | |
| ---------- | ---------- | |
| | MySQL | ----| Indexer |----------- |
| ---------- ---------- |
| dojonet | | dojonet |
|______________________________________________________________| |______________________________________________________________|
<a name="requirements"/> <a name="requirements"/>
## Requirements ## ## Requirements ##
* A dedicated computer (host machine) connected 24/7 to internet * A dedicated computer (host machine) connected 24/7 to internet
* OS: Linux is recommended * OS: Linux is recommended
* Disk: 500GB (minimal) / 1TB (recommended) - SSD is recommended * Disk: 600GB (minimal) / 1TB (recommended) - SSD is recommended
* RAM: 4GB (minimal) * RAM: 4GB (minimal)
* Docker and Docker Compose installed on the host machine (be sure to run a recent version supporting v3.2 of docker-compose files, i.e. Docker Engine v17.04.0+) * Docker and Docker Compose installed on the host machine (be sure to run a recent version supporting v3.2 of docker-compose files, i.e. Docker Engine v17.04.0+)
* Check that the clock of your computer is properly set (required for Tor) * Check that the clock of your computer is properly set (required for Tor)
@ -77,10 +84,11 @@ MyDojo is a set of Docker containers providing a full Samourai backend composed
## Configuration files ## ## Configuration files ##
Each new release of Dojo is packaged with 6 template files stored in the `<dojo_dir>/docker/my-dojo/conf` directory: Each new release of Dojo is packaged with 7 template files stored in the `<dojo_dir>/docker/my-dojo/conf` directory:
- docker-common.conf.tpl - docker-common.conf.tpl
- docker-bitcoin.conf.tpl - docker-bitcoin.conf.tpl
- docker-explorer.conf.tpl - docker-explorer.conf.tpl
- docker-indexer.conf.tpl
- docker-mysql.conf.tpl - docker-mysql.conf.tpl
- docker-node.conf.tpl - docker-node.conf.tpl
- docker-tor.conf.tpl - docker-tor.conf.tpl
@ -106,6 +114,9 @@ For MacOS, see this detailed [installation guide](./DOCKER_mac_setup.MD).
For Synology, see this detailed [installation guide](./DOCKER_synology_setup.md). For Synology, see this detailed [installation guide](./DOCKER_synology_setup.md).
For Raspberry Pi4 and Odroid N2, see the [Ronin Dojo Project](https://github.com/RoninDojo/RoninDojo)
This procedure allows to install a new Dojo from scratch. This procedure allows to install a new Dojo from scratch.
* Install [Docker and Docker Compose](https://docs.docker.com/compose/install/) on the host machine and check that your installation is working. * Install [Docker and Docker Compose](https://docs.docker.com/compose/install/) on the host machine and check that your installation is working.
@ -147,6 +158,8 @@ This procedure allows to install a new Dojo from scratch.
See this [section](#explorer) for more details about the block explorer. See this [section](#explorer) for more details about the block explorer.
* Dojo provides a few additional settings for advanced setups: * Dojo provides a few additional settings for advanced setups:
* installation of an address indexer used for fast imports and rescans,
* support of an external electrum server (ElectrumX or electrs) used for fast imports and rescans,
* static onion address for your full node, * static onion address for your full node,
* bitcoind RPC API exposed to external apps, * bitcoind RPC API exposed to external apps,
* use of an external full node, * use of an external full node,
@ -239,6 +252,7 @@ Available commands:
dojo.sh logs bitcoind : display the logs of bitcoind dojo.sh logs bitcoind : display the logs of bitcoind
dojo.sh logs db : display the logs of the MySQL database dojo.sh logs db : display the logs of the MySQL database
dojo.sh logs tor : display the logs of tor dojo.sh logs tor : display the logs of tor
dojo.sh logs indexer : display the logs of the internal indexer
dojo.sh logs api : display the logs of the REST API (nodejs) dojo.sh logs api : display the logs of the REST API (nodejs)
dojo.sh logs tracker : display the logs of the Tracker (nodejs) dojo.sh logs tracker : display the logs of the Tracker (nodejs)
dojo.sh logs pushtx : display the logs of the pushTx API (nodejs) dojo.sh logs pushtx : display the logs of the pushTx API (nodejs)

10
docker/my-dojo/.env

@ -16,7 +16,8 @@ DOJO_BITCOIND_VERSION_TAG=1.4.1
DOJO_NODEJS_VERSION_TAG=1.4.0 DOJO_NODEJS_VERSION_TAG=1.4.0
DOJO_NGINX_VERSION_TAG=1.4.0 DOJO_NGINX_VERSION_TAG=1.4.0
DOJO_TOR_VERSION_TAG=1.3.0 DOJO_TOR_VERSION_TAG=1.3.0
DOJO_EXPLORER_VERSION_TAG=1.0.0 DOJO_EXPLORER_VERSION_TAG=1.1.0
DOJO_INDEXER_VERSION_TAG=1.0.0
######################################### #########################################
@ -58,3 +59,10 @@ NODE_PREFIX_STATUS_PUSHTX=status
NODE_TRACKER_MEMPOOL_PERIOD=10000 NODE_TRACKER_MEMPOOL_PERIOD=10000
NODE_TRACKER_UNCONF_TXS_PERIOD=300000 NODE_TRACKER_UNCONF_TXS_PERIOD=300000
#########################################
# INDEXER
#########################################
INDEXER_BATCH_SIZE=10

42
docker/my-dojo/conf/docker-indexer.conf.tpl

@ -0,0 +1,42 @@
#########################################
# CONFIGURATION OF A LOCAL INDEXER
#########################################
# Install and run a local indexer inside Docker
# Set this option to 'off' for using an indexer hosted outside of Docker
# or when using a different data source (local bitcoind, OXT)
# Value: on | off
INDEXER_INSTALL=off
# IP address of the local indexer used by Dojo
# Set value to 172.28.1.6 if INDEXER_INSTALL is set to 'on'
# Type: string
INDEXER_IP=172.28.1.6
# Port of the RPC API
# Set value to 50001 if INDEXER_INSTALL is set to 'on'
# Type: integer
INDEXER_RPC_PORT=50001
# Support of batch requests by the local indexer
# Set value to inactive if INDEXER_INSTALL is set to 'on'
# Value: active | inactive
INDEXER_BATCH_SUPPORT=inactive
#
# EXPERT SETTINGS
# (ACTIVE IF INDEXER_INSTALL IS SET TO ON)
#
# Number of blocks to get in one JSONRPC request from bitcoind
# Type: integer
INDEXER_BATCH_SIZE=10
# Total size of block txids to cache (in MB)
# Type: integer
INDEXER_BLK_TXIDS_CACHE_SIZE_MB=10
# Number of transactions to lookup before returning an error
# Type: integer
INDEXER_TXID_LIMIT=501

2
docker/my-dojo/conf/docker-node.conf.tpl

@ -21,7 +21,7 @@ NODE_ADMIN_KEY=myAdminKey
NODE_JWT_SECRET=myJwtSecret NODE_JWT_SECRET=myJwtSecret
# Indexer or third-party service used for imports and rescans of addresses # Indexer or third-party service used for imports and rescans of addresses
# Values: local_bitcoind | third_party_explorer # Values: local_bitcoind | local_indexer | third_party_explorer
NODE_ACTIVE_INDEXER=local_bitcoind NODE_ACTIVE_INDEXER=local_bitcoind
# FEE TYPE USED FOR FEES ESTIMATIONS BY BITCOIND # FEE TYPE USED FOR FEES ESTIMATIONS BY BITCOIND

1
docker/my-dojo/docker-compose.yaml

@ -31,6 +31,7 @@ services:
- ./conf/docker-mysql.conf - ./conf/docker-mysql.conf
- ./conf/docker-bitcoind.conf - ./conf/docker-bitcoind.conf
- ./conf/docker-explorer.conf - ./conf/docker-explorer.conf
- ./conf/docker-indexer.conf
- ./conf/docker-node.conf - ./conf/docker-node.conf
restart: always restart: always
command: "/home/node/app/wait-for-it.sh db:3306 --timeout=720 --strict -- /home/node/app/restart.sh" command: "/home/node/app/wait-for-it.sh db:3306 --timeout=720 --strict -- /home/node/app/restart.sh"

20
docker/my-dojo/dojo.sh

@ -14,6 +14,7 @@ source_file() {
} }
# Source config files # Source config files
source_file "$DIR/conf/docker-indexer.conf"
source_file "$DIR/conf/docker-bitcoind.conf" source_file "$DIR/conf/docker-bitcoind.conf"
source_file "$DIR/conf/docker-explorer.conf" source_file "$DIR/conf/docker-explorer.conf"
source_file "$DIR/conf/docker-common.conf" source_file "$DIR/conf/docker-common.conf"
@ -38,6 +39,10 @@ select_yaml_files() {
yamlFiles="$yamlFiles -f $DIR/overrides/explorer.install.yaml" yamlFiles="$yamlFiles -f $DIR/overrides/explorer.install.yaml"
fi fi
if [ "$INDEXER_INSTALL" == "on" ]; then
yamlFiles="$yamlFiles -f $DIR/overrides/indexer.install.yaml"
fi
# Return yamlFiles # Return yamlFiles
echo "$yamlFiles" echo "$yamlFiles"
} }
@ -154,6 +159,7 @@ uninstall() {
docker image rm samouraiwallet/dojo-nodejs:"$DOJO_NODEJS_VERSION_TAG" docker image rm samouraiwallet/dojo-nodejs:"$DOJO_NODEJS_VERSION_TAG"
docker image rm samouraiwallet/dojo-nginx:"$DOJO_NGINX_VERSION_TAG" docker image rm samouraiwallet/dojo-nginx:"$DOJO_NGINX_VERSION_TAG"
docker image rm samouraiwallet/dojo-tor:"$DOJO_TOR_VERSION_TAG" docker image rm samouraiwallet/dojo-tor:"$DOJO_TOR_VERSION_TAG"
docker image rm samouraiwallet/dojo-indexer:"$DOJO_INDEXER_VERSION_TAG"
docker volume prune docker volume prune
} }
@ -177,6 +183,7 @@ clean() {
del_images_for samouraiwallet/dojo-nodejs "$DOJO_NODEJS_VERSION_TAG" del_images_for samouraiwallet/dojo-nodejs "$DOJO_NODEJS_VERSION_TAG"
del_images_for samouraiwallet/dojo-nginx "$DOJO_NGINX_VERSION_TAG" del_images_for samouraiwallet/dojo-nginx "$DOJO_NGINX_VERSION_TAG"
del_images_for samouraiwallet/dojo-tor "$DOJO_TOR_VERSION_TAG" del_images_for samouraiwallet/dojo-tor "$DOJO_TOR_VERSION_TAG"
del_images_for samouraiwallet/dojo-indexer "$DOJO_INDEXER_VERSION_TAG"
} }
# Upgrade # Upgrade
@ -249,6 +256,7 @@ logs_explorer() {
logs() { logs() {
source_file "$DIR/conf/docker-bitcoind.conf" source_file "$DIR/conf/docker-bitcoind.conf"
source_file "$DIR/conf/docker-indexer.conf"
source_file "$DIR/conf/docker-common.conf" source_file "$DIR/conf/docker-common.conf"
case $1 in case $1 in
@ -267,6 +275,14 @@ logs() {
echo -e "Command not supported for your setup.\nCause: Your Dojo is using an external bitcoind" echo -e "Command not supported for your setup.\nCause: Your Dojo is using an external bitcoind"
fi fi
;; ;;
indexer )
if [ "$INDEXER_INSTALL" == "on" ]; then
yamlFiles=$(select_yaml_files)
eval "docker-compose $yamlFiles logs --tail=50 --follow indexer"
else
echo -e "Command not supported for your setup.\nCause: Your Dojo is not using an internal indexer"
fi
;;
tor ) tor )
docker-compose logs --tail=50 --follow tor docker-compose logs --tail=50 --follow tor
;; ;;
@ -285,6 +301,9 @@ logs() {
if [ "$EXPLORER_INSTALL" == "on" ]; then if [ "$EXPLORER_INSTALL" == "on" ]; then
services="$services explorer" services="$services explorer"
fi fi
if [ "$INDEXER_INSTALL" == "on" ]; then
services="$services indexer"
fi
eval "docker-compose $yamlFiles logs --tail=0 --follow $services" eval "docker-compose $yamlFiles logs --tail=0 --follow $services"
;; ;;
esac esac
@ -312,6 +331,7 @@ help() {
echo " dojo.sh logs bitcoind : display the logs of bitcoind" echo " dojo.sh logs bitcoind : display the logs of bitcoind"
echo " dojo.sh logs db : display the logs of the MySQL database" echo " dojo.sh logs db : display the logs of the MySQL database"
echo " dojo.sh logs tor : display the logs of tor" echo " dojo.sh logs tor : display the logs of tor"
echo " dojo.sh logs indexer : display the logs of the internal indexer"
echo " dojo.sh logs api : display the logs of the REST API (nodejs)" echo " dojo.sh logs api : display the logs of the REST API (nodejs)"
echo " dojo.sh logs tracker : display the logs of the Tracker (nodejs)" echo " dojo.sh logs tracker : display the logs of the Tracker (nodejs)"
echo " dojo.sh logs pushtx : display the logs of the pushTx API (nodejs)" echo " dojo.sh logs pushtx : display the logs of the pushTx API (nodejs)"

5
docker/my-dojo/explorer/Dockerfile

@ -7,6 +7,11 @@ ENV EXPLORER_URL https://github.com/janoside/btc-rpc-explorer/archiv
ENV EXPLORER_VERSION 1.1.5 ENV EXPLORER_VERSION 1.1.5
# Install netcat
RUN set -ex && \
apt-get update && \
apt-get install -y netcat
# Create logs and apps directory # Create logs and apps directory
RUN mkdir -p "$LOGS_DIR" && \ RUN mkdir -p "$LOGS_DIR" && \
chown -R node:node "$LOGS_DIR" && \ chown -R node:node "$LOGS_DIR" && \

23
docker/my-dojo/explorer/restart.sh

@ -18,4 +18,27 @@ explorer_options=(
# Blacklist all functions provided by the RPC API # Blacklist all functions provided by the RPC API
explorer_options+=(--rpc-blacklist "addnode,analyzepsbt,clearbanned,combinepsbt,combinerawtransaction,converttopsbt,createmultisig,createpsbt,createrawtransaction,decodepsbt,decoderawtransaction,decodescript,deriveaddresses,disconnectnode,echo,echojson,estimaterawfee,estimatesmartfee,finalizepsbt,generatetoaddress,generatetodescriptor,getaddednodeinfo,getbestblockhash,getblock,getblockchaininfo,getblockcount,getblockfilter,getblockhash,getblockheader,getblockstats,getblocktemplate,getchaintips,getchaintxstats,getconnectioncount,getdescriptorinfo,getdifficulty,getmemoryinfo,getmempoolancestors,getmempooldescendants,getmempoolentry,getmempoolinfo,getmininginfo,getnettotals,getnetworkhashps,getnetworkinfo,getnodeaddresses,getpeerinfo,getrawmempool,getrawtransaction,getrpcinfo,gettxout,gettxoutproof,gettxoutsetinfo,help,invalidateblock,joinpsbts,listbanned,logging,ping,preciousblock,prioritisetransaction,pruneblockchain,reconsiderblock,savemempool,scantxoutset,sendrawtransaction,setban,setmocktime,setnetworkactive,signmessagewithprivkey,signrawtransactionwithkey,stop,submitblock,submitheader,syncwithvalidationinterfacequeue,testmempoolaccept,uptime,utxoupdatepsbt,validateaddress,verifychain,verifymessage,verifytxoutproof,waitforblock,waitforblockheight,waitfornewblock") explorer_options+=(--rpc-blacklist "addnode,analyzepsbt,clearbanned,combinepsbt,combinerawtransaction,converttopsbt,createmultisig,createpsbt,createrawtransaction,decodepsbt,decoderawtransaction,decodescript,deriveaddresses,disconnectnode,echo,echojson,estimaterawfee,estimatesmartfee,finalizepsbt,generatetoaddress,generatetodescriptor,getaddednodeinfo,getbestblockhash,getblock,getblockchaininfo,getblockcount,getblockfilter,getblockhash,getblockheader,getblockstats,getblocktemplate,getchaintips,getchaintxstats,getconnectioncount,getdescriptorinfo,getdifficulty,getmemoryinfo,getmempoolancestors,getmempooldescendants,getmempoolentry,getmempoolinfo,getmininginfo,getnettotals,getnetworkhashps,getnetworkinfo,getnodeaddresses,getpeerinfo,getrawmempool,getrawtransaction,getrpcinfo,gettxout,gettxoutproof,gettxoutsetinfo,help,invalidateblock,joinpsbts,listbanned,logging,ping,preciousblock,prioritisetransaction,pruneblockchain,reconsiderblock,savemempool,scantxoutset,sendrawtransaction,setban,setmocktime,setnetworkactive,signmessagewithprivkey,signrawtransactionwithkey,stop,submitblock,submitheader,syncwithvalidationinterfacequeue,testmempoolaccept,uptime,utxoupdatepsbt,validateaddress,verifychain,verifymessage,verifytxoutproof,waitforblock,waitforblockheight,waitfornewblock")
# Use the local indexer if one is defined for Dojo
if [ "$NODE_ACTIVE_INDEXER" == "local_indexer" ]; then
explorer_options+=(--address-api electrumx)
explorer_options+=(--electrumx-servers "tcp://$INDEXER_IP:$INDEXER_RPC_PORT")
# Wait for the local indexer
timeout="720"
i="0"
while [ $i -lt $timeout ]
do
nc -z "$INDEXER_IP" "$INDEXER_RPC_PORT" > /dev/null
if [ $? -eq 0 ] ; then
break
fi
sleep 1
i=$[$i+1]
done
if [ $i -eq $timeout ]; then
echo "Operation timed out"
exit 1
fi
fi
node ./bin/cli.js "${explorer_options[@]}" > /data/logs/explorer-error.log 2> /data/logs/explorer-output.log node ./bin/cli.js "${explorer_options[@]}" > /data/logs/explorer-error.log 2> /data/logs/explorer-output.log

43
docker/my-dojo/indexer/Dockerfile

@ -0,0 +1,43 @@
FROM rust:1.37.0-slim
ENV INDEXER_HOME /home/indexer
ENV INDEXER_VERSION 0.1.0
ENV INDEXER_URL https://github.com/Samourai-Wallet/addrindexrs.git
RUN apt-get update && \
apt-get install -y clang cmake git && \
apt-get install -y libsnappy-dev
# Create group and user indexer
RUN addgroup --system -gid 1109 indexer && \
adduser --system --ingroup indexer -uid 1106 indexer
# Create data directory
RUN mkdir "$INDEXER_HOME/addrindexrs" && \
chown -h indexer:indexer "$INDEXER_HOME/addrindexrs"
# Copy restart script
COPY ./restart.sh /restart.sh
RUN chown indexer:indexer /restart.sh && \
chmod 777 /restart.sh
# Copy wait-for-it script
COPY ./wait-for-it.sh /wait-for-it.sh
RUN chown indexer:indexer /wait-for-it.sh && \
chmod u+x /wait-for-it.sh && \
chmod g+x /wait-for-it.sh
USER indexer
# Install addrindexrs
RUN cd "$INDEXER_HOME" && \
git clone "$INDEXER_URL" "$INDEXER_HOME/addrindexrs" && \
cd addrindexrs && \
git checkout "tags/v$INDEXER_VERSION"
RUN cd "$INDEXER_HOME/addrindexrs" && \
cargo install --path .
EXPOSE 50001
STOPSIGNAL SIGINT

22
docker/my-dojo/indexer/restart.sh

@ -0,0 +1,22 @@
#!/bin/bash
set -e
indexer_options=(
-vvvv
--index-batch-size="$INDEXER_BATCH_SIZE"
--jsonrpc-import
--db-dir="/home/indexer/db"
--indexer-rpc-addr="172.28.1.6:50001"
--daemon-rpc-addr="$BITCOIND_IP:$BITCOIND_RPC_PORT"
--cookie="$BITCOIND_RPC_USER:$BITCOIND_RPC_PASSWORD"
--txid-limit="$INDEXER_TXID_LIMIT"
--blocktxids-cache-size-mb="$INDEXER_BLK_TXIDS_CACHE_SIZE_MB"
)
if [ "$COMMON_BTC_NETWORK" == "testnet" ]; then
bitcoind_options+=(--network="testnet")
else
bitcoind_options+=(--network="mainnet")
fi
addrindexrs "${indexer_options[@]}"

178
docker/my-dojo/indexer/wait-for-it.sh

@ -0,0 +1,178 @@
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available
WAITFORIT_cmdname=${0##*/}
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
usage()
{
cat << USAGE >&2
Usage:
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}
wait_for()
{
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
else
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
fi
WAITFORIT_start_ts=$(date +%s)
while :
do
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
WAITFORIT_result=$?
else
(echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
WAITFORIT_result=$?
fi
if [[ $WAITFORIT_result -eq 0 ]]; then
WAITFORIT_end_ts=$(date +%s)
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
break
fi
sleep 1
done
return $WAITFORIT_result
}
wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
else
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
fi
WAITFORIT_PID=$!
trap "kill -INT -$WAITFORIT_PID" INT
wait $WAITFORIT_PID
WAITFORIT_RESULT=$?
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
fi
return $WAITFORIT_RESULT
}
# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
WAITFORIT_hostport=(${1//:/ })
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
shift 1
;;
--child)
WAITFORIT_CHILD=1
shift 1
;;
-q | --quiet)
WAITFORIT_QUIET=1
shift 1
;;
-s | --strict)
WAITFORIT_STRICT=1
shift 1
;;
-h)
WAITFORIT_HOST="$2"
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
WAITFORIT_HOST="${1#*=}"
shift 1
;;
-p)
WAITFORIT_PORT="$2"
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
WAITFORIT_PORT="${1#*=}"
shift 1
;;
-t)
WAITFORIT_TIMEOUT="$2"
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
WAITFORIT_TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
WAITFORIT_CLI=("$@")
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done
if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi
WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
# check to see if timeout is from busybox?
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
WAITFORIT_ISBUSY=1
WAITFORIT_BUSYTIMEFLAG="-t"
else
WAITFORIT_ISBUSY=0
WAITFORIT_BUSYTIMEFLAG=""
fi
if [[ $WAITFORIT_CHILD -gt 0 ]]; then
wait_for
WAITFORIT_RESULT=$?
exit $WAITFORIT_RESULT
else
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
wait_for_wrapper
WAITFORIT_RESULT=$?
else
wait_for
WAITFORIT_RESULT=$?
fi
fi
if [[ $WAITFORIT_CLI != "" ]]; then
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
exit $WAITFORIT_RESULT
fi
exec "${WAITFORIT_CLI[@]}"
else
exit $WAITFORIT_RESULT
fi

5
docker/my-dojo/install/install-scripts.sh

@ -61,7 +61,9 @@ init_config_files() {
cp ./conf/docker-tor.conf.tpl ./conf/docker-tor.conf cp ./conf/docker-tor.conf.tpl ./conf/docker-tor.conf
echo "Initialized docker-tor.conf" echo "Initialized docker-tor.conf"
# Initialize config files for nginx and the maintenance tool cp ./conf/docker-indexer.conf.tpl ./conf/docker-indexer.conf
echo "Initialized docker-indexer.conf"
if [ "$EXPLORER_INSTALL" == "on" ]; then if [ "$EXPLORER_INSTALL" == "on" ]; then
cp ./nginx/explorer.conf ./nginx/dojo-explorer.conf cp ./nginx/explorer.conf ./nginx/dojo-explorer.conf
else else
@ -69,6 +71,7 @@ init_config_files() {
fi fi
echo "Initialized dojo-explorer.conf (nginx)" echo "Initialized dojo-explorer.conf (nginx)"
# Initialize config files for nginx and the maintenance tool
if [ "$COMMON_BTC_NETWORK" == "testnet" ]; then if [ "$COMMON_BTC_NETWORK" == "testnet" ]; then
cp ./nginx/testnet.conf ./nginx/dojo.conf cp ./nginx/testnet.conf ./nginx/dojo.conf
echo "Initialized dojo.conf (nginx)" echo "Initialized dojo.conf (nginx)"

3
docker/my-dojo/install/upgrade-scripts.sh

@ -57,6 +57,9 @@ update_config_files() {
update_config_file ./conf/docker-tor.conf ./conf/docker-tor.conf.tpl update_config_file ./conf/docker-tor.conf ./conf/docker-tor.conf.tpl
echo "Initialized docker-tor.conf" echo "Initialized docker-tor.conf"
update_config_file ./conf/docker-indexer.conf ./conf/docker-indexer.conf.tpl
echo "Initialized docker-indexer.conf"
# Initialize config files for nginx and the maintenance tool # Initialize config files for nginx and the maintenance tool
if [ "$EXPLORER_INSTALL" == "on" ]; then if [ "$EXPLORER_INSTALL" == "on" ]; then
cp ./nginx/explorer.conf ./nginx/dojo-explorer.conf cp ./nginx/explorer.conf ./nginx/dojo-explorer.conf

12
docker/my-dojo/node/keys.index.js

@ -156,8 +156,18 @@ module.exports = {
*/ */
indexer: { indexer: {
// Active indexer // Active indexer
// Values: local_bitcoind | third_party_explorer // Values: local_bitcoind | local_indexer | third_party_explorer
active: process.env.NODE_ACTIVE_INDEXER, active: process.env.NODE_ACTIVE_INDEXER,
// Local indexer
localIndexer: {
// IP address or hostname of the local indexer
host: process.env.INDEXER_IP,
// Port
port: parseInt(process.env.INDEXER_RPC_PORT),
// Support of batch requests by the local indexer
// Values: active | inactive
batchRequests: process.env.INDEXER_BATCH_SUPPORT
},
// Use a SOCKS5 proxy for all communications with external services // Use a SOCKS5 proxy for all communications with external services
// Values: null if no socks5 proxy used, otherwise the url of the socks5 proxy // Values: null if no socks5 proxy used, otherwise the url of the socks5 proxy
socks5Proxy: 'socks5h://172.28.1.4:9050', socks5Proxy: 'socks5h://172.28.1.4:9050',

2
docker/my-dojo/overrides/explorer.install.yaml

@ -9,6 +9,8 @@ services:
env_file: env_file:
- ./.env - ./.env
- ./conf/docker-bitcoind.conf - ./conf/docker-bitcoind.conf
- ./conf/docker-node.conf
- ./conf/docker-indexer.conf
- ./conf/docker-explorer.conf - ./conf/docker-explorer.conf
restart: always restart: always
command: "/home/node/app/restart.sh" command: "/home/node/app/restart.sh"

27
docker/my-dojo/overrides/indexer.install.yaml

@ -0,0 +1,27 @@
version: "3.2"
services:
indexer:
image: "samouraiwallet/dojo-indexer:${DOJO_INDEXER_VERSION_TAG}"
container_name: indexer
build:
context: ./indexer
env_file:
- ./.env
- ./conf/docker-common.conf
- ./conf/docker-bitcoind.conf
- ./conf/docker-indexer.conf
restart: on-failure
command: "/wait-for-it.sh tor:9050 --timeout=360 --strict -- /restart.sh"
expose:
- "50001"
volumes:
- data-indexer:/home/indexer
depends_on:
- tor
networks:
dojonet:
ipv4_address: 172.28.1.6
volumes:
data-indexer:
Loading…
Cancel
Save