mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: Election.validate uses an inefficient query to check that the tx is in the db
Solution: use `is_committed` instead of `get_transaction`
This commit is contained in:
parent
d696a51eab
commit
06ea940707
@ -106,7 +106,7 @@ class Election(Transaction):
|
|||||||
input_conditions = []
|
input_conditions = []
|
||||||
|
|
||||||
duplicates = any(txn for txn in current_transactions if txn.id == self.id)
|
duplicates = any(txn for txn in current_transactions if txn.id == self.id)
|
||||||
if bigchain.get_transaction(self.id) or duplicates:
|
if bigchain.is_committed(self.id) or duplicates:
|
||||||
raise DuplicateTransaction('transaction `{}` already exists'
|
raise DuplicateTransaction('transaction `{}` already exists'
|
||||||
.format(self.id))
|
.format(self.id))
|
||||||
|
|
||||||
|
|||||||
@ -303,18 +303,15 @@ def test_get_validator_update(b, node_keys, node_key, ed25519_node_keys):
|
|||||||
assert not ValidatorElection.approved_update(b, 4, [tx_vote0, tx_vote1])
|
assert not ValidatorElection.approved_update(b, 4, [tx_vote0, tx_vote1])
|
||||||
|
|
||||||
update = ValidatorElection.approved_update(b, 4, [tx_vote0, tx_vote1, tx_vote2])
|
update = ValidatorElection.approved_update(b, 4, [tx_vote0, tx_vote1, tx_vote2])
|
||||||
update_public_key = None
|
|
||||||
if update:
|
|
||||||
update_public_key = codecs.encode(update.pub_key.data, 'base64').decode().rstrip('\n')
|
|
||||||
assert update
|
assert update
|
||||||
|
update_public_key = codecs.encode(update.pub_key.data, 'base64').decode().rstrip('\n')
|
||||||
assert update_public_key == public_key64
|
assert update_public_key == public_key64
|
||||||
|
|
||||||
b.store_bulk_transactions([tx_vote0, tx_vote1])
|
b.store_bulk_transactions([tx_vote0, tx_vote1])
|
||||||
|
|
||||||
update = ValidatorElection.approved_update(b, 4, [tx_vote2])
|
update = ValidatorElection.approved_update(b, 4, [tx_vote2])
|
||||||
if update:
|
|
||||||
update_public_key = codecs.encode(update.pub_key.data, 'base64').decode().rstrip('\n')
|
|
||||||
assert update
|
assert update
|
||||||
|
update_public_key = codecs.encode(update.pub_key.data, 'base64').decode().rstrip('\n')
|
||||||
assert update_public_key == public_key64
|
assert update_public_key == public_key64
|
||||||
|
|
||||||
# remove validator
|
# remove validator
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user