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:
z-bowen 2018-09-10 10:47:40 +02:00
parent d696a51eab
commit 06ea940707
2 changed files with 3 additions and 6 deletions

View File

@ -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))

View File

@ -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