2022-04-10 15:58:24 +02:00
|
|
|
# standard imports
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# external imports
|
2022-05-13 12:32:28 +02:00
|
|
|
import chainlib.eth.cli
|
2022-04-10 15:58:24 +02:00
|
|
|
from chaind.setup import Environment
|
|
|
|
from chaind.filter import StateFilter
|
|
|
|
from chainlib.eth.block import block_latest
|
|
|
|
from hexathon import strip_0x
|
|
|
|
from chainsyncer.store.fs import SyncFsStore
|
|
|
|
from chainsyncer.driver.chain_interface import ChainInterfaceDriver
|
2022-04-27 08:36:01 +02:00
|
|
|
from chainsyncer.error import SyncDone
|
2022-05-13 12:32:28 +02:00
|
|
|
from chainlib.eth.cli.arg import (
|
|
|
|
Arg,
|
|
|
|
ArgFlag,
|
|
|
|
process_args,
|
|
|
|
)
|
|
|
|
from chainlib.eth.cli.config import (
|
|
|
|
Config,
|
|
|
|
process_config,
|
|
|
|
)
|
|
|
|
from chainsyncer.cli.arg import (
|
|
|
|
apply_arg as apply_arg_sync,
|
|
|
|
apply_flag as apply_flag_sync,
|
|
|
|
)
|
|
|
|
from chainsyncer.data import config_dir as chainsyncer_config_dir
|
|
|
|
from chaind.data import config_dir as chaind_config_dir
|
|
|
|
from chaind.cli.arg import (
|
|
|
|
apply_arg,
|
|
|
|
apply_flag,
|
|
|
|
)
|
|
|
|
from chainlib.eth.cli.log import process_log
|
|
|
|
from chaind.settings import ChaindSettings
|
2022-04-27 08:36:01 +02:00
|
|
|
|
2022-04-10 15:58:24 +02:00
|
|
|
# local imports
|
|
|
|
from chaind.eth.cache import EthCacheTx
|
2022-05-13 15:47:58 +02:00
|
|
|
from chaind.eth.settings import (
|
|
|
|
process_settings,
|
|
|
|
process_sync,
|
|
|
|
)
|
2022-05-13 12:32:28 +02:00
|
|
|
|
2022-04-10 15:58:24 +02:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.WARNING)
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
|
|
|
|
|
|
|
env = Environment(domain='eth', env=os.environ)
|
|
|
|
|
2022-05-13 12:32:28 +02:00
|
|
|
arg_flags = ArgFlag()
|
|
|
|
arg_flags = apply_flag_sync(arg_flags)
|
|
|
|
arg_flags = apply_flag(arg_flags)
|
2022-04-26 21:40:58 +02:00
|
|
|
|
2022-05-13 12:32:28 +02:00
|
|
|
arg = Arg(arg_flags)
|
|
|
|
arg = apply_arg_sync(arg)
|
|
|
|
arg = apply_arg(arg)
|
2022-04-26 21:40:58 +02:00
|
|
|
|
2022-05-13 15:47:58 +02:00
|
|
|
flags = arg_flags.STD_BASE | arg_flags.CHAIN_SPEC | arg_flags.PROVIDER | arg_flags.SEQ | arg_flags.STATE
|
2022-05-13 12:32:28 +02:00
|
|
|
flags = arg_flags.more(flags, arg_flags.SYNC_RANGE_EXT)
|
|
|
|
flags = arg_flags.more(flags, arg_flags.CHAIND_BASE)
|
2022-04-26 21:40:58 +02:00
|
|
|
|
2022-05-13 12:32:28 +02:00
|
|
|
argparser = chainlib.eth.cli.ArgumentParser()
|
|
|
|
argparser = process_args(argparser, arg, flags)
|
2022-04-10 15:58:24 +02:00
|
|
|
args = argparser.parse_args()
|
|
|
|
|
2022-05-13 12:32:28 +02:00
|
|
|
logg = process_log(args, logg)
|
|
|
|
|
|
|
|
config = Config()
|
|
|
|
config.add_schema_dir(chainsyncer_config_dir)
|
|
|
|
config.add_schema_dir(chaind_config_dir)
|
|
|
|
config = process_config(config, arg, args, flags)
|
2022-04-26 21:40:58 +02:00
|
|
|
config.add('eth', 'CHAIND_ENGINE', False)
|
2022-04-27 08:36:01 +02:00
|
|
|
config.add('sync', 'CHAIND_COMPONENT', False)
|
2022-04-10 15:58:24 +02:00
|
|
|
logg.debug('config loaded:\n{}'.format(config))
|
|
|
|
|
2022-05-13 15:47:58 +02:00
|
|
|
settings = ChaindSettings(include_sync=True)
|
2022-05-13 12:32:28 +02:00
|
|
|
settings = process_settings(settings, config)
|
2022-05-13 15:47:58 +02:00
|
|
|
settings = process_sync(settings, config)
|
2022-05-13 12:32:28 +02:00
|
|
|
logg.debug('settings loaded:\n{}'.format(settings))
|
2022-04-10 15:58:24 +02:00
|
|
|
|
2022-04-28 14:49:50 +02:00
|
|
|
|
2022-04-10 15:58:24 +02:00
|
|
|
def main():
|
2022-04-30 20:44:52 +02:00
|
|
|
fltr = StateFilter(settings.get('CHAIN_SPEC'), settings.dir_for('queue'), EthCacheTx)
|
2022-05-13 15:47:58 +02:00
|
|
|
sync_store = SyncFsStore(settings.get('SESSION_DATA_PATH'), session_id=settings.get('SESSION_ID'))
|
2022-04-10 15:58:24 +02:00
|
|
|
sync_store.register(fltr)
|
2022-04-26 12:10:04 +02:00
|
|
|
|
2022-04-26 19:24:57 +02:00
|
|
|
logg.debug('session block offset {}'.format(settings.get('SYNCER_OFFSET')))
|
2022-04-10 15:58:24 +02:00
|
|
|
|
2022-04-26 19:24:57 +02:00
|
|
|
drv = ChainInterfaceDriver(sync_store, settings.get('SYNCER_INTERFACE'), offset=settings.get('SYNCER_OFFSET'), target=settings.get('SYNCER_LIMIT'))
|
2022-04-27 08:36:01 +02:00
|
|
|
try:
|
2022-05-13 15:47:58 +02:00
|
|
|
drv.run(settings.get('CONN'))
|
2022-04-27 08:36:01 +02:00
|
|
|
except SyncDone as e:
|
|
|
|
logg.info('sync done: {}'.format(e))
|
2022-04-10 15:58:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|