Merge branch 'master' into sig_handling

This commit is contained in:
Ahmed Muawia Khan 2018-07-26 14:05:01 +02:00
commit c271d41bba
40 changed files with 307 additions and 312 deletions

View File

@ -4,7 +4,7 @@ A high-level description of the files and subdirectories of BigchainDB.
## Files ## Files
### [`tendermint/lib.py`](./tendermint/lib.py) ### [`lib.py`](lib.py)
The `BigchainDB` class is defined here. Most node-level operations and database interactions are found in this file. This is the place to start if you are interested in implementing a server API, since many of these class methods concern BigchainDB interacting with the outside world. The `BigchainDB` class is defined here. Most node-level operations and database interactions are found in this file. This is the place to start if you are interested in implementing a server API, since many of these class methods concern BigchainDB interacting with the outside world.

View File

@ -2,6 +2,9 @@ import copy
import logging import logging
from bigchaindb.log import DEFAULT_LOGGING_CONFIG as log_config from bigchaindb.log import DEFAULT_LOGGING_CONFIG as log_config
from bigchaindb.lib import BigchainDB # noqa
from bigchaindb.version import __version__ # noqa
from bigchaindb.core import App # noqa
# from functools import reduce # from functools import reduce
# PORT_NUMBER = reduce(lambda x, y: x * y, map(ord, 'BigchainDB')) % 2**16 # PORT_NUMBER = reduce(lambda x, y: x * y, map(ord, 'BigchainDB')) % 2**16
@ -84,5 +87,3 @@ config = {
# the user wants to reconfigure the node. Check ``bigchaindb.config_utils`` # the user wants to reconfigure the node. Check ``bigchaindb.config_utils``
# for more info. # for more info.
_config = copy.deepcopy(config) _config = copy.deepcopy(config)
from bigchaindb.tendermint import BigchainDB # noqa
from bigchaindb.version import __version__ # noqa

View File

@ -21,7 +21,7 @@ from bigchaindb.commands import utils
from bigchaindb.commands.utils import (configure_bigchaindb, from bigchaindb.commands.utils import (configure_bigchaindb,
input_on_stderr) input_on_stderr)
from bigchaindb.log import setup_logging from bigchaindb.log import setup_logging
from bigchaindb.tendermint.utils import public_key_from_base64 from bigchaindb.tendermint_utils import public_key_from_base64
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -97,7 +97,7 @@ def run_configure(args):
def run_upsert_validator(args): def run_upsert_validator(args):
"""Store validators which should be synced with Tendermint""" """Store validators which should be synced with Tendermint"""
b = bigchaindb.tendermint.BigchainDB() b = bigchaindb.BigchainDB()
public_key = public_key_from_base64(args.public_key) public_key = public_key_from_base64(args.public_key)
validator = {'pub_key': {'type': 'ed25519', validator = {'pub_key': {'type': 'ed25519',
'data': public_key}, 'data': public_key},
@ -113,7 +113,7 @@ def run_upsert_validator(args):
def _run_init(): def _run_init():
bdb = bigchaindb.tendermint.BigchainDB() bdb = bigchaindb.BigchainDB()
schema.init_database(connection=bdb.connection) schema.init_database(connection=bdb.connection)
@ -170,7 +170,7 @@ def run_start(args):
setup_logging() setup_logging()
logger.info('BigchainDB Version %s', bigchaindb.__version__) logger.info('BigchainDB Version %s', bigchaindb.__version__)
run_recover(bigchaindb.tendermint.lib.BigchainDB()) run_recover(bigchaindb.lib.BigchainDB())
try: try:
if not args.skip_initialize_database: if not args.skip_initialize_database:
@ -180,7 +180,7 @@ def run_start(args):
pass pass
logger.info('Starting BigchainDB main process.') logger.info('Starting BigchainDB main process.')
from bigchaindb.tendermint.commands import start from bigchaindb.start import start
start() start()

View File

@ -0,0 +1,178 @@
"""This module contains all the goodness to integrate BigchainDB
with Tendermint."""
import logging
from abci.application import BaseApplication
from abci.types_pb2 import (
ResponseInitChain,
ResponseInfo,
ResponseCheckTx,
ResponseBeginBlock,
ResponseDeliverTx,
ResponseEndBlock,
ResponseCommit,
Validator,
PubKey
)
from bigchaindb import BigchainDB
from bigchaindb.tendermint_utils import (decode_transaction,
calculate_hash)
from bigchaindb.lib import Block, PreCommitState
from bigchaindb.backend.query import PRE_COMMIT_ID
CodeTypeOk = 0
CodeTypeError = 1
logger = logging.getLogger(__name__)
class App(BaseApplication):
"""Bridge between BigchainDB and Tendermint.
The role of this class is to expose the BigchainDB
transactional logic to the Tendermint Consensus
State Machine."""
def __init__(self, bigchaindb=None):
self.bigchaindb = bigchaindb or BigchainDB()
self.block_txn_ids = []
self.block_txn_hash = ''
self.block_transactions = []
self.validators = None
self.new_height = None
def init_chain(self, validators):
"""Initialize chain with block of height 0"""
block = Block(app_hash='', height=0, transactions=[])
self.bigchaindb.store_block(block._asdict())
return ResponseInitChain()
def info(self, request):
"""Return height of the latest committed block."""
r = ResponseInfo()
block = self.bigchaindb.get_latest_block()
if block:
r.last_block_height = block['height']
r.last_block_app_hash = block['app_hash'].encode('utf-8')
else:
r.last_block_height = 0
r.last_block_app_hash = b''
return r
def check_tx(self, raw_transaction):
"""Validate the transaction before entry into
the mempool.
Args:
raw_tx: a raw string (in bytes) transaction."""
logger.benchmark('CHECK_TX_INIT')
logger.debug('check_tx: %s', raw_transaction)
transaction = decode_transaction(raw_transaction)
if self.bigchaindb.is_valid_transaction(transaction):
logger.debug('check_tx: VALID')
logger.benchmark('CHECK_TX_END, tx_id:%s', transaction['id'])
return ResponseCheckTx(code=CodeTypeOk)
else:
logger.debug('check_tx: INVALID')
logger.benchmark('CHECK_TX_END, tx_id:%s', transaction['id'])
return ResponseCheckTx(code=CodeTypeError)
def begin_block(self, req_begin_block):
"""Initialize list of transaction.
Args:
req_begin_block: block object which contains block header
and block hash.
"""
logger.benchmark('BEGIN BLOCK, height:%s, num_txs:%s',
req_begin_block.header.height,
req_begin_block.header.num_txs)
self.block_txn_ids = []
self.block_transactions = []
return ResponseBeginBlock()
def deliver_tx(self, raw_transaction):
"""Validate the transaction before mutating the state.
Args:
raw_tx: a raw string (in bytes) transaction."""
logger.debug('deliver_tx: %s', raw_transaction)
transaction = self.bigchaindb.is_valid_transaction(
decode_transaction(raw_transaction), self.block_transactions)
if not transaction:
logger.debug('deliver_tx: INVALID')
return ResponseDeliverTx(code=CodeTypeError)
else:
logger.debug('storing tx')
self.block_txn_ids.append(transaction.id)
self.block_transactions.append(transaction)
return ResponseDeliverTx(code=CodeTypeOk)
def end_block(self, request_end_block):
"""Calculate block hash using transaction ids and previous block
hash to be stored in the next block.
Args:
height (int): new height of the chain."""
height = request_end_block.height
self.new_height = height
block_txn_hash = calculate_hash(self.block_txn_ids)
block = self.bigchaindb.get_latest_block()
if self.block_txn_ids:
self.block_txn_hash = calculate_hash([block['app_hash'], block_txn_hash])
else:
self.block_txn_hash = block['app_hash']
validator_updates = self.bigchaindb.get_validator_update()
validator_updates = [encode_validator(v) for v in validator_updates]
# set sync status to true
self.bigchaindb.delete_validator_update()
# Store pre-commit state to recover in case there is a crash
# during `commit`
pre_commit_state = PreCommitState(commit_id=PRE_COMMIT_ID,
height=self.new_height,
transactions=self.block_txn_ids)
logger.debug('Updating PreCommitState: %s', self.new_height)
self.bigchaindb.store_pre_commit_state(pre_commit_state._asdict())
return ResponseEndBlock(validator_updates=validator_updates)
def commit(self):
"""Store the new height and along with block hash."""
data = self.block_txn_hash.encode('utf-8')
# register a new block only when new transactions are received
if self.block_txn_ids:
self.bigchaindb.store_bulk_transactions(self.block_transactions)
block = Block(app_hash=self.block_txn_hash,
height=self.new_height,
transactions=self.block_txn_ids)
# NOTE: storing the block should be the last operation during commit
# this effects crash recovery. Refer BEP#8 for details
self.bigchaindb.store_block(block._asdict())
logger.debug('Commit-ing new block with hash: apphash=%s ,'
'height=%s, txn ids=%s', data, self.new_height,
self.block_txn_ids)
logger.benchmark('COMMIT_BLOCK, height:%s', self.new_height)
return ResponseCommit(data=data)
def encode_validator(v):
ed25519_public_key = v['pub_key']['data']
# NOTE: tendermint expects public to be encoded in go-amino format
pub_key = PubKey(type='ed25519',
data=bytes.fromhex(ed25519_public_key))
return Validator(pub_key=pub_key,
address=b'',
power=v['power'])

View File

@ -8,7 +8,7 @@ import aiohttp
from bigchaindb import config from bigchaindb import config
from bigchaindb.common.utils import gen_timestamp from bigchaindb.common.utils import gen_timestamp
from bigchaindb.events import EventTypes, Event from bigchaindb.events import EventTypes, Event
from bigchaindb.tendermint.utils import decode_transaction_base64 from bigchaindb.tendermint_utils import decode_transaction_base64
HOST = config['tendermint']['host'] HOST = config['tendermint']['host']

View File

@ -16,13 +16,12 @@ except ImportError:
import requests import requests
import bigchaindb import bigchaindb
from bigchaindb import backend, config_utils from bigchaindb import backend, config_utils, fastquery
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import (SchemaValidationError, from bigchaindb.common.exceptions import (SchemaValidationError,
ValidationError, ValidationError,
DoubleSpend) DoubleSpend)
from bigchaindb.tendermint.utils import encode_transaction, merkleroot from bigchaindb.tendermint_utils import encode_transaction, merkleroot
from bigchaindb.tendermint import fastquery
from bigchaindb import exceptions as core_exceptions from bigchaindb import exceptions as core_exceptions
from bigchaindb.consensus import BaseConsensusRules from bigchaindb.consensus import BaseConsensusRules
@ -254,10 +253,10 @@ class BigchainDB(object):
def get_transaction(self, transaction_id, include_status=False): def get_transaction(self, transaction_id, include_status=False):
transaction = backend.query.get_transaction(self.connection, transaction_id) transaction = backend.query.get_transaction(self.connection, transaction_id)
asset = backend.query.get_asset(self.connection, transaction_id)
metadata = backend.query.get_metadata(self.connection, [transaction_id])
if transaction: if transaction:
asset = backend.query.get_asset(self.connection, transaction_id)
metadata = backend.query.get_metadata(self.connection, [transaction_id])
if asset: if asset:
transaction['asset'] = asset transaction['asset'] = asset

View File

@ -14,7 +14,7 @@ class Transaction(Transaction):
"""Validate transaction spend """Validate transaction spend
Args: Args:
bigchain (BigchainDB): an instantiated bigchaindb.tendermint.BigchainDB object. bigchain (BigchainDB): an instantiated bigchaindb.BigchainDB object.
Returns: Returns:
The transaction (Transaction) if the transaction is valid else it The transaction (Transaction) if the transaction is valid else it
@ -108,7 +108,7 @@ class Transaction(Transaction):
asset from the asset table and reconstructs the transaction. asset from the asset table and reconstructs the transaction.
Args: Args:
bigchain (:class:`~bigchaindb.tendermint.BigchainDB`): An instance bigchain (:class:`~bigchaindb.BigchainDB`): An instance
of BigchainDB used to perform database queries. of BigchainDB used to perform database queries.
tx_dict_list (:list:`dict` or :obj:`dict`): The transaction dict or tx_dict_list (:list:`dict` or :obj:`dict`): The transaction dict or
list of transaction dict as returned from the database. list of transaction dict as returned from the database.

View File

@ -2,10 +2,10 @@ import logging
import setproctitle import setproctitle
import bigchaindb import bigchaindb
from bigchaindb.tendermint.lib import BigchainDB from bigchaindb.lib import BigchainDB
from bigchaindb.tendermint.core import App from bigchaindb.core import App
from bigchaindb.web import server, websocket_server from bigchaindb.web import server, websocket_server
from bigchaindb.tendermint import event_stream from bigchaindb import event_stream
from bigchaindb.events import Exchange, EventTypes from bigchaindb.events import Exchange, EventTypes
from bigchaindb.utils import Process from bigchaindb.utils import Process

View File

@ -1,7 +0,0 @@
"""Code necessary for integrating with Tendermint."""
# Order is important!
# If we import core first, core will try to load BigchainDB from
# __init__ itself, causing a loop.
from bigchaindb.tendermint.lib import BigchainDB # noqa
from bigchaindb.tendermint.core import App # noqa

View File

@ -1,178 +0,0 @@
"""This module contains all the goodness to integrate BigchainDB
with Tendermint."""
import logging
from abci.application import BaseApplication
from abci.types_pb2 import (
ResponseInitChain,
ResponseInfo,
ResponseCheckTx,
ResponseBeginBlock,
ResponseDeliverTx,
ResponseEndBlock,
ResponseCommit,
Validator,
PubKey
)
from bigchaindb.tendermint import BigchainDB
from bigchaindb.tendermint.utils import (decode_transaction,
calculate_hash)
from bigchaindb.tendermint.lib import Block, PreCommitState
from bigchaindb.backend.query import PRE_COMMIT_ID
CodeTypeOk = 0
CodeTypeError = 1
logger = logging.getLogger(__name__)
class App(BaseApplication):
"""Bridge between BigchainDB and Tendermint.
The role of this class is to expose the BigchainDB
transactional logic to the Tendermint Consensus
State Machine."""
def __init__(self, bigchaindb=None):
self.bigchaindb = bigchaindb or BigchainDB()
self.block_txn_ids = []
self.block_txn_hash = ''
self.block_transactions = []
self.validators = None
self.new_height = None
def init_chain(self, validators):
"""Initialize chain with block of height 0"""
block = Block(app_hash='', height=0, transactions=[])
self.bigchaindb.store_block(block._asdict())
return ResponseInitChain()
def info(self, request):
"""Return height of the latest committed block."""
r = ResponseInfo()
block = self.bigchaindb.get_latest_block()
if block:
r.last_block_height = block['height']
r.last_block_app_hash = block['app_hash'].encode('utf-8')
else:
r.last_block_height = 0
r.last_block_app_hash = b''
return r
def check_tx(self, raw_transaction):
"""Validate the transaction before entry into
the mempool.
Args:
raw_tx: a raw string (in bytes) transaction."""
logger.benchmark('CHECK_TX_INIT')
logger.debug('check_tx: %s', raw_transaction)
transaction = decode_transaction(raw_transaction)
if self.bigchaindb.is_valid_transaction(transaction):
logger.debug('check_tx: VALID')
logger.benchmark('CHECK_TX_END, tx_id:%s', transaction['id'])
return ResponseCheckTx(code=CodeTypeOk)
else:
logger.debug('check_tx: INVALID')
logger.benchmark('CHECK_TX_END, tx_id:%s', transaction['id'])
return ResponseCheckTx(code=CodeTypeError)
def begin_block(self, req_begin_block):
"""Initialize list of transaction.
Args:
req_begin_block: block object which contains block header
and block hash.
"""
logger.benchmark('BEGIN BLOCK, height:%s, num_txs:%s',
req_begin_block.header.height,
req_begin_block.header.num_txs)
self.block_txn_ids = []
self.block_transactions = []
return ResponseBeginBlock()
def deliver_tx(self, raw_transaction):
"""Validate the transaction before mutating the state.
Args:
raw_tx: a raw string (in bytes) transaction."""
logger.debug('deliver_tx: %s', raw_transaction)
transaction = self.bigchaindb.is_valid_transaction(
decode_transaction(raw_transaction), self.block_transactions)
if not transaction:
logger.debug('deliver_tx: INVALID')
return ResponseDeliverTx(code=CodeTypeError)
else:
logger.debug('storing tx')
self.block_txn_ids.append(transaction.id)
self.block_transactions.append(transaction)
return ResponseDeliverTx(code=CodeTypeOk)
def end_block(self, request_end_block):
"""Calculate block hash using transaction ids and previous block
hash to be stored in the next block.
Args:
height (int): new height of the chain."""
height = request_end_block.height
self.new_height = height
block_txn_hash = calculate_hash(self.block_txn_ids)
block = self.bigchaindb.get_latest_block()
if self.block_txn_ids:
self.block_txn_hash = calculate_hash([block['app_hash'], block_txn_hash])
else:
self.block_txn_hash = block['app_hash']
validator_updates = self.bigchaindb.get_validator_update()
validator_updates = [encode_validator(v) for v in validator_updates]
# set sync status to true
self.bigchaindb.delete_validator_update()
# Store pre-commit state to recover in case there is a crash
# during `commit`
pre_commit_state = PreCommitState(commit_id=PRE_COMMIT_ID,
height=self.new_height,
transactions=self.block_txn_ids)
logger.debug('Updating PreCommitState: %s', self.new_height)
self.bigchaindb.store_pre_commit_state(pre_commit_state._asdict())
return ResponseEndBlock(validator_updates=validator_updates)
def commit(self):
"""Store the new height and along with block hash."""
data = self.block_txn_hash.encode('utf-8')
# register a new block only when new transactions are received
if self.block_txn_ids:
self.bigchaindb.store_bulk_transactions(self.block_transactions)
block = Block(app_hash=self.block_txn_hash,
height=self.new_height,
transactions=self.block_txn_ids)
# NOTE: storing the block should be the last operation during commit
# this effects crash recovery. Refer BEP#8 for details
self.bigchaindb.store_block(block._asdict())
logger.debug('Commit-ing new block with hash: apphash=%s ,'
'height=%s, txn ids=%s', data, self.new_height,
self.block_txn_ids)
logger.benchmark('COMMIT_BLOCK, height:%s', self.new_height)
return ResponseCommit(data=data)
def encode_validator(v):
ed25519_public_key = v['pub_key']['data']
# NOTE: tendermint expects public to be encoded in go-amino format
pub_key = PubKey(type='ed25519',
data=bytes.fromhex(ed25519_public_key))
return Validator(pub_key=pub_key,
address=b'',
power=v['power'])

View File

@ -11,7 +11,7 @@ from flask_cors import CORS
import gunicorn.app.base import gunicorn.app.base
from bigchaindb import utils from bigchaindb import utils
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
from bigchaindb.web.routes import add_routes from bigchaindb.web.routes import add_routes
from bigchaindb.web.strip_content_type_middleware import StripContentTypeMiddleware from bigchaindb.web.strip_content_type_middleware import StripContentTypeMiddleware

View File

@ -1,7 +1,14 @@
# Write a BigchaindB Enhancement Proposal (BEP) # Write a BigchainDB Enhancement Proposal (BEP)
- Review [1/C4](https://github.com/bigchaindb/BEPs/tree/master/1), the process we use to accept any new code or PR of any kind, including one that adds a BEP to `bigchaindb/BEPs`. If you have an idea for a new feature or enhancement, and you want some feedback before you write a full BigchainDB Enhancement Proposal (BEP), then feel free to:
- Review [2/COSS](https://github.com/bigchaindb/BEPs/tree/master/2). Maybe print it for reference. It outlines what can go in a BEP. - ask in the [bigchaindb/bigchaindb Gitter chat room](https://gitter.im/bigchaindb/bigchaindb) or
- Don't spend weeks on your BEP. Version 1 should take up to a few hours to write. You can add to it in the future. The process is iterative. If you need more than a few hours, then consider writing multiple BEPs. - [open a new issue in the bigchaindb/BEPs repo](https://github.com/bigchaindb/BEPs/issues/new) and give it the label **BEP idea**.
- Do _not_ start writing code before you think about it. You should always write a BEP first. Once you do that, you can start implementing it. To do that, make a pull request and say it implements your BEP.
- Do _not_ write your BEP as an issue (i.e. a GitHub issue). If you want to discuss an existing BEP, then [open a new issue in the bigchaindb/BEPs repo](https://github.com/bigchaindb/BEPs/issues/new) and give it the label **discuss existing BEP**.
## Steps to Write a New BEP
1. Look at the structure of existing BEPs in the [bigchaindb/BEPs repo](https://github.com/bigchaindb/BEPs). Note the section headings. [BEP-2](https://github.com/bigchaindb/BEPs/tree/master/2) (our variant of the consensus-oriented specification system [COSS]) says more about the expected structure and process.
1. Write a first draft of your BEP. It doesn't have to be long or perfect.
1. Push your BEP draft to the [bigchaindb/BEPs repo](https://github.com/bigchaindb/BEPs) and make a pull request. [BEP-1](https://github.com/bigchaindb/BEPs/tree/master/1) (our variant of C4) outlines the process we use to handle all pull requests. In particular, we try to merge all pull requests quickly.
1. Your BEP can be revised by pushing more pull requests.

View File

@ -3,7 +3,7 @@ BigchainDB and Smart Contracts
One can store the source code of any smart contract (i.e. a computer program) in BigchainDB, but BigchainDB won't run arbitrary smart contracts. One can store the source code of any smart contract (i.e. a computer program) in BigchainDB, but BigchainDB won't run arbitrary smart contracts.
BigchainDB will run the subset of smart contracts expressible using `Crypto-Conditions <https://tools.ietf.org/html/draft-thomas-crypto-conditions-03>`_. Crypto-conditions are part of the `Interledger Protocol <https://interledger.org/>`_. BigchainDB will run the subset of smart contracts expressible using `Crypto-Conditions <https://tools.ietf.org/html/draft-thomas-crypto-conditions-03>`_.
The owners of an asset can impose conditions on it that must be met for the asset to be transferred to new owners. Examples of possible conditions (crypto-conditions) include: The owners of an asset can impose conditions on it that must be met for the asset to be transferred to new owners. Examples of possible conditions (crypto-conditions) include:

View File

@ -27,9 +27,8 @@ and the other output might have 15 oak trees for another set of owners.
Each output also has an associated condition: the condition that must be met Each output also has an associated condition: the condition that must be met
(by a TRANSFER transaction) to transfer/spend the output. (by a TRANSFER transaction) to transfer/spend the output.
BigchainDB supports a variety of conditions, BigchainDB supports a variety of conditions.
a subset of the [Interledger Protocol (ILP)](https://interledger.org/) For details, see
crypto-conditions. For details, see
the section titled **Transaction Components: Conditions** the section titled **Transaction Components: Conditions**
in the relevant in the relevant
[BigchainDB Transactions Spec](https://github.com/bigchaindb/BEPs/tree/master/tx-specs/). [BigchainDB Transactions Spec](https://github.com/bigchaindb/BEPs/tree/master/tx-specs/).

View File

@ -5,8 +5,7 @@ import os
import os.path import os.path
from bigchaindb.common.transaction import Transaction, Input, TransactionLink from bigchaindb.common.transaction import Transaction, Input, TransactionLink
from bigchaindb.tendermint import BigchainDB from bigchaindb import lib
from bigchaindb.tendermint import lib
from bigchaindb.web import server from bigchaindb.web import server

View File

@ -10,7 +10,6 @@ Appendices
the-bigchaindb-class the-bigchaindb-class
backend backend
commands commands
tendermint-integration
aws-setup aws-setup
generate-key-pair-for-ssh generate-key-pair-for-ssh
firewall-notes firewall-notes

View File

@ -1,26 +0,0 @@
######################
Tendermint Integration
######################
.. automodule:: bigchaindb.tendermint
:special-members: __init__
.. automodule:: bigchaindb.tendermint.lib
:special-members: __init__
:noindex:
.. automodule:: bigchaindb.tendermint.core
:special-members: __init__
.. automodule:: bigchaindb.tendermint.event_stream
:special-members: __init__
.. automodule:: bigchaindb.tendermint.fastquery
:special-members: __init__
.. automodule:: bigchaindb.tendermint.commands
:special-members: __init__
.. automodule:: bigchaindb.tendermint.utils
:special-members: __init__

View File

@ -2,4 +2,4 @@
The BigchainDB Class The BigchainDB Class
#################### ####################
.. autoclass:: bigchaindb.tendermint.BigchainDB .. autoclass:: bigchaindb.BigchainDB

View File

@ -244,6 +244,19 @@ If you followed the recommended approach and created startup scripts for Bigchai
If you followed the above instructions, then your node should be publicly-accessible with BigchainDB Root URL `http://hostname:9984` (where hostname is something like `bdb7.canada.vmsareus.net` or `17.122.200.76`). That is, anyone can interact with your node using the [BigchainDB HTTP API](http-client-server-api.html) exposed at that address. The most common way to do that is to use one of the [BigchainDB Drivers](./drivers-clients/index.html). If you followed the above instructions, then your node should be publicly-accessible with BigchainDB Root URL `http://hostname:9984` (where hostname is something like `bdb7.canada.vmsareus.net` or `17.122.200.76`). That is, anyone can interact with your node using the [BigchainDB HTTP API](http-client-server-api.html) exposed at that address. The most common way to do that is to use one of the [BigchainDB Drivers](./drivers-clients/index.html).
## Troubleshooting
To check which nodes your node is connected to (via Tendermint protocols), do:
```text
# if you don't jq installed, then install it
sudo apt install jq
# then do
curl -s localhost:26657/net_info | jq ".result.peers[].node_info | {id, listen_addr, moniker}"
```
Tendermint has other endpoints besides `/net_info`: see [the Tendermint RPC docs](https://tendermint.github.io/slate/?shell#introduction).
## Refreshing Your Node ## Refreshing Your Node
If you want to refresh your node back to a fresh empty state, then your best bet is to terminate it and deploy a new virtual machine, but if that's not an option, then you can: If you want to refresh your node back to a fresh empty state, then your best bet is to terminate it and deploy a new virtual machine, but if that's not an option, then you can:

View File

@ -13,6 +13,7 @@
- name: Get Running BigchainDB Process(es) - name: Get Running BigchainDB Process(es)
shell: "ps aux | grep \"[b]igchaindb\" | awk '{print $2}'" shell: "ps aux | grep \"[b]igchaindb\" | awk '{print $2}'"
register: bdb_ps register: bdb_ps
ignore_errors: yes
when: stack_type|lower == "local" when: stack_type|lower == "local"
tags: [bigchaindb] tags: [bigchaindb]

View File

@ -8,7 +8,8 @@ distribution_major: "{{ ansible_distribution_major_version }}"
server_arch: "amd64,arm64" server_arch: "amd64,arm64"
# MongoDB Repos # MongoDB Repos
mongodb_apt_repo: "deb [arch={{ server_arch }}] http://repo.mongodb.org/apt/{{ distribution_name }} {{ distribution_codename }}/{{ mongodb_package }}/{{ mongo_version }} {{'main' if ansible_distribution == 'debian' else 'multiverse'}}" mongodb_apt_repo: "deb [arch={{ server_arch }}] http://repo.mongodb.org/apt/{{ distribution_name }} {{ distribution_codename }}/{{ mongodb_package }}/{{ mongo_version }} multiverse"
mongodb_deb_repo: "deb http://repo.mongodb.org/apt/{{ distribution_name }} {{ distribution_codename }}/{{ mongodb_package }}/{{ mongo_version }} main"
mongodb_yum_base_url: "https://repo.mongodb.org/yum/{{ ansible_os_family|lower }}/$releasever/{{ mongodb_package }}/{{ mongo_version }}/{{ ansible_architecture }}" mongodb_yum_base_url: "https://repo.mongodb.org/yum/{{ ansible_os_family|lower }}/$releasever/{{ mongodb_package }}/{{ mongo_version }}/{{ ansible_architecture }}"
mongodb_dnf_base_url: "https://repo.mongodb.org/yum/{{ ansible_os_family|lower }}/7/{{ mongodb_package }}/{{ mongo_version }}/{{ ansible_architecture }}" mongodb_dnf_base_url: "https://repo.mongodb.org/yum/{{ ansible_os_family|lower }}/7/{{ mongodb_package }}/{{ mongo_version }}/{{ ansible_architecture }}"

View File

@ -22,6 +22,15 @@
repo: "{{ mongodb_apt_repo }}" repo: "{{ mongodb_apt_repo }}"
state: present state: present
update_cache: no update_cache: no
when: distribution_name == "ubuntu"
tags: [mongodb]
- name: Add MongoDB repo and update cache | deb
apt_repository:
repo: "{{ mongodb_deb_repo }}"
state: present
update_cache: no
when: distribution_name == "debian"
tags: [mongodb] tags: [mongodb]
- name: Install MongoDB | apt - name: Install MongoDB | apt

View File

@ -229,7 +229,7 @@ def test_get_spending_transactions(user_pk, user_sk):
def test_store_block(): def test_store_block():
from bigchaindb.backend import connect, query from bigchaindb.backend import connect, query
from bigchaindb.tendermint.lib import Block from bigchaindb.lib import Block
conn = connect() conn = connect()
block = Block(app_hash='random_utxo', block = Block(app_hash='random_utxo',
@ -242,7 +242,7 @@ def test_store_block():
def test_get_block(): def test_get_block():
from bigchaindb.backend import connect, query from bigchaindb.backend import connect, query
from bigchaindb.tendermint.lib import Block from bigchaindb.lib import Block
conn = connect() conn = connect()
block = Block(app_hash='random_utxo', block = Block(app_hash='random_utxo',
@ -345,7 +345,7 @@ def test_get_unspent_outputs(db_context, utxoset):
def test_store_pre_commit_state(db_context): def test_store_pre_commit_state(db_context):
from bigchaindb.backend import query from bigchaindb.backend import query
from bigchaindb.tendermint.lib import PreCommitState from bigchaindb.lib import PreCommitState
state = PreCommitState(commit_id='test', state = PreCommitState(commit_id='test',
height=3, height=3,
@ -359,7 +359,7 @@ def test_store_pre_commit_state(db_context):
def test_get_pre_commit_state(db_context): def test_get_pre_commit_state(db_context):
from bigchaindb.backend import query from bigchaindb.backend import query
from bigchaindb.tendermint.lib import PreCommitState from bigchaindb.lib import PreCommitState
state = PreCommitState(commit_id='test2', state = PreCommitState(commit_id='test2',
height=3, height=3,

View File

@ -90,7 +90,7 @@ def test_bigchain_run_init_when_db_exists(mocker, capsys):
def test__run_init(mocker): def test__run_init(mocker):
from bigchaindb.commands.bigchaindb import _run_init from bigchaindb.commands.bigchaindb import _run_init
bigchain_mock = mocker.patch( bigchain_mock = mocker.patch(
'bigchaindb.commands.bigchaindb.bigchaindb.tendermint.BigchainDB') 'bigchaindb.commands.bigchaindb.bigchaindb.BigchainDB')
init_db_mock = mocker.patch( init_db_mock = mocker.patch(
'bigchaindb.commands.bigchaindb.schema.init_database', 'bigchaindb.commands.bigchaindb.schema.init_database',
autospec=True, autospec=True,
@ -274,7 +274,7 @@ def test_calling_main(start_mock, base_parser_mock, parse_args_mock,
@patch('bigchaindb.config_utils.autoconfigure') @patch('bigchaindb.config_utils.autoconfigure')
@patch('bigchaindb.commands.bigchaindb.run_recover') @patch('bigchaindb.commands.bigchaindb.run_recover')
@patch('bigchaindb.tendermint.commands.start') @patch('bigchaindb.start.start')
def test_recover_db_on_start(mock_autoconfigure, def test_recover_db_on_start(mock_autoconfigure,
mock_run_recover, mock_run_recover,
mock_start, mock_start,
@ -293,7 +293,7 @@ def test_recover_db_on_start(mock_autoconfigure,
def test_run_recover(b, alice, bob): def test_run_recover(b, alice, bob):
from bigchaindb.commands.bigchaindb import run_recover from bigchaindb.commands.bigchaindb import run_recover
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.tendermint.lib import Block, PreCommitState from bigchaindb.lib import Block, PreCommitState
from bigchaindb.backend.query import PRE_COMMIT_ID from bigchaindb.backend.query import PRE_COMMIT_ID
from bigchaindb.backend import query from bigchaindb.backend import query

View File

@ -17,7 +17,7 @@ from pymongo import MongoClient
from bigchaindb.common import crypto from bigchaindb.common import crypto
from bigchaindb.log import setup_logging from bigchaindb.log import setup_logging
from bigchaindb.tendermint.lib import Block from bigchaindb.lib import Block
TEST_DB_NAME = 'bigchain_test' TEST_DB_NAME = 'bigchain_test'
@ -269,13 +269,13 @@ def merlin_pubkey(merlin):
@pytest.fixture @pytest.fixture
def b(): def b():
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
return BigchainDB() return BigchainDB()
@pytest.fixture @pytest.fixture
def tb(): def tb():
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
return BigchainDB() return BigchainDB()
@ -514,7 +514,7 @@ def event_loop(request):
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
def abci_server(): def abci_server():
from abci import ABCIServer from abci import ABCIServer
from bigchaindb.tendermint.core import App from bigchaindb.core import App
from bigchaindb.utils import Process from bigchaindb.utils import Process
app = ABCIServer(app=App()) app = ABCIServer(app=App())

View File

@ -280,7 +280,7 @@ class TestBigchainApi(object):
@pytest.mark.usefixtures('inputs') @pytest.mark.usefixtures('inputs')
def test_write_transaction(self, b, user_pk, user_sk): def test_write_transaction(self, b, user_pk, user_sk):
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
input_tx = b.get_owned_ids(user_pk).pop() input_tx = b.get_owned_ids(user_pk).pop()
@ -439,7 +439,7 @@ class TestBigchainApi(object):
from bigchaindb.common.exceptions import InputDoesNotExist from bigchaindb.common.exceptions import InputDoesNotExist
from bigchaindb.common.transaction import Input, TransactionLink from bigchaindb.common.transaction import Input, TransactionLink
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
# Create an input for a non existing transaction # Create an input for a non existing transaction
input = Input(Ed25519Sha256(public_key=b58decode(user_pk)), input = Input(Ed25519Sha256(public_key=b58decode(user_pk)),
@ -970,8 +970,8 @@ class TestMultipleInputs(object):
def test_get_owned_ids_calls_get_outputs_filtered(): def test_get_owned_ids_calls_get_outputs_filtered():
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
with patch('bigchaindb.tendermint.BigchainDB.get_outputs_filtered') as gof: with patch('bigchaindb.BigchainDB.get_outputs_filtered') as gof:
b = BigchainDB() b = BigchainDB()
res = b.get_owned_ids('abc') res = b.get_owned_ids('abc')
gof.assert_called_once_with('abc', spent=False) gof.assert_called_once_with('abc', spent=False)
@ -981,13 +981,13 @@ def test_get_owned_ids_calls_get_outputs_filtered():
@pytest.mark.tendermint @pytest.mark.tendermint
def test_get_outputs_filtered_only_unspent(): def test_get_outputs_filtered_only_unspent():
from bigchaindb.common.transaction import TransactionLink from bigchaindb.common.transaction import TransactionLink
from bigchaindb.tendermint.lib import BigchainDB from bigchaindb.lib import BigchainDB
go = 'bigchaindb.tendermint.fastquery.FastQuery.get_outputs_by_public_key' go = 'bigchaindb.fastquery.FastQuery.get_outputs_by_public_key'
with patch(go) as get_outputs: with patch(go) as get_outputs:
get_outputs.return_value = [TransactionLink('a', 1), get_outputs.return_value = [TransactionLink('a', 1),
TransactionLink('b', 2)] TransactionLink('b', 2)]
fs = 'bigchaindb.tendermint.fastquery.FastQuery.filter_spent_outputs' fs = 'bigchaindb.fastquery.FastQuery.filter_spent_outputs'
with patch(fs) as filter_spent: with patch(fs) as filter_spent:
filter_spent.return_value = [TransactionLink('b', 2)] filter_spent.return_value = [TransactionLink('b', 2)]
out = BigchainDB().get_outputs_filtered('abc', spent=False) out = BigchainDB().get_outputs_filtered('abc', spent=False)
@ -998,12 +998,12 @@ def test_get_outputs_filtered_only_unspent():
@pytest.mark.tendermint @pytest.mark.tendermint
def test_get_outputs_filtered_only_spent(): def test_get_outputs_filtered_only_spent():
from bigchaindb.common.transaction import TransactionLink from bigchaindb.common.transaction import TransactionLink
from bigchaindb.tendermint.lib import BigchainDB from bigchaindb.lib import BigchainDB
go = 'bigchaindb.tendermint.fastquery.FastQuery.get_outputs_by_public_key' go = 'bigchaindb.fastquery.FastQuery.get_outputs_by_public_key'
with patch(go) as get_outputs: with patch(go) as get_outputs:
get_outputs.return_value = [TransactionLink('a', 1), get_outputs.return_value = [TransactionLink('a', 1),
TransactionLink('b', 2)] TransactionLink('b', 2)]
fs = 'bigchaindb.tendermint.fastquery.FastQuery.filter_unspent_outputs' fs = 'bigchaindb.fastquery.FastQuery.filter_unspent_outputs'
with patch(fs) as filter_spent: with patch(fs) as filter_spent:
filter_spent.return_value = [TransactionLink('b', 2)] filter_spent.return_value = [TransactionLink('b', 2)]
out = BigchainDB().get_outputs_filtered('abc', spent=True) out = BigchainDB().get_outputs_filtered('abc', spent=True)
@ -1012,13 +1012,13 @@ def test_get_outputs_filtered_only_spent():
@pytest.mark.tendermint @pytest.mark.tendermint
@patch('bigchaindb.tendermint.fastquery.FastQuery.filter_unspent_outputs') @patch('bigchaindb.fastquery.FastQuery.filter_unspent_outputs')
@patch('bigchaindb.tendermint.fastquery.FastQuery.filter_spent_outputs') @patch('bigchaindb.fastquery.FastQuery.filter_spent_outputs')
def test_get_outputs_filtered(filter_spent, filter_unspent): def test_get_outputs_filtered(filter_spent, filter_unspent):
from bigchaindb.common.transaction import TransactionLink from bigchaindb.common.transaction import TransactionLink
from bigchaindb.tendermint.lib import BigchainDB from bigchaindb.lib import BigchainDB
go = 'bigchaindb.tendermint.fastquery.FastQuery.get_outputs_by_public_key' go = 'bigchaindb.fastquery.FastQuery.get_outputs_by_public_key'
with patch(go) as get_outputs: with patch(go) as get_outputs:
get_outputs.return_value = [TransactionLink('a', 1), get_outputs.return_value = [TransactionLink('a', 1),
TransactionLink('b', 2)] TransactionLink('b', 2)]

View File

@ -3,7 +3,7 @@ import pytest
@pytest.fixture @pytest.fixture
def b(): def b():
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
return BigchainDB() return BigchainDB()

View File

@ -6,7 +6,7 @@ from abci.types_pb2 import (
RequestEndBlock RequestEndBlock
) )
from bigchaindb.tendermint.core import CodeTypeOk, CodeTypeError from bigchaindb.core import CodeTypeOk, CodeTypeError
pytestmark = [pytest.mark.tendermint, pytest.mark.bdb] pytestmark = [pytest.mark.tendermint, pytest.mark.bdb]
@ -17,7 +17,7 @@ def encode_tx_to_bytes(transaction):
def test_check_tx__signed_create_is_ok(b): def test_check_tx__signed_create_is_ok(b):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
@ -34,7 +34,7 @@ def test_check_tx__signed_create_is_ok(b):
def test_check_tx__unsigned_create_is_error(b): def test_check_tx__unsigned_create_is_error(b):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
@ -51,7 +51,7 @@ def test_check_tx__unsigned_create_is_error(b):
@pytest.mark.bdb @pytest.mark.bdb
def test_deliver_tx__valid_create_updates_db(b): def test_deliver_tx__valid_create_updates_db(b):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
@ -84,7 +84,7 @@ def test_deliver_tx__valid_create_updates_db(b):
def test_deliver_tx__double_spend_fails(b): def test_deliver_tx__double_spend_fails(b):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
@ -113,7 +113,7 @@ def test_deliver_tx__double_spend_fails(b):
def test_deliver_transfer_tx__double_spend_fails(b): def test_deliver_transfer_tx__double_spend_fails(b):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
@ -157,9 +157,9 @@ def test_deliver_transfer_tx__double_spend_fails(b):
def test_end_block_return_validator_updates(b): def test_end_block_return_validator_updates(b):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.backend import query from bigchaindb.backend import query
from bigchaindb.tendermint.core import encode_validator from bigchaindb.core import encode_validator
from bigchaindb.backend.query import VALIDATOR_UPDATE_ID from bigchaindb.backend.query import VALIDATOR_UPDATE_ID
app = App(b) app = App(b)
@ -183,7 +183,7 @@ def test_end_block_return_validator_updates(b):
def test_store_pre_commit_state_in_end_block(b, alice): def test_store_pre_commit_state_in_end_block(b, alice):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.backend import query from bigchaindb.backend import query
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.backend.query import PRE_COMMIT_ID from bigchaindb.backend.query import PRE_COMMIT_ID

View File

@ -8,7 +8,7 @@ import pytest
@pytest.mark.tendermint @pytest.mark.tendermint
def test_process_event_new_block(): def test_process_event_new_block():
from bigchaindb.tendermint.event_stream import process_event from bigchaindb.event_stream import process_event
event = '{"jsonrpc": "2.0", "id": "test_stream_id#event", "result": {'\ event = '{"jsonrpc": "2.0", "id": "test_stream_id#event", "result": {'\
'"query": "tm.event=\'NewBlock\'", "data": { "type": "CF18EA939D3240",'\ '"query": "tm.event=\'NewBlock\'", "data": { "type": "CF18EA939D3240",'\
@ -46,7 +46,7 @@ def test_process_event_new_block():
@pytest.mark.tendermint @pytest.mark.tendermint
def test_process_event_empty_block(): def test_process_event_empty_block():
from bigchaindb.tendermint.event_stream import process_event from bigchaindb.event_stream import process_event
event = '{"jsonrpc": "2.0", "id": "bigchaindb_stream_1524555674#event",'\ event = '{"jsonrpc": "2.0", "id": "bigchaindb_stream_1524555674#event",'\
'"result": {"query": "tm.event=\'NewBlock\'", "data": {"type": '\ '"result": {"query": "tm.event=\'NewBlock\'", "data": {"type": '\
@ -67,7 +67,7 @@ def test_process_event_empty_block():
@pytest.mark.tendermint @pytest.mark.tendermint
def test_process_unknown_event(): def test_process_unknown_event():
from bigchaindb.tendermint.event_stream import process_event from bigchaindb.event_stream import process_event
event = '{"jsonrpc": "2.0", "id": "test_stream_id#event",'\ event = '{"jsonrpc": "2.0", "id": "test_stream_id#event",'\
' "result": { "query": "tm.event=\'UnknownEvent\'" }}' ' "result": { "query": "tm.event=\'UnknownEvent\'" }}'
@ -80,7 +80,7 @@ def test_process_unknown_event():
@pytest.mark.asyncio @pytest.mark.asyncio
@pytest.mark.abci @pytest.mark.abci
async def test_subscribe_events(tendermint_ws_url, b): async def test_subscribe_events(tendermint_ws_url, b):
from bigchaindb.tendermint.event_stream import subscribe_events from bigchaindb.event_stream import subscribe_events
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
from bigchaindb.models import Transaction from bigchaindb.models import Transaction

View File

@ -12,8 +12,8 @@ from io import BytesIO
@pytest.mark.tendermint @pytest.mark.tendermint
@pytest.mark.bdb @pytest.mark.bdb
def test_app(tb): def test_app(tb):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.tendermint.utils import calculate_hash from bigchaindb.tendermint_utils import calculate_hash
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
@ -103,7 +103,7 @@ def test_upsert_validator(b, alice):
from bigchaindb.backend.query import VALIDATOR_UPDATE_ID from bigchaindb.backend.query import VALIDATOR_UPDATE_ID
from bigchaindb.backend import query, connect from bigchaindb.backend import query, connect
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.tendermint.utils import public_key_to_base64 from bigchaindb.tendermint_utils import public_key_to_base64
import time import time
conn = connect() conn = connect()

View File

@ -47,7 +47,7 @@ def test_asset_is_separated_from_transaciton(b):
@pytest.mark.bdb @pytest.mark.bdb
def test_get_latest_block(tb): def test_get_latest_block(tb):
from bigchaindb.tendermint.lib import Block from bigchaindb.lib import Block
b = tb b = tb
for i in range(10): for i in range(10):
@ -63,7 +63,7 @@ def test_get_latest_block(tb):
@pytest.mark.bdb @pytest.mark.bdb
@patch('bigchaindb.backend.query.get_block', return_value=None) @patch('bigchaindb.backend.query.get_block', return_value=None)
@patch('bigchaindb.tendermint.lib.BigchainDB.get_latest_block', return_value={'height': 10}) @patch('bigchaindb.BigchainDB.get_latest_block', return_value={'height': 10})
def test_get_empty_block(_0, _1, tb): def test_get_empty_block(_0, _1, tb):
assert tb.get_block(5) == {'height': 5, 'transactions': []} assert tb.get_block(5) == {'height': 5, 'transactions': []}
@ -86,7 +86,7 @@ def test_validation_error(b):
def test_write_and_post_transaction(mock_post, b): def test_write_and_post_transaction(mock_post, b):
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
from bigchaindb.tendermint.utils import encode_transaction from bigchaindb.tendermint_utils import encode_transaction
alice = generate_key_pair() alice = generate_key_pair()
tx = Transaction.create([alice.public_key], tx = Transaction.create([alice.public_key],

View File

@ -12,7 +12,7 @@ pytestmark = pytest.mark.tendermint
def test_encode_decode_transaction(b): def test_encode_decode_transaction(b):
from bigchaindb.tendermint.utils import (encode_transaction, from bigchaindb.tendermint_utils import (encode_transaction,
decode_transaction) decode_transaction)
asset = { asset = {
@ -30,7 +30,7 @@ def test_encode_decode_transaction(b):
def test_calculate_hash_no_key(b): def test_calculate_hash_no_key(b):
from bigchaindb.tendermint.utils import calculate_hash from bigchaindb.tendermint_utils import calculate_hash
# pass an empty list # pass an empty list
assert calculate_hash([]) == '' assert calculate_hash([]) == ''
@ -38,7 +38,7 @@ def test_calculate_hash_no_key(b):
# TODO test for the case of an empty list of hashes, and possibly other cases. # TODO test for the case of an empty list of hashes, and possibly other cases.
def test_merkleroot(): def test_merkleroot():
from bigchaindb.tendermint.utils import merkleroot from bigchaindb.tendermint_utils import merkleroot
hashes = [sha3_256(i.encode()).digest() for i in 'abc'] hashes = [sha3_256(i.encode()).digest() for i in 'abc']
assert merkleroot(hashes) == ( assert merkleroot(hashes) == (
'78c7c394d3158c218916b7ae0ebdea502e0f4e85c08e3b371e3dfd824d389fa3') '78c7c394d3158c218916b7ae0ebdea502e0f4e85c08e3b371e3dfd824d389fa3')
@ -54,14 +54,14 @@ SAMPLE_PUBLIC_KEY = {
def test_convert_base64_public_key_to_address(): def test_convert_base64_public_key_to_address():
from bigchaindb.tendermint.utils import public_key64_to_address from bigchaindb.tendermint_utils import public_key64_to_address
address = public_key64_to_address(SAMPLE_PUBLIC_KEY['pub_key']['value']) address = public_key64_to_address(SAMPLE_PUBLIC_KEY['pub_key']['value'])
assert address == SAMPLE_PUBLIC_KEY['address'] assert address == SAMPLE_PUBLIC_KEY['address']
def test_public_key_encoding_decoding(): def test_public_key_encoding_decoding():
from bigchaindb.tendermint.utils import (public_key_from_base64, from bigchaindb.tendermint_utils import (public_key_from_base64,
public_key_to_base64) public_key_to_base64)
public_key = public_key_from_base64(SAMPLE_PUBLIC_KEY['pub_key']['value']) public_key = public_key_from_base64(SAMPLE_PUBLIC_KEY['pub_key']['value'])

View File

@ -35,7 +35,7 @@ def test_bigchain_instance_raises_when_not_configured(request, monkeypatch):
import bigchaindb import bigchaindb
from bigchaindb import config_utils from bigchaindb import config_utils
from bigchaindb.common import exceptions from bigchaindb.common import exceptions
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
assert 'CONFIGURED' not in bigchaindb.config assert 'CONFIGURED' not in bigchaindb.config
# We need to disable ``bigchaindb.config_utils.autoconfigure`` to avoid reading # We need to disable ``bigchaindb.config_utils.autoconfigure`` to avoid reading

View File

@ -31,7 +31,7 @@ def config(request, monkeypatch):
@pytest.mark.skipif(reason='will be fixed in another PR') @pytest.mark.skipif(reason='will be fixed in another PR')
def test_bigchain_class_default_initialization(config): def test_bigchain_class_default_initialization(config):
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
from bigchaindb.consensus import BaseConsensusRules from bigchaindb.consensus import BaseConsensusRules
from bigchaindb.backend.connection import Connection from bigchaindb.backend.connection import Connection
bigchain = BigchainDB() bigchain = BigchainDB()
@ -44,7 +44,7 @@ def test_bigchain_class_default_initialization(config):
@pytest.mark.skipif(reason='will be fixed in another PR') @pytest.mark.skipif(reason='will be fixed in another PR')
def test_bigchain_class_initialization_with_parameters(config): def test_bigchain_class_initialization_with_parameters(config):
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
from bigchaindb.backend import connect from bigchaindb.backend import connect
from bigchaindb.consensus import BaseConsensusRules from bigchaindb.consensus import BaseConsensusRules
init_db_kwargs = { init_db_kwargs = {
@ -65,7 +65,7 @@ def test_bigchain_class_initialization_with_parameters(config):
@pytest.mark.skipif(reason='will be fixed in another PR') @pytest.mark.skipif(reason='will be fixed in another PR')
def test_get_blocks_status_containing_tx(monkeypatch): def test_get_blocks_status_containing_tx(monkeypatch):
from bigchaindb.backend import query as backend_query from bigchaindb.backend import query as backend_query
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
blocks = [ blocks = [
{'id': 1}, {'id': 2} {'id': 1}, {'id': 2}
] ]

View File

@ -4,7 +4,7 @@ import pytest
@pytest.fixture @pytest.fixture
def app(request): def app(request):
from bigchaindb.web import server from bigchaindb.web import server
from bigchaindb.tendermint.lib import BigchainDB from bigchaindb.lib import BigchainDB
if request.config.getoption('--database-backend') == 'localmongodb': if request.config.getoption('--database-backend') == 'localmongodb':
app = server.create_app(debug=True, bigchaindb_factory=BigchainDB) app = server.create_app(debug=True, bigchaindb_factory=BigchainDB)

View File

@ -1,7 +1,7 @@
import pytest import pytest
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.tendermint.lib import Block from bigchaindb.lib import Block
BLOCKS_ENDPOINT = '/api/v1/blocks/' BLOCKS_ENDPOINT = '/api/v1/blocks/'

View File

@ -11,7 +11,7 @@ def test_get_outputs_endpoint(client, user_pk):
m = MagicMock() m = MagicMock()
m.txid = 'a' m.txid = 'a'
m.output = 0 m.output = 0
with patch('bigchaindb.tendermint.lib.BigchainDB.get_outputs_filtered') as gof: with patch('bigchaindb.BigchainDB.get_outputs_filtered') as gof:
gof.return_value = [m, m] gof.return_value = [m, m]
res = client.get(OUTPUTS_ENDPOINT + '?public_key={}'.format(user_pk)) res = client.get(OUTPUTS_ENDPOINT + '?public_key={}'.format(user_pk))
assert res.json == [ assert res.json == [
@ -27,7 +27,7 @@ def test_get_outputs_endpoint_unspent(client, user_pk):
m = MagicMock() m = MagicMock()
m.txid = 'a' m.txid = 'a'
m.output = 0 m.output = 0
with patch('bigchaindb.tendermint.lib.BigchainDB.get_outputs_filtered') as gof: with patch('bigchaindb.BigchainDB.get_outputs_filtered') as gof:
gof.return_value = [m] gof.return_value = [m]
params = '?spent=False&public_key={}'.format(user_pk) params = '?spent=False&public_key={}'.format(user_pk)
res = client.get(OUTPUTS_ENDPOINT + params) res = client.get(OUTPUTS_ENDPOINT + params)
@ -41,7 +41,7 @@ def test_get_outputs_endpoint_spent(client, user_pk):
m = MagicMock() m = MagicMock()
m.txid = 'a' m.txid = 'a'
m.output = 0 m.output = 0
with patch('bigchaindb.tendermint.lib.BigchainDB.get_outputs_filtered') as gof: with patch('bigchaindb.BigchainDB.get_outputs_filtered') as gof:
gof.return_value = [m] gof.return_value = [m]
params = '?spent=true&public_key={}'.format(user_pk) params = '?spent=true&public_key={}'.format(user_pk)
res = client.get(OUTPUTS_ENDPOINT + params) res = client.get(OUTPUTS_ENDPOINT + params)

View File

@ -372,7 +372,7 @@ def test_transactions_get_list_good(client):
asset_id = '1' * 64 asset_id = '1' * 64
with patch('bigchaindb.tendermint.BigchainDB.get_transactions_filtered', get_txs_patched): with patch('bigchaindb.BigchainDB.get_transactions_filtered', get_txs_patched):
url = TX_ENDPOINT + '?asset_id=' + asset_id url = TX_ENDPOINT + '?asset_id=' + asset_id
assert client.get(url).json == [ assert client.get(url).json == [
['asset_id', asset_id], ['asset_id', asset_id],
@ -389,7 +389,7 @@ def test_transactions_get_list_good(client):
def test_transactions_get_list_bad(client): def test_transactions_get_list_bad(client):
def should_not_be_called(): def should_not_be_called():
assert False assert False
with patch('bigchaindb.tendermint.BigchainDB.get_transactions_filtered', with patch('bigchaindb.BigchainDB.get_transactions_filtered',
lambda *_, **__: should_not_be_called()): lambda *_, **__: should_not_be_called()):
# Test asset id validated # Test asset id validated
url = TX_ENDPOINT + '?asset_id=' + '1' * 63 url = TX_ENDPOINT + '?asset_id=' + '1' * 63
@ -404,7 +404,7 @@ def test_transactions_get_list_bad(client):
@pytest.mark.tendermint @pytest.mark.tendermint
def test_return_only_valid_transaction(client): def test_return_only_valid_transaction(client):
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
def get_transaction_patched(status): def get_transaction_patched(status):
def inner(self, tx_id, include_status): def inner(self, tx_id, include_status):
@ -415,12 +415,12 @@ def test_return_only_valid_transaction(client):
# UNDECIDED or VALID block, as well as transactions from the backlog. # UNDECIDED or VALID block, as well as transactions from the backlog.
# As the endpoint uses `get_transaction`, we don't have to test # As the endpoint uses `get_transaction`, we don't have to test
# against invalid transactions here. # against invalid transactions here.
with patch('bigchaindb.tendermint.BigchainDB.get_transaction', with patch('bigchaindb.BigchainDB.get_transaction',
get_transaction_patched(BigchainDB.TX_UNDECIDED)): get_transaction_patched(BigchainDB.TX_UNDECIDED)):
url = '{}{}'.format(TX_ENDPOINT, '123') url = '{}{}'.format(TX_ENDPOINT, '123')
assert client.get(url).status_code == 404 assert client.get(url).status_code == 404
with patch('bigchaindb.tendermint.BigchainDB.get_transaction', with patch('bigchaindb.BigchainDB.get_transaction',
get_transaction_patched(BigchainDB.TX_IN_BACKLOG)): get_transaction_patched(BigchainDB.TX_IN_BACKLOG)):
url = '{}{}'.format(TX_ENDPOINT, '123') url = '{}{}'.format(TX_ENDPOINT, '123')
assert client.get(url).status_code == 404 assert client.get(url).status_code == 404