diff --git a/apps/cic-cache/cic_cache/runnable/daemons/tracker.py b/apps/cic-cache/cic_cache/runnable/daemons/tracker.py index 279176bd..0746df7f 100644 --- a/apps/cic-cache/cic_cache/runnable/daemons/tracker.py +++ b/apps/cic-cache/cic_cache/runnable/daemons/tracker.py @@ -46,12 +46,21 @@ from cic_cache.runnable.daemons.filters import ( script_dir = os.path.realpath(os.path.dirname(__file__)) +def add_block_args(argparser): + argparser.add_argument('--history-start', type=int, default=0, dest='history_start', help='Start block height for initial history sync') + argparser.add_argument('--no-history', action='store_true', dest='no_history', help='Skip initial history sync') + return argparser + + logg = cic_base.log.create() argparser = cic_base.argparse.create(script_dir, cic_base.argparse.full_template) -#argparser = cic_base.argparse.add(argparser, add_traffic_args, 'traffic') +argparser = cic_base.argparse.add(argparser, add_block_args, 'block') args = cic_base.argparse.parse(argparser, logg) config = cic_base.config.create(args.c, args, args.env_prefix) +config.add(args.history_start, 'SYNCER_HISTORY_START', True) +config.add(args.no_history, '_NO_HISTORY', True) + cic_base.config.log(config) dsn = dsn_from_config(config) @@ -60,7 +69,6 @@ SessionBase.connect(dsn, debug=config.true('DATABASE_DEBUG')) chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC')) -#RPCConnection.register_location(config.get('ETH_PROVIDER'), chain_spec, 'default') cic_base.rpc.setup(chain_spec, config.get('ETH_PROVIDER')) @@ -84,7 +92,7 @@ def main(): r = rpc.do(o) block_offset = int(strip_0x(r), 16) + 1 - logg.debug('starting at block {}'.format(block_offset)) + logg.debug('current block height {}'.format(block_offset)) syncers = [] @@ -93,8 +101,13 @@ def main(): syncer_backends = SQLBackend.resume(chain_spec, block_offset) if len(syncer_backends) == 0: - logg.info('found no backends to resume') - syncer_backends.append(SQLBackend.initial(chain_spec, block_offset)) + initial_block_start = config.get('SYNCER_HISTORY_START') + initial_block_offset = block_offset + if config.get('_NO_HISTORY'): + initial_block_start = block_offset + initial_block_offset += 1 + syncer_backends.append(SQLBackend.initial(chain_spec, initial_block_offset, start_block_height=initial_block_start)) + logg.info('found no backends to resume, adding initial sync from history start {} end {}'.format(initial_block_start, initial_block_offset)) else: for syncer_backend in syncer_backends: logg.info('resuming sync session {}'.format(syncer_backend)) diff --git a/apps/cic-cache/config/docker/eth.ini b/apps/cic-cache/config/docker/eth.ini index d61e9647..321384f8 100644 --- a/apps/cic-cache/config/docker/eth.ini +++ b/apps/cic-cache/config/docker/eth.ini @@ -1,2 +1,2 @@ [eth] -provider = ws://localhost:63546 +provider = http://localhost:63545 diff --git a/apps/cic-cache/config/docker/syncer.ini b/apps/cic-cache/config/docker/syncer.ini index 452fb81c..c811bccc 100644 --- a/apps/cic-cache/config/docker/syncer.ini +++ b/apps/cic-cache/config/docker/syncer.ini @@ -1,2 +1,3 @@ [syncer] loop_interval = 1 +history_start = 0 diff --git a/apps/cic-cache/config/syncer.ini b/apps/cic-cache/config/syncer.ini index 42e7cd88..f26739c7 100644 --- a/apps/cic-cache/config/syncer.ini +++ b/apps/cic-cache/config/syncer.ini @@ -1,2 +1,3 @@ [syncer] loop_interval = 5 +history_start = 0 diff --git a/apps/cic-cache/requirements.txt b/apps/cic-cache/requirements.txt index 6095d479..ad1232c3 100644 --- a/apps/cic-cache/requirements.txt +++ b/apps/cic-cache/requirements.txt @@ -1,4 +1,4 @@ -cic-base~=0.1.2b9 +cic-base~=0.1.2b10 alembic==1.4.2 confini~=0.3.6rc3 uwsgi==2.0.19.1 diff --git a/apps/cic-eth/cic_eth/runnable/daemons/tracker.py b/apps/cic-eth/cic_eth/runnable/daemons/tracker.py index d20dc338..10ef5154 100644 --- a/apps/cic-eth/cic_eth/runnable/daemons/tracker.py +++ b/apps/cic-eth/cic_eth/runnable/daemons/tracker.py @@ -51,15 +51,23 @@ from cic_eth.registry import ( script_dir = os.path.realpath(os.path.dirname(__file__)) +def add_block_args(argparser): + argparser.add_argument('--history-start', type=int, default=0, dest='history_start', help='Start block height for initial history sync') + argparser.add_argument('--no-history', action='store_true', dest='no_history', help='Skip initial history sync') + return argparser + + logg = cic_base.log.create() argparser = cic_base.argparse.create(script_dir, cic_base.argparse.full_template) -#argparser = cic_base.argparse.add(argparser, add_traffic_args, 'traffic') +argparser = cic_base.argparse.add(argparser, add_block_args, 'block') args = cic_base.argparse.parse(argparser, logg) + config = cic_base.config.create(args.c, args, args.env_prefix) config.add(args.y, '_KEYSTORE_FILE', True) - config.add(args.q, '_CELERY_QUEUE', True) +config.add(args.history_start, 'SYNCER_HISTORY_START', True) +config.add(args.no_history, '_NO_HISTORY', True) cic_base.config.log(config) @@ -69,9 +77,9 @@ SessionBase.connect(dsn, pool_size=16, debug=config.true('DATABASE_DEBUG')) chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC')) -#RPCConnection.register_location(config.get('ETH_PROVIDER'), chain_spec, 'default') cic_base.rpc.setup(chain_spec, config.get('ETH_PROVIDER')) + def main(): # connect to celery celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=config.get('CELERY_RESULT_URL')) @@ -89,7 +97,7 @@ def main(): stat = init_chain_stat(rpc, block_start=block_current) loop_interval = stat.block_average() - logg.debug('starting at block {}'.format(block_offset)) + logg.debug('current block height {}'.format(block_offset)) syncers = [] @@ -98,8 +106,13 @@ def main(): syncer_backends = SQLBackend.resume(chain_spec, block_offset) if len(syncer_backends) == 0: - logg.info('found no backends to resume') - syncer_backends.append(SQLBackend.initial(chain_spec, block_offset)) + initial_block_start = config.get('SYNCER_HISTORY_START') + initial_block_offset = block_offset + if config.get('_NO_HISTORY'): + initial_block_start = block_offset + initial_block_offset += 1 + syncer_backends.append(SQLBackend.initial(chain_spec, initial_block_offset, start_block_height=initial_block_start)) + logg.info('found no backends to resume, adding initial sync from history start {} end {}'.format(initial_block_start, initial_block_offset)) else: for syncer_backend in syncer_backends: logg.info('resuming sync session {}'.format(syncer_backend)) @@ -155,7 +168,6 @@ def main(): for cf in callback_filters: syncer.add_filter(cf) - #r = syncer.loop(int(config.get('SYNCER_LOOP_INTERVAL')), rpc) r = syncer.loop(int(loop_interval), rpc) sys.stderr.write("sync {} done at block {}\n".format(syncer, r)) diff --git a/apps/cic-eth/config/docker/syncer.ini b/apps/cic-eth/config/docker/syncer.ini index 9c452999..fc88c7f4 100644 --- a/apps/cic-eth/config/docker/syncer.ini +++ b/apps/cic-eth/config/docker/syncer.ini @@ -1,2 +1,3 @@ [SYNCER] loop_interval = +history_start = 0 diff --git a/apps/cic-eth/config/syncer.ini b/apps/cic-eth/config/syncer.ini index 9c452999..fc88c7f4 100644 --- a/apps/cic-eth/config/syncer.ini +++ b/apps/cic-eth/config/syncer.ini @@ -1,2 +1,3 @@ [SYNCER] loop_interval = +history_start = 0 diff --git a/apps/cic-eth/requirements.txt b/apps/cic-eth/requirements.txt index 4ec9c34e..a4fb22b6 100644 --- a/apps/cic-eth/requirements.txt +++ b/apps/cic-eth/requirements.txt @@ -14,7 +14,7 @@ semver==2.13.0 websocket-client==0.57.0 moolb~=0.1.1b2 eth-address-index~=0.1.1a11 -chainlib~=0.0.3a1 +chainlib~=0.0.3a2 hexathon~=0.0.1a7 chainsyncer[sql]~=0.0.2a4 chainqueue~=0.0.2a2