mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Renamed "consensus" to "validation" where relevant
This commit is contained in:
parent
126e90e732
commit
3b5f2cc36e
@ -18,9 +18,9 @@ The `BigchainDB` class is defined here. Most node-level operations and database
|
|||||||
|
|
||||||
`Block`, `Transaction`, and `Asset` classes are defined here. The classes mirror the block and transaction structure from the [documentation](https://docs.bigchaindb.com/projects/server/en/latest/data-models/index.html), but also include methods for validation and signing.
|
`Block`, `Transaction`, and `Asset` classes are defined here. The classes mirror the block and transaction structure from the [documentation](https://docs.bigchaindb.com/projects/server/en/latest/data-models/index.html), but also include methods for validation and signing.
|
||||||
|
|
||||||
### [`consensus.py`](./consensus.py)
|
### [`validation.py`](./validation.py)
|
||||||
|
|
||||||
Base class for consensus methods (verification of votes, blocks, and transactions). The actual logic is mostly found in `transaction` and `block` models, defined in [`models.py`](./models.py).
|
Base class for validation methods (verification of votes, blocks, and transactions). The actual logic is mostly found in `transaction` and `block` models, defined in [`models.py`](./models.py).
|
||||||
|
|
||||||
### [`processes.py`](./processes.py)
|
### [`processes.py`](./processes.py)
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ from bigchaindb.common import exceptions
|
|||||||
|
|
||||||
import bigchaindb
|
import bigchaindb
|
||||||
|
|
||||||
from bigchaindb.consensus import BaseConsensusRules
|
from bigchaindb.validation import BaseValidationRules
|
||||||
|
|
||||||
# TODO: move this to a proper configuration file for logging
|
# TODO: move this to a proper configuration file for logging
|
||||||
logging.getLogger('requests').setLevel(logging.WARNING)
|
logging.getLogger('requests').setLevel(logging.WARNING)
|
||||||
@ -258,38 +258,38 @@ def autoconfigure(filename=None, config=None, force=False):
|
|||||||
|
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache()
|
||||||
def load_consensus_plugin(name=None):
|
def load_validation_plugin(name=None):
|
||||||
"""Find and load the chosen consensus plugin.
|
"""Find and load the chosen validation plugin.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (string): the name of the entry_point, as advertised in the
|
name (string): the name of the entry_point, as advertised in the
|
||||||
setup.py of the providing package.
|
setup.py of the providing package.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
an uninstantiated subclass of ``bigchaindb.consensus.AbstractConsensusRules``
|
an uninstantiated subclass of ``bigchaindb.validation.AbstractValidationRules``
|
||||||
"""
|
"""
|
||||||
if not name:
|
if not name:
|
||||||
return BaseConsensusRules
|
return BaseValidationRules
|
||||||
|
|
||||||
# TODO: This will return the first plugin with group `bigchaindb.consensus`
|
# TODO: This will return the first plugin with group `bigchaindb.validation`
|
||||||
# and name `name` in the active WorkingSet.
|
# and name `name` in the active WorkingSet.
|
||||||
# We should probably support Requirements specs in the config, e.g.
|
# We should probably support Requirements specs in the config, e.g.
|
||||||
# consensus_plugin: 'my-plugin-package==0.0.1;default'
|
# validation_plugin: 'my-plugin-package==0.0.1;default'
|
||||||
plugin = None
|
plugin = None
|
||||||
for entry_point in iter_entry_points('bigchaindb.consensus', name):
|
for entry_point in iter_entry_points('bigchaindb.validation', name):
|
||||||
plugin = entry_point.load()
|
plugin = entry_point.load()
|
||||||
|
|
||||||
# No matching entry_point found
|
# No matching entry_point found
|
||||||
if not plugin:
|
if not plugin:
|
||||||
raise ResolutionError(
|
raise ResolutionError(
|
||||||
'No plugin found in group `bigchaindb.consensus` with name `{}`'.
|
'No plugin found in group `bigchaindb.validation` with name `{}`'.
|
||||||
format(name))
|
format(name))
|
||||||
|
|
||||||
# Is this strictness desireable?
|
# Is this strictness desireable?
|
||||||
# It will probably reduce developer headaches in the wild.
|
# It will probably reduce developer headaches in the wild.
|
||||||
if not issubclass(plugin, (BaseConsensusRules,)):
|
if not issubclass(plugin, (BaseValidationRules,)):
|
||||||
raise TypeError('object of type "{}" does not implement `bigchaindb.'
|
raise TypeError('object of type "{}" does not implement `bigchaindb.'
|
||||||
'consensus.BaseConsensusRules`'.format(type(plugin)))
|
'validation.BaseValidationRules`'.format(type(plugin)))
|
||||||
|
|
||||||
return plugin
|
return plugin
|
||||||
|
|
||||||
|
|||||||
@ -40,8 +40,7 @@ class App(BaseApplication):
|
|||||||
"""Bridge between BigchainDB and Tendermint.
|
"""Bridge between BigchainDB and Tendermint.
|
||||||
|
|
||||||
The role of this class is to expose the BigchainDB
|
The role of this class is to expose the BigchainDB
|
||||||
transactional logic to the Tendermint Consensus
|
transaction logic to Tendermint Core.
|
||||||
State Machine.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, bigchaindb=None, events_queue=None):
|
def __init__(self, bigchaindb=None, events_queue=None):
|
||||||
|
|||||||
@ -27,7 +27,7 @@ from bigchaindb.common.exceptions import (SchemaValidationError,
|
|||||||
DoubleSpend)
|
DoubleSpend)
|
||||||
from bigchaindb.tendermint_utils import encode_transaction, merkleroot
|
from bigchaindb.tendermint_utils import encode_transaction, merkleroot
|
||||||
from bigchaindb import exceptions as core_exceptions
|
from bigchaindb import exceptions as core_exceptions
|
||||||
from bigchaindb.consensus import BaseConsensusRules
|
from bigchaindb.validation import BaseValidationRules
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -64,12 +64,12 @@ class BigchainDB(object):
|
|||||||
self.tendermint_port = bigchaindb.config['tendermint']['port']
|
self.tendermint_port = bigchaindb.config['tendermint']['port']
|
||||||
self.endpoint = 'http://{}:{}/'.format(self.tendermint_host, self.tendermint_port)
|
self.endpoint = 'http://{}:{}/'.format(self.tendermint_host, self.tendermint_port)
|
||||||
|
|
||||||
consensusPlugin = bigchaindb.config.get('consensus_plugin')
|
validationPlugin = bigchaindb.config.get('validation_plugin')
|
||||||
|
|
||||||
if consensusPlugin:
|
if validationPlugin:
|
||||||
self.consensus = config_utils.load_consensus_plugin(consensusPlugin)
|
self.validation = config_utils.load_validation_plugin(validationPlugin)
|
||||||
else:
|
else:
|
||||||
self.consensus = BaseConsensusRules
|
self.validation = BaseValidationRules
|
||||||
|
|
||||||
self.connection = connection if connection else backend.connect(**bigchaindb.config['database'])
|
self.connection = connection if connection else backend.connect(**bigchaindb.config['database'])
|
||||||
|
|
||||||
|
|||||||
@ -3,23 +3,22 @@
|
|||||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
|
|
||||||
class BaseConsensusRules():
|
class BaseValidationRules():
|
||||||
"""Base consensus rules for Bigchain.
|
"""Base validation rules for BigchainDB.
|
||||||
|
|
||||||
A consensus plugin must expose a class inheriting from this one via an entry_point.
|
A validation plugin must expose a class inheriting from this one via an entry_point.
|
||||||
|
|
||||||
All methods listed below must be implemented.
|
All methods listed below must be implemented.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_transaction(bigchain, transaction):
|
def validate_transaction(bigchaindb, transaction):
|
||||||
"""See :meth:`bigchaindb.models.Transaction.validate`
|
"""See :meth:`bigchaindb.models.Transaction.validate`
|
||||||
for documentation.
|
for documentation.
|
||||||
"""
|
"""
|
||||||
return transaction.validate(bigchain)
|
return transaction.validate(bigchaindb)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_block(bigchain, block):
|
def validate_block(bigchaindb, block):
|
||||||
"""See :meth:`bigchaindb.models.Block.validate` for documentation."""
|
"""See :meth:`bigchaindb.models.Block.validate` for documentation."""
|
||||||
return block.validate(bigchain)
|
return block.validate(bigchaindb)
|
||||||
@ -31,24 +31,24 @@ def test_bigchain_instance_is_initialized_when_conf_provided():
|
|||||||
assert bigchaindb.config['CONFIGURED'] is True
|
assert bigchaindb.config['CONFIGURED'] is True
|
||||||
|
|
||||||
|
|
||||||
def test_load_consensus_plugin_loads_default_rules_without_name():
|
def test_load_validation_plugin_loads_default_rules_without_name():
|
||||||
from bigchaindb import config_utils
|
from bigchaindb import config_utils
|
||||||
from bigchaindb.consensus import BaseConsensusRules
|
from bigchaindb.validation import BaseValidationRules
|
||||||
|
|
||||||
assert config_utils.load_consensus_plugin() == BaseConsensusRules
|
assert config_utils.load_validation_plugin() == BaseValidationRules
|
||||||
|
|
||||||
|
|
||||||
def test_load_consensus_plugin_raises_with_unknown_name():
|
def test_load_validation_plugin_raises_with_unknown_name():
|
||||||
from pkg_resources import ResolutionError
|
from pkg_resources import ResolutionError
|
||||||
from bigchaindb import config_utils
|
from bigchaindb import config_utils
|
||||||
|
|
||||||
with pytest.raises(ResolutionError):
|
with pytest.raises(ResolutionError):
|
||||||
config_utils.load_consensus_plugin('bogus')
|
config_utils.load_validation_plugin('bogus')
|
||||||
|
|
||||||
|
|
||||||
def test_load_consensus_plugin_raises_with_invalid_subclass(monkeypatch):
|
def test_load_validation_plugin_raises_with_invalid_subclass(monkeypatch):
|
||||||
# Monkeypatch entry_point.load to return something other than a
|
# Monkeypatch entry_point.load to return something other than a
|
||||||
# ConsensusRules instance
|
# ValidationRules instance
|
||||||
from bigchaindb import config_utils
|
from bigchaindb import config_utils
|
||||||
import time
|
import time
|
||||||
monkeypatch.setattr(config_utils,
|
monkeypatch.setattr(config_utils,
|
||||||
@ -58,7 +58,7 @@ def test_load_consensus_plugin_raises_with_invalid_subclass(monkeypatch):
|
|||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
# Since the function is decorated with `lru_cache`, we need to
|
# Since the function is decorated with `lru_cache`, we need to
|
||||||
# "miss" the cache using a name that has not been used previously
|
# "miss" the cache using a name that has not been used previously
|
||||||
config_utils.load_consensus_plugin(str(time.time()))
|
config_utils.load_validation_plugin(str(time.time()))
|
||||||
|
|
||||||
|
|
||||||
def test_load_events_plugins(monkeypatch):
|
def test_load_events_plugins(monkeypatch):
|
||||||
|
|||||||
@ -35,20 +35,20 @@ def config(request, monkeypatch):
|
|||||||
|
|
||||||
def test_bigchain_class_default_initialization(config):
|
def test_bigchain_class_default_initialization(config):
|
||||||
from bigchaindb import BigchainDB
|
from bigchaindb import BigchainDB
|
||||||
from bigchaindb.consensus import BaseConsensusRules
|
from bigchaindb.validation import BaseValidationRules
|
||||||
from bigchaindb.backend.connection import Connection
|
from bigchaindb.backend.connection import Connection
|
||||||
bigchain = BigchainDB()
|
bigchain = BigchainDB()
|
||||||
assert isinstance(bigchain.connection, Connection)
|
assert isinstance(bigchain.connection, Connection)
|
||||||
assert bigchain.connection.host == config['database']['host']
|
assert bigchain.connection.host == config['database']['host']
|
||||||
assert bigchain.connection.port == config['database']['port']
|
assert bigchain.connection.port == config['database']['port']
|
||||||
assert bigchain.connection.dbname == config['database']['name']
|
assert bigchain.connection.dbname == config['database']['name']
|
||||||
assert bigchain.consensus == BaseConsensusRules
|
assert bigchain.validation == BaseValidationRules
|
||||||
|
|
||||||
|
|
||||||
def test_bigchain_class_initialization_with_parameters():
|
def test_bigchain_class_initialization_with_parameters():
|
||||||
from bigchaindb import BigchainDB
|
from bigchaindb import BigchainDB
|
||||||
from bigchaindb.backend import connect
|
from bigchaindb.backend import connect
|
||||||
from bigchaindb.consensus import BaseConsensusRules
|
from bigchaindb.validation import BaseValidationRules
|
||||||
init_db_kwargs = {
|
init_db_kwargs = {
|
||||||
'backend': 'localmongodb',
|
'backend': 'localmongodb',
|
||||||
'host': 'this_is_the_db_host',
|
'host': 'this_is_the_db_host',
|
||||||
@ -61,7 +61,7 @@ def test_bigchain_class_initialization_with_parameters():
|
|||||||
assert bigchain.connection.host == init_db_kwargs['host']
|
assert bigchain.connection.host == init_db_kwargs['host']
|
||||||
assert bigchain.connection.port == init_db_kwargs['port']
|
assert bigchain.connection.port == init_db_kwargs['port']
|
||||||
assert bigchain.connection.dbname == init_db_kwargs['name']
|
assert bigchain.connection.dbname == init_db_kwargs['name']
|
||||||
assert bigchain.consensus == BaseConsensusRules
|
assert bigchain.validation == BaseValidationRules
|
||||||
|
|
||||||
|
|
||||||
def test_get_spent_issue_1271(b, alice, bob, carol):
|
def test_get_spent_issue_1271(b, alice, bob, carol):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user