Compare commits

..

18 Commits

Author SHA1 Message Date
lash
c360edbf75
Change license classifier 2022-11-14 08:13:25 +00:00
lash
96cc0e2c3c
Change license to AGPL3, waive copyright 2022-11-14 07:38:34 +00:00
lash
443e64f3e9
Add chain spec parts to session paths 2022-05-15 11:32:42 +00:00
lash
bb5e0b359f
Bump deps 2022-05-14 16:24:03 +00:00
lash
8bc49e7408
Bump minor version 2022-05-14 16:22:40 +00:00
lash
c83aade144
Add data config path module 2022-05-14 12:40:21 +00:00
lash
63a1d07a28
Update dir arg destinations in config handle 2022-05-14 12:39:53 +00:00
lash
6da2a1ced9
Update config processing 2022-05-14 12:24:24 +00:00
lash
9f2a791b1f
Update state config names, remove dead code 2022-05-13 13:47:11 +00:00
lash
ba894044d8
Remove redundant chaind init file 2022-05-13 10:35:21 +00:00
lash
e5a18d1abf
Make flag and arg preparations stateless 2022-05-13 10:32:56 +00:00
lash
139e2772af
Implement settings processing on chainlib 0.3.0 structure 2022-05-13 09:40:18 +00:00
lash
0a5818ebf1
Update settings for queue and syncer 2022-05-10 06:13:56 +00:00
lash
5d2d73fa64
Upgrade chainqueue, chainsyncer 2022-05-09 19:44:28 +00:00
lash
dd1879bb91
Implement mocks on generic tx, block 2022-05-09 19:25:31 +00:00
lash
e264ed5c37
Upgrade deps, to avoid shep sync on persist set 2022-05-05 17:08:09 +00:00
lash
d472bd4f7c
Upgrade deps, handle filestore list exception in shep 2022-05-05 15:41:30 +00:00
lash
465d692956
Upgrade deps 2022-05-05 15:02:21 +00:00
16 changed files with 297 additions and 244 deletions

View File

@ -1,3 +1,14 @@
- 0.3.1
* Change license to AGPL3 and copyright waived to public domain
- 0.3.0
* Implement on chainlib 0.3.0
- 0.2.12
* Breaking upgrade of chainlib.
* Implement generic block and tx.
- 0.2.11
* Upgrade shep to handle exception in filestore list
- 0.2.10
* Upgrade shep to guarantee state lock atomicity
- 0.2.9
* Minimize instantiations of adapters in filter execution
- 0.2.8

141
LICENSE
View File

@ -1,5 +1,5 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
@ -7,17 +7,15 @@
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
@ -26,44 +24,34 @@ them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
@ -72,7 +60,7 @@ modification follow.
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
@ -549,35 +537,45 @@ to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
@ -635,40 +633,29 @@ the "copyright" line and a pointer to where the full notice is found.
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View File

