chaind-eth

Queue server for ethereum
Log | Files | Refs | README | LICENSE

commit a6420eacfbe3f7fda3094b425d65a6f2fca8dcea
parent 388910a4ac8f7f69dc6323ecf910272200653f48
Author: nolash <dev@holbrook.no>
Date:   Sat, 17 Jul 2021 08:22:02 +0200

Add base config

Diffstat:
Achaind_eth/data/config/config.ini | 18++++++++++++++++++
Mchaind_eth/runnable/server.py | 22+++++++++++++++-------
Mchainqueue/adapters/eth.py | 10++++++++++
3 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/chaind_eth/data/config/config.ini b/chaind_eth/data/config/config.ini @@ -0,0 +1,18 @@ +[session] +socket_path = +runtime_dir = +id = +data_dir = + +[chain] +spec = evm:ethereum:1 + +[database] +engine = +name = chaind_eth +driver = +user = +password = +host = +port = +debug = 0 diff --git a/chaind_eth/runnable/server.py b/chaind_eth/runnable/server.py @@ -26,6 +26,9 @@ from chainqueue.adapters.eth import EthAdapter 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) argparser = argparse.ArgumentParser('chainqueue transaction submission and trigger server') @@ -45,11 +48,11 @@ elif args.v: logg.setLevel(logging.INFO) # process config -config = confini.Config(args.c) +config = confini.Config(config_dir, override_dirs=[args.c]) config.process() args_override = { 'SESSION_RUNTIME_DIR': getattr(args, 'runtime_dir'), - 'SESSION_CHAIN_SPEC': getattr(args, 'i'), + 'CHAIN_SPEC': getattr(args, 'i'), 'RPC_ENDPOINT': getattr(args, 'p'), 'SESSION_DATA_DIR': getattr(args, 'data_dir'), 'SESSION_ID': getattr(args, 'session_id'), @@ -115,13 +118,21 @@ ctrl = SessionController(config) signal.signal(signal.SIGINT, ctrl.shutdown) signal.signal(signal.SIGTERM, ctrl.shutdown) -chain_spec = ChainSpec.from_chain_str(config.get('SESSION_CHAIN_SPEC')) +chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC')) dsn = dsn_from_config(config) backend = SQLBackend(dsn, debug=config.true('DATABASE_DEBUG')) adapter = EthAdapter(backend) rpc = EthHTTPConnection(url=config.get('RPC_ENDPOINT'), chain_spec=chain_spec) + +def process_outgoing(chain_spec, adapter, rpc): + dispatcher = Dispatcher(chain_spec, adapter) + session = adapter.create_session() + r = dispatcher.process(rpc, session) + session.close() + + def main(): havesends = 0 while True: @@ -140,10 +151,7 @@ def main(): break if srvs == None: logg.debug('timeout (remote socket is none)') - dispatcher = Dispatcher(chain_spec, adapter) - session = backend.create_session() - r = dispatcher.process(rpc, session) - session.close() + process_outgoing(chain_spec, adapter, rpc) if r > 0: ctrl.srv.settimeout(0.1) else: diff --git a/chainqueue/adapters/eth.py b/chainqueue/adapters/eth.py @@ -24,6 +24,16 @@ class EthAdapter(Adapter): return tx + def dispatch(self, chain_spec, rpc, tx_hash, signed_tx, session=None): + o = raw(signed_tx) + r = self.backend.dispatch(chain_spec, rpc, tx_hash, o) + return r + + + def upcoming(self, chain_spec, session=None): + return self.backend.get(chain_spec, StatusBits.QUEUED, self.translate) # possible maldesign, up-stack should use our session? + + def add(self, chain_spec, bytecode, session=None): tx = self.translate(chain_spec, bytecode) r = self.backend.create(chain_spec, tx['nonce'], tx['from'], tx['hash'], add_0x(bytecode.hex()), session=session)