mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge pull request #390 from bigchaindb/rename_federation_nodes
Renamed Bigchain.federation_nodes as Bigchain.nodes_except_me
This commit is contained in:
commit
fab9b3ec36
@ -138,7 +138,7 @@ class BaseConsensusRules(AbstractConsensusRules):
|
|||||||
raise ValueError('A CREATE operation has no inputs')
|
raise ValueError('A CREATE operation has no inputs')
|
||||||
# TODO: for now lets assume a CREATE transaction only has one current_owner
|
# TODO: for now lets assume a CREATE transaction only has one current_owner
|
||||||
if transaction['transaction']['fulfillments'][0]['current_owners'][0] not in (
|
if transaction['transaction']['fulfillments'][0]['current_owners'][0] not in (
|
||||||
bigchain.federation_nodes + [bigchain.me]):
|
bigchain.nodes_except_me + [bigchain.me]):
|
||||||
raise exceptions.OperationError(
|
raise exceptions.OperationError(
|
||||||
'Only federation nodes can use the operation `CREATE`')
|
'Only federation nodes can use the operation `CREATE`')
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ class BaseConsensusRules(AbstractConsensusRules):
|
|||||||
raise exceptions.InvalidHash()
|
raise exceptions.InvalidHash()
|
||||||
|
|
||||||
# Check if the block was created by a federation node
|
# Check if the block was created by a federation node
|
||||||
if block['block']['node_pubkey'] not in (bigchain.federation_nodes + [bigchain.me]):
|
if block['block']['node_pubkey'] not in (bigchain.nodes_except_me + [bigchain.me]):
|
||||||
raise exceptions.OperationError('Only federation nodes can create blocks')
|
raise exceptions.OperationError('Only federation nodes can create blocks')
|
||||||
|
|
||||||
# Check if block signature is valid
|
# Check if block signature is valid
|
||||||
|
@ -59,7 +59,7 @@ class Bigchain(object):
|
|||||||
self.dbname = dbname or bigchaindb.config['database']['name']
|
self.dbname = dbname or bigchaindb.config['database']['name']
|
||||||
self.me = public_key or bigchaindb.config['keypair']['public']
|
self.me = public_key or bigchaindb.config['keypair']['public']
|
||||||
self.me_private = private_key or bigchaindb.config['keypair']['private']
|
self.me_private = private_key or bigchaindb.config['keypair']['private']
|
||||||
self.federation_nodes = keyring or bigchaindb.config['keyring']
|
self.nodes_except_me = keyring or bigchaindb.config['keyring']
|
||||||
self.consensus = config_utils.load_consensus_plugin(consensus_plugin)
|
self.consensus = config_utils.load_consensus_plugin(consensus_plugin)
|
||||||
|
|
||||||
if not self.me or not self.me_private:
|
if not self.me or not self.me_private:
|
||||||
@ -127,8 +127,8 @@ class Bigchain(object):
|
|||||||
# we will assign this transaction to `one` node. This way we make sure that there are no duplicate
|
# we will assign this transaction to `one` node. This way we make sure that there are no duplicate
|
||||||
# transactions on the bigchain
|
# transactions on the bigchain
|
||||||
|
|
||||||
if self.federation_nodes:
|
if self.nodes_except_me:
|
||||||
assignee = random.choice(self.federation_nodes)
|
assignee = random.choice(self.nodes_except_me)
|
||||||
else:
|
else:
|
||||||
# I am the only node
|
# I am the only node
|
||||||
assignee = self.me
|
assignee = self.me
|
||||||
@ -395,7 +395,7 @@ class Bigchain(object):
|
|||||||
'timestamp': util.timestamp(),
|
'timestamp': util.timestamp(),
|
||||||
'transactions': validated_transactions,
|
'transactions': validated_transactions,
|
||||||
'node_pubkey': self.me,
|
'node_pubkey': self.me,
|
||||||
'voters': self.federation_nodes + [self.me]
|
'voters': self.nodes_except_me + [self.me]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Calculate the hash of the new block
|
# Calculate the hash of the new block
|
||||||
|
@ -30,9 +30,9 @@ class BlockStream(object):
|
|||||||
# database to get the old blocks.
|
# database to get the old blocks.
|
||||||
|
|
||||||
# TODO how about a one liner, something like:
|
# TODO how about a one liner, something like:
|
||||||
# self.unvoted_blocks = b.get_unvoted_blocks() if not b.federation_nodes else []
|
# self.unvoted_blocks = b.get_unvoted_blocks() if not b.nodes_except_me else []
|
||||||
self.unvoted_blocks = []
|
self.unvoted_blocks = []
|
||||||
if not b.federation_nodes:
|
if not b.nodes_except_me:
|
||||||
self.unvoted_blocks = b.get_unvoted_blocks()
|
self.unvoted_blocks = b.get_unvoted_blocks()
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
|
@ -149,7 +149,7 @@ class TestBigchainApi(object):
|
|||||||
def test_assign_transaction_multiple_nodes(self, b, user_vk, user_sk):
|
def test_assign_transaction_multiple_nodes(self, b, user_vk, user_sk):
|
||||||
# create 5 federation nodes
|
# create 5 federation nodes
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
b.federation_nodes.append(crypto.generate_key_pair()[1])
|
b.nodes_except_me.append(crypto.generate_key_pair()[1])
|
||||||
|
|
||||||
# test assignee for several transactions
|
# test assignee for several transactions
|
||||||
for _ in range(20):
|
for _ in range(20):
|
||||||
@ -161,8 +161,8 @@ class TestBigchainApi(object):
|
|||||||
# retrieve the transaction
|
# retrieve the transaction
|
||||||
response = r.table('backlog').get(tx_signed['id']).run(b.conn)
|
response = r.table('backlog').get(tx_signed['id']).run(b.conn)
|
||||||
|
|
||||||
# check if the assignee is the federation_nodes
|
# check if the assignee is one of the _other_ federation nodes
|
||||||
assert response['assignee'] in b.federation_nodes
|
assert response['assignee'] in b.nodes_except_me
|
||||||
|
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_genesis_block(self, b):
|
def test_genesis_block(self, b):
|
||||||
@ -440,7 +440,7 @@ class TestBlockValidation(object):
|
|||||||
'timestamp': util.timestamp(),
|
'timestamp': util.timestamp(),
|
||||||
'transactions': [tx_invalid],
|
'transactions': [tx_invalid],
|
||||||
'node_pubkey': b.me,
|
'node_pubkey': b.me,
|
||||||
'voters': b.federation_nodes
|
'voters': b.nodes_except_me
|
||||||
}
|
}
|
||||||
|
|
||||||
block_data = util.serialize(block)
|
block_data = util.serialize(block)
|
||||||
|
@ -496,7 +496,7 @@ class TestBlockStream(object):
|
|||||||
|
|
||||||
def test_if_federation_size_is_greater_than_one_ignore_past_blocks(self, b):
|
def test_if_federation_size_is_greater_than_one_ignore_past_blocks(self, b):
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
b.federation_nodes.append(crypto.generate_key_pair()[1])
|
b.nodes_except_me.append(crypto.generate_key_pair()[1])
|
||||||
new_blocks = mp.Queue()
|
new_blocks = mp.Queue()
|
||||||
bs = BlockStream(new_blocks)
|
bs = BlockStream(new_blocks)
|
||||||
block_1 = dummy_block()
|
block_1 = dummy_block()
|
||||||
|
@ -32,7 +32,7 @@ def test_bigchain_class_default_initialization(config):
|
|||||||
assert bigchain.dbname == config['database']['name']
|
assert bigchain.dbname == config['database']['name']
|
||||||
assert bigchain.me == config['keypair']['public']
|
assert bigchain.me == config['keypair']['public']
|
||||||
assert bigchain.me_private == config['keypair']['private']
|
assert bigchain.me_private == config['keypair']['private']
|
||||||
assert bigchain.federation_nodes == config['keyring']
|
assert bigchain.nodes_except_me == config['keyring']
|
||||||
assert bigchain.consensus == BaseConsensusRules
|
assert bigchain.consensus == BaseConsensusRules
|
||||||
assert bigchain._conn is None
|
assert bigchain._conn is None
|
||||||
|
|
||||||
@ -55,6 +55,6 @@ def test_bigchain_class_initialization_with_parameters(config):
|
|||||||
assert bigchain.dbname == init_kwargs['dbname']
|
assert bigchain.dbname == init_kwargs['dbname']
|
||||||
assert bigchain.me == init_kwargs['public_key']
|
assert bigchain.me == init_kwargs['public_key']
|
||||||
assert bigchain.me_private == init_kwargs['private_key']
|
assert bigchain.me_private == init_kwargs['private_key']
|
||||||
assert bigchain.federation_nodes == init_kwargs['keyring']
|
assert bigchain.nodes_except_me == init_kwargs['keyring']
|
||||||
assert bigchain.consensus == BaseConsensusRules
|
assert bigchain.consensus == BaseConsensusRules
|
||||||
assert bigchain._conn is None
|
assert bigchain._conn is None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user