@ -1 +1 @@
include *requirements.txt chaind/data/config/* chaind/data/config/syncer/*
include *requirements.txt LICENSE WAIVER WAIVER.asc CHANGELOG chaind/data/config/* chaind/data/config/syncer/*

17
WAIVER Normal file
View File

@ -0,0 +1,17 @@
# Copyright waiver for the python package "chaind"
I dedicate any and all copyright interest in this software to the
public domain. I make this dedication for the benefit of the public at
large and to the detriment of my heirs and successors. I intend this
dedication to be an overt act of relinquishment in perpetuity of all
present and future rights to this software under copyright law.
To the best of my knowledge and belief, my contributions are either
originally authored by me or are derived from prior works which I have
verified are also in the public domain and are not subject to claims
of copyright by other parties.
To the best of my knowledge and belief, no individual, business,
organization, government, or other entity has any copyright interest
in my contributions, and I affirm that I will not make contributions
that are otherwise encumbered.

28
WAIVER.asc Normal file
View File

@ -0,0 +1,28 @@
-----BEGIN PGP MESSAGE-----
owGVU2tQVFUcX0BkvY6jTQFjBJ4FA2tWgl6YyZLD8BIFiYeQOXT37lnuifviPnbd
AkIweRnhCAbpEDBWyHNsoJkm0QYICpTZScIv4IAPHlEqZTU0gp27C2r1qQ87s/ee
///3PLdynZtG66L7Yfrrkp7Po13a3Djj6n0749KiXqdybl8KAJG8YBNRFi0DK4ks
UARmXgQyDYFgk2meAwJJZZNZEPhTNIk4kz9BxAETNCGKlCEgORv+mQDJMIB6AIQ4
GYpQUv9gJCQBiTfLVlKEQOZVaEJQjAyigIlnMWQwiAMsmQ2do8vQCDOvCDFCDpqR
DHizU5dzmZQJhhSzoIPfiYuXZRGxkHPMsjZAQyRKjgFJoSgoSbwoqXSqQHULExKP
EGIUo4oHeJyDDEjKgSNCBnE5CpJoBzL2JEBRgLKCZJt6jr0TArarHqpUZkVWsFVH
FJJT2aMRKJwJh/wwLIa0BhNECr9sVVrRns3xVgaalg0asQho1qsHFM9hl0ZFlYzN
YUiI8K5I8BgQcVgO7kTB3YkQ79kACwEOUp3DxLhhrFDkWSCICL+28mK2BKw0omic
C01aIIG9IzPCY+oKyUi8s8YHwTtbc9aOJzhexuka34Y4LWyWYkjESgT28NAiFsGr
CvFdEmUEpf/hl1PZTciCTArJ6IFRkRCHe9Rjs1kkh95xFKcHWWpjnNqPXjXrZMNP
akU0KTnu6X/vJ4Ft/DtQvYM+DpBmMxJZLJKU8ZMV4QuuOnVc1H8sEI4RNQkHqxVJ
uBCOUlgj5jAFE6WuL6zSuGg1vl66VdrAXxqErX7F/deKk1a+SHdX9TvUEGs2rLz5
8sT6++kJ1+OPLe74jGlMjj5M+Obp7L+3921dXaWZ+Nk7sN2jubh1Ls/65kD5YCIb
USRMCEc2kImvFBYacgOT6wa1jQHD9ry5xYqhvu+fGR5dd4jtqk+3HCBTH6ub3p17
cMvuK4XdMaGV8wl0WpR7fG3DpwtTZ5VWu2z5KPPdn5gztye3HzxRWlrt1x4WuQf2
pUy2E6H+sSdv2OHxXV0ex9tCaWlpku5cmz9U00nQixUdcWlzpfaRJ+WWWo/W87MX
N22M6j2WEX0+vSCiXvx4gyE/dn/NtpHMsjtrqmPGerq2B53y/OTH2VsGw+jpirVF
C6476QmXHZqae16VS2dto/xTTQfSzK9e0Dz3wRSXOfINsfelsj/aky2DxTfOlX8X
YprouzCli6mN+O3Zy8arh2D9E/d3hRf4Td1L6Viafc0eftJt/nSnT0vWW3HMuSt3
iyuo8Nw/xzx9P2wzzle5N5fHdGi/8Aj71hIemxLi4v3r0eTJJK/h1CbLzaKBW2Tr
V4szM1pD0+XenIik2fUNOqH5TC/dFTXSX7kxhKpyObLp5Yp9wYk+qfnTGd3XDFzH
4Za/xsf33DW835bSe9Q7drNWDHtxf+1A/RsLngWFmrSJgchTnmU943XRNwu6rzam
PG5IzEhYuFMyu6Vy296gGh82ngvo181cD4p+enNDbmGJUG26NDT8fMbF98b+Bg==
=vZcN
-----END PGP MESSAGE-----

View File

@ -1,12 +0,0 @@
# standard imports
import os
# local imports
from .base import *
from .arg import process_flags
from .config import process_config
__script_dir = os.path.dirname(os.path.realpath(__file__))
data_dir = os.path.join(os.path.dirname(__script_dir), 'data')
config_dir = os.path.join(data_dir, 'config')

View File

@ -1,17 +1,19 @@
# local imports
from .base import ChaindFlag
def apply_flag(flag):
flag.add('session')
flag.add('dispatch')
flag.add('socket')
flag.add('socket_client')
flag.add('token')
def process_flags(argparser, flags):
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')
flag.alias('chaind_base', 'session')
flag.alias('chaind_socket_client', 'session', 'socket', 'socket_client')
if flags & ChaindFlag.SOCKET > 0:
argparser.add_argument('--socket-path', dest='socket', type=str, help='UNIX socket path')
return flag
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')
def apply_arg(arg):
arg.add_long('session-id', 'session', help='Session to store state and data under')
arg.add_long('socket-path', 'socket', help='UNIX socket path')
arg.add_long('send-socket', 'socket_client', typ=bool, help='Send to UNIX socket')
arg.add_long('token-module', 'token', help='Python module path to resolve tokens from identifiers')
return arg

View File

@ -1,23 +1,19 @@
# external imports
from chaind.cli import ChaindFlag
def process_config(config, args, flags):
def process_config(config, arg, args, flags):
args_override = {}
if flags & ChaindFlag.SESSION:
if arg.match('session', flags):
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['SESSION_RUNTIME_DIR'] = getattr(args, 'runtime_path')
args_override['SESSION_DATA_DIR'] = getattr(args, 'state_path')
if flags & ChaindFlag.SOCKET:
if arg.match('socket', flags):
args_override['SESSION_SOCKET_PATH'] = getattr(args, 'socket')
if flags & ChaindFlag.TOKEN:
if arg.match('token', flags):
args_override['TOKEN_MODULE'] = getattr(args, 'token_module')
config.dict_override(args_override, 'local cli args')
if flags & ChaindFlag.SOCKET_CLIENT:
config.add(getattr(args, 'socket_send'), '_SOCKET_SEND', False)
if arg.match('socket_client', flags):
config.add(getattr(args, 'send_socket'), '_SOCKET_SEND', False)
return config

6
chaind/data/__init__.py Normal file
View File

@ -0,0 +1,6 @@
# standard imports
import os
data_dir = os.path.realpath(os.path.dirname(__file__))
config_dir = os.path.join(data_dir, 'config')

View File

@ -1,5 +1,5 @@
[session]
socket_path =
runtime_dir =
runtime_path =
id =
data_dir =
data_path =

View File

@ -76,7 +76,6 @@ class StateFilter(SyncFilter):
break
except NotLocalTxError:
logg.debug('skipping not local transaction {}'.format(tx.hash))
self.__stop_adapter()
return False
except BackendError as e:
logg.error('adapter get failed: {}, one more try'.format(e))
@ -116,7 +115,7 @@ class StateFilter(SyncFilter):
queue_adapter = self.__get_adapter(block, force_reload=True)
continue
logg.info('filter registered {} for {} in {}'.format(tx.status.name, tx.hash, block))
logg.info('filter registered {} for {} in {}'.format(tx.status_name, tx.hash, block))
if self.throttler != None:
self.throttler.dec(tx.hash)

View File

@ -4,122 +4,123 @@ import os
import uuid
# external imports
from chainsyncer.settings import ChainsyncerSettings
from chainqueue.settings import ChainqueueSettings
from chainlib.settings import ChainSettings
from chainqueue.settings import *
logg = logging.getLogger(__name__)
class ChaindSettings(ChainsyncerSettings, ChainqueueSettings):
class ChaindSettings(ChainSettings):
def __init__(self, include_sync=False, include_queue=False):
super(ChaindSettings, self).__init__()
self.include_sync = include_sync
self.include_queue = include_queue
def process_session(self, config):
session_id = config.get('SESSION_ID')
base_dir = os.getcwd()
data_dir = config.get('SESSION_DATA_DIR')
if data_dir == None:
data_dir = os.path.join(base_dir, '.chaind', 'chaind', self.o.get('CHAIND_BACKEND'))
data_engine_dir = os.path.join(data_dir, config.get('CHAIND_ENGINE'))
os.makedirs(data_engine_dir, exist_ok=True)
# check if existing session
if session_id == None:
fp = os.path.join(data_engine_dir, 'default')
try:
os.stat(fp)
fp = os.path.realpath(fp)
except FileNotFoundError:
fp = None
if fp != None:
session_id = os.path.basename(fp)
make_default = False
if session_id == None:
session_id = str(uuid.uuid4())
make_default = True
# create the session persistent dir
session_dir = os.path.join(data_engine_dir, session_id)
if make_default:
fp = os.path.join(data_engine_dir, 'default')
os.symlink(session_dir, fp)
#data_dir = os.path.join(session_dir, config.get('CHAIND_COMPONENT'))
data_dir = session_dir
os.makedirs(data_dir, exist_ok=True)
# create volatile dir
uid = os.getuid()
runtime_dir = config.get('SESSION_RUNTIME_DIR')
if runtime_dir == None:
runtime_dir = os.path.join('/run', 'user', str(uid), 'chaind', self.o.get('CHAIND_BACKEND'))
#runtime_dir = os.path.join(runtime_dir, config.get('CHAIND_ENGINE'), session_id, config.get('CHAIND_COMPONENT'))
runtime_dir = os.path.join(runtime_dir, config.get('CHAIND_ENGINE'), session_id)
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
def process_sync_interface(self, config):
raise NotImplementedError('no sync interface implementation defined')
def process_sync(self, config):
self.process_sync_interface(config)
self.process_sync_range(config)
def process_socket(self, config):
socket_path = config.get('SESSION_SOCKET_PATH')
if socket_path == None:
socket_path = os.path.join(self.o['SESSION_RUNTIME_DIR'], 'chaind.sock')
self.o['SESSION_SOCKET_PATH'] = socket_path
def process_dispatch(self, config):
self.o['SESSION_DISPATCH_DELAY'] = 0.01
def process_token(self, config):
self.o['TOKEN_MODULE'] = config.get('TOKEN_MODULE')
def process_backend(self, config):
if self.include_sync and self.include_queue:
if self.o['QUEUE_BACKEND'] != self.o['SYNCER_BACKEND']:
raise ValueError('queue and syncer backends must match. queue "{}" != syncer "{}"'.format(self.o['QUEUE_BACKEND'], self.o['SYNCER_BACKEND']))
self.o['CHAIND_BACKEND'] = self.o['SYNCER_BACKEND']
elif self.include_sync:
self.o['CHAIND_BACKEND'] = self.o['SYNCER_BACKEND']
elif self.include_queue:
self.o['CHAIND_BACKEND'] = self.o['QUEUE_BACKEND']
else:
raise ValueError('at least one backend must be set')
def process(self, config):
super(ChaindSettings, self).process(config)
if self.include_sync:
self.process_sync(config)
self.process_sync_backend(config)
if self.include_queue:
self.process_queue_backend(config)
self.process_dispatch(config)
self.process_token(config)
self.process_backend(config)
self.process_session(config)
self.process_socket(config)
def __init__(settings, include_sync=False, include_queue=False):
super(ChaindSettings, settings).__init__()
settings.include_sync = include_sync
settings.include_queue = include_queue
def dir_for(self, k):
return os.path.join(self.o['SESSION_DIR'], k)
return os.path.join(self.o['SESSION_PATH'], k)
def process_session(settings, config):
session_id = config.get('SESSION_ID')
base_dir = os.getcwd()
data_dir = config.get('SESSION_DATA_PATH')
if data_dir == None:
data_dir = os.path.join(base_dir, '.chaind', 'chaind', settings.get('CHAIND_BACKEND'))
data_engine_dir = os.path.join(data_dir, config.get('CHAIND_ENGINE'))
os.makedirs(data_engine_dir, exist_ok=True)
# check if existing session
if session_id == None:
fp = os.path.join(data_engine_dir, 'default')
try:
os.stat(fp)
fp = os.path.realpath(fp)
except FileNotFoundError:
fp = None
if fp != None:
session_id = os.path.basename(fp)
make_default = False
if session_id == None:
session_id = str(uuid.uuid4())
make_default = True
chain_spec = settings.get('CHAIN_SPEC')
network_id_str = str(chain_spec.network_id())
# create the session persistent dir
session_path = os.path.join(
data_engine_dir,
chain_spec.arch(),
chain_spec.fork(),
network_id_str,
session_id,
)
if make_default:
fp = os.path.join(data_engine_dir, 'default')
os.symlink(session_path, fp)
data_path = session_path
os.makedirs(data_path, exist_ok=True)
# create volatile dir
uid = os.getuid()
runtime_path = config.get('SESSION_RUNTIME_PATH')
if runtime_path == None:
runtime_path = os.path.join('/run', 'user', str(uid), 'chaind', settings.get('CHAIND_BACKEND'))
runtime_path = os.path.join(
runtime_path,
config.get('CHAIND_ENGINE'),
chain_spec.arch(),
chain_spec.fork(),
str(chain_spec.network_id()),
session_id,
)
os.makedirs(runtime_path, exist_ok=True)
settings.set('SESSION_RUNTIME_PATH', runtime_path)
settings.set('SESSION_PATH', session_path)
settings.set('SESSION_DATA_PATH', data_path)
settings.set('SESSION_ID', session_id)
return settings
def process_socket(settings, config):
socket_path = config.get('SESSION_SOCKET_PATH')
if socket_path == None:
socket_path = os.path.join(settings.get('SESSION_RUNTIME_PATH'), 'chaind.sock')
settings.set('SESSION_SOCKET_PATH', socket_path)
return settings
def process_dispatch(settings, config):
settings.set('SESSION_DISPATCH_DELAY', 0.01)
return settings
def process_token(settings, config):
settings.set('TOKEN_MODULE', config.get('TOKEN_MODULE'))
return settings
def process_backend(settings, config):
settings.set('CHAIND_BACKEND', config.get('STATE_BACKEND')) #backend)
return settings
def process_queue(settings, config):
if config.get('STATE_PATH') == None:
queue_state_dir = settings.dir_for('queue')
config.add(queue_state_dir, 'STATE_PATH', False)
logg.debug('setting queue state path {}'.format(queue_state_dir))
settings = process_queue_tx(settings, config)
settings = process_queue_paths(settings, config)
if config.get('STATE_BACKEND') == 'fs':
settings = process_queue_backend_fs(settings, config)
settings = process_queue_store(settings, config)
return settings

View File

@ -7,6 +7,11 @@ from chainqueue.cache import CacheTokenTx
from chainlib.status import Status as TxStatus
from chainlib.chain import ChainSpec
from chainlib.error import RPCException
from chainlib.tx import (
Tx,
TxResult,
)
from chainlib.block import Block
class MockCacheAdapter(CacheTokenTx):
@ -34,8 +39,17 @@ class MockDispatcher:
pass
class MockTx:
class MockTx(Tx):
def __init__(self, tx_hash, status=TxStatus.SUCCESS):
self.hash = tx_hash
self.status = status
result = TxResult()
result.status = status
super(MockTx, self).__init__(result=result)
self.set_hash(tx_hash)
class MockBlock(Block):
def __init__(self, number):
super(MockBlock, self).__init__()
self.number = number

View File

@ -1,6 +1,6 @@
chainlib~=0.1.2
chainqueue~=0.1.12
chainsyncer~=0.4.4
confini~=0.6.0
chainlib~=0.3.0
chainqueue~=0.2.0
chainsyncer~=0.5.0
confini~=0.6.1
funga~=0.5.2
pyxdg~=0.26

View File

@ -1,24 +1,24 @@
[metadata]
name = chaind
version = 0.2.9
version = 0.3.2
description = Base package for chain queue service
author = Louis Holbrook
author_email = dev@holbrook.no
url = https://gitlab.com/chaintool/chaind
url = https://git.defalsify.org/chaind.eth
keywords =
blockchain
cryptocurrency
p2p
dlt
classifiers =
Programming Language :: Python :: 3
Operating System :: OS Independent
Development Status :: 3 - Alpha
Environment :: Console
Intended Audience :: Developers
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
Topic :: Internet
# Topic :: Blockchain :: EVM
license = GPL3
license = OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
licence_files =
LICENSE
@ -30,6 +30,7 @@ packages =
# chaind.runnable
chaind.adapters
chaind.unittest
chaind.data
chaind.cli
#[options.entry_points]

View File

@ -14,6 +14,7 @@ from chaind.filter import StateFilter
# test imports
from chaind.unittest.common import (
MockTx,
MockBlock,
MockCacheAdapter,
MockDispatcher,
)
@ -76,7 +77,8 @@ class TestChaindFs(TestChaindFsBase):
fltr = StateFilter(self.chain_spec, self.path, MockCacheAdapter)
tx = MockTx(hsh)
fltr.filter(None, None, tx)
block = MockBlock(42)
fltr.filter(None, block, tx)
def test_fs_filter_fail(self):
@ -87,7 +89,8 @@ class TestChaindFs(TestChaindFsBase):
fltr = StateFilter(self.chain_spec, self.path, MockCacheAdapter)
tx = MockTx(hsh, TxStatus.ERROR)
fltr.filter(None, None, tx)
block = MockBlock(42)
fltr.filter(None, block, tx)
def test_upcoming(self):