Implement cic-base cli module

This commit is contained in:
lash 2022-04-24 19:28:55 +00:00
parent 09af7896c0
commit cca44575e5
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 26 additions and 25 deletions

View File

@ -1,6 +1,7 @@
[sync]
[syncer]
filter = cic_sync_filter.tx.TxFilter,cic_sync_filter.gas.GasFilter,cic_sync_filter.register.RegistrationFilter,cic_sync_filter.token.TokenFilter,cic_sync_filter.callback.CallbackFilter
backend = fs
dir = .cic-tracker
session_id = default
offset = 0
limit = -1

View File

@ -9,7 +9,7 @@ from chainsyncer.error import SyncDone
from chainsyncer.driver.chain_interface import ChainInterfaceDriver
# cic_eth legacy imports
import cic_eth.cli
import cic_base.cli
# local imports
#from cic_tracker.cache import SyncTimeRedisCache
@ -30,19 +30,19 @@ script_dir = os.path.realpath(os.path.dirname(__file__))
exec_dir = os.path.realpath(os.getcwd()) #default_config_dir = os.environ.get('CONFINI_DIR', os.path.join(exec_dir, 'config'))
base_config_dir = os.path.join(script_dir, '..', 'data', 'config')
arg_flags = cic_eth.cli.argflag_std_read
local_arg_flags = cic_eth.cli.argflag_local_sync
argparser = cic_eth.cli.ArgumentParser(arg_flags)
arg_flags = cic_base.cli.argflag_std_read
local_arg_flags = cic_base.cli.argflag_local_sync
argparser = cic_base.cli.ArgumentParser(arg_flags)
argparser.add_argument('--session-id', dest='session_id', type=str, help='Session id to use for state store')
argparser.add_argument('--until', type=int, default=0, help='Stop sync at the given block. 0 = infinite sync')
argparser.process_local_flags(local_arg_flags)
args = argparser.parse_args()
# process config
config = cic_eth.cli.Config.from_args(args, arg_flags, local_arg_flags, base_config_dir=base_config_dir)
config = cic_base.cli.Config.from_args(args, arg_flags, local_arg_flags, base_config_dir=base_config_dir)
args_override = {
'SYNC_OFFSET': getattr(args, 'offset'),
'SYNC_SESSION_ID': getattr(args, 'session_id'),
'SYNCER_OFFSET': getattr(args, 'offset'),
'SYNCER_SESSION_ID': getattr(args, 'session_id'),
}
config.add(args.until, '_UNTIL', True)
@ -53,10 +53,10 @@ def main():
logg.debug('settings:\n' + str(settings))
drv = ChainInterfaceDriver(
settings.get('SYNC_STORE'),
settings.get('SYNC_INTERFACE'),
settings.get('SYNC_OFFSET'),
settings.get('SYNC_LIMIT'),
settings.get('SYNCER_STORE'),
settings.get('SYNCER_INTERFACE'),
settings.get('SYNCER_OFFSET'),
settings.get('SYNCER_LIMIT'),
pre_callback=pre_callback,
post_callback=post_callback,
block_callback=block_callback,

View File

@ -35,7 +35,7 @@ class CICTrackerSettings(CICSettings):
def process_sync_interface(self, config):
self.o['SYNC_INTERFACE'] = EthChainInterface()
self.o['SYNCER_INTERFACE'] = EthChainInterface()
def process_sync_range(self, config):
@ -47,7 +47,7 @@ class CICTrackerSettings(CICSettings):
keep_alive = False
session_block_offset = 0
block_limit = 0
session_block_offset = int(config.get('SYNC_OFFSET'))
session_block_offset = int(config.get('SYNCER_OFFSET'))
until = int(config.get('_UNTIL'))
if until > 0:
@ -64,34 +64,34 @@ class CICTrackerSettings(CICSettings):
if block_limit == 0:
lock_limit = block_offset
self.o['SYNC_OFFSET'] = session_block_offset
self.o['SYNC_LIMIT'] = block_limit
self.o['SYNCER_OFFSET'] = session_block_offset
self.o['SYNCER_LIMIT'] = block_limit
def process_sync_store(self, config):
syncer_store_module = None
syncer_store_class = None
if config.get('SYNC_BACKEND') == 'fs':
if config.get('SYNCER_BACKEND') == 'fs':
syncer_store_module = importlib.import_module('chainsyncer.store.fs')
syncer_store_class = getattr(syncer_store_module, 'SyncFsStore')
elif config.get('SYNC_BACKEND') == 'rocksdb':
elif config.get('SYNCER_BACKEND') == 'rocksdb':
syncer_store_module = importlib.import_module('chainsyncer.store.rocksdb')
syncer_store_class = getattr(syncer_store_module, 'SyncRocksDbStore')
else:
syncer_store_module = importlib.import_module(config.get('SYNC_BACKEND'))
syncer_store_module = importlib.import_module(config.get('SYNCER_BACKEND'))
syncer_store_class = getattr(syncer_store_module, 'SyncStore')
logg.info('using engine {} module {}.{}'.format(config.get('SYNC_BACKEND'), syncer_store_module.__file__, syncer_store_class.__name__))
logg.info('using engine {} module {}.{}'.format(config.get('SYNCER_BACKEND'), syncer_store_module.__file__, syncer_store_class.__name__))
state_dir = os.path.join(config.get('SYNC_DIR'), config.get('SYNC_BACKEND'))
sync_store = syncer_store_class(state_dir, session_id=config.get('SYNC_SESSION_ID'), state_event_callback=state_change_callback, filter_state_event_callback=filter_change_callback)
state_dir = os.path.join(config.get('SYNCER_DIR'), config.get('SYNCER_BACKEND'))
sync_store = syncer_store_class(state_dir, session_id=config.get('SYNCER_SESSION_ID'), state_event_callback=state_change_callback, filter_state_event_callback=filter_change_callback)
logg.info('sync session is {}'.format(sync_store.session_id))
self.o['SYNC_STORE'] = sync_store
self.o['SYNCER_STORE'] = sync_store
def process_sync_filters(self, config):
for v in config.get('SYNC_FILTER').split(','):
for v in config.get('SYNCER_FILTER').split(','):
logg.debug('processing filter {}'.format(v))
(path, cls) = v.rsplit('.', maxsplit=1)
m = importlib.import_module(path)
@ -102,7 +102,7 @@ class CICTrackerSettings(CICSettings):
m.set_method()
o.trusted_addresses = trusted_addresses
self.o['SYNC_STORE'].register(m)
self.o['SYNCER_STORE'].register(m)
def process(self, config):