From ae30f54f2f507f4f4795020cd056475ca01eb0ff Mon Sep 17 00:00:00 2001 From: nolash Date: Sat, 24 Apr 2021 09:35:59 +0200 Subject: [PATCH] Add signer error raise to erc and account have check --- apps/cic-eth/cic_eth/eth/account.py | 20 +++++++++++--------- apps/cic-eth/cic_eth/eth/erc20.py | 7 ++++++- apps/cic-eth/cic_eth/eth/gas.py | 14 ++++++++++++-- docker-compose.yml | 2 ++ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/apps/cic-eth/cic_eth/eth/account.py b/apps/cic-eth/cic_eth/eth/account.py index 8b521dfa..46b0060c 100644 --- a/apps/cic-eth/cic_eth/eth/account.py +++ b/apps/cic-eth/cic_eth/eth/account.py @@ -4,10 +4,10 @@ import logging # external imports import celery from erc20_single_shot_faucet import SingleShotFaucet as Faucet -from chainlib.eth.constant import ZERO_ADDRESS from hexathon import ( strip_0x, ) +from chainlib.eth.constant import ZERO_ADDRESS from chainlib.connection import RPCConnection from chainlib.eth.sign import ( new_account, @@ -19,6 +19,7 @@ from chainlib.eth.tx import ( unpack, ) from chainlib.chain import ChainSpec +from chainlib.error import JSONRPCException from eth_accounts_index import AccountRegistry from sarafu_faucet import MinterFaucet as Faucet from chainqueue.db.models.tx import TxCache @@ -226,21 +227,22 @@ def have(self, account, chain_spec_dict): """ chain_spec = ChainSpec.from_dict(chain_spec_dict) o = sign_message(account, '0x2a') - try: - conn = RPCConnection.connect(chain_spec, 'signer') - except Exception as e: - logg.debug('cannot sign with {}: {}'.format(account, e)) - return None + conn = RPCConnection.connect(chain_spec, 'signer') try: conn.do(o) - conn.disconnect() - return account - except Exception as e: + except ConnectionError as e: + raise SignerError(e) + except FileNotFoundError as e: + raise SignerError(e) + except JSONRPCException as e: logg.debug('cannot sign with {}: {}'.format(account, e)) conn.disconnect() return None + conn.disconnect() + return account + @celery_app.task(bind=True, base=CriticalSQLAlchemyTask) def set_role(self, tag, address, chain_spec_dict): diff --git a/apps/cic-eth/cic_eth/eth/erc20.py b/apps/cic-eth/cic_eth/eth/erc20.py index bc2d593f..71dfd6a2 100644 --- a/apps/cic-eth/cic_eth/eth/erc20.py +++ b/apps/cic-eth/cic_eth/eth/erc20.py @@ -177,7 +177,12 @@ def approve(self, tokens, holder_address, spender_address, value, chain_spec_dic nonce_oracle = CustodialTaskNonceOracle(holder_address, self.request.root_id, session=session) gas_oracle = self.create_gas_oracle(rpc, MaxGasOracle.gas) c = ERC20(chain_spec, signer=rpc_signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle) - (tx_hash_hex, tx_signed_raw_hex) = c.approve(t['address'], holder_address, spender_address, value, tx_format=TxFormat.RLP_SIGNED) + try: + (tx_hash_hex, tx_signed_raw_hex) = c.approve(t['address'], holder_address, spender_address, value, tx_format=TxFormat.RLP_SIGNED) + except FileNotFoundError as e: + raise SignerError(e) + except ConnectionError as e: + raise SignerError(e) rpc_signer.disconnect() rpc.disconnect() diff --git a/apps/cic-eth/cic_eth/eth/gas.py b/apps/cic-eth/cic_eth/eth/gas.py index f7b71eb9..258054c0 100644 --- a/apps/cic-eth/cic_eth/eth/gas.py +++ b/apps/cic-eth/cic_eth/eth/gas.py @@ -328,7 +328,12 @@ def refill_gas(self, recipient_address, chain_spec_dict): # build and add transaction logg.debug('tx send gas amount {} from provider {} to {}'.format(refill_amount, gas_provider, recipient_address)) - (tx_hash_hex, tx_signed_raw_hex) = c.create(gas_provider, recipient_address, refill_amount, tx_format=TxFormat.RLP_SIGNED) + try: + (tx_hash_hex, tx_signed_raw_hex) = c.create(gas_provider, recipient_address, refill_amount, tx_format=TxFormat.RLP_SIGNED) + except ConnectionError as e: + raise SignerError(e) + except FileNotFoundError as e: + raise SignerError(e) logg.debug('adding queue refill gas tx {}'.format(tx_hash_hex)) cache_task = 'cic_eth.eth.gas.cache_gas_data' register_tx(tx_hash_hex, tx_signed_raw_hex, chain_spec, queue, cache_task=cache_task, session=session) @@ -404,7 +409,12 @@ def resend_with_higher_gas(self, txold_hash_hex, chain_spec_dict, gas=None, defa c = TxFactory(chain_spec, signer=rpc_signer, gas_oracle=gas_oracle) logg.debug('change gas price from old {} to new {} for tx {}'.format(tx['gasPrice'], new_gas_price, tx)) tx['gasPrice'] = new_gas_price - (tx_hash_hex, tx_signed_raw_hex) = c.build_raw(tx) + try: + (tx_hash_hex, tx_signed_raw_hex) = c.build_raw(tx) + except ConnectionError as e: + raise SignerError(e) + except FileNotFoundError as e: + raise SignerError(e) queue_create( chain_spec, tx['nonce'], diff --git a/docker-compose.yml b/docker-compose.yml index 26681d8f..a3abb776 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -240,6 +240,8 @@ services: DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2} DATABASE_DEBUG: ${DATABASE_DEBUG:-0} DATABASE_POOL_SIZE: 0 + REDIS_PORT: 6379 + REDIS_HOST: redis PGPASSWORD: ${DATABASE_PASSWORD:-tralala} CIC_CHAIN_SPEC: ${CIC_CHAIN_SPEC:-evm:bloxberg:8996} BANCOR_DIR: ${BANCOR_DIR:-/usr/local/share/cic/bancor}