mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-06-26 03:06:43 +02:00
Added a simple plugin system for consensus rules using setuputils entry_points
This commit is contained in:
parent
0ed5341c32
commit
8a9030e5c0
|
@ -39,7 +39,10 @@ config = {
|
|||
'host': e('BIGCHAIN_STATSD_HOST', default='localhost'),
|
||||
'port': e('BIGCHAIN_STATSD_PORT', default=8125),
|
||||
'rate': e('BIGCHAIN_STATSD_SAMPLERATE', default=0.01)
|
||||
}
|
||||
},
|
||||
'consensus_plugins': [
|
||||
'base'
|
||||
],
|
||||
}
|
||||
|
||||
# We need to maintain a backup copy of the original config dict in case
|
||||
|
|
|
@ -17,6 +17,8 @@ import json
|
|||
import logging
|
||||
import collections
|
||||
|
||||
from pkg_resources import iter_entry_points
|
||||
|
||||
import bigchaindb
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -100,3 +102,21 @@ def autoconfigure():
|
|||
except FileNotFoundError:
|
||||
logger.warning('Cannot find your config file. Run `bigchaindb configure` to create one')
|
||||
|
||||
|
||||
def get_plugins(plugin_names):
|
||||
if not plugin_names:
|
||||
plugin_names = bigchaindb.config.get('consensus_plugins', [])
|
||||
|
||||
plugins = []
|
||||
|
||||
# It's important to maintain plugin ordering as stated in the config file.
|
||||
# e.g. Expensive validation tasks should happen after cheap ones.
|
||||
#
|
||||
# TODO: We might want to add some sort of priority system, but for now we
|
||||
# simply assume everything in a given plugin is designed to run at the
|
||||
# same time.
|
||||
for name in plugin_names:
|
||||
for entry_point in iter_entry_points('bigchaindb.plugins', name):
|
||||
plugins.append(entry_point.load())
|
||||
|
||||
return plugins
|
||||
|
|
0
bigchaindb/consensus/__init__.py
Normal file
0
bigchaindb/consensus/__init__.py
Normal file
|
@ -30,7 +30,8 @@ class Bigchain(object):
|
|||
"""
|
||||
|
||||
def __init__(self, host=None, port=None, dbname=None,
|
||||
public_key=None, private_key=None, keyring=[]):
|
||||
public_key=None, private_key=None, keyring=[],
|
||||
consensus_plugins=['base']):
|
||||
"""Initialize the Bigchain instance
|
||||
|
||||
There are three ways in which the Bigchain instance can get its parameters.
|
||||
|
@ -56,6 +57,7 @@ class Bigchain(object):
|
|||
self.me = public_key or bigchaindb.config['keypair']['public']
|
||||
self.me_private = private_key or bigchaindb.config['keypair']['private']
|
||||
self.federation_nodes = keyring or bigchaindb.config['keyring']
|
||||
self.consensus_plugins = config_utils.get_plugins(consensus_plugins)
|
||||
|
||||
if not self.me or not self.me_private:
|
||||
raise KeypairNotFoundException()
|
||||
|
|
10
setup.py
10
setup.py
|
@ -54,13 +54,21 @@ setup(
|
|||
'Operating System :: POSIX :: Linux',
|
||||
],
|
||||
|
||||
packages=['bigchaindb', 'bigchaindb.commands', 'bigchaindb.db'],
|
||||
packages=[
|
||||
'bigchaindb',
|
||||
'bigchaindb.commands',
|
||||
'bigchaindb.db',
|
||||
'bigchaindb.consensus'
|
||||
],
|
||||
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'bigchaindb=bigchaindb.commands.bigchain:main',
|
||||
'bigchaindb-benchmark=bigchaindb.commands.bigchain_benchmark:main'
|
||||
],
|
||||
'bigchaindb.plugins': [
|
||||
'base=bigchaindb.consensus.base:ConsensusRules'
|
||||
]
|
||||
},
|
||||
install_requires=[
|
||||
'rethinkdb==2.2.0.post4',
|
||||
|
|
Loading…
Reference in New Issue
Block a user