commit 800b70680bead69612a71d8edd907ee5c9bfea69
parent e54f03a8f66d9ed0da057cd3d785db4cb86d8a79
Author: lash <dev@holbrook.no>
Date: Wed, 27 Apr 2022 06:29:46 +0000
Improve data dir generation, improve socket settings handling
Diffstat:
7 files changed, 40 insertions(+), 19 deletions(-)
diff --git a/chaind/adapters/fs.py b/chaind/adapters/fs.py
@@ -28,7 +28,6 @@ class ChaindFsAdapter(ChaindAdapter):
def put(self, signed_tx):
- #cache_tx = self.deserialize(signed_tx)
(s, tx_hash,) = self.store.put(signed_tx, cache_adapter=self.cache_adapter)
return tx_hash
diff --git a/chaind/cli/arg.py b/chaind/cli/arg.py
@@ -2,10 +2,16 @@
from .base import ChaindFlag
def process_flags(argparser, flags):
- if flags & ChaindFlag.SESSION:
+ if flags & ChaindFlag.SESSION > 0:
argparser.add_argument('--session-id', dest='session_id', type=str, help='Session to store state and data under')
argparser.add_argument('--runtime-dir', dest='runtime_dir', type=str, help='Directory to store volatile data')
argparser.add_argument('--data-dir', dest='data_dir', type=str, help='Directory to store persistent data')
- if flags & ChaindFlag.SOCKET:
- argparser.add_argument('--socket', type=str, help='Socket path to send transactions to (assumes -s).')
+ if flags & ChaindFlag.SOCKET > 0:
+ argparser.add_argument('--socket-path', dest='socket', type=str, help='UNIX socket path')
+
+ if flags & ChaindFlag.SOCKET_CLIENT > 0:
+ argparser.add_argument('--send-socket', dest='socket_send', action='store_true', help='Send to UNIX socket')
+
+ if flags & ChaindFlag.TOKEN > 0:
+ argparser.add_argument('--token-module', dest='token_module', type=str, help='Python module path to resolve tokens from identifiers')
diff --git a/chaind/cli/base.py b/chaind/cli/base.py
@@ -4,7 +4,10 @@ import enum
class ChaindFlag(enum.IntEnum):
SESSION = 1
- DISPATCH = 512
- SOCKET = 4096
+ DISPATCH = 2
+ SOCKET = 16
+ SOCKET_CLIENT = 32
+ TOKEN = 256
argflag_local_base = ChaindFlag.SESSION
+argflag_local_socket_client = ChaindFlag.SESSION | ChaindFlag.SOCKET | ChaindFlag.SOCKET_CLIENT
diff --git a/chaind/cli/config.py b/chaind/cli/config.py
@@ -3,15 +3,21 @@ from chaind.cli import ChaindFlag
def process_config(config, args, flags):
- args_override = {}
- if flags & ChaindFlag.SESSION:
- args_override['SESSION_ID'] = getattr(args, 'session_id')
- args_override['SESSION_RUNTIME_DIR'] = getattr(args, 'runtime_dir')
- args_override['SESSION_DATA_DIR'] = getattr(args, 'data_dir')
+ args_override = {}
+ if flags & ChaindFlag.SESSION:
+ args_override['SESSION_ID'] = getattr(args, 'session_id')
+ args_override['SESSION_RUNTIME_DIR'] = getattr(args, 'runtime_dir')
+ args_override['SESSION_DATA_DIR'] = getattr(args, 'data_dir')
- if flags & ChaindFlag.SOCKET:
- args_override['SESSION_SOCKET_PATH'] = getattr(args, 'socket')
+ if flags & ChaindFlag.SOCKET:
+ args_override['SESSION_SOCKET_PATH'] = getattr(args, 'socket')
- config.dict_override(args_override, 'local cli args')
+ if flags & ChaindFlag.TOKEN:
+ args_override['TOKEN_MODULE'] = getattr(args, 'token_module')
- return config
+ config.dict_override(args_override, 'local cli args')
+
+ if flags & ChaindFlag.SOCKET_CLIENT:
+ config.add(getattr(args, 'socket_send'), '_SOCKET_SEND', False)
+
+ return config
diff --git a/chaind/data/config/config.ini b/chaind/data/config/config.ini
@@ -3,3 +3,4 @@ socket_path =
runtime_dir =
id =
data_dir =
+
diff --git a/chaind/filter.py b/chaind/filter.py
@@ -21,6 +21,7 @@ class StateFilter(SyncFilter):
except NotLocalTxError:
logg.debug('skipping not local transaction {}'.format(tx.hash))
return False
+
if tx.status == TxStatus.SUCCESS:
self.adapter.succeed(block, tx)
else:
diff --git a/chaind/settings.py b/chaind/settings.py
@@ -1,6 +1,7 @@
# standard imports
import logging
import os
+import uuid
# external imports
from chainlib.chain import ChainSpec
@@ -20,9 +21,8 @@ class ChaindSettings(ChainsyncerSettings):
def process_common(self, config):
self.o['CHAIN_SPEC'] = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
- self.o['SOCKET_PATH'] = config.get('SESSION_SOCKET_PATH')
-
+
def process_session(self, config):
session_id = config.get('SESSION_ID')
@@ -55,7 +55,7 @@ class ChaindSettings(ChainsyncerSettings):
fp = os.path.join(data_engine_dir, 'default')
os.symlink(session_dir, fp)
- data_dir = os.path.join(session_dir, 'sync')
+ data_dir = os.path.join(session_dir, config.get('CHAIND_COMPONENT'))
os.makedirs(data_dir, exist_ok=True)
# create volatile dir
@@ -63,10 +63,11 @@ class ChaindSettings(ChainsyncerSettings):
runtime_dir = config.get('SESSION_RUNTIME_DIR')
if runtime_dir == None:
runtime_dir = os.path.join('/run', 'user', str(uid), 'chaind')
- runtime_dir = os.path.join(runtime_dir, config.get('CHAIND_ENGINE'), session_id, 'sync')
+ runtime_dir = os.path.join(runtime_dir, config.get('CHAIND_ENGINE'), session_id, config.get('CHAIND_COMPONENT'))
os.makedirs(runtime_dir, exist_ok=True)
self.o['SESSION_RUNTIME_DIR'] = runtime_dir
+ self.o['SESSION_DIR'] = session_dir
self.o['SESSION_DATA_DIR'] = data_dir
self.o['SESSION_ID'] = session_id
@@ -101,6 +102,10 @@ class ChaindSettings(ChainsyncerSettings):
self.process_dispatch(config)
+ def dir_for(self, k):
+ return os.path.join(self.o['SESSION_DIR'], k)
+
+
def __str__(self):
ks = list(self.o.keys())
ks.sort()