From 67b61fc3f402864a372eddaef798bd55700732fd Mon Sep 17 00:00:00 2001 From: "John L. Jegutanis" Date: Sun, 21 Jun 2020 23:28:17 +0300 Subject: [PATCH 1/3] Some improvements 1) Use a prefix for the temp folders. 2) When starting the node, wait for the RPC to be ready. Results if faster start of the script. 3) When terminating the node, wait of the process to finish (kills it after a timeout). Results in faster termination of the script. --- testchain/runner.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/testchain/runner.py b/testchain/runner.py index 2c22a41..35341c7 100644 --- a/testchain/runner.py +++ b/testchain/runner.py @@ -52,7 +52,7 @@ def _setup_chain_params(self): bitcointx.SelectAlternativeParams(CoreLitecoinParams, RegtestLitecoinParams) def _setup_bitcoind(self): - self.tempdir = tempfile.TemporaryDirectory() + self.tempdir = tempfile.TemporaryDirectory(prefix="testchain-generator-") self.log.info("datadir: {}".format(self.tempdir.name)) if self.chain == "btc" or self.chain == "bch": @@ -80,16 +80,31 @@ def _setup_bitcoind(self): # kill process when generator is done atexit.register(self._terminate) - self.log.info("Waiting 10 seconds for node to start") - sleep(10) + # Call a common RPC i.e. `getblockcount` to check if node is started + self.log.info("Waiting up to 10 seconds for node to start") + for _ in range(10): + tmp_proxy = bitcointx.rpc.Proxy(btc_conf_file=self.conf_file) + try: + tmp_proxy.getblockcount() + break + except (ConnectionRefusedError, bitcointx.rpc.InWarmupError): + sleep(1) + # ... and try again + finally: + tmp_proxy.close() def _terminate(self): """ Kills the bitcoind process """ + self.proxy.close() # Close connection so the node don't have to wait self.proc.terminate() - self.log.info("Waiting 5 seconds for node to quit") - sleep(5) + self.log.info("Waiting up to 10 seconds for node to quit...") + try: + self.proc.wait(10) + except subprocess.TimeoutExpired: + self.log.info("Could not terminate node, killing...") + self.proc.kill() def next_timestamp(self): self.current_time += 600 From 793340a0b39ddb310ed97c3900daa947ada135bb Mon Sep 17 00:00:00 2001 From: "John L. Jegutanis" Date: Mon, 22 Jun 2020 00:14:27 +0300 Subject: [PATCH 2/3] Fix crash in latest bitcoind When running the latest bitcoin 0.20.0, the script crashes when "Creating output with 0 BTC" because the node rejects the "dust" transaction. Here we remove the relay fee and fix the issue. --- bitcoin.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/bitcoin.conf b/bitcoin.conf index 424382a..fe80498 100644 --- a/bitcoin.conf +++ b/bitcoin.conf @@ -2,3 +2,4 @@ server=1 regtest=1 rpcuser=rpcuser rpcpassword=rpcpassword +dustrelayfee=0 \ No newline at end of file From 93c42f0b71b822d7729d27abae22477a00b16eff Mon Sep 17 00:00:00 2001 From: "John L. Jegutanis" Date: Mon, 22 Jun 2020 00:15:10 +0300 Subject: [PATCH 3/3] Fix travis tests --- .travis.yml | 15 ++++++++++++--- runall.sh | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9dc27f9..d02c20a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,15 +9,23 @@ cache: before_install: - git clone https://github.com/bitcoin-core/secp256k1.git - - sudo apt-add-repository ppa:bitcoin/bitcoin -y - sudo apt-get update - mkdir bin + - wget https://bitcoincore.org/bin/bitcoin-core-0.20.0/bitcoin-0.20.0-x86_64-linux-gnu.tar.gz + - echo "35ec10f87b6bc1e44fd9cd1157e5dfa483eaf14d7d9a9c274774539e7824c427 bitcoin-0.20.0-x86_64-linux-gnu.tar.gz" | sha256sum --check + - tar -xzvf bitcoin-0.20.0-x86_64-linux-gnu.tar.gz + - mv ./bitcoin-0.20.0/bin/bitcoind ./bin/bitcoind - wget https://download.bitcoinabc.org/0.18.5/linux/bitcoin-abc-0.18.5-x86_64-linux-gnu.tar.gz + - echo "11439fcdae421ae96d2a7ddc3d43c9c284af44716cb5f363c61e53885a5a8811 bitcoin-abc-0.18.5-x86_64-linux-gnu.tar.gz" | sha256sum --check - tar -xzvf bitcoin-abc-0.18.5-x86_64-linux-gnu.tar.gz - mv ./bitcoin-abc-0.18.5/bin/bitcoind ./bin/bitcoin-cash + - wget https://download.litecoin.org/litecoin-0.18.1/linux/litecoin-0.18.1-x86_64-linux-gnu.tar.gz + - echo "ca50936299e2c5a66b954c266dcaaeef9e91b2f5307069b9894048acf3eb5751 litecoin-0.18.1-x86_64-linux-gnu.tar.gz" | sha256sum --check + - tar -xzvf litecoin-0.18.1-x86_64-linux-gnu.tar.gz + - mv ./litecoin-0.18.1/bin/litecoind ./bin/litecoind install: - - sudo apt-get install build-essential automake pkg-config libtool libgmp-dev bitcoind -y + - sudo apt-get install build-essential automake pkg-config libtool libgmp-dev -y - pip install -r requirements.txt - cd secp256k1 - ./autogen.sh @@ -29,7 +37,8 @@ install: - export LD_LIBRARY_PATH script: - - python generate_chain.py --output-dir=.output --chain=btc + - python generate_chain.py --output-dir=.output --chain=btc --exec=./bin/bitcoind - python generate_chain.py --output-dir=.output --chain=bch --exec=./bin/bitcoin-cash + - python generate_chain.py --output-dir=.output --chain=ltc --exec=./bin/litecoind - cd tests && pytest diff --git a/runall.sh b/runall.sh index 3de2b98..4a38d57 100755 --- a/runall.sh +++ b/runall.sh @@ -1,4 +1,4 @@ #!/bin/sh -python3 generate_chain.py --output-dir=output +python3 generate_chain.py --output-dir=output --chain=btc --exec=./bin/bitcoind python3 generate_chain.py --output-dir=output --chain=bch --exec=./bin/bitcoin-cash python3 generate_chain.py --output-dir=output --chain=ltc --exec=./bin/litecoind