mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-06-28 08:37:45 +02:00
Rename validity to blocks_validity_status
This commit is contained in:
parent
e8ee39463f
commit
4056f315ae
|
@ -229,14 +229,16 @@ class Bigchain(object):
|
||||||
|
|
||||||
response, tx_status = None, None
|
response, tx_status = None, None
|
||||||
|
|
||||||
validity = self.get_blocks_status_containing_tx(txid)
|
blocks_validity_status = self.get_blocks_status_containing_tx(txid)
|
||||||
check_backlog = True
|
check_backlog = True
|
||||||
|
|
||||||
if validity:
|
if blocks_validity_status:
|
||||||
# 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()
|
blocks_validity_status = {
|
||||||
if status != Bigchain.BLOCK_INVALID}
|
_id: status for _id, status in blocks_validity_status.items()
|
||||||
if validity:
|
if status != Bigchain.BLOCK_INVALID
|
||||||
|
}
|
||||||
|
if blocks_validity_status:
|
||||||
|
|
||||||
# The transaction _was_ found in an undecided or valid block,
|
# The transaction _was_ found in an undecided or valid block,
|
||||||
# so there's no need to look in the backlog table
|
# so there's no need to look in the backlog table
|
||||||
|
@ -246,8 +248,8 @@ class Bigchain(object):
|
||||||
# If the transaction is in a valid or any undecided block, return it. Does not check
|
# If the transaction is in a valid or any undecided block, return it. Does not check
|
||||||
# if transactions in undecided blocks are consistent, but selects the valid block
|
# if transactions in undecided blocks are consistent, but selects the valid block
|
||||||
# before undecided ones
|
# before undecided ones
|
||||||
for target_block_id in validity:
|
for target_block_id in blocks_validity_status:
|
||||||
if validity[target_block_id] == Bigchain.BLOCK_VALID:
|
if blocks_validity_status[target_block_id] == Bigchain.BLOCK_VALID:
|
||||||
tx_status = self.TX_VALID
|
tx_status = self.TX_VALID
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -305,20 +307,24 @@ class Bigchain(object):
|
||||||
blocks = backend.query.get_blocks_status_from_transaction(self.connection, txid)
|
blocks = backend.query.get_blocks_status_from_transaction(self.connection, txid)
|
||||||
if blocks:
|
if blocks:
|
||||||
# Determine the election status of each block
|
# Determine the election status of each block
|
||||||
validity = {block['id']: self.block_election_status(block)
|
blocks_validity_status = {
|
||||||
for block in blocks}
|
block['id']: self.block_election_status(block)
|
||||||
|
for block in blocks
|
||||||
|
}
|
||||||
|
|
||||||
# NOTE: If there are multiple valid blocks with this transaction,
|
# NOTE: If there are multiple valid blocks with this transaction,
|
||||||
# something has gone wrong
|
# something has gone wrong
|
||||||
if list(validity.values()).count(Bigchain.BLOCK_VALID) > 1:
|
if list(blocks_validity_status.values()).count(Bigchain.BLOCK_VALID) > 1:
|
||||||
block_ids = str([block for block in validity
|
block_ids = str([
|
||||||
if validity[block] == Bigchain.BLOCK_VALID])
|
block for block in blocks_validity_status
|
||||||
|
if blocks_validity_status[block] == Bigchain.BLOCK_VALID
|
||||||
|
])
|
||||||
raise core_exceptions.CriticalDoubleInclusion(
|
raise core_exceptions.CriticalDoubleInclusion(
|
||||||
'Transaction {tx} is present in '
|
'Transaction {tx} is present in '
|
||||||
'multiple valid blocks: {block_ids}'
|
'multiple valid blocks: {block_ids}'
|
||||||
.format(tx=txid, block_ids=block_ids))
|
.format(tx=txid, block_ids=block_ids))
|
||||||
|
|
||||||
return validity
|
return blocks_validity_status
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Vote:
|
||||||
self.last_voted_id = Bigchain().get_last_voted_block().id
|
self.last_voted_id = Bigchain().get_last_voted_block().id
|
||||||
|
|
||||||
self.counters = Counter()
|
self.counters = Counter()
|
||||||
self.validity = {}
|
self.blocks_validity_status = {}
|
||||||
|
|
||||||
dummy_tx = Transaction.create([self.bigchain.me],
|
dummy_tx = Transaction.create([self.bigchain.me],
|
||||||
[([self.bigchain.me], 1)]).to_dict()
|
[([self.bigchain.me], 1)]).to_dict()
|
||||||
|
@ -127,16 +127,16 @@ class Vote:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.counters[block_id] += 1
|
self.counters[block_id] += 1
|
||||||
self.validity[block_id] = tx_validity and self.validity.get(block_id,
|
self.blocks_validity_status[block_id] = tx_validity and self.blocks_validity_status.get(block_id,
|
||||||
True)
|
True)
|
||||||
|
|
||||||
if self.counters[block_id] == num_tx:
|
if self.counters[block_id] == num_tx:
|
||||||
vote = self.bigchain.vote(block_id,
|
vote = self.bigchain.vote(block_id,
|
||||||
self.last_voted_id,
|
self.last_voted_id,
|
||||||
self.validity[block_id])
|
self.blocks_validity_status[block_id])
|
||||||
self.last_voted_id = block_id
|
self.last_voted_id = block_id
|
||||||
del self.counters[block_id]
|
del self.counters[block_id]
|
||||||
del self.validity[block_id]
|
del self.blocks_validity_status[block_id]
|
||||||
return vote, num_tx
|
return vote, num_tx
|
||||||
|
|
||||||
def write_vote(self, vote, num_tx):
|
def write_vote(self, vote, num_tx):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user