2022-04-10 15:58:24 +02:00
|
|
|
# standard imports
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# external imports
|
2022-04-26 21:40:58 +02:00
|
|
|
import chainlib.cli
|
|
|
|
import chainsyncer.cli
|
2022-04-26 19:24:57 +02:00
|
|
|
import chaind.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
|
|
|
|
|
|
|
|
# local imports
|
2022-04-26 19:24:57 +02:00
|
|
|
from chaind.eth.settings import ChaindEthSettings
|
2022-04-10 15:58:24 +02:00
|
|
|
|
2022-04-27 08:36:01 +02:00
|
|
|
|
2022-04-10 15:58:24 +02:00
|
|
|
# local imports
|
|
|
|
from chaind.eth.cache import EthCacheTx
|
|
|
|
|
|
|
|
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-04-26 21:40:58 +02:00
|
|
|
arg_flags = chainlib.cli.argflag_std_base | chainlib.cli.Flag.CHAIN_SPEC
|
|
|
|
argparser = chainlib.cli.ArgumentParser(arg_flags)
|
|
|
|
|
|
|
|
local_arg_flags = chaind.cli.argflag_local_base
|
|
|
|
chaind.cli.process_flags(argparser, local_arg_flags)
|
|
|
|
|
|
|
|
sync_flags = chainsyncer.cli.SyncFlag.RANGE | chainsyncer.cli.SyncFlag.HEAD
|
|
|
|
chainsyncer.cli.process_flags(argparser, sync_flags)
|
|
|
|
|
2022-04-10 15:58:24 +02:00
|
|
|
args = argparser.parse_args()
|
|
|
|
|
2022-04-26 21:40:58 +02:00
|
|
|
base_config_dir = [
|
|
|
|
chainsyncer.cli.config_dir,
|
|
|
|
chaind.cli.config_dir,
|
|
|
|
]
|
|
|
|
config = chainlib.cli.Config.from_args(args, arg_flags, base_config_dir=base_config_dir)
|
|
|
|
config = chainsyncer.cli.process_config(config, args, sync_flags)
|
|
|
|
config = chaind.cli.process_config(config, args, local_arg_flags)
|
|
|
|
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-04-26 21:40:58 +02:00
|
|
|
settings = ChaindEthSettings(include_sync=True)
|
2022-04-26 19:24:57 +02:00
|
|
|
settings.process(config)
|
2022-04-10 15:58:24 +02:00
|
|
|
|
2022-04-26 19:24:57 +02:00
|
|
|
logg.debug('settings:\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-04-27 08:36:01 +02:00
|
|
|
sync_store = SyncFsStore(settings.get('SESSION_DATA_DIR'), 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:
|
|
|
|
drv.run(settings.get('RPC'))
|
|
|
|
except SyncDone as e:
|
|
|
|
logg.info('sync done: {}'.format(e))
|
2022-04-10 15:58:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|