From 8a200979348c6356e47e06ead91392ff19d53832 Mon Sep 17 00:00:00 2001 From: nolash Date: Wed, 21 Apr 2021 14:43:30 +0200 Subject: [PATCH] Add gas gifter balance check --- apps/cic-eth/cic_eth/checks/gas.py | 40 +++++++++++++++++++ .../cic_eth/runnable/daemons/tasker.py | 3 ++ apps/cic-eth/cic_eth/task.py | 5 +++ apps/cic-eth/config/docker/eth.ini | 7 +--- apps/cic-eth/config/docker/signer.ini | 2 +- 5 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 apps/cic-eth/cic_eth/checks/gas.py diff --git a/apps/cic-eth/cic_eth/checks/gas.py b/apps/cic-eth/cic_eth/checks/gas.py new file mode 100644 index 00000000..fae873d5 --- /dev/null +++ b/apps/cic-eth/cic_eth/checks/gas.py @@ -0,0 +1,40 @@ +# standard imports +import logging + +# external imports +from chainlib.connection import RPCConnection +from chainlib.chain import ChainSpec +from chainlib.eth.gas import balance + +# local imports +from cic_eth.db.models.role import AccountRole +from cic_eth.db.models.base import SessionBase + +logg = logging.getLogger().getChild(__name__) + + +def health(*args, **kwargs): + + session = SessionBase.create_session() + + logg.info('kwargs {} {}'.format(kwargs, args)) + config = kwargs['config'] + chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC')) + + gas_provider = AccountRole.get_address('GAS_GIFTER', session=session) + session.close() + + rpc = RPCConnection.connect(chain_spec, 'default') + o = balance(gas_provider) + r = rpc.do(o) + try: + r = int(r, 16) + except TypeError: + r = int(r) + gas_min = int(config.get('ETH_GAS_GIFTER_MINIMUM_BALANCE')) + if r < gas_min: + logg.error('EEK! gas gifter has balance {}, below minimum {}'.format(r, gas_min)) + return False + + + 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 bfaf8ee1..d399b80e 100644 --- a/apps/cic-eth/cic_eth/runnable/daemons/tasker.py +++ b/apps/cic-eth/cic_eth/runnable/daemons/tasker.py @@ -139,6 +139,9 @@ RPCConnection.register_location(config.get('SIGNER_SOCKET_PATH'), chain_spec, 's Otx.tracing = config.true('TASKS_TRACE_QUEUE_STATUS') +import cic_eth.checks.gas +if not cic_eth.checks.gas.health(config=config): + raise RuntimeError() def main(): argv = ['worker'] diff --git a/apps/cic-eth/cic_eth/task.py b/apps/cic-eth/cic_eth/task.py index e95f482f..33bcae18 100644 --- a/apps/cic-eth/cic_eth/task.py +++ b/apps/cic-eth/cic_eth/task.py @@ -94,3 +94,8 @@ class CriticalWeb3AndSignerTask(CriticalTask): def hello(self): time.sleep(0.1) return id(SessionBase.create_session) + + +@celery_app.task() +def shutdown(self): + celery.app.control.shutdown() diff --git a/apps/cic-eth/config/docker/eth.ini b/apps/cic-eth/config/docker/eth.ini index d162a5e5..a7905917 100644 --- a/apps/cic-eth/config/docker/eth.ini +++ b/apps/cic-eth/config/docker/eth.ini @@ -1,8 +1,3 @@ [eth] -#ws_provider = ws://localhost:8546 -#ttp_provider = http://localhost:8545 provider = http://localhost:63545 -gas_provider_address = -#chain_id = -abi_dir = /home/lash/src/ext/cic/grassrootseconomics/cic-contracts/abis -account_accounts_index_writer = +gas_gifter_minimum_balance = 1000000000000000 diff --git a/apps/cic-eth/config/docker/signer.ini b/apps/cic-eth/config/docker/signer.ini index 69df88d8..fe72206f 100644 --- a/apps/cic-eth/config/docker/signer.ini +++ b/apps/cic-eth/config/docker/signer.ini @@ -1,5 +1,5 @@ [signer] -socket_path = /tmp/crypto-dev-signer/jsonrpc.ipc +socket_path = ipc:///tmp/crypto-dev-signer/jsonrpc.ipc secret = deedbeef database_name = signer_test dev_keys_path =