From d94e51444514b2cecc9067b7492ea7e7441b9309 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 9 May 2021 11:56:48 +0000 Subject: [PATCH] CoinDaemon: support multiple instances --- mmgen/daemon.py | 14 +++++++++----- test/start-coin-daemons.py | 6 +++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/mmgen/daemon.py b/mmgen/daemon.py index 18e66776..1cee732e 100755 --- a/mmgen/daemon.py +++ b/mmgen/daemon.py @@ -423,7 +423,9 @@ class CoinDaemon(Daemon): test_suite = False, flags = None, proto = None, - opts = None ): + opts = None, + port_shift = None, + datadir = None ): assert network_id or proto, 'CoinDaemon_chk1' assert not (network_id and proto), 'CoinDaemon_chk2' @@ -450,7 +452,9 @@ class CoinDaemon(Daemon): test_suite = False, flags = None, proto = None, - opts = None ): + opts = None, + port_shift = None, + datadir = None ): super().__init__() @@ -495,8 +499,8 @@ class CoinDaemon(Daemon): if test_suite: dfl_datadir = os.path.join(os.getcwd(),rel_datadir) - # user-set value takes precedence - datadir = g.daemon_data_dir or dfl_datadir + # user-set values take precedence + datadir = datadir or g.daemon_data_dir or dfl_datadir self.datadir = os.path.abspath(datadir) @@ -505,7 +509,7 @@ class CoinDaemon(Daemon): if self.datadir_is_subdir: self.datadir = os.path.join(self.datadir,self.testnet_dir) - self.port_shift = 1237 if test_suite else 0 + self.port_shift = (1237 if test_suite else 0) + (port_shift or 0) self.rpc_port = { 'mainnet': self.dfl_rpc, 'testnet': self.dfl_rpc_tn, diff --git a/test/start-coin-daemons.py b/test/start-coin-daemons.py index 51a90895..bbbd4fd2 100755 --- a/test/start-coin-daemons.py +++ b/test/start-coin-daemons.py @@ -16,7 +16,9 @@ opts_data = { -h, --help Print this help message --, --longhelp Print help message for long options (common options) -D, --debug Produce debugging output (implies --verbose) +-d, --datadir= Override the default datadir -n, --no-daemonize Don't fork daemon to background +-p, --port-shift= Shift the RPC port by this number -s, --get-state Get the state of the daemon(s) and exit -t, --testing Testing mode. Print commands but don't execute them -v, --verbose Produce more verbose output @@ -58,7 +60,9 @@ for network_id in ids: d = CoinDaemon( network_id, test_suite = True, - opts = ['no_daemonize'] if opt.no_daemonize else None ) + opts = ['no_daemonize'] if opt.no_daemonize else None, + port_shift = int(opt.port_shift or 0), + datadir = opt.datadir ) d.debug = opt.debug d.wait = not opt.no_wait if opt.get_state: