Compare commits
12 Commits
lash/chain
...
dev-0.2.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
abc619d7b2
|
||
|
|
42aa809500
|
||
|
|
e31367853c
|
||
|
|
9522729fa0
|
||
|
|
097a6f4b53
|
||
|
|
8d0a1f589b
|
||
|
|
24a71b6c7f
|
||
|
|
b893aaa7b1
|
||
|
|
ab1977b802
|
||
|
|
3d39fea7f8
|
||
|
|
b19b948be3
|
||
|
|
f961345652
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ build/
|
|||||||
*.egg-info
|
*.egg-info
|
||||||
*.sqlite
|
*.sqlite
|
||||||
.coverage
|
.coverage
|
||||||
|
.chaind
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
from chainlib.interface import ChainInterface
|
from chainlib.interface import ChainInterface
|
||||||
from chainlib.eth.block import (
|
from chainlib.eth.block import (
|
||||||
block_by_number,
|
block_by_number,
|
||||||
|
block_latest,
|
||||||
Block,
|
Block,
|
||||||
)
|
)
|
||||||
from chainlib.eth.tx import (
|
from chainlib.eth.tx import (
|
||||||
@@ -16,3 +17,4 @@ class EthChainInterface(ChainInterface):
|
|||||||
self._block_from_src = Block.from_src
|
self._block_from_src = Block.from_src
|
||||||
self._tx_receipt = receipt
|
self._tx_receipt = receipt
|
||||||
self._src_normalize = Tx.src_normalize
|
self._src_normalize = Tx.src_normalize
|
||||||
|
self._block_latest = block_latest
|
||||||
|
|||||||
@@ -4,13 +4,3 @@ runtime_dir =
|
|||||||
id =
|
id =
|
||||||
data_dir =
|
data_dir =
|
||||||
dispatch_delay = 0.01
|
dispatch_delay = 0.01
|
||||||
|
|
||||||
[database]
|
|
||||||
engine =
|
|
||||||
name = chaind
|
|
||||||
driver =
|
|
||||||
user =
|
|
||||||
password =
|
|
||||||
host =
|
|
||||||
port =
|
|
||||||
debug = 0
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import signal
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
|
import chaind.cli
|
||||||
|
import chainqueue.cli
|
||||||
from chaind.session import SessionController
|
from chaind.session import SessionController
|
||||||
from chaind.setup import Environment
|
from chaind.setup import Environment
|
||||||
from chaind.error import (
|
from chaind.error import (
|
||||||
@@ -26,10 +28,12 @@ from chainqueue.cache import CacheTokenTx
|
|||||||
from chainlib.encode import TxHexNormalizer
|
from chainlib.encode import TxHexNormalizer
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chaind.adapters.fs import ChaindFsAdapter
|
from chaind.adapters.fs import ChaindFsAdapter
|
||||||
|
from chaind.dispatch import DispatchProcessor
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chaind.eth.dispatch import EthDispatcher
|
|
||||||
from chaind.eth.cache import EthCacheTx
|
from chaind.eth.cache import EthCacheTx
|
||||||
|
from chaind.eth.settings import ChaindEthSettings
|
||||||
|
from chaind.eth.dispatch import EthDispatcher
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
@@ -41,61 +45,43 @@ env = Environment(domain='eth', env=os.environ)
|
|||||||
|
|
||||||
arg_flags = chainlib.eth.cli.argflag_std_read
|
arg_flags = chainlib.eth.cli.argflag_std_read
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||||
argparser.add_argument('--data-dir', type=str, help='data directory')
|
|
||||||
argparser.add_argument('--runtime-dir', type=str, help='runtime directory')
|
queue_arg_flags = 0
|
||||||
argparser.add_argument('--session-id', dest='session_id', type=str, help='session identifier')
|
chainqueue.cli.process_flags(argparser, queue_arg_flags)
|
||||||
argparser.add_argument('--dispatch-delay', dest='dispatch_delay', type=float, help='socket timeout before processing queue')
|
|
||||||
|
local_arg_flags = chaind.cli.argflag_local_base | chaind.cli.ChaindFlag.DISPATCH | chaind.cli.ChaindFlag.SOCKET
|
||||||
|
chaind.cli.process_flags(argparser, local_arg_flags)
|
||||||
|
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
extra_args = {
|
|
||||||
'runtime_dir': 'SESSION_RUNTIME_DIR',
|
|
||||||
'data_dir': 'SESSION_DATA_DIR',
|
|
||||||
'session_id': 'SESSION_ID',
|
|
||||||
'dispatch_delay': 'SESSION_DISPATCH_DELAY',
|
|
||||||
}
|
|
||||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, base_config_dir=config_dir)
|
|
||||||
|
|
||||||
logg.debug('session id {} {}'.format(type(config.get('SESSION_ID')), config.get('SESSION_ID')))
|
|
||||||
if config.get('SESSION_ID') == None:
|
|
||||||
config.add(env.session, 'SESSION_ID', exists_ok=True)
|
|
||||||
if config.get('SESSION_RUNTIME_DIR') == None:
|
|
||||||
config.add(env.runtime_dir, 'SESSION_RUNTIME_DIR', exists_ok=True)
|
|
||||||
if config.get('SESSION_DATA_DIR') == None:
|
|
||||||
config.add(env.data_dir, 'SESSION_DATA_DIR', exists_ok=True)
|
|
||||||
if not config.get('SESSION_SOCKET_PATH'):
|
|
||||||
socket_path = os.path.join(config.get('SESSION_RUNTIME_DIR'), config.get('SESSION_ID'), 'chaind.sock')
|
|
||||||
config.add(socket_path, 'SESSION_SOCKET_PATH', True)
|
|
||||||
|
|
||||||
|
base_config_dir = [chainqueue.cli.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 = chainqueue.cli.process_config(config, args, queue_arg_flags)
|
||||||
|
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))
|
||||||
|
|
||||||
def process_outgoing(chain_spec, adapter, rpc, limit=100):
|
settings = ChaindEthSettings(include_queue=True)
|
||||||
upcoming = adapter.upcoming()
|
settings.process(config)
|
||||||
logg.info('process {} {} {}'.format(chain_spec, adapter, rpc))
|
|
||||||
logg.info('upcoming {}'.format(upcoming))
|
|
||||||
i = 0
|
|
||||||
for tx_hash in upcoming:
|
|
||||||
if adapter.dispatch(tx_hash):
|
|
||||||
i += 1
|
|
||||||
return i
|
|
||||||
|
|
||||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
logg.debug('settings:\n{}'.format(settings))
|
||||||
|
|
||||||
rpc = chainlib.eth.cli.Rpc()
|
rpc = chainlib.eth.cli.Rpc()
|
||||||
conn = rpc.connect_by_config(config)
|
conn = rpc.connect_by_config(config)
|
||||||
|
|
||||||
tx_normalizer = TxHexNormalizer().tx_hash
|
tx_normalizer = TxHexNormalizer().tx_hash
|
||||||
token_cache_store = CacheTokenTx(chain_spec, normalizer=tx_normalizer)
|
token_cache_store = CacheTokenTx(settings.get('CHAIN_SPEC'), normalizer=tx_normalizer)
|
||||||
dispatcher = EthDispatcher(conn)
|
|
||||||
queue_adapter = ChaindFsAdapter(
|
dispatcher = EthDispatcher(conn)
|
||||||
chain_spec,
|
processor = DispatchProcessor(settings.get('CHAIN_SPEC'), settings.dir_for('queue'), dispatcher)
|
||||||
config.get('SESSION_DATA_DIR'),
|
ctrl = SessionController(settings, processor.process)
|
||||||
EthCacheTx,
|
|
||||||
dispatcher,
|
|
||||||
)
|
|
||||||
|
|
||||||
ctrl = SessionController(config, queue_adapter, process_outgoing)
|
|
||||||
signal.signal(signal.SIGINT, ctrl.shutdown)
|
signal.signal(signal.SIGINT, ctrl.shutdown)
|
||||||
signal.signal(signal.SIGTERM, ctrl.shutdown)
|
signal.signal(signal.SIGTERM, ctrl.shutdown)
|
||||||
|
|
||||||
|
logg.info('session id is ' + settings.get('SESSION_ID'))
|
||||||
|
logg.info('session socket path is ' + settings.get('SESSION_SOCKET_PATH'))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
while True:
|
while True:
|
||||||
@@ -116,6 +102,14 @@ def main():
|
|||||||
ctrl.process(conn)
|
ctrl.process(conn)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
queue_adapter = ChaindFsAdapter(
|
||||||
|
settings.get('CHAIN_SPEC'),
|
||||||
|
settings.dir_for('queue'),
|
||||||
|
EthCacheTx,
|
||||||
|
dispatcher,
|
||||||
|
store_sync=False,
|
||||||
|
)
|
||||||
|
|
||||||
result_data = None
|
result_data = None
|
||||||
r = 0 # no error
|
r = 0 # no error
|
||||||
try:
|
try:
|
||||||
@@ -10,6 +10,8 @@ import socket
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
|
import chainqueue.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 +26,41 @@ 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.ChaindFlag.TOKEN
|
||||||
|
chaind.cli.process_flags(argparser, local_arg_flags)
|
||||||
|
|
||||||
|
chainqueue.cli.process_flags(argparser, 0)
|
||||||
|
|
||||||
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, chainqueue.cli.config_dir]
|
||||||
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, base_config_dir=base_config_dir)
|
||||||
|
config = chainqueue.cli.process_config(config, args, 0)
|
||||||
|
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 +69,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
|
||||||
@@ -82,11 +93,25 @@ if config.get('_SOURCE') == None:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
class SocketSender:
|
||||||
|
|
||||||
|
def __init__(self, settings):
|
||||||
|
self.path = settings.get('SESSION_SOCKET_PATH')
|
||||||
|
|
||||||
|
def send(self, tx):
|
||||||
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
s.connect(self.path)
|
||||||
|
s.sendall(tx.encode('utf-8'))
|
||||||
|
r = s.recv(68)
|
||||||
|
s.close()
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
token_resolver = None
|
token_resolver = None
|
||||||
if config.get('TOKEN_MODULE') != None:
|
if settings.get('TOKEN_MODULE') != None:
|
||||||
import importlib
|
import importlib
|
||||||
m = importlib.import_module(config.get('TOKEN_MODULE'))
|
m = importlib.import_module(settings.get('TOKEN_MODULE'))
|
||||||
m = m.TokenResolver
|
m = m.TokenResolver
|
||||||
else:
|
else:
|
||||||
from chaind.eth.token.gas import GasTokenResolver
|
from chaind.eth.token.gas import GasTokenResolver
|
||||||
@@ -103,6 +128,11 @@ def main():
|
|||||||
sys.stderr.write('processing error: {}. processors: {}\n'.format(str(e), str(processor)))
|
sys.stderr.write('processing error: {}. processors: {}\n'.format(str(e), str(processor)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
sender = None
|
||||||
|
if config.true('_SOCKET_SEND'):
|
||||||
|
if settings.get('SESSION_SOCKET_PATH') != None:
|
||||||
|
sender = SocketSender(settings)
|
||||||
|
|
||||||
tx_iter = iter(processor)
|
tx_iter = iter(processor)
|
||||||
out = Outputter(mode)
|
out = Outputter(mode)
|
||||||
while True:
|
while True:
|
||||||
@@ -112,6 +142,9 @@ def main():
|
|||||||
except StopIteration:
|
except StopIteration:
|
||||||
break
|
break
|
||||||
tx_hex = tx_bytes.hex()
|
tx_hex = tx_bytes.hex()
|
||||||
|
if sender != None:
|
||||||
|
r = sender.send(tx_hex)
|
||||||
|
logg.info('sent {} result {}'.format(tx_hex, r))
|
||||||
print(out.do(tx_hex))
|
print(out.do(tx_hex))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,23 @@ import os
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import chainlib.eth.cli
|
import chainlib.cli
|
||||||
|
import chainsyncer.cli
|
||||||
|
import chaind.cli
|
||||||
from chaind.setup import Environment
|
from chaind.setup import Environment
|
||||||
from chaind.filter import StateFilter
|
from chaind.filter import StateFilter
|
||||||
from chaind.adapters.fs import ChaindFsAdapter
|
|
||||||
from chainlib.eth.block import block_latest
|
from chainlib.eth.block import block_latest
|
||||||
from chainlib.eth.connection import EthHTTPConnection
|
|
||||||
from chainlib.chain import ChainSpec
|
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chaind.eth.cache import EthCacheTx
|
from chaind.eth.cache import EthCacheTx
|
||||||
from chaind.eth.chain import EthChainInterface
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
@@ -26,91 +29,46 @@ config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
|||||||
|
|
||||||
env = Environment(domain='eth', env=os.environ)
|
env = Environment(domain='eth', env=os.environ)
|
||||||
|
|
||||||
arg_flags = chainlib.eth.cli.argflag_std_read
|
arg_flags = chainlib.cli.argflag_std_base | chainlib.cli.Flag.CHAIN_SPEC
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
argparser = chainlib.cli.ArgumentParser(arg_flags)
|
||||||
argparser.add_argument('--data-dir', type=str, help='data directory')
|
|
||||||
argparser.add_argument('--runtime-dir', type=str, help='runtime directory')
|
local_arg_flags = chaind.cli.argflag_local_base
|
||||||
argparser.add_argument('--session-id', dest='session_id', type=str, help='session identifier')
|
chaind.cli.process_flags(argparser, local_arg_flags)
|
||||||
argparser.add_argument('--dispatch-delay', dest='dispatch_delay', type=float, help='socket timeout before processing queue')
|
|
||||||
argparser.add_argument('--offset', type=int, default=0, help='Start sync on this block')
|
sync_flags = chainsyncer.cli.SyncFlag.RANGE | chainsyncer.cli.SyncFlag.HEAD
|
||||||
argparser.add_argument('--until', type=int, default=0, help='Terminate sync on this block')
|
chainsyncer.cli.process_flags(argparser, sync_flags)
|
||||||
argparser.add_argument('--head', action='store_true', help='Start at current block height (overrides --offset, assumes --keep-alive)')
|
|
||||||
argparser.add_argument('--keep-alive', action='store_true', dest='keep_alive', help='Continue to sync head after history sync complete')
|
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
extra_args = {
|
|
||||||
'runtime_dir': 'SESSION_RUNTIME_DIR',
|
|
||||||
'data_dir': 'SESSION_DATA_DIR',
|
|
||||||
'session_id': 'SESSION_ID',
|
|
||||||
'dispatch_delay': 'SESSION_DISPATCH_DELAY',
|
|
||||||
}
|
|
||||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, base_config_dir=config_dir)
|
|
||||||
|
|
||||||
logg.debug('session id {} {}'.format(type(config.get('SESSION_ID')), config.get('SESSION_ID')))
|
|
||||||
if config.get('SESSION_ID') == None:
|
|
||||||
config.add(env.session, 'SESSION_ID', exists_ok=True)
|
|
||||||
if config.get('SESSION_RUNTIME_DIR') == None:
|
|
||||||
config.add(env.runtime_dir, 'SESSION_RUNTIME_DIR', exists_ok=True)
|
|
||||||
if config.get('SESSION_DATA_DIR') == None:
|
|
||||||
config.add(env.data_dir, 'SESSION_DATA_DIR', exists_ok=True)
|
|
||||||
if not config.get('SESSION_SOCKET_PATH'):
|
|
||||||
socket_path = os.path.join(config.get('SESSION_RUNTIME_DIR'), config.get('SESSION_ID'), 'chaind.sock')
|
|
||||||
config.add(socket_path, 'SESSION_SOCKET_PATH', True)
|
|
||||||
config.add(args.keep_alive, '_KEEP_ALIVE', True)
|
|
||||||
config.add(args.head, '_HEAD', True)
|
|
||||||
config.add(args.offset, '_SYNC_OFFSET', True)
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
config.add('sync', 'CHAIND_COMPONENT', False)
|
||||||
logg.debug('config loaded:\n{}'.format(config))
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
|
|
||||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
settings = ChaindEthSettings(include_sync=True)
|
||||||
|
settings.process(config)
|
||||||
|
|
||||||
conn = EthHTTPConnection(url=config.get('RPC_PROVIDER'), chain_spec=chain_spec)
|
logg.debug('settings:\n{}'.format(settings))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
o = block_latest()
|
fltr = StateFilter(settings.get('CHAIN_SPEC'), settings.dir_for('queue'), EthCacheTx)
|
||||||
r = conn.do(o)
|
sync_store = SyncFsStore(settings.get('SESSION_DATA_DIR'), session_id=settings.get('SESSION_ID'))
|
||||||
block_offset = int(strip_0x(r), 16) + 1
|
|
||||||
logg.info('network block height is {}'.format(block_offset))
|
|
||||||
|
|
||||||
keep_alive = False
|
|
||||||
session_block_offset = 0
|
|
||||||
block_limit = 0
|
|
||||||
if args.head:
|
|
||||||
session_block_offset = block_offset
|
|
||||||
block_limit = -1
|
|
||||||
keep_alive = True
|
|
||||||
else:
|
|
||||||
session_block_offset = args.offset
|
|
||||||
|
|
||||||
if args.until > 0:
|
|
||||||
if not args.head and args.until <= session_block_offset:
|
|
||||||
raise ValueError('sync termination block number must be later than offset ({} >= {})'.format(session_block_offset, args.until))
|
|
||||||
block_limit = args.until
|
|
||||||
elif config.true('_KEEP_ALIVE'):
|
|
||||||
keep_alive=True
|
|
||||||
block_limit = -1
|
|
||||||
|
|
||||||
if session_block_offset == -1:
|
|
||||||
session_block_offset = block_offset
|
|
||||||
elif not config.true('_KEEP_ALIVE'):
|
|
||||||
if block_limit == 0:
|
|
||||||
block_limit = block_offset
|
|
||||||
|
|
||||||
queue_adapter = ChaindFsAdapter(
|
|
||||||
chain_spec,
|
|
||||||
config.get('SESSION_DATA_DIR'),
|
|
||||||
EthCacheTx,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
fltr = StateFilter(queue_adapter)
|
|
||||||
sync_store = SyncFsStore(config.get('SESSION_RUNTIME_DIR'), session_id=config.get('SESSION_ID'))
|
|
||||||
sync_store.register(fltr)
|
sync_store.register(fltr)
|
||||||
|
|
||||||
logg.debug('session block ofset {}'.format(session_block_offset))
|
logg.debug('session block offset {}'.format(settings.get('SYNCER_OFFSET')))
|
||||||
|
|
||||||
chain_interface = EthChainInterface()
|
drv = ChainInterfaceDriver(sync_store, settings.get('SYNCER_INTERFACE'), offset=settings.get('SYNCER_OFFSET'), target=settings.get('SYNCER_LIMIT'))
|
||||||
drv = ChainInterfaceDriver(sync_store, chain_interface, offset=session_block_offset, target=block_limit)
|
try:
|
||||||
drv.run(conn)
|
drv.run(settings.get('RPC'))
|
||||||
|
except SyncDone as e:
|
||||||
|
logg.info('sync done: {}'.format(e))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
18
chaind/eth/settings.py
Normal file
18
chaind/eth/settings.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# external imports
|
||||||
|
from chainlib.eth.connection import EthHTTPConnection
|
||||||
|
from chaind.settings import ChaindSettings
|
||||||
|
from chaind.eth.chain import EthChainInterface
|
||||||
|
|
||||||
|
|
||||||
|
class ChaindEthSettings(ChaindSettings):
|
||||||
|
|
||||||
|
def process_sync_interface(self, config):
|
||||||
|
self.o['SYNCER_INTERFACE'] = EthChainInterface()
|
||||||
|
|
||||||
|
|
||||||
|
def process_common(self, config):
|
||||||
|
super(ChaindEthSettings, self).process_common(config)
|
||||||
|
rpc_provider = config.get('RPC_PROVIDER')
|
||||||
|
if rpc_provider == None:
|
||||||
|
rpc_provider = 'http://localhost:8545'
|
||||||
|
self.o['RPC'] = EthHTTPConnection(url=rpc_provider, chain_spec=self.o['CHAIN_SPEC'])
|
||||||
@@ -9,7 +9,7 @@ logg = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class BaseTokenResolver:
|
class BaseTokenResolver:
|
||||||
|
|
||||||
def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle):
|
def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle, advance_nonce=False):
|
||||||
self.chain_spec = chain_spec
|
self.chain_spec = chain_spec
|
||||||
self.chain_id = chain_spec.chain_id()
|
self.chain_id = chain_spec.chain_id()
|
||||||
self.signer = signer
|
self.signer = signer
|
||||||
@@ -19,6 +19,10 @@ class BaseTokenResolver:
|
|||||||
self.factory = None
|
self.factory = None
|
||||||
self.gas_limit_start = None
|
self.gas_limit_start = None
|
||||||
self.gas_price_start = None
|
self.gas_price_start = None
|
||||||
|
if advance_nonce:
|
||||||
|
self.nonce_getter = self.nonce_oracle.next_nonce
|
||||||
|
else:
|
||||||
|
self.nonce_getter = self.nonce_oracle.get_nonce
|
||||||
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
@@ -28,7 +32,7 @@ class BaseTokenResolver:
|
|||||||
|
|
||||||
|
|
||||||
def get_values(self, gas_value, value, executable_address=None):
|
def get_values(self, gas_value, value, executable_address=None):
|
||||||
nonce = self.nonce_oracle.next_nonce()
|
nonce = self.nonce_getter()
|
||||||
|
|
||||||
if executable_address == None:
|
if executable_address == None:
|
||||||
return (value, 0, nonce)
|
return (value, 0, nonce)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from chaind.eth.token import BaseTokenResolver
|
|||||||
class GasTokenResolver(BaseTokenResolver):
|
class GasTokenResolver(BaseTokenResolver):
|
||||||
|
|
||||||
def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle):
|
def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle):
|
||||||
super(GasTokenResolver, self).__init__(chain_spec, sender, signer, gas_oracle, nonce_oracle)
|
super(GasTokenResolver, self).__init__(chain_spec, sender, signer, gas_oracle, nonce_oracle, advance_nonce=True)
|
||||||
self.factory = Gas(self.chain_spec, signer=self.signer, gas_oracle=self.gas_oracle, nonce_oracle=self.nonce_oracle)
|
self.factory = Gas(self.chain_spec, signer=self.signer, gas_oracle=self.gas_oracle, nonce_oracle=self.nonce_oracle)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
chaind~=0.1.0
|
chaind~=0.2.4
|
||||||
hexathon~=0.1.5
|
hexathon~=0.1.5
|
||||||
chainlib-eth~=0.1.0
|
chainlib-eth~=0.1.1
|
||||||
pyxdg~=0.27
|
pyxdg~=0.27
|
||||||
shep~=0.2.3
|
shep~=0.2.5
|
||||||
funga-eth~=0.6.0
|
funga-eth~=0.6.0
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = chaind-eth
|
name = chaind-eth
|
||||||
version = 0.1.0
|
version = 0.2.2
|
||||||
description = Queue server for ethereum
|
description = Queue server for ethereum
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
@@ -31,10 +31,11 @@ packages =
|
|||||||
chaind.eth
|
chaind.eth
|
||||||
chaind.eth.runnable
|
chaind.eth.runnable
|
||||||
chaind.eth.cli
|
chaind.eth.cli
|
||||||
|
chaind.eth.token
|
||||||
|
|
||||||
[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
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -27,7 +27,7 @@ while True:
|
|||||||
l = f.readline()
|
l = f.readline()
|
||||||
if l == '':
|
if l == '':
|
||||||
break
|
break
|
||||||
test_requirements.append(l.rstrip())
|
erc20_requirements.append(l.rstrip())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Chainqueue transaction dispatch interface
|
Description=Chainqueue transaction dispatch interface
|
||||||
Requires=chaind-eth-sync@.service
|
#Requires=chaind-eth-sync@.service
|
||||||
After=chaind-eth-sync@.service
|
#After=chaind-eth-sync@.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Environment="SESSION_ID=%i"
|
Environment="SESSION_ID=%i"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from chainlib.chain import ChainSpec
|
|||||||
from chainqueue.cache import CacheTokenTx
|
from chainqueue.cache import CacheTokenTx
|
||||||
from chainlib.error import RPCException
|
from chainlib.error import RPCException
|
||||||
from chainlib.status import Status as TxStatus
|
from chainlib.status import Status as TxStatus
|
||||||
from chaind.unittest.common import TestChaindFsBase
|
from chaind.unittest.fs import TestChaindFsBase
|
||||||
from chaind.driver import QueueDriver
|
from chaind.driver import QueueDriver
|
||||||
from chaind.filter import StateFilter
|
from chaind.filter import StateFilter
|
||||||
from chainlib.eth.gas import Gas
|
from chainlib.eth.gas import Gas
|
||||||
|
|||||||
Reference in New Issue
Block a user