From 54dd5acb627da8fb0fe505ec8018a99ddb51b33c Mon Sep 17 00:00:00 2001 From: Louis Holbrook Date: Mon, 12 Jul 2021 19:50:32 +0000 Subject: [PATCH 1/2] Only match account registry on correct contract address --- .../runnable/daemons/filters/register.py | 10 +++++++--- .../cic-eth/cic_eth/runnable/daemons/tracker.py | 12 ++++++++++-- apps/cic-eth/services_requirements.txt | 1 + apps/cic-eth/tests/filters/test_filter_bogus.py | 3 ++- .../tests/filters/test_register_filter.py | 17 +++++++++++++++-- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/apps/cic-eth/cic_eth/runnable/daemons/filters/register.py b/apps/cic-eth/cic_eth/runnable/daemons/filters/register.py index 23953229..54b8ad58 100644 --- a/apps/cic-eth/cic_eth/runnable/daemons/filters/register.py +++ b/apps/cic-eth/cic_eth/runnable/daemons/filters/register.py @@ -12,20 +12,24 @@ from hexathon import ( # local imports from .base import SyncFilter -logg = logging.getLogger().getChild(__name__) +logg = logging.getLogger(__name__) account_registry_add_log_hash = '0x9cc987676e7d63379f176ea50df0ae8d2d9d1141d1231d4ce15b5965f73c9430' class RegistrationFilter(SyncFilter): - def __init__(self, chain_spec, queue): + def __init__(self, chain_spec, contract_address, queue=None): self.chain_spec = chain_spec self.queue = queue + self.contract_address = contract_address def filter(self, conn, block, tx, db_session=None): - registered_address = None + if self.contract_address != tx.inputs[0]: + logg.debug('not an account registry tx; {} != {}'.format(self.contract_address, tx.inputs[0])) + return None + for l in tx.logs: event_topic_hex = l['topics'][0] if event_topic_hex == account_registry_add_log_hash: diff --git a/apps/cic-eth/cic_eth/runnable/daemons/tracker.py b/apps/cic-eth/cic_eth/runnable/daemons/tracker.py index 0a977825..94b29883 100644 --- a/apps/cic-eth/cic_eth/runnable/daemons/tracker.py +++ b/apps/cic-eth/cic_eth/runnable/daemons/tracker.py @@ -78,6 +78,14 @@ chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC')) cic_base.rpc.setup(chain_spec, config.get('ETH_PROVIDER')) +rpc = RPCConnection.connect(chain_spec, 'default') +registry = None +try: + registry = connect_registry(rpc, chain_spec, config.get('CIC_REGISTRY_ADDRESS')) +except UnknownContractError as e: + logg.exception('Registry contract connection failed for {}: {}'.format(config.get('CIC_REGISTRY_ADDRESS'), e)) + sys.exit(1) +logg.info('connected contract registry {}'.format(config.get('CIC_REGISTRY_ADDRESS'))) def main(): @@ -85,7 +93,6 @@ def main(): celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=config.get('CELERY_RESULT_URL')) # Connect to blockchain with chainlib - rpc = RPCConnection.connect(chain_spec, 'default') o = block_latest() r = rpc.do(o) @@ -151,7 +158,8 @@ def main(): tx_filter = TxFilter(chain_spec, config.get('_CELERY_QUEUE')) - registration_filter = RegistrationFilter(chain_spec, config.get('_CELERY_QUEUE')) + account_registry_address = registry.by_name('AccountRegistry') + registration_filter = RegistrationFilter(chain_spec, account_registry_address, queue=config.get('_CELERY_QUEUE')) gas_filter = GasFilter(chain_spec, config.get('_CELERY_QUEUE')) diff --git a/apps/cic-eth/services_requirements.txt b/apps/cic-eth/services_requirements.txt index cab48e40..e5e7b0de 100644 --- a/apps/cic-eth/services_requirements.txt +++ b/apps/cic-eth/services_requirements.txt @@ -13,3 +13,4 @@ erc20-faucet~=0.2.2a1 erc20-transfer-authorization~=0.3.2a1 sarafu-faucet~=0.0.4a1 moolb~=0.1.1b2 +erc20-transfer-authorization~=0.3.2a1 diff --git a/apps/cic-eth/tests/filters/test_filter_bogus.py b/apps/cic-eth/tests/filters/test_filter_bogus.py index 30edbc70..01539a5b 100644 --- a/apps/cic-eth/tests/filters/test_filter_bogus.py +++ b/apps/cic-eth/tests/filters/test_filter_bogus.py @@ -18,6 +18,7 @@ def test_filter_bogus( cic_registry, contract_roles, register_lookups, + account_registry, ): fltrs = [ @@ -26,7 +27,7 @@ def test_filter_bogus( TxFilter(default_chain_spec, None), CallbackFilter(default_chain_spec, None, None, caller_address=contract_roles['CONTRACT_DEPLOYER']), StragglerFilter(default_chain_spec, None), - RegistrationFilter(default_chain_spec, queue=None), + RegistrationFilter(default_chain_spec, account_registry, queue=None), ] for fltr in fltrs: diff --git a/apps/cic-eth/tests/filters/test_register_filter.py b/apps/cic-eth/tests/filters/test_register_filter.py index ce4543bb..431da1fb 100644 --- a/apps/cic-eth/tests/filters/test_register_filter.py +++ b/apps/cic-eth/tests/filters/test_register_filter.py @@ -1,3 +1,7 @@ +# standard imports +import logging +import os + # external imports from eth_accounts_index.registry import AccountRegistry from chainlib.connection import RPCConnection @@ -14,12 +18,17 @@ from chainlib.eth.block import ( Block, ) from erc20_faucet import Faucet -from hexathon import strip_0x +from hexathon import ( + strip_0x, + add_0x, + ) from chainqueue.sql.query import get_account_tx # local imports from cic_eth.runnable.daemons.filters.register import RegistrationFilter +logg = logging.getLogger() + def test_register_filter( default_chain_spec, @@ -60,7 +69,11 @@ def test_register_filter( tx = Tx(tx_src, block=block, rcpt=rcpt) tx.apply_receipt(rcpt) - fltr = RegistrationFilter(default_chain_spec, queue=None) + fltr = RegistrationFilter(default_chain_spec, add_0x(os.urandom(20).hex()), queue=None) + t = fltr.filter(eth_rpc, block, tx, db_session=init_database) + assert t == None + + fltr = RegistrationFilter(default_chain_spec, account_registry, queue=None) t = fltr.filter(eth_rpc, block, tx, db_session=init_database) t.get_leaf() From 8f173fa30bff37379e1012c17e3d5b90676d0e4d Mon Sep 17 00:00:00 2001 From: Louis Holbrook Date: Mon, 12 Jul 2021 19:50:48 +0000 Subject: [PATCH 2/2] Add contextual token symbol and name defaults --- apps/contract-migration/reset.sh | 34 +++++++++++++++++++++----------- docker-compose.yml | 4 ++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/apps/contract-migration/reset.sh b/apps/contract-migration/reset.sh index cf8798fe..445b1e95 100755 --- a/apps/contract-migration/reset.sh +++ b/apps/contract-migration/reset.sh @@ -3,14 +3,9 @@ set -a default_token=giftable_erc20_token -CIC_DEFAULT_TOKEN_SYMBOL=${CIC_DEFAULT_TOKEN_SYMBOL:-GFT} TOKEN_SYMBOL=${CIC_DEFAULT_TOKEN_SYMBOL} -TOKEN_NAME=${TOKEN_NAME:-$TOKEN_SYMBOL} +TOKEN_NAME=${TOKEN_NAME} TOKEN_TYPE=${TOKEN_TYPE:-$default_token} -if [ $TOKEN_TYPE == 'default' ]; then - >&2 echo resolving "default" token to $default_token - TOKEN_TYPE=$default_token -fi cat <&2 echo token symbol not set, setting defaults for type $TOKEN_TYPE + TOKEN_SYMBOL="GFT" + TOKEN_NAME="Giftable Token" + elif [ -z "$TOKEN_NAME" ]; then + >&2 echo token name not set, setting same as symbol for type $TOKEN_TYPE + TOKEN_NAME=$TOKEN_SYMBOL + fi >&2 echo deploying default token $TOKEN_TYPE - DEV_RESERVE_ADDRESS=`giftable-token-deploy $gas_price_arg -p $ETH_PROVIDER -y $DEV_ETH_KEYSTORE_FILE -i $CIC_CHAIN_SPEC -vv -ww --name $TOKEN_NAME --symbol $TOKEN_SYMBOL --decimals 6 -vv` - elif [ $TOKEN_TYPE == 'erc20_demurrage_token' ]; then + echo giftable-token-deploy $gas_price_arg -p $ETH_PROVIDER -y $DEV_ETH_KEYSTORE_FILE -i $CIC_CHAIN_SPEC -vv -ww --name "$TOKEN_NAME" --symbol $TOKEN_SYMBOL --decimals 6 -vv + DEV_RESERVE_ADDRESS=`giftable-token-deploy $gas_price_arg -p $ETH_PROVIDER -y $DEV_ETH_KEYSTORE_FILE -i $CIC_CHAIN_SPEC -vv -ww --name "$TOKEN_NAME" --symbol $TOKEN_SYMBOL --decimals 6 -vv` + elif [ "$TOKEN_TYPE" == "erc20_demurrage_token" ]; then + if [ -z "$TOKEN_SYMBOL" ]; then + >&2 echo token symbol not set, setting defaults for type $TOKEN_TYPE + TOKEN_SYMBOL="SARAFU" + TOKEN_NAME="Sarafu Token" + elif [ -z "$TOKEN_NAME" ]; then + >&2 echo token name not set, setting same as symbol for type $TOKEN_TYPE + TOKEN_NAME=$TOKEN_SYMBOL + fi >&2 echo deploying token $TOKEN_TYPE if [ -z $TOKEN_SINK_ADDRESS ]; then if [ ! -z $TOKEN_REDISTRIBUTION_PERIOD ]; then >&2 echo -e "\033[;93mtoken sink address not set, so redistribution will be BURNED\033[;39m" fi fi - DEV_RESERVE_ADDRESS=`erc20-demurrage-token-deploy $gas_price_arg -p $ETH_PROVIDER -y $DEV_ETH_KEYSTORE_FILE -i $CIC_CHAIN_SPEC -vv -ww` + DEV_RESERVE_ADDRESS=`erc20-demurrage-token-deploy $gas_price_arg -p $ETH_PROVIDER -y $DEV_ETH_KEYSTORE_FILE -i $CIC_CHAIN_SPEC --name "$TOKEN_NAME" --symbol $TOKEN_SYMBOL -vv -ww` else >&2 echo unknown token type $TOKEN_TYPE exit 1 @@ -154,3 +165,4 @@ set +e echo -n 2 > $init_level_file exec "$@" +l:83 diff --git a/docker-compose.yml b/docker-compose.yml index f3f78c80..00e176cb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -103,14 +103,14 @@ services: DEV_FAUCET_AMOUNT: ${DEV_FAUCET_AMOUNT:-0} #DEV_SARAFU_DEMURRAGE_LEVEL: ${DEV_SARAFU_DEMURRAGE_LEVEL:-196454828847045000000000000000000} DEV_ETH_GAS_PRICE: ${DEV_ETH_GAS_PRICE:-1} - CIC_DEFAULT_TOKEN_SYMBOL: ${CIC_DEFAULT_TOKEN_SYMBOL:-GFT} + CIC_DEFAULT_TOKEN_SYMBOL: $CIC_DEFAULT_TOKEN_SYMBOL TOKEN_NAME: $TOKEN_NAME TOKEN_DECIMALS: $TOKEN_DECIMALS TOKEN_REDISTRIBUTION_PERIOD: $TOKEN_REDISTRIBUTION_PERIOD TOKEN_SUPPLY_LIMIT: $TOKEN_SUPPLY_LIMIT TOKEN_DEMURRAGE_LEVEL: ${TOKEN_DEMURRAGE_LEVEL:-196454828847045000000000000000000} TOKEN_SINK_ADDRESS: $TOKEN_SINK_ADDRESS - TOKEN_TYPE: ${TOKEN_TYPE:-default} + TOKEN_TYPE: $TOKEN_TYPE #CONFINI_DIR: ${CONFINI_DIR:-/tmp/cic/config} command: ["./run_job.sh"] #command: ["./reset.sh"]