From a43576a10e2f3adba35ccf01fb2b99b31d4de2eb Mon Sep 17 00:00:00 2001 From: Jonathan Zernik Date: Mon, 23 Nov 2020 14:43:17 -0500 Subject: [PATCH] Use bitcoincore for bitcoin node (#481) * Got docker-compose working with bitcoin-core * Got itest working * Add bitcoin use_ssl config * Rename service to bitcoin-core in docker-compose --- docker/config.ini | 2 +- docker/docker-compose.yml | 45 +++++++++++++------ docker/lnd/start-lnd.sh | 34 ++++++++++++++ itests/config.ini | 1 + .../bitcoin/bitcoin_blockchain_client.py | 4 +- squeaknode/config/config.py | 8 +++- squeaknode/main.py | 1 + 7 files changed, 77 insertions(+), 18 deletions(-) diff --git a/docker/config.ini b/docker/config.ini index 0795bf8e..32dd45e9 100644 --- a/docker/config.ini +++ b/docker/config.ini @@ -6,7 +6,7 @@ sync_interval_s=10 host=lnd [bitcoin] -rpc_host=btcd +rpc_host=bitcoin-core rpc_user=devuser rpc_pass=devpass diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index caee3168..72c98edf 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,18 +1,34 @@ version: '3' services: - btcd: - image: btcd - container_name: btcd - build: - context: ../ - dockerfile: docker/btcd/Dockerfile + # btcd: + # image: btcd + # container_name: btcd + # build: + # context: ../ + # dockerfile: docker/btcd/Dockerfile + # volumes: + # - shared:/rpc + # - ~/.btcd/data:/data + # environment: + # - NETWORK + # entrypoint: ["./start-btcd.sh"] + + bitcoin-core: + image: ruimarinho/bitcoin-core + container_name: bitcoin-core volumes: - - shared:/rpc - - ~/.btcd/data:/data - environment: - - NETWORK - entrypoint: ["./start-btcd.sh"] + - ~/.bitcoin:/home/bitcoin/.bitcoin + command: + -printtoconsole + -testnet=1 + -server=1 + -rpcbind=0.0.0.0 + -rpcallowip=0.0.0.0/0 + -rpcuser=devuser + -rpcpassword=devpass + -zmqpubrawblock=tcp://0.0.0.0:28332 + -zmqpubrawtx=tcp://0.0.0.0:28333 lnd: image: lnd @@ -22,14 +38,15 @@ services: dockerfile: docker/lnd/Dockerfile environment: - NETWORK - - RPCHOST=btcd + - RPCHOST=bitcoin-core + - BACKEND=bitcoind volumes: - shared:/rpc - ~/.lnd:/root/.lnd ports: - 9735:9735 links: - - "btcd:btcd" + - "bitcoin-core:bitcoin-core" sysctls: - net.ipv6.conf.all.disable_ipv6=0 entrypoint: ["./start-lnd.sh"] @@ -56,7 +73,7 @@ services: - 8774:8774 - 12994:12994 links: - - "btcd:btcd" + - "bitcoin-core:bitcoin-core" - "lnd:lnd" sysctls: - net.ipv6.conf.all.disable_ipv6=0 diff --git a/docker/lnd/start-lnd.sh b/docker/lnd/start-lnd.sh index 9da32a10..34abf1a5 100644 --- a/docker/lnd/start-lnd.sh +++ b/docker/lnd/start-lnd.sh @@ -58,6 +58,40 @@ if [[ "$BACKEND" == "neutrino" ]]; then --debuglevel="$DEBUG" \ --tlsextradomain=lnd \ "$@" +elif [[ "$BACKEND" == "bitcoind" ]]; then + + sleep 60 + echo lnd \ + --noseedbackup \ + --logdir="/data" \ + "--$CHAIN.active" \ + "--$CHAIN.$NETWORK" \ + "--$CHAIN.node"="$BACKEND" \ + "--$BACKEND.rpchost"="$RPCHOST" \ + "--$BACKEND.rpcuser"="$RPCUSER" \ + "--$BACKEND.rpcpass"="$RPCPASS" \ + "--$BACKEND.zmqpubrawblock"="tcp://${RPCHOST}:28332" \ + "--$BACKEND.zmqpubrawtx"="tcp://${RPCHOST}:28333" \ + --rpclisten=0.0.0.0:10009 \ + --debuglevel="$DEBUG" \ + --tlsextradomain=lnd \ + "$@" + + exec lnd \ + --noseedbackup \ + --logdir="/data" \ + "--$CHAIN.active" \ + "--$CHAIN.$NETWORK" \ + "--$CHAIN.node"="$BACKEND" \ + "--$BACKEND.rpchost"="$RPCHOST" \ + "--$BACKEND.rpcuser"="$RPCUSER" \ + "--$BACKEND.rpcpass"="$RPCPASS" \ + "--$BACKEND.zmqpubrawblock"="tcp://${RPCHOST}:28332" \ + "--$BACKEND.zmqpubrawtx"="tcp://${RPCHOST}:28333" \ + --rpclisten=0.0.0.0:10009 \ + --debuglevel="$DEBUG" \ + --tlsextradomain=lnd \ + "$@" else exec lnd \ --noseedbackup \ diff --git a/itests/config.ini b/itests/config.ini index 60fef100..55c52501 100644 --- a/itests/config.ini +++ b/itests/config.ini @@ -11,6 +11,7 @@ external_host=lnd_server rpc_host=btcd rpc_user=devuser rpc_pass=devpass +rpc_use_ssl=true [postgresql] host=db diff --git a/squeaknode/bitcoin/bitcoin_blockchain_client.py b/squeaknode/bitcoin/bitcoin_blockchain_client.py index 2a12e8be..b86b443e 100644 --- a/squeaknode/bitcoin/bitcoin_blockchain_client.py +++ b/squeaknode/bitcoin/bitcoin_blockchain_client.py @@ -19,8 +19,10 @@ class BitcoinBlockchainClient(BlockchainClient): port: int, rpc_user: str, rpc_password: str, + use_ssl: bool, ) -> None: - self.url = f"https://{rpc_user}:{rpc_password}@{host}:{port}" + protocol = "https" if use_ssl else "http" + self.url = f"{protocol}://{rpc_user}:{rpc_password}@{host}:{port}" self.headers = {"content-type": "application/json"} def get_best_block_info(self) -> BlockInfo: diff --git a/squeaknode/config/config.py b/squeaknode/config/config.py index bcf42fc3..d6c39ec5 100644 --- a/squeaknode/config/config.py +++ b/squeaknode/config/config.py @@ -17,8 +17,8 @@ WEBADMIN_HOST = "0.0.0.0" WEBADMIN_PORT = 12994 DEFAULT_BITCOIN_RPC_PORT = 8334 BITCOIN_RPC_PORT = { - 'mainnet': 8334, - 'testnet': 18334, + 'mainnet': 8332, + 'testnet': 18332, 'simnet': 18556, } DEFAULT_LND_PORT = 9735 @@ -44,6 +44,7 @@ class Config: self._configs['bitcoin_rpc_port'] = self._get_bitcoin_rpc_port() self._configs['bitcoin_rpc_user'] = self._get_bitcoin_rpc_user() self._configs['bitcoin_rpc_pass'] = self._get_bitcoin_rpc_pass() + self._configs['bitcoin_rpc_use_ssl'] = self._get_bitcoin_rpc_use_ssl() #lnd self._configs['lnd_host'] = self._get_lnd_host() @@ -107,6 +108,9 @@ class Config: def _get_bitcoin_rpc_pass(self): return self.parser.get("bitcoin", "rpc_pass") + def _get_bitcoin_rpc_use_ssl(self): + return self.parser.getboolean("bitcoin", "rpc_use_ssl", fallback=False) + def _get_lnd_host(self): return self.parser.get("lnd", "host") diff --git a/squeaknode/main.py b/squeaknode/main.py index d8cdb7a6..1890631e 100644 --- a/squeaknode/main.py +++ b/squeaknode/main.py @@ -119,6 +119,7 @@ def load_blockchain_client(config): config.bitcoin_rpc_port, config.bitcoin_rpc_user, config.bitcoin_rpc_pass, + config.bitcoin_rpc_use_ssl, )