diff --git a/lnprototest/backend/bitcoind.py b/lnprototest/backend/bitcoind.py index 82359d2..e07172e 100644 --- a/lnprototest/backend/bitcoind.py +++ b/lnprototest/backend/bitcoind.py @@ -71,9 +71,8 @@ def __init__(self, basedir: str): "-logtimestamps", "-nolisten", ] - self.port = reserve() self.btc_version = None - logging.debug("Port is {}, dir is {}".format(self.port, self.bitcoin_dir)) + logging.debug("dir is {}".format(self.bitcoin_dir)) def __init_bitcoin_conf(self): """Init the bitcoin core directory with all the necessary information @@ -124,6 +123,10 @@ def __is__bitcoind_ready(self) -> bool: return True def start(self) -> None: + # Now we're about to start, we can allocate the port. + # We used to do this at init, but in parallel cases another + # bitcoin could use the port when we restart! + self.port = reserve() if self.rpc is None: self.__init_bitcoin_conf() # TODO: We can move this to a single call and not use Popen @@ -148,7 +151,7 @@ def stop(self) -> None: shutil.rmtree(os.path.join(self.bitcoin_dir, "regtest")) def restart(self) -> None: - # Only restart if we have to. + # Only restart if we have to: may change port! if self.rpc.getblockcount() != 101 or self.rpc.getrawmempool() != []: self.stop() self.start() diff --git a/lnprototest/clightning/clightning.py b/lnprototest/clightning/clightning.py index a1de1e5..82f91dd 100644 --- a/lnprototest/clightning/clightning.py +++ b/lnprototest/clightning/clightning.py @@ -118,11 +118,7 @@ def start(self) -> None: self.__init_sandbox_dir() if self.bitcoind is None: self.bitcoind = Bitcoind(self.directory) - try: - self.bitcoind.start() - except Exception as ex: - self.logger.debug(f"Exception with message {ex}") - self.logger.debug("RUN Bitcoind") + self.bitcoind.start() self.proc = subprocess.Popen( [ "{}/lightningd/lightningd".format(LIGHTNING_SRC),