Connect syncer cli args
This commit is contained in:
parent
f5e422cadd
commit
db0d1743ba
@ -20,6 +20,16 @@ from chainlib.connection import (
|
|||||||
)
|
)
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chainlib.eth.connection import EthUnixSignerConnection
|
from chainlib.eth.connection import EthUnixSignerConnection
|
||||||
|
from chainlib.eth.block import (
|
||||||
|
block_by_number,
|
||||||
|
Block,
|
||||||
|
)
|
||||||
|
from chainlib.eth.tx import (
|
||||||
|
receipt,
|
||||||
|
Tx,
|
||||||
|
)
|
||||||
|
from chainlib.interface import ChainInterface
|
||||||
|
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -74,6 +84,11 @@ class Config(BaseConfig):
|
|||||||
|
|
||||||
if local_arg_flags & CICFlag.CELERY:
|
if local_arg_flags & CICFlag.CELERY:
|
||||||
local_args_override['CELERY_QUEUE'] = getattr(args, 'celery_queue')
|
local_args_override['CELERY_QUEUE'] = getattr(args, 'celery_queue')
|
||||||
|
|
||||||
|
if local_arg_flags & CICFlag.SYNCER:
|
||||||
|
local_args_override['SYNCER_OFFSET'] = getattr(args, 'offset')
|
||||||
|
local_args_override['SYNCER_NO_HISTORY'] = getattr(args, 'no_history')
|
||||||
|
|
||||||
config.dict_override(local_args_override, 'local cli args')
|
config.dict_override(local_args_override, 'local cli args')
|
||||||
|
|
||||||
if local_arg_flags & CICFlag.REDIS_CALLBACK:
|
if local_arg_flags & CICFlag.REDIS_CALLBACK:
|
||||||
@ -104,7 +119,7 @@ class ArgumentParser(BaseArgumentParser):
|
|||||||
if local_arg_flags & CICFlag.CELERY:
|
if local_arg_flags & CICFlag.CELERY:
|
||||||
self.add_argument('-q', '--celery-queue', dest='celery_queue', type=str, default='cic-eth', help='Task queue')
|
self.add_argument('-q', '--celery-queue', dest='celery_queue', type=str, default='cic-eth', help='Task queue')
|
||||||
if local_arg_flags & CICFlag.SYNCER:
|
if local_arg_flags & CICFlag.SYNCER:
|
||||||
self.add_argument('--history-start', type=int, default=0, dest='history_start', help='Start block height for initial history sync')
|
self.add_argument('--offset', type=int, default=0, help='Start block height for initial history sync')
|
||||||
self.add_argument('--no-history', action='store_true', dest='no_history', help='Skip initial history sync')
|
self.add_argument('--no-history', action='store_true', dest='no_history', help='Skip initial history sync')
|
||||||
if local_arg_flags & CICFlag.CHAIN:
|
if local_arg_flags & CICFlag.CHAIN:
|
||||||
self.add_argument('-r', '--registry-address', type=str, dest='registry_address', help='CIC registry contract address')
|
self.add_argument('-r', '--registry-address', type=str, dest='registry_address', help='CIC registry contract address')
|
||||||
@ -153,3 +168,14 @@ class RPC:
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'RPC factory, chain {}, rpc {}, signer {}'.format(self.chain_spec, self.rpc_provider, self.signer_provider)
|
return 'RPC factory, chain {}, rpc {}, signer {}'.format(self.chain_spec, self.rpc_provider, self.signer_provider)
|
||||||
|
|
||||||
|
|
||||||
|
class EthChainInterface(ChainInterface):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._tx_receipt = receipt
|
||||||
|
self._block_by_number = block_by_number
|
||||||
|
self._block_from_src = Block.from_src
|
||||||
|
self._src_normalize = Tx.src_normalize
|
||||||
|
|
||||||
|
chain_interface = EthChainInterface()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[syncer]
|
[syncer]
|
||||||
loop_interval = 1
|
loop_interval = 1
|
||||||
block_offset =
|
offset = 0
|
||||||
no_history = 0
|
no_history = 0
|
||||||
|
@ -8,7 +8,6 @@ import sys
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from cic_base.eth.syncer import chain_interface
|
|
||||||
from cic_eth_registry.error import UnknownContractError
|
from cic_eth_registry.error import UnknownContractError
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chainlib.eth.constant import ZERO_ADDRESS
|
from chainlib.eth.constant import ZERO_ADDRESS
|
||||||
@ -102,9 +101,9 @@ def main():
|
|||||||
syncer_backends = SQLBackend.resume(chain_spec, block_offset)
|
syncer_backends = SQLBackend.resume(chain_spec, block_offset)
|
||||||
|
|
||||||
if len(syncer_backends) == 0:
|
if len(syncer_backends) == 0:
|
||||||
initial_block_start = config.get('SYNCER_HISTORY_START')
|
initial_block_start = config.get('SYNCER_OFFSET')
|
||||||
initial_block_offset = block_offset
|
initial_block_offset = block_offset
|
||||||
if config.get('_NO_HISTORY'):
|
if config.true('SYNCER_NO_HISTORY'):
|
||||||
initial_block_start = block_offset
|
initial_block_start = block_offset
|
||||||
initial_block_offset += 1
|
initial_block_offset += 1
|
||||||
syncer_backends.append(SQLBackend.initial(chain_spec, initial_block_offset, start_block_height=initial_block_start))
|
syncer_backends.append(SQLBackend.initial(chain_spec, initial_block_offset, start_block_height=initial_block_start))
|
||||||
@ -117,11 +116,11 @@ def main():
|
|||||||
|
|
||||||
for syncer_backend in syncer_backends:
|
for syncer_backend in syncer_backends:
|
||||||
try:
|
try:
|
||||||
syncers.append(HistorySyncer(syncer_backend, chain_interface))
|
syncers.append(HistorySyncer(syncer_backend, cic_eth.cli.chain_interface))
|
||||||
logg.info('Initializing HISTORY syncer on backend {}'.format(syncer_backend))
|
logg.info('Initializing HISTORY syncer on backend {}'.format(syncer_backend))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
logg.info('Initializing HEAD syncer on backend {}'.format(syncer_backend))
|
logg.info('Initializing HEAD syncer on backend {}'.format(syncer_backend))
|
||||||
syncers.append(HeadSyncer(syncer_backend, chain_interface))
|
syncers.append(HeadSyncer(syncer_backend, cic_eth.cli.chain_interface))
|
||||||
|
|
||||||
connect_registry(conn, chain_spec, config.get('CIC_REGISTRY_ADDRESS'))
|
connect_registry(conn, chain_spec, config.get('CIC_REGISTRY_ADDRESS'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user