Correct paths between syncer and queuer
This commit is contained in:
parent
ab1977b802
commit
b893aaa7b1
@ -50,10 +50,10 @@ chaind.cli.process_flags(argparser, local_arg_flags)
|
|||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
base_config_dir = [chaind.cli.config_dir]
|
base_config_dir = [chaind.cli.config_dir]
|
||||||
config = chainlib.cli.Config.from_args(args, arg_flags, base_config_dir=base_config_dir)
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, base_config_dir=base_config_dir)
|
||||||
config = chaind.cli.process_config(config, args, local_arg_flags)
|
config = chaind.cli.process_config(config, args, local_arg_flags)
|
||||||
config.add('eth', 'CHAIND_ENGINE', False)
|
config.add('eth', 'CHAIND_ENGINE', False)
|
||||||
|
config.add('queue', 'CHAIND_COMPONENT', False)
|
||||||
logg.debug('config loaded:\n{}'.format(config))
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
|
|
||||||
settings = ChaindEthSettings(include_queue=True)
|
settings = ChaindEthSettings(include_queue=True)
|
@ -10,6 +10,7 @@ import socket
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
|
import chaind.cli
|
||||||
from chaind.setup import Environment
|
from chaind.setup import Environment
|
||||||
from chainlib.eth.gas import price
|
from chainlib.eth.gas import price
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
@ -24,32 +25,38 @@ from chaind.eth.cli.output import (
|
|||||||
Outputter,
|
Outputter,
|
||||||
OpMode,
|
OpMode,
|
||||||
)
|
)
|
||||||
|
from chaind.eth.settings import ChaindEthSettings
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
|
||||||
|
|
||||||
|
|
||||||
arg_flags = chainlib.eth.cli.argflag_std_write
|
arg_flags = chainlib.eth.cli.argflag_std_write
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
argparser = chainlib.eth.cli.ArgumentParser(arg_flags, arg_long={'-s': '--send-rpc'})
|
||||||
argparser.add_argument('--socket', dest='socket', type=str, help='Socket to send transactions to')
|
|
||||||
argparser.add_argument('--token-module', dest='token_module', type=str, help='Python module path to resolve tokens from identifiers')
|
|
||||||
argparser.add_positional('source', required=False, type=str, help='Transaction source file')
|
argparser.add_positional('source', required=False, type=str, help='Transaction source file')
|
||||||
|
|
||||||
|
local_arg_flags = chaind.cli.argflag_local_socket_client
|
||||||
|
chaind.cli.process_flags(argparser, local_arg_flags)
|
||||||
|
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
extra_args = {
|
|
||||||
'socket': None,
|
|
||||||
'source': None,
|
|
||||||
}
|
|
||||||
env = Environment(domain='eth', env=os.environ)
|
env = Environment(domain='eth', env=os.environ)
|
||||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, base_config_dir=config_dir)
|
|
||||||
config.add(args.token_module, 'TOKEN_MODULE', True)
|
base_config_dir = [chaind.cli.config_dir]
|
||||||
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, base_config_dir=base_config_dir)
|
||||||
|
config = chaind.cli.process_config(config, args, local_arg_flags)
|
||||||
|
config.add(args.source, '_SOURCE', False)
|
||||||
|
config.add('eth', 'CHAIND_ENGINE', False)
|
||||||
|
config.add('queue', 'CHAIND_COMPONENT', False)
|
||||||
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
|
|
||||||
wallet = chainlib.eth.cli.Wallet()
|
wallet = chainlib.eth.cli.Wallet()
|
||||||
wallet.from_config(config)
|
wallet.from_config(config)
|
||||||
|
|
||||||
|
settings = ChaindEthSettings(include_queue=True)
|
||||||
|
settings.process(config)
|
||||||
|
|
||||||
|
logg.debug('settings:\n{}'.format(settings))
|
||||||
|
|
||||||
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
||||||
conn = rpc.connect_by_config(config)
|
conn = rpc.connect_by_config(config)
|
||||||
|
|
||||||
@ -58,19 +65,19 @@ chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
|||||||
mode = OpMode.STDOUT
|
mode = OpMode.STDOUT
|
||||||
|
|
||||||
re_unix = r'^ipc://(/.+)'
|
re_unix = r'^ipc://(/.+)'
|
||||||
m = re.match(re_unix, config.get('_SOCKET', ''))
|
m = re.match(re_unix, config.get('SESSION_SOCKET_PATH', ''))
|
||||||
if m != None:
|
if m != None:
|
||||||
config.add(m.group(1), '_SOCKET', exists_ok=True)
|
config.add(m.group(1), 'SESSION_SOCKET_PATH', exists_ok=True)
|
||||||
r = 0
|
r = 0
|
||||||
try:
|
try:
|
||||||
stat_info = os.stat(config.get('_SOCKET'))
|
stat_info = os.stat(config.get('SESSION_SOCKET_PATH'))
|
||||||
if not stat.S_ISSOCK(stat_info.st_mode):
|
if not stat.S_ISSOCK(stat_info.st_mode):
|
||||||
r = 1
|
r = 1
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
r = 1
|
r = 1
|
||||||
|
|
||||||
if r > 0:
|
if r > 0:
|
||||||
sys.stderr.write('{} is not a socket\n'.format(config.get('_SOCKET')))
|
sys.stderr.write('{} is not a socket\n'.format(config.get('SESSION_SOCKET_PATH')))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
mode = OpMode.UNIX
|
mode = OpMode.UNIX
|
||||||
@ -84,8 +91,8 @@ if config.get('_SOURCE') == None:
|
|||||||
|
|
||||||
class SocketSender:
|
class SocketSender:
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, settings):
|
||||||
self.path = config.get('_SOCKET')
|
self.path = settings.get('SESSION_SOCKET_PATH')
|
||||||
|
|
||||||
def send(self, tx):
|
def send(self, tx):
|
||||||
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
@ -118,9 +125,9 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
sender = None
|
sender = None
|
||||||
if config.get('_RPC_SEND'):
|
if config.true('_SOCKET_SEND'):
|
||||||
if config.get('_SOCKET') != None:
|
if settings.get('SESSION_SOCKET_PATH') != None:
|
||||||
sender = SocketSender(config)
|
sender = SocketSender(settings)
|
||||||
|
|
||||||
tx_iter = iter(processor)
|
tx_iter = iter(processor)
|
||||||
out = Outputter(mode)
|
out = Outputter(mode)
|
||||||
|
@ -13,8 +13,12 @@ from chainlib.eth.block import block_latest
|
|||||||
from hexathon import strip_0x
|
from hexathon import strip_0x
|
||||||
from chainsyncer.store.fs import SyncFsStore
|
from chainsyncer.store.fs import SyncFsStore
|
||||||
from chainsyncer.driver.chain_interface import ChainInterfaceDriver
|
from chainsyncer.driver.chain_interface import ChainInterfaceDriver
|
||||||
|
from chainsyncer.error import SyncDone
|
||||||
|
|
||||||
|
# local imports
|
||||||
from chaind.eth.settings import ChaindEthSettings
|
from chaind.eth.settings import ChaindEthSettings
|
||||||
|
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chaind.eth.cache import EthCacheTx
|
from chaind.eth.cache import EthCacheTx
|
||||||
|
|
||||||
@ -45,6 +49,7 @@ config = chainlib.cli.Config.from_args(args, arg_flags, base_config_dir=base_con
|
|||||||
config = chainsyncer.cli.process_config(config, args, sync_flags)
|
config = chainsyncer.cli.process_config(config, args, sync_flags)
|
||||||
config = chaind.cli.process_config(config, args, local_arg_flags)
|
config = chaind.cli.process_config(config, args, local_arg_flags)
|
||||||
config.add('eth', 'CHAIND_ENGINE', False)
|
config.add('eth', 'CHAIND_ENGINE', False)
|
||||||
|
config.add('sync', 'CHAIND_COMPONENT', False)
|
||||||
logg.debug('config loaded:\n{}'.format(config))
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
|
|
||||||
settings = ChaindEthSettings(include_sync=True)
|
settings = ChaindEthSettings(include_sync=True)
|
||||||
@ -55,18 +60,21 @@ logg.debug('settings:\n{}'.format(settings))
|
|||||||
def main():
|
def main():
|
||||||
queue_adapter = ChaindFsAdapter(
|
queue_adapter = ChaindFsAdapter(
|
||||||
settings.get('CHAIN_SPEC'),
|
settings.get('CHAIN_SPEC'),
|
||||||
settings.get('SESSION_DATA_DIR'),
|
settings.dir_for('queue'),
|
||||||
EthCacheTx,
|
EthCacheTx,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
fltr = StateFilter(queue_adapter)
|
fltr = StateFilter(queue_adapter)
|
||||||
sync_store = SyncFsStore(settings.get('SESSION_RUNTIME_DIR'), session_id=settings.get('SESSION_ID'))
|
sync_store = SyncFsStore(settings.get('SESSION_DATA_DIR'), session_id=settings.get('SESSION_ID'))
|
||||||
sync_store.register(fltr)
|
sync_store.register(fltr)
|
||||||
|
|
||||||
logg.debug('session block offset {}'.format(settings.get('SYNCER_OFFSET')))
|
logg.debug('session block offset {}'.format(settings.get('SYNCER_OFFSET')))
|
||||||
|
|
||||||
drv = ChainInterfaceDriver(sync_store, settings.get('SYNCER_INTERFACE'), offset=settings.get('SYNCER_OFFSET'), target=settings.get('SYNCER_LIMIT'))
|
drv = ChainInterfaceDriver(sync_store, settings.get('SYNCER_INTERFACE'), offset=settings.get('SYNCER_OFFSET'), target=settings.get('SYNCER_LIMIT'))
|
||||||
drv.run(settings.get('RPC'))
|
try:
|
||||||
|
drv.run(settings.get('RPC'))
|
||||||
|
except SyncDone as e:
|
||||||
|
logg.info('sync done: {}'.format(e))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -34,7 +34,7 @@ packages =
|
|||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
chaind-eth-tasker = chaind.eth.runnable.tasker:main
|
chaind-eth-queuer = chaind.eth.runnable.queuer:main
|
||||||
chaind-eth-syncer = chaind.eth.runnable.syncer:main
|
chaind-eth-syncer = chaind.eth.runnable.syncer:main
|
||||||
chaind-eth-send = chaind.eth.runnable.send:main
|
chaind-eth-send = chaind.eth.runnable.send:main
|
||||||
#chaind-eth-resend = chaind_eth.runnable.resend:main
|
#chaind-eth-resend = chaind_eth.runnable.resend:main
|
||||||
|
Loading…
Reference in New Issue
Block a user