mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge branch 'core/191/ignore-invalid-blocks' of github.com:bigchaindb/bigchaindb into core/192/ignore-invalid-blocks
This commit is contained in:
commit
d8b51f904f
@ -154,7 +154,8 @@ class Bigchain(object):
|
|||||||
|
|
||||||
if validity:
|
if validity:
|
||||||
# Disregard invalid blocks, and return if there are no valid or undecided blocks
|
# Disregard invalid blocks, and return if there are no valid or undecided blocks
|
||||||
validity = {_id: status for _id, status in validity.items() if status != 'invalid'}
|
validity = {_id: status for _id, status in validity.items()
|
||||||
|
if status != Bigchain.BLOCK_INVALID}
|
||||||
if not validity:
|
if not validity:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -163,7 +164,7 @@ class Bigchain(object):
|
|||||||
# undecided ones
|
# undecided ones
|
||||||
for _id in validity:
|
for _id in validity:
|
||||||
target_block_id = _id
|
target_block_id = _id
|
||||||
if validity[_id] == 'valid':
|
if validity[_id] == Bigchain.BLOCK_VALID:
|
||||||
break
|
break
|
||||||
|
|
||||||
# Query the transaction in the target block and return
|
# Query the transaction in the target block and return
|
||||||
@ -200,7 +201,8 @@ class Bigchain(object):
|
|||||||
txid (str): transaction id of the transaction to query
|
txid (str): transaction id of the transaction to query
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A dict of blocks containing the transaction, e.g. {block_id_1: 'valid', block_id_2: 'invalid' ...}, or None
|
A dict of blocks containing the transaction,
|
||||||
|
e.g. {block_id_1: 'valid', block_id_2: 'invalid' ...}, or None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# First, get information on all blocks which contain this transaction
|
# First, get information on all blocks which contain this transaction
|
||||||
@ -211,10 +213,11 @@ class Bigchain(object):
|
|||||||
validity = {block['id']: self.block_election_status(block) for block in blocks}
|
validity = {block['id']: self.block_election_status(block) for block in blocks}
|
||||||
|
|
||||||
# If there are multiple valid blocks with this transaction, something has gone wrong
|
# If there are multiple valid blocks with this transaction, something has gone wrong
|
||||||
if list(validity.values()).count('valid') > 1:
|
if list(validity.values()).count(Bigchain.BLOCK_VALID) > 1:
|
||||||
|
block_ids = str([block for block in validity
|
||||||
|
if validity[block] == Bigchain.BLOCK_VALID])
|
||||||
raise Exception('Transaction {tx} is present in multiple valid blocks: {block_ids}'
|
raise Exception('Transaction {tx} is present in multiple valid blocks: {block_ids}'
|
||||||
.format(tx=txid,
|
.format(tx=txid, block_ids=block_ids))
|
||||||
block_ids=str([block for block in validity if validity[block] == 'valid'])))
|
|
||||||
|
|
||||||
return validity
|
return validity
|
||||||
|
|
||||||
@ -309,8 +312,8 @@ class Bigchain(object):
|
|||||||
for tx in response:
|
for tx in response:
|
||||||
# disregard transactions from invalid blocks
|
# disregard transactions from invalid blocks
|
||||||
validity = self.get_blocks_status_containing_tx(tx['id'])
|
validity = self.get_blocks_status_containing_tx(tx['id'])
|
||||||
if 'valid' not in validity.values():
|
if Bigchain.BLOCK_VALID not in validity.values():
|
||||||
if 'undecided' not in validity.values():
|
if Bigchain.BLOCK_UNDECIDED not in validity.values():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# a transaction can contain multiple outputs (conditions) so we need to iterate over all of them
|
# a transaction can contain multiple outputs (conditions) so we need to iterate over all of them
|
||||||
|
Loading…
x
Reference in New Issue
Block a user