From dc48b2269c176e04fa431b89d7f70c8862a05f58 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 25 Feb 2021 16:15:24 +0300 Subject: [PATCH] Daemon version checking: allow override in cfg file and environment - add coin-specific 'ignore_daemon_version' vars to cfg file - recognize 'MMGEN_IGNORE_DAEMON_VERSION' environment variable - display warning when unsupported daemon version is being ignored --- data_files/mmgen.cfg | 15 +++++++++++++++ mmgen/daemon.py | 26 +++++++++++++------------- mmgen/globalvars.py | 6 +++++- mmgen/protocol.py | 1 + mmgen/rpc.py | 41 ++++++++++++++++++++++++----------------- 5 files changed, 58 insertions(+), 31 deletions(-) diff --git a/data_files/mmgen.cfg b/data_files/mmgen.cfg index 89365b43..4ee3015f 100644 --- a/data_files/mmgen.cfg +++ b/data_files/mmgen.cfg @@ -77,6 +77,21 @@ # also turns off all information output for the configured wordlists: # mnemonic_entry_modes mmgen:minimal bip39:fixed xmrseed:short +############################ +## Ignore daemon versions ## +############################ + +# Ignore Bitcoin Core version: +# btc_ignore_daemon_version + +# Ignore Litecoin Core version: +# ltc_ignore_daemon_version + +# Ignore Bitcoin Cash Node version: +# bch_ignore_daemon_version + +# Ignore OpenEthereum version: +# eth_ignore_daemon_version ##################### ## Altcoin options ## diff --git a/mmgen/daemon.py b/mmgen/daemon.py index 37445b81..f520a718 100755 --- a/mmgen/daemon.py +++ b/mmgen/daemon.py @@ -300,8 +300,8 @@ class CoinDaemon(Daemon): 'coin', 'cls_pfx', 'coind_name', - 'coind_exec', 'coind_version', 'coind_version_str', # latest tested version + 'coind_exec', 'cli_exec', 'cfg_file', 'testnet_dir', @@ -313,8 +313,8 @@ class CoinDaemon(Daemon): 'btc': cd( 'Bitcoin', 'Bitcoin', - 'Bitcoin Core', - 'bitcoind', 200100, '0.20.1', + 'Bitcoin Core', 200100, '0.20.1', + 'bitcoind', 'bitcoin-cli', 'bitcoin.conf', 'testnet3', @@ -322,8 +322,8 @@ class CoinDaemon(Daemon): 'bch': cd( 'BitcoinCashNode', 'Bitcoin', - 'Bitcoin Cash Node', - 'bitcoind-bchn', 22020000, '22.2.0', + 'Bitcoin Cash Node', 22020000, '22.2.0', + 'bitcoind-bchn', 'bitcoin-cli-bchn', 'bitcoin.conf', 'testnet3', @@ -331,8 +331,8 @@ class CoinDaemon(Daemon): 'ltc': cd( 'Litecoin', 'Bitcoin', - 'Litecoin Core', - 'litecoind', 180100, '0.18.1', + 'Litecoin Core', 180100, '0.18.1', + 'litecoind', 'litecoin-cli', 'litecoin.conf', 'testnet4', @@ -340,8 +340,8 @@ class CoinDaemon(Daemon): 'xmr': cd( 'Monero', 'Monero', - 'Monero', - 'monerod', 'N/A', 'N/A', + 'Monero', 'N/A', 'N/A', + 'monerod', 'monerod', 'bitmonero.conf', None, @@ -349,8 +349,8 @@ class CoinDaemon(Daemon): 'eth': cd( 'Ethereum', 'Ethereum', - 'OpenEthereum', - 'openethereum', 3000001, '3.0.1', + 'OpenEthereum', 3000001, '3.0.1', + 'openethereum', 'openethereum', 'parity.conf', None, @@ -358,8 +358,8 @@ class CoinDaemon(Daemon): 'etc': cd( 'Ethereum Classic', 'Ethereum', - 'OpenEthereum', - 'openethereum', 3000001, '3.0.1', + 'OpenEthereum', 3000001, '3.0.1', + 'openethereum', 'openethereum', 'parity.conf', None, diff --git a/mmgen/globalvars.py b/mmgen/globalvars.py index fb47848f..af0ead1b 100755 --- a/mmgen/globalvars.py +++ b/mmgen/globalvars.py @@ -98,6 +98,7 @@ class GlobalContext(Lockable): rpc_port = 0 rpc_user = '' rpc_password = '' + ignore_daemon_version = False monero_wallet_rpc_host = 'localhost' monero_wallet_rpc_user = 'monero' monero_wallet_rpc_password = '' @@ -165,7 +166,7 @@ class GlobalContext(Lockable): 'rpc_host','rpc_port','rpc_user','rpc_password','rpc_backend','aiohttp_rpc_queue_len', 'monero_wallet_rpc_host','monero_wallet_rpc_user','monero_wallet_rpc_password', 'daemon_data_dir','force_256_color','regtest','coin','bob','alice', - 'accept_defaults','token' + 'accept_defaults','token','ignore_daemon_version' ) # opts initialized to None by opts.init() if not set by user required_opts = ( @@ -188,6 +189,8 @@ class GlobalContext(Lockable): 'monero_wallet_rpc_host','monero_wallet_rpc_user','monero_wallet_rpc_password', 'daemon_data_dir','force_256_color','regtest','subseeds','mnemonic_entry_modes', 'btc_max_tx_fee','ltc_max_tx_fee','bch_max_tx_fee','eth_max_tx_fee', + 'btc_ignore_daemon_version','bch_ignore_daemon_version', + 'ltc_ignore_daemon_version','eth_ignore_daemon_version', 'eth_mainnet_chain_name','eth_testnet_chain_name', 'max_tx_file_size','max_input_size' ) @@ -219,6 +222,7 @@ class GlobalContext(Lockable): 'MMGEN_REGTEST', 'MMGEN_TRACEBACK', 'MMGEN_RPC_BACKEND', + 'MMGEN_IGNORE_DAEMON_VERSION', 'MMGEN_USE_STANDALONE_SCRYPT_MODULE', 'MMGEN_DISABLE_COLOR', diff --git a/mmgen/protocol.py b/mmgen/protocol.py index 80f35f28..dcd35631 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -87,6 +87,7 @@ class CoinProtocol(MMGenObject): base_proto = None is_fork_of = None networks = ('mainnet','testnet','regtest') + ignore_daemon_version = False def __init__(self,coin,name,network,tokensym=None): self.coin = coin.upper() diff --git a/mmgen/rpc.py b/mmgen/rpc.py index e0ea4e28..3a8db5b2 100755 --- a/mmgen/rpc.py +++ b/mmgen/rpc.py @@ -596,6 +596,28 @@ class MoneroWalletRPCClient(RPCClient): 'refresh', # start_height ) +def handle_unsupported_daemon_version(rpc,proto,ignore_daemon_version,warning_shown=[]): + if ignore_daemon_version or proto.ignore_daemon_version or g.ignore_daemon_version: + if not type(proto) in warning_shown: + ymsg(f'WARNING: ignoring unsupported {rpc.daemon.coind_name} daemon version at user request') + warning_shown.append(type(proto)) + else: + rdie(1,fmt( + """ + The running {} daemon has version {}. + This version of MMGen is tested only on {} v{} and below. + + To avoid this error, downgrade your daemon to a supported version. + + Alternatively, you may invoke the command with the --ignore-daemon-version + option, in which case you proceed at your own risk. + """.format( + rpc.daemon.coind_name, + rpc.daemon_version_str, + rpc.daemon.coind_name, + rpc.daemon.coind_version_str, + ),indent=' ').rstrip()) + async def rpc_init(proto,backend=None,ignore_daemon_version=False): if not 'rpc' in proto.mmcaps: @@ -610,23 +632,8 @@ async def rpc_init(proto,backend=None,ignore_daemon_version=False): daemon = CoinDaemon(proto=proto,test_suite=g.test_suite), backend = backend or opt.rpc_backend ) - if not (ignore_daemon_version or opt.ignore_daemon_version): - if rpc.daemon_version > rpc.daemon.coind_version: - rdie(1,fmt( - """ - The running {} daemon has version {}. - This version of MMGen is tested only on {} v{} and below. - - To avoid this error, downgrade your daemon to a supported version. - - Alternatively, you may invoke the command with the --ignore-daemon-version - option, in which case you proceed at your own risk. - """.format( - rpc.daemon.coind_name, - rpc.daemon_version_str, - rpc.daemon.coind_name, - rpc.daemon.coind_version_str, - ),indent=' ').rstrip()) + if rpc.daemon_version > rpc.daemon.coind_version: + handle_unsupported_daemon_version(rpc,proto,ignore_daemon_version) if proto.chain_name != rpc.chain: raise RPCChainMismatch(