From 2320a6b39bb766df4dbe1ec1b7e515cac97a53a1 Mon Sep 17 00:00:00 2001 From: nolash Date: Fri, 23 Apr 2021 22:39:56 +0200 Subject: [PATCH] Add signer liveness check --- apps/cic-eth/cic_eth/check/db.py | 1 + apps/cic-eth/cic_eth/check/signer.py | 26 +++++++++++++++++++ .../cic_eth/runnable/daemons/tasker.py | 5 ++-- apps/cic-eth/config/cic.ini | 3 ++- apps/cic-eth/config/docker/cic.ini | 2 ++ apps/cic-eth/requirements.txt | 4 +-- 6 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 apps/cic-eth/cic_eth/check/signer.py diff --git a/apps/cic-eth/cic_eth/check/db.py b/apps/cic-eth/cic_eth/check/db.py index 485e1b56..3382a33d 100644 --- a/apps/cic-eth/cic_eth/check/db.py +++ b/apps/cic-eth/cic_eth/check/db.py @@ -1,5 +1,6 @@ from cic_eth.db.models.base import SessionBase + def health(*args, **kwargs): session = SessionBase.create_session() session.execute('SELECT count(*) from alembic_version') diff --git a/apps/cic-eth/cic_eth/check/signer.py b/apps/cic-eth/cic_eth/check/signer.py new file mode 100644 index 00000000..49d04345 --- /dev/null +++ b/apps/cic-eth/cic_eth/check/signer.py @@ -0,0 +1,26 @@ +# standard imports +import logging +from urllib.error import URLError + +# external imports +from chainlib.connection import RPCConnection +from chainlib.eth.constant import ZERO_ADDRESS +from chainlib.eth.sign import sign_message +from chainlib.error import JSONRPCException + +logg = logging.getLogger().getChild(__name__) + + +def health(*args, **kwargs): + conn = RPCConnection.connect(kwargs['config'].get('CIC_CHAIN_SPEC'), tag='signer') + try: + conn.do(sign_message(ZERO_ADDRESS, '0x2a')) + except FileNotFoundError: + return False + except ConnectionError: + return False + except URLError: + return False + except JSONRPCException as e: + pass + return True diff --git a/apps/cic-eth/cic_eth/runnable/daemons/tasker.py b/apps/cic-eth/cic_eth/runnable/daemons/tasker.py index d17a1038..38689243 100644 --- a/apps/cic-eth/cic_eth/runnable/daemons/tasker.py +++ b/apps/cic-eth/cic_eth/runnable/daemons/tasker.py @@ -140,14 +140,15 @@ else: chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC')) RPCConnection.register_location(config.get('ETH_PROVIDER'), chain_spec, 'default') -RPCConnection.register_location(config.get('SIGNER_SOCKET_PATH'), chain_spec, 'signer', constructor=EthUnixSignerConnection) +#RPCConnection.register_location(config.get('SIGNER_SOCKET_PATH'), chain_spec, 'signer', constructor=EthUnixSignerConnection) +RPCConnection.register_location(config.get('SIGNER_SOCKET_PATH'), chain_spec, 'signer') Otx.tracing = config.true('TASKS_TRACE_QUEUE_STATUS') #import cic_eth.checks.gas #if not cic_eth.checks.gas.health(config=config): # raise RuntimeError() -liveness.linux.load(health_modules, config=config) +liveness.linux.load(health_modules, rundir=config.get('CIC_RUN_DIR'), config=config) def main(): argv = ['worker'] diff --git a/apps/cic-eth/config/cic.ini b/apps/cic-eth/config/cic.ini index d97826d4..20f1fe8e 100644 --- a/apps/cic-eth/config/cic.ini +++ b/apps/cic-eth/config/cic.ini @@ -3,4 +3,5 @@ registry_address = chain_spec = evm:bloxberg:8996 tx_retry_delay = trust_address = -health_modules = cic_eth.check.db,cic_eth.check.gas +health_modules = cic_eth.check.db,cic_eth.check.signer,cic_eth.check.gas +run_dir = /run diff --git a/apps/cic-eth/config/docker/cic.ini b/apps/cic-eth/config/docker/cic.ini index 50032aa9..45bd47ea 100644 --- a/apps/cic-eth/config/docker/cic.ini +++ b/apps/cic-eth/config/docker/cic.ini @@ -3,3 +3,5 @@ registry_address = chain_spec = evm:bloxberg:8996 trust_address = 0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C tx_retry_delay = 20 +health_modules = cic_eth.check.db,cic_eth.check.signer,cic_eth.check.gas +run_dir = /run diff --git a/apps/cic-eth/requirements.txt b/apps/cic-eth/requirements.txt index 953eea77..44d8b272 100644 --- a/apps/cic-eth/requirements.txt +++ b/apps/cic-eth/requirements.txt @@ -1,6 +1,6 @@ -cic-base==0.1.2a79+build.d412618d +cic-base==0.1.2b1 celery==4.4.7 -crypto-dev-signer~=0.4.14b2 +crypto-dev-signer~=0.4.14b3 confini~=0.3.6rc3 cic-eth-registry~=0.5.4a16 #cic-bancor~=0.0.6